From 74b68f21633e6f053e02d0a192ce8bd1e2839c38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Mon, 25 Nov 2024 20:13:51 +0200 Subject: [PATCH 1/2] bridge-proxy: sc,test fixes --- bridge-proxy/src/bridge-proxy.rs | 11 +++++++--- bridge-proxy/src/config.rs | 4 ++++ .../tests/bridge_proxy_blackbox_test.rs | 21 +++++++++++++------ bridge-proxy/wasm/src/lib.rs | 6 ++++-- 4 files changed, 31 insertions(+), 11 deletions(-) diff --git a/bridge-proxy/src/bridge-proxy.rs b/bridge-proxy/src/bridge-proxy.rs index f66581d4..7926817a 100644 --- a/bridge-proxy/src/bridge-proxy.rs +++ b/bridge-proxy/src/bridge-proxy.rs @@ -122,13 +122,16 @@ pub trait BridgeProxyContract: #[promises_callback] fn execution_callback(&self, #[call_result] result: ManagedAsyncCallResult<()>, tx_id: usize) { if result.is_err() { - self.refund_transaction(tx_id); + // self.refund_transaction(tx_id); + let tx = self.get_pending_transaction_by_id(tx_id); + self.refund_transactions(tx_id).set(&tx); } self.cleanup_transaction(tx_id); } + #[endpoint(refundTransaction)] fn refund_transaction(&self, tx_id: usize) { - let tx = self.get_pending_transaction_by_id(tx_id); + let tx = self.refund_transactions(tx_id).get(); let esdt_safe_contract_address = self.get_esdt_safe_address(); let unwrapped_token = self.unwrap_token(&tx.token_id, tx_id); @@ -185,7 +188,9 @@ pub trait BridgeProxyContract: } fn finish_execute_gracefully(&self, tx_id: usize) { - self.refund_transaction(tx_id); + // self.refund_transaction(tx_id); + let tx = self.get_pending_transaction_by_id(tx_id); + self.refund_transactions(tx_id).set(&tx); self.cleanup_transaction(tx_id); } diff --git a/bridge-proxy/src/config.rs b/bridge-proxy/src/config.rs index c65aa314..d320a0f2 100644 --- a/bridge-proxy/src/config.rs +++ b/bridge-proxy/src/config.rs @@ -7,6 +7,10 @@ pub trait ConfigModule { #[storage_mapper("pendingTransactions")] fn pending_transactions(&self) -> MapMapper>; + #[view(refundTransactions)] + #[storage_mapper("refundTransactions")] + fn refund_transactions(&self, tx_id: usize) -> SingleValueMapper>; + #[storage_mapper("payments")] fn payments(&self, tx_id: usize) -> SingleValueMapper>; diff --git a/bridge-proxy/tests/bridge_proxy_blackbox_test.rs b/bridge-proxy/tests/bridge_proxy_blackbox_test.rs index 8536cfff..d9c10bdb 100644 --- a/bridge-proxy/tests/bridge_proxy_blackbox_test.rs +++ b/bridge-proxy/tests/bridge_proxy_blackbox_test.rs @@ -760,7 +760,7 @@ fn bridge_proxy_too_small_gas_sc_call_test() { .to(BRIDGE_PROXY_ADDRESS) .typed(bridge_proxy_contract_proxy::BridgeProxyContractProxy) .get_pending_transaction_by_id(1u32) - .returns(ExpectValue(eth_tx)) + .returns(ExpectValue(eth_tx.clone())) .run(); test.world @@ -771,10 +771,12 @@ fn bridge_proxy_too_small_gas_sc_call_test() { .execute(1u32) .run(); - // Refund: Funds are transfered to EsdtSafe test.world - .check_account(ESDT_SAFE_ADDRESS) - .esdt_balance(BRIDGE_TOKEN_ID, amount.clone()); + .check_account(BRIDGE_PROXY_ADDRESS) + .check_storage("str:refundTransactions|u32:1", "0x30313032303330343035303630373038303931300000000000000000050063726f7766756e64696e675f5f5f5f5f5f5f5f5f5f5f0000000d4252494447452d3132333435360000000201f4000000000000000101000000150000000466756e6400000000000f42400100000000") + .check_storage("str:batchId|u32:1", "1") + .check_storage("str:highestTxId", "1") + .check_storage("str:payments|u32:1", "nested:str:BRIDGE-123456|u64:0|biguint:500"); } #[test] @@ -841,7 +843,14 @@ fn bridge_proxy_empty_endpoint_with_args_test() { .run(); // Refund: Funds are transfered to EsdtSafe + // test.world + // .check_account(ESDT_SAFE_ADDRESS) + // .esdt_balance(BRIDGE_TOKEN_ID, amount.clone()); + test.world - .check_account(ESDT_SAFE_ADDRESS) - .esdt_balance(BRIDGE_TOKEN_ID, amount.clone()); + .check_account(BRIDGE_PROXY_ADDRESS) + .check_storage("str:refundTransactions|u32:1", "0x30313032303330343035303630373038303931300000000000000000050063726f7766756e64696e675f5f5f5f5f5f5f5f5f5f5f0000000d4252494447452d3132333435360000000201f4000000000000000101000000110000000000000000009896800100000000") + .check_storage("str:batchId|u32:1", "1") + .check_storage("str:highestTxId", "1") + .check_storage("str:payments|u32:1", "nested:str:BRIDGE-123456|u64:0|biguint:500"); } diff --git a/bridge-proxy/wasm/src/lib.rs b/bridge-proxy/wasm/src/lib.rs index 97c28d7c..76e2b616 100644 --- a/bridge-proxy/wasm/src/lib.rs +++ b/bridge-proxy/wasm/src/lib.rs @@ -6,10 +6,10 @@ // Init: 1 // Upgrade: 1 -// Endpoints: 8 +// Endpoints: 10 // Async Callback (empty): 1 // Promise callbacks: 1 -// Total number of exported functions: 12 +// Total number of exported functions: 14 #![no_std] @@ -23,8 +23,10 @@ multiversx_sc_wasm_adapter::endpoints! { upgrade => upgrade deposit => deposit execute => execute + refundTransaction => refund_transaction getPendingTransactionById => get_pending_transaction_by_id getPendingTransactions => get_pending_transactions + refundTransactions => refund_transactions highestTxId => highest_tx_id pause => pause_endpoint unpause => unpause_endpoint From 0da9aa341fa369f7e08bf64ee1e71552dd335041 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Mon, 25 Nov 2024 20:16:19 +0200 Subject: [PATCH 2/2] clean commented code --- bridge-proxy/src/bridge-proxy.rs | 2 -- bridge-proxy/tests/bridge_proxy_blackbox_test.rs | 5 ----- 2 files changed, 7 deletions(-) diff --git a/bridge-proxy/src/bridge-proxy.rs b/bridge-proxy/src/bridge-proxy.rs index 7926817a..14f3ac63 100644 --- a/bridge-proxy/src/bridge-proxy.rs +++ b/bridge-proxy/src/bridge-proxy.rs @@ -122,7 +122,6 @@ pub trait BridgeProxyContract: #[promises_callback] fn execution_callback(&self, #[call_result] result: ManagedAsyncCallResult<()>, tx_id: usize) { if result.is_err() { - // self.refund_transaction(tx_id); let tx = self.get_pending_transaction_by_id(tx_id); self.refund_transactions(tx_id).set(&tx); } @@ -188,7 +187,6 @@ pub trait BridgeProxyContract: } fn finish_execute_gracefully(&self, tx_id: usize) { - // self.refund_transaction(tx_id); let tx = self.get_pending_transaction_by_id(tx_id); self.refund_transactions(tx_id).set(&tx); self.cleanup_transaction(tx_id); diff --git a/bridge-proxy/tests/bridge_proxy_blackbox_test.rs b/bridge-proxy/tests/bridge_proxy_blackbox_test.rs index d9c10bdb..99062aae 100644 --- a/bridge-proxy/tests/bridge_proxy_blackbox_test.rs +++ b/bridge-proxy/tests/bridge_proxy_blackbox_test.rs @@ -842,11 +842,6 @@ fn bridge_proxy_empty_endpoint_with_args_test() { .execute(1u32) .run(); - // Refund: Funds are transfered to EsdtSafe - // test.world - // .check_account(ESDT_SAFE_ADDRESS) - // .esdt_balance(BRIDGE_TOKEN_ID, amount.clone()); - test.world .check_account(BRIDGE_PROXY_ADDRESS) .check_storage("str:refundTransactions|u32:1", "0x30313032303330343035303630373038303931300000000000000000050063726f7766756e64696e675f5f5f5f5f5f5f5f5f5f5f0000000d4252494447452d3132333435360000000201f4000000000000000101000000110000000000000000009896800100000000")