From a3e770dbdffcece325874ee10041310a6dfe51ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Tue, 14 Jan 2025 18:37:51 +0200 Subject: [PATCH] Debugging setup --- .../src/multi_transfer_esdt_proxy.rs | 9 + multi-transfer-esdt/src/lib.rs | 29 +- multi-transfer-esdt/wasm/src/lib.rs | 5 +- ..._multiversx_call_data_empty_test.scen.json | 441 ++++++++++++++++++ multisig/tests/multisig_blackbox_test.rs | 17 + multisig/tests/scenario_go_test.rs | 5 + 6 files changed, 502 insertions(+), 4 deletions(-) create mode 100644 multisig/scenarios/ethereum_to_multiversx_call_data_empty_test.scen.json diff --git a/common/sc-proxies/src/multi_transfer_esdt_proxy.rs b/common/sc-proxies/src/multi_transfer_esdt_proxy.rs index 1fa4e469..e6ca4946 100644 --- a/common/sc-proxies/src/multi_transfer_esdt_proxy.rs +++ b/common/sc-proxies/src/multi_transfer_esdt_proxy.rs @@ -97,6 +97,15 @@ where .original_result() } + pub fn my_storage( + self, + ) -> TxTypedCall> { + self.wrapped_tx + .payment(NotPayable) + .raw_call("myStorage") + .original_result() + } + pub fn move_refund_batch_to_safe( self, ) -> TxTypedCall { diff --git a/multi-transfer-esdt/src/lib.rs b/multi-transfer-esdt/src/lib.rs index b377c752..5111ccce 100644 --- a/multi-transfer-esdt/src/lib.rs +++ b/multi-transfer-esdt/src/lib.rs @@ -118,15 +118,38 @@ pub trait MultiTransferEsdt: } valid_tx_list.push(eth_tx.clone()); - valid_payments_list.push(EsdtTokenPayment::new(eth_tx.token_id, 0, eth_tx.amount)); + valid_payments_list.push(EsdtTokenPayment::new( + eth_tx.token_id.clone(), + 0, + eth_tx.amount.clone(), + )); + self.my_storage().set(EsdtTokenPayment::new( + eth_tx.token_id.clone(), + 0, + eth_tx.amount, + )); + + sc_print!("payment {}\n", eth_tx.token_id); + let a = valid_payments_list.get(0).clone(); + sc_print!("payment {}\n", a.token_identifier); + sc_print!("payment {}\n", a.clone().token_identifier); + let b = self.my_storage().get(); + sc_print!("payment {}\n", b.token_identifier); } + for p in valid_payments_list.clone() { + sc_print!("payment {}\n", p.token_identifier); + } let payments_after_wrapping = self.wrap_tokens(valid_payments_list); self.distribute_payments(valid_tx_list, payments_after_wrapping, batch_id); self.add_multiple_tx_to_batch(&refund_tx_list); } + #[view(myStorage)] + #[storage_mapper("unprocessedRefundTxs")] + fn my_storage(&self) -> SingleValueMapper>; + #[only_owner] #[endpoint(moveRefundBatchToSafe)] fn move_refund_batch_to_safe(&self) { @@ -293,9 +316,11 @@ pub trait MultiTransferEsdt: .single_esdt(&p.token_identifier, 0, &p.amount) .sync_call(); } else { + let payment = p.clone(); self.tx() .to(ð_tx.to) - .single_esdt(&p.token_identifier, 0, &p.amount) + .raw_call("") + .single_esdt(&payment.token_identifier, 0, &payment.amount) .callback(self.callbacks().transfer_callback(eth_tx.clone(), batch_id)) .gas(self.blockchain().get_gas_left()) // .gas_for_callback(CALLBACK_ESDT_TRANSFER_GAS_LIMIT) diff --git a/multi-transfer-esdt/wasm/src/lib.rs b/multi-transfer-esdt/wasm/src/lib.rs index 2beb4e6c..2ae45531 100644 --- a/multi-transfer-esdt/wasm/src/lib.rs +++ b/multi-transfer-esdt/wasm/src/lib.rs @@ -6,10 +6,10 @@ // Init: 1 // Upgrade: 1 -// Endpoints: 13 +// Endpoints: 14 // Async Callback (empty): 1 // Promise callbacks: 1 -// Total number of exported functions: 17 +// Total number of exported functions: 18 #![no_std] @@ -22,6 +22,7 @@ multiversx_sc_wasm_adapter::endpoints! { init => init upgrade => upgrade batchTransferEsdtToken => batch_transfer_esdt_token + myStorage => my_storage moveRefundBatchToSafe => move_refund_batch_to_safe addUnprocessedRefundTxToBatch => add_unprocessed_refund_tx_to_batch setMaxTxBatchSize => set_max_tx_batch_size diff --git a/multisig/scenarios/ethereum_to_multiversx_call_data_empty_test.scen.json b/multisig/scenarios/ethereum_to_multiversx_call_data_empty_test.scen.json new file mode 100644 index 00000000..1d4d2721 --- /dev/null +++ b/multisig/scenarios/ethereum_to_multiversx_call_data_empty_test.scen.json @@ -0,0 +1,441 @@ +{ + "steps": [ + { + "step": "setState", + "accounts": { + "address:owner": { + "nonce": "0", + "balance": "0", + "storage": {} + }, + "address:relayer1": { + "nonce": "0", + "balance": "1000", + "storage": {} + }, + "address:relayer2": { + "nonce": "0", + "balance": "1000", + "storage": {} + }, + "address:relayer3": { + "nonce": "0", + "balance": "1000", + "storage": {} + }, + "address:user1": { + "nonce": "0", + "balance": "0", + "esdt": { + "str:WEGLD-123456": "100,000,000,000", + "str:ETH-123456": "200,000,000,000" + }, + "storage": {} + }, + "sc:multisig": { + "nonce": "0", + "balance": "0", + "code": "*" + } + }, + "newAddresses": [ + { + "creatorAddress": "address:owner", + "creatorNonce": "1", + "newAddress": "sc:multisig" + } + ] + }, + { + "step": "scDeploy", + "id": "", + "tx": { + "from": "address:owner", + "contractCode": "mxsc:../output/multisig.mxsc.json", + "arguments": [ + "0x00000000000000000500657364742d736166655f5f5f5f5f5f5f5f5f5f5f5f5f", + "0x000000000000000005006d756c74692d7472616e736665725f5f5f5f5f5f5f5f", + "0x000000000000000005006272696467652d70726f78795f5f5f5f5f5f5f5f5f5f", + "0x00000000000000000500627269646765642d746f6b656e732d77726170706572", + "0x0000000000000000050070726963652d61676772656761746f725f5f5f5f5f5f", + "0x03e8", + "0x01f4", + "0x02", + "0x72656c61796572315f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f", + "0x72656c61796572325f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f" + ], + "gasLimit": "50,000,000" + }, + "expect": { + "out": [], + "status": "0" + } + }, + { + "step": "setState", + "newAddresses": [ + { + "creatorAddress": "sc:multisig", + "creatorNonce": "0", + "newAddress": "sc:esdt-safe" + } + ] + }, + { + "step": "scDeploy", + "id": "", + "tx": { + "from": "sc:multisig", + "contractCode": "mxsc:../../esdt-safe/output/esdt-safe.mxsc.json", + "arguments": [ + "0x0249f0" + ], + "gasLimit": "5,000,000" + }, + "expect": { + "out": [], + "status": "0" + } + }, + { + "step": "setState", + "newAddresses": [ + { + "creatorAddress": "sc:multisig", + "creatorNonce": "1", + "newAddress": "sc:multi-transfer" + } + ] + }, + { + "step": "scDeploy", + "id": "", + "tx": { + "from": "sc:multisig", + "contractCode": "mxsc:../../multi-transfer-esdt/output/multi-transfer-esdt.mxsc.json", + "arguments": [], + "gasLimit": "5,000,000" + }, + "expect": { + "out": [], + "status": "0" + } + }, + { + "step": "setState", + "newAddresses": [ + { + "creatorAddress": "sc:multisig", + "creatorNonce": "2", + "newAddress": "sc:bridge-proxy" + } + ] + }, + { + "step": "scDeploy", + "id": "", + "tx": { + "from": "sc:multisig", + "contractCode": "mxsc:../../bridge-proxy/output/bridge-proxy.mxsc.json", + "arguments": [], + "gasLimit": "5,000,000" + }, + "expect": { + "out": [], + "status": "0" + } + }, + { + "step": "setState", + "newAddresses": [ + { + "creatorAddress": "sc:multisig", + "creatorNonce": "3", + "newAddress": "sc:bridged-tokens-wrapper" + } + ] + }, + { + "step": "scDeploy", + "id": "", + "tx": { + "from": "sc:multisig", + "contractCode": "mxsc:../../bridged-tokens-wrapper/output/bridged-tokens-wrapper.mxsc.json", + "arguments": [], + "gasLimit": "5,000,000" + }, + "expect": { + "out": [], + "status": "0" + } + }, + { + "step": "scCall", + "id": "", + "tx": { + "from": "sc:multisig", + "to": "sc:esdt-safe", + "function": "addTokenToWhitelist", + "arguments": [ + "0x5745474c442d313233343536", + "0x5745474c44", + "0x01", + "0x", + "0x", + "0x", + "0x", + "0x0249f0" + ], + "gasLimit": "5,000,000" + }, + "expect": { + "out": [], + "status": "0" + } + }, + { + "step": "scCall", + "id": "", + "tx": { + "from": "sc:multisig", + "to": "sc:esdt-safe", + "function": "addTokenToWhitelist", + "arguments": [ + "0x4554482d313233343536", + "0x455448", + "0x01", + "0x", + "0x", + "0x", + "0x", + "0x0249f0" + ], + "gasLimit": "5,000,000" + }, + "expect": { + "out": [], + "status": "0" + } + }, + { + "step": "scCall", + "id": "", + "tx": { + "from": "sc:multisig", + "to": "sc:esdt-safe", + "function": "addTokenToWhitelist", + "arguments": [ + "0x45474c442d313233343536", + "0x45474c44", + "0x", + "0x01", + "0x", + "0x", + "0x", + "0x0249f0" + ], + "gasLimit": "5,000,000" + }, + "expect": { + "out": [], + "status": "0" + } + }, + { + "step": "scCall", + "id": "", + "tx": { + "from": "address:owner", + "to": "sc:multisig", + "function": "unpause", + "arguments": [], + "gasLimit": "5,000,000" + }, + "expect": { + "out": [], + "status": "0" + } + }, + { + "step": "scCall", + "id": "", + "tx": { + "from": "sc:multisig", + "to": "sc:bridged-tokens-wrapper", + "function": "unpause", + "arguments": [], + "gasLimit": "5,000,000" + }, + "expect": { + "out": [], + "status": "0" + } + }, + { + "step": "scCall", + "id": "", + "tx": { + "from": "sc:multisig", + "to": "sc:bridge-proxy", + "function": "unpause", + "arguments": [], + "gasLimit": "5,000,000" + }, + "expect": { + "out": [], + "status": "0" + } + }, + { + "step": "scCall", + "id": "", + "tx": { + "from": "sc:multisig", + "to": "sc:esdt-safe", + "function": "unpause", + "arguments": [], + "gasLimit": "5,000,000" + }, + "expect": { + "out": [], + "status": "0" + } + }, + { + "step": "scCall", + "id": "", + "tx": { + "from": "address:relayer1", + "to": "sc:multisig", + "egldValue": "1000", + "function": "stake", + "arguments": [], + "gasLimit": "5,000,000" + }, + "expect": { + "out": [], + "status": "0" + } + }, + { + "step": "scCall", + "id": "", + "tx": { + "from": "address:relayer2", + "to": "sc:multisig", + "egldValue": "1000", + "function": "stake", + "arguments": [], + "gasLimit": "5,000,000" + }, + "expect": { + "out": [], + "status": "0" + } + }, + { + "step": "scQuery", + "id": "", + "tx": { + "to": "sc:multisig", + "function": "getAllStakedRelayers", + "arguments": [] + }, + "expect": { + "out": [ + "0x72656c61796572315f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f", + "0x72656c61796572325f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f" + ], + "status": "0" + } + }, + { + "step": "scCall", + "id": "", + "tx": { + "from": "address:relayer1", + "to": "sc:multisig", + "function": "proposeMultiTransferEsdtBatch", + "arguments": [ + "0x01", + "0x3031303230333034303530363037303830393130", + "0x75736572315f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f", + "0x5745474c442d313233343536", + "0x0487ab00", + "0x01", + "0x" + ], + "gasLimit": "5,000,000" + }, + "expect": { + "out": [ + "0x01" + ], + "status": "0" + } + }, + { + "step": "scCall", + "id": "", + "tx": { + "from": "address:relayer2", + "to": "sc:multisig", + "function": "sign", + "arguments": [ + "0x01" + ], + "gasLimit": "5,000,000" + }, + "expect": { + "out": [], + "status": "0" + } + }, + { + "step": "scCall", + "id": "", + "tx": { + "from": "address:relayer1", + "to": "sc:multisig", + "function": "performAction", + "arguments": [ + "0x01" + ], + "gasLimit": "5,000,000" + }, + "expect": { + "out": [], + "status": "0" + } + }, + { + "step": "scQuery", + "id": "", + "tx": { + "to": "sc:multi-transfer", + "function": "myStorage", + "arguments": [] + }, + "expect": { + "out": [ + "0x0000000c5745474c442d3132333435360000000000000000000000040487ab00" + ], + "status": "0" + } + }, + { + "step": "checkState", + "accounts": { + "address:user1": { + "esdt": { + "str:WEGLD-123456": "76,100,000", + "+": "" + }, + "storage": "*", + "code": "*", + "owner": "*" + } + } + } + ] +} \ No newline at end of file diff --git a/multisig/tests/multisig_blackbox_test.rs b/multisig/tests/multisig_blackbox_test.rs index 36849c9a..25a1d932 100644 --- a/multisig/tests/multisig_blackbox_test.rs +++ b/multisig/tests/multisig_blackbox_test.rs @@ -553,6 +553,8 @@ fn ethereum_to_multiversx_call_data_empty_test() { let mut state = MultiTransferTestState::new(); let token_amount = BigUint::from(76_000_000u64); + state.world.start_trace(); + state.deploy_contracts_config(); let eth_tx = EthTxAsMultiValue::::from(( @@ -597,10 +599,25 @@ fn ethereum_to_multiversx_call_data_empty_test() { .perform_action_endpoint(1usize) .run(); + let a = state + .world + .query() + .to(MULTI_TRANSFER_ADDRESS) + .typed(multi_transfer_esdt_proxy::MultiTransferEsdtProxy) + .my_storage() + .returns(ReturnsResult) + .run(); + + assert!(a.token_identifier == TokenIdentifier::from(WEGLD_TOKEN_ID)); + state .world .check_account(USER1_ADDRESS) .esdt_balance(WEGLD_TOKEN_ID, token_amount.clone() + 100000u64); + + state + .world + .write_scenario_trace("scenarios/ethereum_to_multiversx_call_data_empty_test.scen.json"); } #[test] diff --git a/multisig/tests/scenario_go_test.rs b/multisig/tests/scenario_go_test.rs index a14f3b24..ab30e3bd 100644 --- a/multisig/tests/scenario_go_test.rs +++ b/multisig/tests/scenario_go_test.rs @@ -19,6 +19,11 @@ fn ethereum_to_multiversx_tx_batch_ok_go() { world().run("scenarios/ethereum_to_multiversx_tx_batch_ok.scen.json"); } +#[test] +fn ethereum_to_multiversx_call_data_empty_test_go() { + world().run("scenarios/ethereum_to_multiversx_call_data_empty_test.scen.json"); +} + #[test] #[ignore] //Ignore for now fn ethereum_to_multiversx_tx_batch_rejected_go() {