diff --git a/packages/fuel-indexer-tests/tests/trybuild.rs b/packages/fuel-indexer-tests/tests/trybuild.rs index af587009c..25cae3d04 100644 --- a/packages/fuel-indexer-tests/tests/trybuild.rs +++ b/packages/fuel-indexer-tests/tests/trybuild.rs @@ -37,109 +37,109 @@ module: ); let tests = vec![ - // ( - // "fail_if_attribute_manifest_schema_arg_is_invalid.rs", - // "invalid_schema_simple_wasm.yaml", - // TestKind::Fail, - // // Using a custom manifest here - // format!( - // r#" - // namespace: test_namespace - // identifier: simple_wasm_executor - // abi: {tests_root_str}/contracts/simple-wasm/out/debug/contracts-abi.json - // # This schema file doesn't actually exist - // graphql_schema: schema.graphql - // contract_id: ~ - // module: - // wasm: {project_root_str}/target/wasm32-unknown-unknown/release/simple_wasm.wasm"# - // ), - // ), - // ( - // "fail_if_attribute_args_include_self.rs", - // "simple_wasm.yaml", - // TestKind::Fail, - // manifest_content.clone(), - // ), - // ( - // "fail_if_attribute_args_not_included.rs", - // "simple_wasm.yaml", - // TestKind::Fail, - // manifest_content.clone(), - // ), - // ( - // "fail_if_attribute_abi_arg_includes_invalid_type.rs", - // "simple_wasm.yaml", - // TestKind::Fail, - // manifest_content.clone(), - // ), - // ( - // "fail_if_indexer_module_is_empty.rs", - // "simple_wasm.yaml", - // TestKind::Fail, - // manifest_content.clone(), - // ), - // ( - // "fail_if_arg_not_passed_to_handler_function.rs", - // "simple_wasm.yaml", - // TestKind::Fail, - // manifest_content.clone(), - // ), - // ( - // "pass_if_indexer_is_valid_single_type.rs", - // "simple_wasm.yaml", - // TestKind::Pass, - // manifest_content.clone(), - // ), - // ( - // "pass_if_indexer_is_valid_multi_type.rs", - // "simple_wasm.yaml", - // TestKind::Pass, - // manifest_content.clone(), - // ), - // ( - // "pass_if_unsupported_types_are_used.rs", - // "simple_wasm.yaml", - // TestKind::Pass, - // // Using a custom manifest here - // manifest_content.clone(), - // ), - // ( - // "fail_if_abi_contains_reserved_fuel_type.rs", - // "invalid_abi_type_simple_wasm.yaml", - // TestKind::Fail, - // // Using a custom manifest here - // format!( - // r#" - // namespace: test_namespace - // identifier: simple_wasm_executor - // abi: {tests_root_str}/contracts/simple-wasm/out/debug/contracts-abi-reserved-name.json - // graphql_schema: {tests_root_str}/indexers/simple-wasm/schema/simple_wasm.graphql - // contract_id: ~ - // module: - // wasm: {project_root_str}/target/wasm32-unknown-unknown/release/simple_wasm.wasm"# - // ), - // ), - // ( - // "fail_if_ident_not_defined_in_abi.rs", - // "simple_wasm.yaml", - // TestKind::Fail, - // manifest_content.clone(), - // ), - // ( - // "fail_if_non_function_patterns_included_in_module.rs", - // "simple_wasm.yaml", - // TestKind::Fail, - // manifest_content.clone(), - // ), - // ( - // "fail_if_unsupported_type_used_in_handler_args.rs", - // "simple_wasm.yaml", - // TestKind::Fail, - // manifest_content.clone(), - // ), ( - "pass_if_using_sway_amm_abi.rs", + "fail_if_attribute_manifest_schema_arg_is_invalid.rs", + "invalid_schema_simple_wasm.yaml", + TestKind::Fail, + // Using a custom manifest here + format!( + r#" + namespace: test_namespace + identifier: simple_wasm_executor + abi: {tests_root_str}/contracts/simple-wasm/out/debug/contracts-abi.json + # This schema file doesn't actually exist + graphql_schema: schema.graphql + contract_id: ~ + module: + wasm: {project_root_str}/target/wasm32-unknown-unknown/release/simple_wasm.wasm"# + ), + ), + ( + "fail_if_attribute_args_include_self.rs", + "simple_wasm.yaml", + TestKind::Fail, + manifest_content.clone(), + ), + ( + "fail_if_attribute_args_not_included.rs", + "simple_wasm.yaml", + TestKind::Fail, + manifest_content.clone(), + ), + ( + "fail_if_attribute_abi_arg_includes_invalid_type.rs", + "simple_wasm.yaml", + TestKind::Fail, + manifest_content.clone(), + ), + ( + "fail_if_indexer_module_is_empty.rs", + "simple_wasm.yaml", + TestKind::Fail, + manifest_content.clone(), + ), + ( + "fail_if_arg_not_passed_to_handler_function.rs", + "simple_wasm.yaml", + TestKind::Fail, + manifest_content.clone(), + ), + ( + "pass_if_indexer_is_valid_single_type.rs", + "simple_wasm_single.yaml", + TestKind::Pass, + manifest_content.clone(), + ), + ( + "pass_if_indexer_is_valid_multi_type.rs", + "simple_wasm_multi.yaml", + TestKind::Pass, + manifest_content.clone(), + ), + ( + "pass_if_unsupported_types_are_used.rs", + "simple_wasm_unsupported.yaml", + TestKind::Pass, + // Using a custom manifest here + manifest_content.clone(), + ), + ( + "fail_if_abi_contains_reserved_fuel_type.rs", + "invalid_abi_type_simple_wasm.yaml", + TestKind::Fail, + // Using a custom manifest here + format!( + r#" + namespace: test_namespace + identifier: simple_wasm_executor + abi: {tests_root_str}/contracts/simple-wasm/out/debug/contracts-abi-reserved-name.json + graphql_schema: {tests_root_str}/indexers/simple-wasm/schema/simple_wasm.graphql + contract_id: ~ + module: + wasm: {project_root_str}/target/wasm32-unknown-unknown/release/simple_wasm.wasm"# + ), + ), + ( + "fail_if_ident_not_defined_in_abi.rs", + "simple_wasm.yaml", + TestKind::Fail, + manifest_content.clone(), + ), + ( + "fail_if_non_function_patterns_included_in_module.rs", + "simple_wasm.yaml", + TestKind::Fail, + manifest_content.clone(), + ), + ( + "fail_if_unsupported_type_used_in_handler_args.rs", "simple_wasm.yaml", + TestKind::Fail, + manifest_content.clone(), + ), + ( + "pass_if_using_sway_amm_abi.rs", + "sway_amm.yaml", TestKind::Pass, // Using a custom manifest here format!( @@ -153,6 +153,22 @@ module: wasm: {project_root_str}/target/wasm32-unknown-unknown/release/simple_wasm.wasm"# ), ), + ( + "pass_if_using_sway_dao_abi.rs", + "simple_wasm.yaml", + TestKind::Pass, + // Using a custom manifest here + format!( + r#" + namespace: test_namespace + identifier: simple_wasm_executor + abi: {abi_root_str}/DAO-contract-abi.json + graphql_schema: {tests_root_str}/indexers/simple-wasm/schema/simple_wasm.graphql + contract_id: ~ + module: + wasm: {project_root_str}/target/wasm32-unknown-unknown/release/simple_wasm.wasm"# + ), + ), ]; for (name, manifest_name, kind, manifest_content) in tests { diff --git a/packages/fuel-indexer-tests/trybuild/abi/DAO-contract-abi.json b/packages/fuel-indexer-tests/trybuild/abi/DAO-contract-abi.json index fffac4dfb..6daa57505 100644 --- a/packages/fuel-indexer-tests/trybuild/abi/DAO-contract-abi.json +++ b/packages/fuel-indexer-tests/trybuild/abi/DAO-contract-abi.json @@ -469,16 +469,16 @@ "typeArguments": null }, "attributes": [ - { - "name": "payable", - "arguments": [] - }, { "name": "storage", "arguments": [ "read", "write" ] + }, + { + "name": "payable", + "arguments": [] } ] }, diff --git a/packages/fuel-indexer-tests/trybuild/abi/auction-contract-abi.json b/packages/fuel-indexer-tests/trybuild/abi/auction-contract-abi.json index e4b39ab5b..69395103e 100644 --- a/packages/fuel-indexer-tests/trybuild/abi/auction-contract-abi.json +++ b/packages/fuel-indexer-tests/trybuild/abi/auction-contract-abi.json @@ -426,16 +426,16 @@ "typeArguments": null }, "attributes": [ + { + "name": "payable", + "arguments": [] + }, { "name": "storage", "arguments": [ "read", "write" ] - }, - { - "name": "payable", - "arguments": [] } ] }, @@ -509,16 +509,16 @@ "typeArguments": null }, "attributes": [ + { + "name": "payable", + "arguments": [] + }, { "name": "storage", "arguments": [ "read", "write" ] - }, - { - "name": "payable", - "arguments": [] } ] }, diff --git a/packages/fuel-indexer-tests/trybuild/abi/distributor-contract-abi.json b/packages/fuel-indexer-tests/trybuild/abi/distributor-contract-abi.json index 1e254df14..3d5c04698 100644 --- a/packages/fuel-indexer-tests/trybuild/abi/distributor-contract-abi.json +++ b/packages/fuel-indexer-tests/trybuild/abi/distributor-contract-abi.json @@ -407,16 +407,16 @@ "typeArguments": null }, "attributes": [ - { - "name": "payable", - "arguments": [] - }, { "name": "storage", "arguments": [ "read", "write" ] + }, + { + "name": "payable", + "arguments": [] } ] }, diff --git a/packages/fuel-indexer-tests/trybuild/abi/escrow-contract-abi.json b/packages/fuel-indexer-tests/trybuild/abi/escrow-contract-abi.json index 21e680969..7eb2f1deb 100644 --- a/packages/fuel-indexer-tests/trybuild/abi/escrow-contract-abi.json +++ b/packages/fuel-indexer-tests/trybuild/abi/escrow-contract-abi.json @@ -664,16 +664,16 @@ "typeArguments": null }, "attributes": [ - { - "name": "payable", - "arguments": [] - }, { "name": "storage", "arguments": [ "read", "write" ] + }, + { + "name": "payable", + "arguments": [] } ] }, @@ -749,16 +749,16 @@ "typeArguments": null }, "attributes": [ - { - "name": "payable", - "arguments": [] - }, { "name": "storage", "arguments": [ "read", "write" ] + }, + { + "name": "payable", + "arguments": [] } ] }, diff --git a/packages/fuel-indexer-tests/trybuild/abi/exchange-contract-abi.json b/packages/fuel-indexer-tests/trybuild/abi/exchange-contract-abi.json index 820ff35f9..0fb28e5e5 100644 --- a/packages/fuel-indexer-tests/trybuild/abi/exchange-contract-abi.json +++ b/packages/fuel-indexer-tests/trybuild/abi/exchange-contract-abi.json @@ -567,16 +567,16 @@ "typeArguments": null }, "attributes": [ + { + "name": "payable", + "arguments": [] + }, { "name": "storage", "arguments": [ "read", "write" ] - }, - { - "name": "payable", - "arguments": [] } ] }, diff --git a/packages/fuel-indexer-tests/trybuild/abi/registry-contract-abi.json b/packages/fuel-indexer-tests/trybuild/abi/registry-contract-abi.json index ce39e6074..92e1ee64d 100644 --- a/packages/fuel-indexer-tests/trybuild/abi/registry-contract-abi.json +++ b/packages/fuel-indexer-tests/trybuild/abi/registry-contract-abi.json @@ -310,16 +310,16 @@ "typeArguments": null }, "attributes": [ + { + "name": "payable", + "arguments": [] + }, { "name": "storage", "arguments": [ "read", "write" ] - }, - { - "name": "payable", - "arguments": [] } ] }, @@ -358,16 +358,16 @@ "typeArguments": null }, "attributes": [ + { + "name": "payable", + "arguments": [] + }, { "name": "storage", "arguments": [ "read", "write" ] - }, - { - "name": "payable", - "arguments": [] } ] }, diff --git a/packages/fuel-indexer-tests/trybuild/pass_if_indexer_is_valid_multi_type.rs b/packages/fuel-indexer-tests/trybuild/pass_if_indexer_is_valid_multi_type.rs index 7a6196747..9b5c3678d 100644 --- a/packages/fuel-indexer-tests/trybuild/pass_if_indexer_is_valid_multi_type.rs +++ b/packages/fuel-indexer-tests/trybuild/pass_if_indexer_is_valid_multi_type.rs @@ -13,7 +13,7 @@ fn ff_put_many_to_many_record(_inp: ()) {} #[no_mangle] fn ff_early_exit(_inp: ()) {} -#[indexer(manifest = "packages/fuel-indexer-tests/trybuild/simple_wasm.yaml")] +#[indexer(manifest = "packages/fuel-indexer-tests/trybuild/simple_wasm_multi.yaml")] mod indexer { fn function_one(event: SomeEvent) { let SomeEvent { id, account } = event; diff --git a/packages/fuel-indexer-tests/trybuild/pass_if_indexer_is_valid_single_type.rs b/packages/fuel-indexer-tests/trybuild/pass_if_indexer_is_valid_single_type.rs index c097f1e24..2cb61b371 100644 --- a/packages/fuel-indexer-tests/trybuild/pass_if_indexer_is_valid_single_type.rs +++ b/packages/fuel-indexer-tests/trybuild/pass_if_indexer_is_valid_single_type.rs @@ -13,7 +13,7 @@ fn ff_put_many_to_many_record(_inp: ()) {} #[no_mangle] fn ff_early_exit(_inp: ()) {} -#[indexer(manifest = "packages/fuel-indexer-tests/trybuild/simple_wasm.yaml")] +#[indexer(manifest = "packages/fuel-indexer-tests/trybuild/simple_wasm_single.yaml")] mod indexer { fn function_one(event: SomeEvent) { let SomeEvent { id, account } = event; diff --git a/packages/fuel-indexer-tests/trybuild/pass_if_unsupported_types_are_used.rs b/packages/fuel-indexer-tests/trybuild/pass_if_unsupported_types_are_used.rs index bcc01f01b..726a14197 100644 --- a/packages/fuel-indexer-tests/trybuild/pass_if_unsupported_types_are_used.rs +++ b/packages/fuel-indexer-tests/trybuild/pass_if_unsupported_types_are_used.rs @@ -13,7 +13,7 @@ fn ff_put_many_to_many_record(_inp: ()) {} #[no_mangle] fn ff_early_exit(_inp: ()) {} -#[indexer(manifest = "packages/fuel-indexer-tests/trybuild/simple_wasm.yaml")] +#[indexer(manifest = "packages/fuel-indexer-tests/trybuild/simple_wasm_unsupported.yaml")] mod indexer { fn function_one(event: SomeEvent) { let SomeEvent { id, account } = event; diff --git a/packages/fuel-indexer-tests/trybuild/pass_if_using_sway_amm_abi.rs b/packages/fuel-indexer-tests/trybuild/pass_if_using_sway_amm_abi.rs index a0a0c93fd..2a713f4bb 100644 --- a/packages/fuel-indexer-tests/trybuild/pass_if_using_sway_amm_abi.rs +++ b/packages/fuel-indexer-tests/trybuild/pass_if_using_sway_amm_abi.rs @@ -13,7 +13,7 @@ fn ff_put_many_to_many_record(_inp: ()) {} #[no_mangle] fn ff_early_exit(_inp: ()) {} -#[indexer(manifest = "packages/fuel-indexer-tests/trybuild/simple_wasm.yaml")] +#[indexer(manifest = "packages/fuel-indexer-tests/trybuild/sway_amm.yaml")] mod indexer { fn function_one(_event: RegisterPoolEvent) {} } diff --git a/packages/fuel-indexer-tests/trybuild/pass_if_using_sway_dao_abi.rs b/packages/fuel-indexer-tests/trybuild/pass_if_using_sway_dao_abi.rs new file mode 100644 index 000000000..c803b7e72 --- /dev/null +++ b/packages/fuel-indexer-tests/trybuild/pass_if_using_sway_dao_abi.rs @@ -0,0 +1,113 @@ +extern crate alloc; +use fuel_indexer_utils::prelude::*; + +#[no_mangle] +fn ff_log_data(_inp: ()) {} + +#[no_mangle] +fn ff_put_object(_inp: ()) {} + +#[no_mangle] +fn ff_put_many_to_many_record(_inp: ()) {} + +#[no_mangle] +fn ff_early_exit(_inp: ()) {} + +#[indexer(manifest = "packages/fuel-indexer-tests/trybuild/simple_wasm.yaml")] +mod indexer { + fn function_one(_event: CreateProposalEvent) {} +} + +fn main() { + use fuels::core::codec::ABIEncoder; + + let event = CreateProposalEvent { + id: 1, + proposal_info: ProposalInfo { + acceptance_percentage: 1, + author: Identity::default(), + deadline: 1, + executed: true, + no_votes: 1, + proposal_transaction: Proposal { + amount: 1, + asset: ContractId::default(), + call_data: CallData { + id: ContractId::default(), + arguments: 1, + function_selector: 1, + }, + gas: 1, + }, + yes_votes: 1, + } + }; + + let encoded1 = ABIEncoder::encode(&[event.into_token()]).expect("Failed compile test"); + let bytes1 = encoded1.resolve(0); + + let data: Vec = vec![BlockData { + id: [0u8; 32].into(), + time: 1, + producer: None, + height: 0, + consensus: fuel::Consensus::default(), + header: fuel::Header { + id: [0u8; 32].into(), + da_height: 1, + transactions_count: 1, + message_receipt_count: 1, + transactions_root: [0u8; 32].into(), + height: 1, + prev_root: [0u8; 32].into(), + time: 1, + application_hash: [0u8; 32].into(), + message_receipt_root: [0u8; 32].into(), + }, + transactions: vec![fuel::TransactionData { + id: [0u8; 32].into(), + status: fuel::TransactionStatus::default(), + receipts: vec![ + fuel::Receipt::Call { + id: [0u8; 32].into(), + to: [0u8; 32].into(), + amount: 400, + asset_id: [0u8; 32].into(), + gas: 4, + param1: 2048508220, + param2: 0, + pc: 0, + is: 0, + }, + fuel::Receipt::ReturnData { + id: [0u8; 32].into(), + ptr: 2342143, + len: bytes1.len() as u64, + digest: [0u8; 32].into(), + data: Some(bytes1), + pc: 0, + is: 0, + }, + fuel::Receipt::Call { + id: [0u8; 32].into(), + to: [0u8; 32].into(), + amount: 400, + asset_id: [0u8; 32].into(), + gas: 4, + param1: 2379805026, + param2: 0, + pc: 0, + is: 0, + }, + ], + transaction: fuel::Transaction::default(), + }], + }]; + + let mut bytes = serialize(&data); + + let ptr = bytes.as_mut_ptr(); + let len = bytes.len(); + + handle_events(ptr, len); +}