diff --git a/bridged-tokens-wrapper/tests/dfp_big_uint_test.rs b/bridged-tokens-wrapper/tests/dfp_big_uint_test.rs index 31a2c9b5..add8399b 100644 --- a/bridged-tokens-wrapper/tests/dfp_big_uint_test.rs +++ b/bridged-tokens-wrapper/tests/dfp_big_uint_test.rs @@ -4,7 +4,7 @@ use multiversx_sc_scenario::DebugApi; #[test] fn test_biguint() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let raw = 123456u64; let dfp = DFPBigUint::::from_raw(raw.into(), 6); let converted = dfp.clone().convert(9); @@ -12,12 +12,12 @@ fn test_biguint() { assert!(converted.clone().convert(9).to_raw() == 123456000u64); assert!(converted.clone().convert(1).to_raw() == 1u64); assert!(converted.clone().convert(3).to_raw() == 123u64); - assert!(converted.clone().convert(5).to_raw() == 12345u64); + assert!(converted.convert(5).to_raw() == 12345u64); } #[test] fn test_mandos_scenario_values() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let raw = 300000000000000u64; let dfp = DFPBigUint::::from_raw(raw.into(), 18); assert!(dfp.convert(6).to_raw() == 300u64); diff --git a/common/token-module/src/lib.rs b/common/token-module/src/lib.rs index 78f19203..b1e668b6 100644 --- a/common/token-module/src/lib.rs +++ b/common/token-module/src/lib.rs @@ -100,10 +100,6 @@ pub trait TokenModule: fee_estimator_module::FeeEstimatorModule { ); if self.mint_burn_allowed(token_id).get() { let accumulated_burned_tokens_mapper = self.accumulated_burned_tokens(token_id); - require!( - !accumulated_burned_tokens_mapper.is_empty(), - "Accumulated burned tokens storage is not initialized!" - ); accumulated_burned_tokens_mapper.update(|burned| { require!(*burned >= *amount, "Not enough accumulated burned tokens!"); *burned -= amount; @@ -156,6 +152,12 @@ pub trait TokenModule: fee_estimator_module::FeeEstimatorModule { } } + #[only_owner] + #[endpoint(setAccumulatedBurnedTokens)] + fn set_accumulated_burned_tokens(&self, token_id: &TokenIdentifier, value: BigUint) { + self.accumulated_burned_tokens(token_id).set_if_empty(value); + } + // storage #[view(getAllKnownTokens)] diff --git a/esdt-safe/src/lib.rs b/esdt-safe/src/lib.rs index 14c040b7..3adf6ae8 100644 --- a/esdt-safe/src/lib.rs +++ b/esdt-safe/src/lib.rs @@ -50,7 +50,27 @@ pub trait EsdtSafe: } #[upgrade] - fn upgrade(&self) {} + fn upgrade(&self, fee_estimator_contract_address: ManagedAddress, eth_tx_gas_limit: BigUint) { + self.fee_estimator_contract_address() + .set(&fee_estimator_contract_address); + self.eth_tx_gas_limit().set(ð_tx_gas_limit); + + self.max_tx_batch_size() + .set_if_empty(DEFAULT_MAX_TX_BATCH_SIZE); + self.max_tx_batch_block_duration() + .set_if_empty(DEFAULT_MAX_TX_BATCH_BLOCK_DURATION); + + // batch ID 0 is considered invalid + self.first_batch_id().set_if_empty(1); + self.last_batch_id().set_if_empty(1); + + // set ticker for "GWEI" + let gwei_token_id = TokenIdentifier::from(GWEI_STRING); + self.token_ticker(&gwei_token_id) + .set(gwei_token_id.as_managed_buffer()); + + self.set_paused(true); + } /// Sets the statuses for the transactions, after they were executed on the Ethereum side. /// diff --git a/multi-transfer-esdt/src/lib.rs b/multi-transfer-esdt/src/lib.rs index f2c289ea..dfa75acf 100644 --- a/multi-transfer-esdt/src/lib.rs +++ b/multi-transfer-esdt/src/lib.rs @@ -27,7 +27,15 @@ pub trait MultiTransferEsdt: } #[upgrade] - fn upgrade(&self) {} + fn upgrade(&self) { + self.max_tx_batch_size() + .set_if_empty(DEFAULT_MAX_TX_BATCH_SIZE); + self.max_tx_batch_block_duration() + .set_if_empty(DEFAULT_MAX_TX_BATCH_BLOCK_DURATION); + // batch ID 0 is considered invalid + self.first_batch_id().set_if_empty(1); + self.last_batch_id().set_if_empty(1); + } #[only_owner] #[endpoint(batchTransferEsdtToken)] @@ -48,9 +56,6 @@ pub trait MultiTransferEsdt: if eth_tx.to.is_zero() { self.transfer_failed_invalid_destination(batch_id, eth_tx.tx_nonce); must_refund = true; - } else if !self.is_local_role_set(ð_tx.token_id, &EsdtLocalRole::Mint) { - self.transfer_failed_invalid_token(batch_id, eth_tx.tx_nonce); - must_refund = true; } else if self.is_above_max_amount(ð_tx.token_id, ð_tx.amount) { self.transfer_over_max_amount(batch_id, eth_tx.tx_nonce); must_refund = true; @@ -73,7 +78,7 @@ pub trait MultiTransferEsdt: let minted_token = self .get_esdt_safe_contract_proxy_instance() .mint_token(ð_tx.token_id, ð_tx.amount) - .with_esdt_transfer((eth_tx.token_id.clone(), 0, eth_tx.amount.clone())) + // .with_esdt_transfer((eth_tx.token_id.clone(), 0, eth_tx.amount.clone())) .execute_on_dest_context(); // emit event before the actual transfer so we don't have to save the tx_nonces as well diff --git a/multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs b/multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs index cb29c397..fc2c2eec 100644 --- a/multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs +++ b/multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs @@ -1,6 +1,6 @@ #![allow(unused)] -use bridge_proxy::ProxyTrait as _; +use bridge_proxy::{config::ProxyTrait as _, ProxyTrait as _}; use bridged_tokens_wrapper::ProxyTrait as _; use esdt_safe::{EsdtSafe, ProxyTrait as _}; use multi_transfer_esdt::ProxyTrait as _; @@ -26,6 +26,7 @@ use multiversx_sc_scenario::{ }; use eth_address::*; +use token_module::ProxyTrait as _; use transaction::{EthTransaction, EthTransactionPayment}; const BRIDGE_TOKEN_ID: &[u8] = b"BRIDGE-123456"; @@ -33,7 +34,7 @@ const BRIDGE_TOKEN_ID_EXPR: &str = "str:BRIDGE-123456"; const USER_ETHEREUM_ADDRESS: &[u8] = b"0x0102030405060708091011121314151617181920"; -const GAS_LIMIT: u64 = 1_000_000; +const GAS_LIMIT: u64 = 100_000_000; const MULTI_TRANSFER_PATH_EXPR: &str = "file:output/multi-transfer-esdt.wasm"; const BRIDGE_PROXY_PATH_EXPR: &str = "file:../bridge-proxy/output/bridge-proxy.wasm"; @@ -110,6 +111,18 @@ impl MultiTransferTestState { bridged_tokens_wrapper: BridgedTokensWrapperContract::new("sc:bridged_tokens_wrapper"), }; + let multi_transfer_code = state.world.code_expression(MULTI_TRANSFER_PATH_EXPR); + let bridge_proxy_code = state.world.code_expression(BRIDGE_PROXY_PATH_EXPR); + let esdt_safe_code = state.world.code_expression(ESDT_SAFE_PATH_EXPR); + let bridged_tokens_wrapper_code = state + .world + .code_expression(BRIDGED_TOKENS_WRAPPER_PATH_EXPR); + + let roles = vec![ + "ESDTRoleLocalMint".to_string(), + "ESDTRoleLocalBurn".to_string(), + ]; + state.world.set_state_step( SetStateStep::new() .put_account( @@ -123,19 +136,20 @@ impl MultiTransferTestState { .new_address(&state.owner, 1, MULTI_TRANSFER_ADDRESS_EXPR) .new_address(&state.owner, 2, BRIDGE_PROXY_ADDRESS_EXPR) .new_address(&state.owner, 3, ESDT_SAFE_ADDRESS_EXPR) + .put_account( + ESDT_SAFE_ADDRESS_EXPR, + Account::new() + .code(&esdt_safe_code) + .owner(&state.owner) + .esdt_roles(BRIDGE_TOKEN_ID_EXPR, roles) + .esdt_balance(BRIDGE_TOKEN_ID_EXPR, "1_000"), + ) .new_address(&state.owner, 4, BRIDGED_TOKENS_WRAPPER_ADDRESS_EXPR), ); - state } fn multi_transfer_deploy(&mut self) -> &mut Self { - // let bridge_proxy_addr = self - // .bridge_proxy - // .address - // .clone() - // .unwrap_or_sc_panic("Cannot get Bridge Proxy Contract address!"); - self.world.sc_deploy( ScDeployStep::new() .from(self.owner.clone()) @@ -158,14 +172,11 @@ impl MultiTransferTestState { } fn safe_deploy(&mut self, price_aggregator_contract_address: Address) -> &mut Self { - self.world.sc_deploy( - ScDeployStep::new() - .from(self.owner.clone()) - .code(self.world.code_expression(ESDT_SAFE_PATH_EXPR)) - .call( - self.esdt_safe - .init(ManagedAddress::zero(), ESDT_SAFE_ETH_TX_GAS_LIMIT), - ), + self.world.sc_call( + ScCallStep::new().from(self.owner.clone()).call( + self.esdt_safe + .upgrade(ManagedAddress::zero(), ESDT_SAFE_ETH_TX_GAS_LIMIT), + ), ); self @@ -182,30 +193,77 @@ impl MultiTransferTestState { self } - fn config_multi_transfer( - &mut self, - bridged_tokens_wrapper_contract_address: Address, - bridge_proxy_contract_address: Address, - ) { - self.world.sc_call( - ScCallStep::new() - .from(self.owner.clone()) - .to(&self.multi_transfer) - .call( - self.multi_transfer - .set_wrapping_contract_address(bridged_tokens_wrapper_contract_address), - ), - ); - - self.world.sc_call( - ScCallStep::new() - .from(self.owner.clone()) - .to(&self.multi_transfer) - .call( - self.multi_transfer - .set_bridge_proxy_contract_address(bridge_proxy_contract_address), - ), - ); + fn config_multi_transfer(&mut self) { + self.world + .sc_call( + ScCallStep::new() + .from(self.owner.clone()) + .to(&self.multi_transfer) + .call( + self.multi_transfer.set_wrapping_contract_address( + self.bridged_tokens_wrapper.to_address(), + ), + ), + ) + .sc_call( + ScCallStep::new() + .from(self.owner.clone()) + .to(&self.multi_transfer) + .call( + self.multi_transfer + .set_bridge_proxy_contract_address(self.bridge_proxy.to_address()), + ), + ) + .sc_call( + ScCallStep::new() + .from(self.owner.clone()) + .to(&self.multi_transfer) + .call( + self.multi_transfer + .set_esdt_safe_contract_address(self.esdt_safe.to_address()), + ), + ) + .sc_call( + ScCallStep::new() + .from(self.owner.clone()) + .to(&self.esdt_safe) + .call( + self.esdt_safe + .set_multi_transfer_contract_address(self.multi_transfer.to_address()), + ), + ) + .sc_call( + ScCallStep::new() + .from(self.owner.clone()) + .to(&self.esdt_safe) + .call(self.esdt_safe.add_token_to_whitelist( + TokenIdentifier::from_esdt_bytes("BRIDGE-123456"), + "BRIDGE", + true, + BigUint::from(ESDT_SAFE_ETH_TX_GAS_LIMIT), + )), + ) + .sc_call( + ScCallStep::new() + .from(self.owner.clone()) + .to(&self.esdt_safe) + .call(self.esdt_safe.set_accumulated_burned_tokens( + TokenIdentifier::from_esdt_bytes("BRIDGE-123456"), + BigUint::from(1_000u64), + )), + ); + + //mint_burn_allowed + + // .sc_call( + // ScCallStep::new() + // .from(self.owner.clone()) + // .to(&self.bridge_proxy) + // .call( + // self.bridge_proxy + // .set_multi_transfer_contract_address(self.multi_transfer.to_address()), + // ), + // ); } } @@ -216,13 +274,9 @@ fn basic_setup_test() { test.multi_transfer_deploy(); test.bridge_proxy_deploy(); - // test.price_aggregator_deploy(); test.safe_deploy(Address::zero()); test.bridged_tokens_wrapper_deploy(); - test.config_multi_transfer( - test.bridged_tokens_wrapper.to_address(), - test.bridge_proxy.to_address(), - ); + test.config_multi_transfer(); test.world.set_state_step(SetStateStep::new().put_account( &test.owner, @@ -248,7 +302,8 @@ fn basic_setup_test() { .check_storage("str:wrappingContractAddress", "sc:bridged_tokens_wrapper") .check_storage("str:maxTxBatchBlockDuration", "0xffffffffffffffff") .check_storage("str:maxTxBatchSize", "10") - .check_storage("str:firstBatchId", "0x01"), + .check_storage("str:firstBatchId", "0x01") + .check_storage("str:esdtSafeContractAddress", "sc:esdt_safe"), ), ); } @@ -260,13 +315,9 @@ fn basic_transfer_test() { test.multi_transfer_deploy(); test.bridge_proxy_deploy(); - // test.price_aggregator_deploy(); test.safe_deploy(Address::zero()); test.bridged_tokens_wrapper_deploy(); - test.config_multi_transfer( - test.bridged_tokens_wrapper.to_address(), - test.bridge_proxy.to_address(), - ); + test.config_multi_transfer(); let eth_tx = EthTransaction { from: test.eth_user, @@ -287,27 +338,32 @@ fn basic_transfer_test() { .check_storage("str:wrappingContractAddress", "sc:bridged_tokens_wrapper") .check_storage("str:maxTxBatchBlockDuration", "0xffffffffffffffff") .check_storage("str:maxTxBatchSize", "10") - .check_storage("str:firstBatchId", "0x01"), + .check_storage("str:firstBatchId", "0x01") + .check_storage("str:esdtSafeContractAddress", "sc:esdt_safe"), ), ); let mut transfers = MultiValueEncoded::new(); - // transfers.push(eth_tx); + transfers.push(eth_tx); test.world.sc_call( ScCallStep::new() .from(&test.owner) .to(&test.esdt_safe) - .call(test.esdt_safe.unpause_endpoint()), // .esdt_transfer(bridge_token_id_expr, 0u64, 500u64), + .call(test.esdt_safe.unpause_endpoint()), ); test.world.sc_call( ScCallStep::new() .from(&test.owner) .to(&test.bridged_tokens_wrapper) - .call(test.bridged_tokens_wrapper.unpause_endpoint()), // .esdt_transfer(bridge_token_id_expr, 0u64, 500u64), + .call(test.bridged_tokens_wrapper.unpause_endpoint()), ); test.world.dump_state_step(); + let roles = vec![ + "ESDTRoleLocalMint".to_string(), + "ESDTRoleLocalBurn".to_string(), + ]; test.world.sc_call( ScCallStep::new() @@ -316,7 +372,7 @@ fn basic_transfer_test() { .call( test.multi_transfer .batch_transfer_esdt_token(1u32, transfers), - ), // .esdt_transfer(BRIDGE_TOKEN_ID_EXPR, 0u64, BALANCE), + ), ); test.world @@ -324,11 +380,4 @@ fn basic_transfer_test() { test.user1, CheckAccount::new().esdt_balance(BRIDGE_TOKEN_ID_EXPR, token_amount), )); - - // test.world.sc_query( - // ScQueryStep::new() - // .to(&test.multi_transfer) - // .call(test.multi_transfer.get_eth_transaction_by_id(1u32)) - // .expect_value(eth_tx), - // ); }