From 939105ff0ebf68e4f48ce464ff0a6f4c38554e1f Mon Sep 17 00:00:00 2001 From: Andrei Marinica Date: Wed, 23 Oct 2024 18:37:53 +0300 Subject: [PATCH] promises error test --- .../promises_multi_transfer_err.scen.json | 184 ++++++++++++++++++ .../tests/composability_scenario_go_test.rs | 5 + .../tests/composability_scenario_rs_test.rs | 6 + .../composability/vault/src/vault.rs | 6 + .../vault/wasm-vault-promises/src/lib.rs | 5 +- .../composability/vault/wasm/src/lib.rs | 5 +- 6 files changed, 207 insertions(+), 4 deletions(-) create mode 100644 contracts/feature-tests/composability/scenarios/promises_multi_transfer_err.scen.json diff --git a/contracts/feature-tests/composability/scenarios/promises_multi_transfer_err.scen.json b/contracts/feature-tests/composability/scenarios/promises_multi_transfer_err.scen.json new file mode 100644 index 0000000000..a57daf45ea --- /dev/null +++ b/contracts/feature-tests/composability/scenarios/promises_multi_transfer_err.scen.json @@ -0,0 +1,184 @@ +{ + "steps": [ + { + "step": "setState", + "accounts": { + "address:a_user": { + "nonce": "0", + "balance": "2000" + }, + "sc:promises": { + "nonce": "0", + "balance": "0", + "esdt": { + "str:FWD-TOKEN": "1000", + "str:NFT-123456": { + "instances": [ + { + "nonce": "1", + "balance": "1" + } + ] + }, + "str:SFT-456789": { + "instances": [ + { + "nonce": "3", + "balance": "10" + } + ] + } + }, + "code": "mxsc:../promises-features/output/promises-features.mxsc.json" + }, + "sc:vault": { + "nonce": "0", + "balance": "0", + "code": "mxsc:../vault/output/vault.mxsc.json" + } + } + }, + { + "step": "scCall", + "id": "multi-transfer-through-promises", + "tx": { + "from": "address:a_user", + "to": "sc:promises", + "function": "promise_raw_multi_transfer", + "arguments": [ + "sc:vault", + "str:explicit_panic", + "5,000", + "str:FWD-TOKEN", + "0", + "500", + "str:NFT-123456", + "1", + "1", + "str:SFT-456789", + "3", + "6" + ], + "gasLimit": "100,000,000", + "gasPrice": "0" + }, + "expect": { + "out": [], + "status": "0", + "message": "", + "logs": [ + { + "address": "sc:promises", + "endpoint": "str:MultiESDTNFTTransfer", + "topics": [ + "str:FWD-TOKEN", + "0", + "500", + "str:NFT-123456", + "1", + "1", + "str:SFT-456789", + "3", + "6", + "sc:vault" + ], + "data": [ + "str:AsyncCall", + "str:MultiESDTNFTTransfer", + "sc:vault", + "3", + "str:FWD-TOKEN", + "0", + "500", + "str:NFT-123456", + "1", + "1", + "str:SFT-456789", + "3", + "6", + "str:explicit_panic" + ] + }, + { + "address": "sc:vault", + "endpoint": "str:transferValueOnly", + "topics": [ + "", + "sc:promises" + ], + "data": [ + "str:AsyncCallback", + "str:the_one_callback", + "0x04", + "str:explicit panic" + ] + }, + { + "address": "sc:promises", + "endpoint": "str:the_one_callback", + "topics": [ + "str:async_call_event_callback", + "2001", + "2002" + ], + "data": [ + [ + "nested:0x04", + "nested:str:explicit panic" + ] + ] + }, + { + "address": "address:a_user", + "endpoint": "str:internalVMErrors", + "topics": [ + "sc:promises", + "str:promise_raw_multi_transfer" + ], + "data": [ + "*" + ] + } + ] + } + }, + { + "step": "checkState", + "accounts": { + "address:a_user": { + "nonce": "*", + "balance": "2000" + }, + "sc:promises": { + "nonce": "0", + "balance": "0", + "esdt": { + "str:FWD-TOKEN": "1000", + "str:NFT-123456": { + "instances": [ + { + "nonce": "1", + "balance": "1" + } + ] + }, + "str:SFT-456789": { + "instances": [ + { + "nonce": "3", + "balance": "10" + } + ] + } + }, + "code": "mxsc:../promises-features/output/promises-features.mxsc.json" + }, + "sc:vault": { + "nonce": "0", + "balance": "0", + "code": "mxsc:../vault/output/vault.mxsc.json" + } + } + } + ] +} diff --git a/contracts/feature-tests/composability/tests/composability_scenario_go_test.rs b/contracts/feature-tests/composability/tests/composability_scenario_go_test.rs index 8f61befdbe..3dfb9fdc2d 100644 --- a/contracts/feature-tests/composability/tests/composability_scenario_go_test.rs +++ b/contracts/feature-tests/composability/tests/composability_scenario_go_test.rs @@ -443,6 +443,11 @@ fn promises_multi_transfer_go() { world().run("scenarios/promises_multi_transfer.scen.json"); } +#[test] +fn promises_multi_transfer_err_go() { + world().run("scenarios/promises_multi_transfer_err.scen.json"); +} + #[test] fn promises_single_transfer_go() { world().run("scenarios/promises_single_transfer.scen.json"); diff --git a/contracts/feature-tests/composability/tests/composability_scenario_rs_test.rs b/contracts/feature-tests/composability/tests/composability_scenario_rs_test.rs index 33db8b4b49..a5b7cd46e1 100644 --- a/contracts/feature-tests/composability/tests/composability_scenario_rs_test.rs +++ b/contracts/feature-tests/composability/tests/composability_scenario_rs_test.rs @@ -492,6 +492,12 @@ fn promises_multi_transfer_rs() { world().run("scenarios/promises_multi_transfer.scen.json"); } +#[test] +#[ignore = "TODO - some log is missing"] +fn promises_multi_transfer_err_rs() { + world().run("scenarios/promises_multi_transfer_err.scen.json"); +} + #[test] #[ignore = "gas"] fn promises_single_transfer_rs() { diff --git a/contracts/feature-tests/composability/vault/src/vault.rs b/contracts/feature-tests/composability/vault/src/vault.rs index 1fb32cccdd..d663d2bd21 100644 --- a/contracts/feature-tests/composability/vault/src/vault.rs +++ b/contracts/feature-tests/composability/vault/src/vault.rs @@ -225,6 +225,12 @@ pub trait Vault { self.tx().to(ToCaller).payment(new_tokens).transfer(); } + #[endpoint] + #[payable("*")] + fn explicit_panic(&self) { + sc_panic!("explicit panic"); + } + #[event("accept_funds")] fn accept_funds_event( &self, diff --git a/contracts/feature-tests/composability/vault/wasm-vault-promises/src/lib.rs b/contracts/feature-tests/composability/vault/wasm-vault-promises/src/lib.rs index 014291f680..4e8d43c7df 100644 --- a/contracts/feature-tests/composability/vault/wasm-vault-promises/src/lib.rs +++ b/contracts/feature-tests/composability/vault/wasm-vault-promises/src/lib.rs @@ -5,9 +5,9 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 16 +// Endpoints: 17 // Async Callback (empty): 1 -// Total number of exported functions: 18 +// Total number of exported functions: 19 #![no_std] @@ -29,6 +29,7 @@ multiversx_sc_wasm_adapter::endpoints! { retrieve_funds => retrieve_funds retrieve_multi_funds_async => retrieve_multi_funds_async burn_and_create_retrieve_async => burn_and_create_retrieve_async + explicit_panic => explicit_panic get_owner_address => get_owner_address call_counts => call_counts num_called_retrieve_funds_promises => num_called_retrieve_funds_promises diff --git a/contracts/feature-tests/composability/vault/wasm/src/lib.rs b/contracts/feature-tests/composability/vault/wasm/src/lib.rs index 9849ddf8ae..d40a5d0532 100644 --- a/contracts/feature-tests/composability/vault/wasm/src/lib.rs +++ b/contracts/feature-tests/composability/vault/wasm/src/lib.rs @@ -6,9 +6,9 @@ // Init: 1 // Upgrade: 1 -// Endpoints: 15 +// Endpoints: 16 // Async Callback (empty): 1 -// Total number of exported functions: 18 +// Total number of exported functions: 19 #![no_std] @@ -31,6 +31,7 @@ multiversx_sc_wasm_adapter::endpoints! { retrieve_funds => retrieve_funds retrieve_multi_funds_async => retrieve_multi_funds_async burn_and_create_retrieve_async => burn_and_create_retrieve_async + explicit_panic => explicit_panic get_owner_address => get_owner_address call_counts => call_counts num_called_retrieve_funds_promises => num_called_retrieve_funds_promises