From 864bcf0122aa1114043a21ad2a3de53e475b40f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Mon, 14 Aug 2023 00:29:29 +0300 Subject: [PATCH 1/4] bridge-proxy: Add tests --- bridge-proxy/Cargo.toml | 3 + bridge-proxy/scenarios/bridge-proxy.scen.json | 45 ------ bridge-proxy/src/bridge-proxy.rs | 8 +- bridge-proxy/src/config.rs | 25 ++- .../tests/bridge-proxy-blackbox-setup/mod.rs | 56 +++++++ .../tests/bridge_proxy_blackbox_test.rs | 148 ++++++++++++++++++ bridge-proxy/tests/bridge_proxy_rust_test.rs | 64 -------- .../tests/bridge_proxy_scenario_go_test.rs | 10 -- .../tests/bridge_proxy_scenario_rs_test.rs | 16 -- bridge-proxy/wasm/Cargo.lock | 1 + bridge-proxy/wasm/src/lib.rs | 2 +- 11 files changed, 232 insertions(+), 146 deletions(-) delete mode 100644 bridge-proxy/scenarios/bridge-proxy.scen.json create mode 100644 bridge-proxy/tests/bridge-proxy-blackbox-setup/mod.rs create mode 100644 bridge-proxy/tests/bridge_proxy_blackbox_test.rs delete mode 100644 bridge-proxy/tests/bridge_proxy_rust_test.rs delete mode 100644 bridge-proxy/tests/bridge_proxy_scenario_go_test.rs delete mode 100644 bridge-proxy/tests/bridge_proxy_scenario_rs_test.rs diff --git a/bridge-proxy/Cargo.toml b/bridge-proxy/Cargo.toml index 4d5c3413..b9b4542d 100644 --- a/bridge-proxy/Cargo.toml +++ b/bridge-proxy/Cargo.toml @@ -10,6 +10,9 @@ path = "src/bridge-proxy.rs" [dependencies.transaction] path = "../common/transaction" +[dependencies.eth-address] +path = "../common/eth-address" + [dependencies.multiversx-sc] version = "0.42.0" diff --git a/bridge-proxy/scenarios/bridge-proxy.scen.json b/bridge-proxy/scenarios/bridge-proxy.scen.json deleted file mode 100644 index 7161bd2c..00000000 --- a/bridge-proxy/scenarios/bridge-proxy.scen.json +++ /dev/null @@ -1,45 +0,0 @@ -{ - "name": "bridge-proxy", - "steps": [ - { - "step": "setState", - "accounts": { - "address:owner": { - "nonce": "1", - "balance": "0" - } - }, - "newAddresses": [ - { - "creatorAddress": "address:owner", - "creatorNonce": "1", - "newAddress": "sc:bridge-proxy" - }, - { - "creatorAddress": "address:owner", - "creatorNonce": "0", - "newAddress": "sc:multi_transfer_esdt" - } - - ] - }, - { - "step": "scDeploy", - "id": "deploy", - "tx": { - "from": "address:owner", - "contractCode": "file:../output/bridge-proxy.wasm", - "arguments": ["sc:multi_transfer_esdt"], - "gasLimit": "5,000,000", - "gasPrice": "0" - }, - "expect": { - "out": [], - "status": "", - "logs": [], - "gas": "*", - "refund": "*" - } - } - ] -} \ No newline at end of file diff --git a/bridge-proxy/src/bridge-proxy.rs b/bridge-proxy/src/bridge-proxy.rs index df5f6447..c86e809e 100644 --- a/bridge-proxy/src/bridge-proxy.rs +++ b/bridge-proxy/src/bridge-proxy.rs @@ -3,18 +3,18 @@ multiversx_sc::imports!(); multiversx_sc::derive_imports!(); -mod config; +pub mod config; use transaction::{EthTransaction, EthTransactionPayment}; #[multiversx_sc::contract] pub trait BridgeProxyContract: config::ConfigModule { #[init] - fn init(&self, multi_transfer_address: ManagedAddress) { - self.multi_transfer_address() - .set_if_empty(&multi_transfer_address); + fn init(&self, opt_multi_transfer_address: OptionalValue) { + self.set_multi_transfer_contract_address(opt_multi_transfer_address); } + #[payable("*")] #[endpoint] fn deposit(&self, eth_tx: EthTransaction) { let (token_id, nonce, amount) = self.call_value().single_esdt().into_tuple(); diff --git a/bridge-proxy/src/config.rs b/bridge-proxy/src/config.rs index 2f035cdd..f2c002e9 100644 --- a/bridge-proxy/src/config.rs +++ b/bridge-proxy/src/config.rs @@ -7,13 +7,26 @@ use transaction::EthTransactionPayment; pub trait ConfigModule { #[only_owner] #[endpoint(setupMultiTransfer)] - fn setup_multi_transfer(&self, multi_transfer_address: ManagedAddress) { - require!( - self.blockchain().is_smart_contract(&multi_transfer_address), - "Invalid multi-transfer address" - ); + fn set_multi_transfer_contract_address(&self, opt_multi_transfer_address: OptionalValue) { + match opt_multi_transfer_address { + OptionalValue::Some(sc_addr) => { + require!( + self.blockchain().is_smart_contract(&sc_addr), + "Invalid multi-transfer address" + ); + self.multi_transfer_address().set(&sc_addr); + } + OptionalValue::None => self.multi_transfer_address().clear(), + } + } - self.multi_transfer_address().set(&multi_transfer_address); + #[view(getEthTransactionById)] + fn get_eth_transaction_by_id(&self, id: u32) -> ManagedBuffer { + let eth_tx_list = self.eth_transaction_list(); + match eth_tx_list.get_node_by_id(id) { + Some(tx) => tx.get_value_cloned().eth_tx.data, + None => sc_panic!("No transaction with this id!") + } } #[view(getMultiTransferAddress)] diff --git a/bridge-proxy/tests/bridge-proxy-blackbox-setup/mod.rs b/bridge-proxy/tests/bridge-proxy-blackbox-setup/mod.rs new file mode 100644 index 00000000..c2404b1f --- /dev/null +++ b/bridge-proxy/tests/bridge-proxy-blackbox-setup/mod.rs @@ -0,0 +1,56 @@ + +use bridge_proxy::bridge_proxy::ConfigModule; + +use multiversx_sc::{ + api::ManagedTypeApi, + codec::multi_types::OptionalValue, + types::{Address, BigUint, BoxedBytes, CodeMetadata, ManagedBuffer, ManagedVec}, +}; +use multiversx_sc_scenario::{managed_address, rust_biguint, testing_framework::*, DebugApi}; + + +const BRIDGE_PROXY_WASM_PATH: &str = "bridge-proxy/output/bridge-proxy.wasm"; +const BRIDGE_TOKEN_ID: &[u8] = b"BRIDGE-123456"; + + +pub struct BridgeProxySetup +where + BridgeProxyObjBuilder: 'static + Copy + Fn() -> bridge_proxy::ContractObj, +{ + pub b_mock: BlockchainStateWrapper, + pub owner_address: Address, + pub bp_wrapper: ContractObjWrapper, BridgeProxyObjBuilder>, +} + +impl BridgeProxySetup +where + BridgeProxyObjBuilder: 'static + Copy + Fn() -> bridge_proxy::ContractObj, +{ + pub fn new(bp_builder: BridgeProxyObjBuilder) -> Self { + let rust_zero = rust_biguint!(0u64); + let mut b_mock = BlockchainStateWrapper::new(); + let owner_address = b_mock.create_user_account(&rust_zero); + + let bp_wrapper = b_mock.create_sc_account( + &rust_zero, + Some(&owner_address), + bp_builder, + BRIDGE_PROXY_PATH, + ); + b_mock + .execute_tx(&owner_address, &ms_wrapper, &rust_zero, |sc| { + let mut board_members = ManagedVec::new(); + board_members.push(managed_address!(&board_member_address)); + + sc.init(QUORUM_SIZE, board_members.into()); + sc.change_user_role(0, managed_address!(&proposer_address), UserRole::Proposer); + }) + .assert_ok(); + + Self { + b_mock, + owner_address, + bp_wrapper, + } + } +} \ No newline at end of file diff --git a/bridge-proxy/tests/bridge_proxy_blackbox_test.rs b/bridge-proxy/tests/bridge_proxy_blackbox_test.rs new file mode 100644 index 00000000..8a4e0f0d --- /dev/null +++ b/bridge-proxy/tests/bridge_proxy_blackbox_test.rs @@ -0,0 +1,148 @@ +#![allow(unused)] + +use std::collections::LinkedList; + +use bridge_proxy::config::ProxyTrait as _; +use bridge_proxy::ProxyTrait; + +use multiversx_sc::{ + api::ManagedTypeApi, + codec::multi_types::{MultiValueVec, OptionalValue}, + storage::mappers::SingleValue, + types::{ + Address, BigUint, CodeMetadata, ManagedAddress, ManagedBuffer, ManagedByteArray, + TokenIdentifier, + }, +}; +use multiversx_sc_scenario::{ + api::StaticApi, + scenario_format::interpret_trait::{InterpretableFrom, InterpreterContext}, + scenario_model::*, + ContractInfo, ScenarioWorld, +}; + +use eth_address::*; +use transaction::{EthTransaction, EthTransactionPayment}; + +const BRIDGE_TOKEN_ID: &[u8] = b"BRIDGE-123456"; +const MULTI_TRANSFER_CONTRACT_ADDRESS: &str = + "0x0000000000000000000000000000000000000000000000000000000000000000"; + +const USER_ETHEREUM_ADDRESS: &[u8] = b"0x0102030405060708091011121314151617181920"; + +const GAS_LIMIT: u64 = 1_000_000; + +const BRIDGE_PROXY_PATH_EXPR: &str = "file:output/bridge-proxy.wasm"; +// const MULTI_TRANSFER_PATH_EXPR: &str = "file:../multi-transfer-esdt/output/multi-transfer-esdt.wasm"; +// const ADDER_PATH_EXPR: &str = "file:test-contracts/adder.wasm"; + +fn world() -> ScenarioWorld { + let mut blockchain = ScenarioWorld::new(); + + blockchain.register_contract(BRIDGE_PROXY_PATH_EXPR, bridge_proxy::ContractBuilder); + blockchain +} + +#[test] +fn basic_setup_test() { + let mut test = BridgeProxyTestState::setup(); + let bridge_token_id_expr = "str:BRIDGE-123456"; // when specifying the token transfer + + test.bridge_proxy_deploy(); + + let eth_tx = EthTransaction { + from: test.eth_user, + to: ManagedAddress::from_address(&test.user.value), + token_id: TokenIdentifier::from_esdt_bytes(BRIDGE_TOKEN_ID), + amount: BigUint::from(500u64), + tx_nonce: 1u64, + data: ManagedBuffer::from("data"), + gas_limit: GAS_LIMIT, + }; + + test.world.set_state_step(SetStateStep::new().put_account( + &test.owner, + Account::new().esdt_balance(bridge_token_id_expr, 1_000u64), + )); + + test.world.sc_call( + ScCallStep::new() + .from(&test.owner) + .to(&test.bridge_proxy) + .call(test.bridge_proxy.deposit(ð_tx)) + .esdt_transfer(bridge_token_id_expr, 0u64, 500u64), + ); + + test.world.sc_query( + ScQueryStep::new() + .to(&test.bridge_proxy) + .call(test.bridge_proxy.get_eth_transaction_by_id(1u32)) + .expect_value(eth_tx.data)); + // |tr| { + // let respose: LinkedList> = tr.result.unwrap(); + // let reponse_eth_tx = respose.pop_front(); + + // let eth_tx_payment = EthTransactionPayment { + // token_id: TokenIdentifier::from_esdt_bytes(BRIDGE_TOKEN_ID), + // nonce: 0u64, + // amount: BigUint::from(500u64), + // eth_tx, + // }; + // match reponse_eth_tx { + // Some(tx) => assert!(tx.eq(ð_tx_payment), "Transactions not equal!"), + // None => panic!("No transaction registered!"), + // } + // }, + // ); +} + +type BridgeProxyContract = ContractInfo>; + +struct BridgeProxyTestState { + world: ScenarioWorld, + owner: AddressValue, + user: AddressValue, + eth_user: EthAddress, + bridge_proxy: BridgeProxyContract, +} + +impl BridgeProxyTestState { + fn setup() -> Self { + let world = world(); + let ic = &world.interpreter_context(); + + let mut state = BridgeProxyTestState { + world, + owner: "address:owner".into(), + user: "address:user".into(), + eth_user: EthAddress { + raw_addr: ManagedByteArray::default(), + }, + bridge_proxy: BridgeProxyContract::new("sc:bridge_proxy"), + }; + + state + .world + .set_state_step(SetStateStep::new().put_account(&state.owner, Account::new().nonce(1))); + + state + } + + fn bridge_proxy_deploy(&mut self) -> &mut Self { + self.world.set_state_step( + SetStateStep::new() + .put_account(&self.owner, Account::new().nonce(1)) + .new_address(&self.owner, 1, &self.bridge_proxy), + ); + + let ic = &self.world.interpreter_context(); + self.world.sc_deploy( + ScDeployStep::new() + .from(self.owner.clone()) + .code(self.world.code_expression(BRIDGE_PROXY_PATH_EXPR)) + .call(self.bridge_proxy.init(ManagedAddress::zero())), + ); + + self + } +} diff --git a/bridge-proxy/tests/bridge_proxy_rust_test.rs b/bridge-proxy/tests/bridge_proxy_rust_test.rs deleted file mode 100644 index 28227ca6..00000000 --- a/bridge-proxy/tests/bridge_proxy_rust_test.rs +++ /dev/null @@ -1,64 +0,0 @@ -use bridge_proxy::*; -use multiversx_sc::types::Address; -use multiversx_sc_scenario::{managed_address, rust_biguint, testing_framework::*, DebugApi}; - -const BRIDGE_PROXY_PATH: &str = "output/bridge-proxy.wasm"; - -struct ContractSetup -where - BridgeProxyObjBuilder: 'static + Copy + Fn() -> bridge_proxy::ContractObj, -{ - pub blockchain_wrapper: BlockchainStateWrapper, - pub owner_address: Address, - pub bridge_proxy_wrapper: - ContractObjWrapper, BridgeProxyObjBuilder>, -} - -fn setup_contract( - bridge_proxy_builder: BridgeProxyObjBuilder, -) -> ContractSetup -where - BridgeProxyObjBuilder: 'static + Copy + Fn() -> bridge_proxy::ContractObj, -{ - let rust_zero = rust_biguint!(0u64); - let mut blockchain_wrapper = BlockchainStateWrapper::new(); - let owner_address = blockchain_wrapper.create_user_account(&rust_zero); - let bridge_proxy_wrapper = blockchain_wrapper.create_sc_account( - &rust_zero, - Some(&owner_address), - bridge_proxy_builder, - BRIDGE_PROXY_PATH, - ); - - blockchain_wrapper - .execute_tx(&owner_address, &bridge_proxy_wrapper, &rust_zero, |sc| { - sc.init(managed_address!(&Address::zero())); - }) - .assert_ok(); - - blockchain_wrapper.add_mandos_set_account(bridge_proxy_wrapper.address_ref()); - - ContractSetup { - blockchain_wrapper, - owner_address, - bridge_proxy_wrapper, - } -} - -#[test] -fn deploy_test() { - let mut setup = setup_contract(bridge_proxy::contract_obj); - - // simulate deploy - setup - .blockchain_wrapper - .execute_tx( - &setup.owner_address, - &setup.bridge_proxy_wrapper, - &rust_biguint!(0u64), - |sc| { - sc.init(managed_address!(&Address::zero())); - }, - ) - .assert_ok(); -} diff --git a/bridge-proxy/tests/bridge_proxy_scenario_go_test.rs b/bridge-proxy/tests/bridge_proxy_scenario_go_test.rs deleted file mode 100644 index 2fca5f45..00000000 --- a/bridge-proxy/tests/bridge_proxy_scenario_go_test.rs +++ /dev/null @@ -1,10 +0,0 @@ -use multiversx_sc_scenario::*; - -fn world() -> ScenarioWorld { - ScenarioWorld::vm_go() -} - -#[test] -fn bridge_proxy_go() { - world().run("scenarios/bridge-proxy.scen.json"); -} diff --git a/bridge-proxy/tests/bridge_proxy_scenario_rs_test.rs b/bridge-proxy/tests/bridge_proxy_scenario_rs_test.rs deleted file mode 100644 index 9f8940b6..00000000 --- a/bridge-proxy/tests/bridge_proxy_scenario_rs_test.rs +++ /dev/null @@ -1,16 +0,0 @@ -use multiversx_sc_scenario::*; - -fn world() -> ScenarioWorld { - let mut blockchain = ScenarioWorld::new(); - - blockchain.register_contract( - "file:output/bridge-proxy.wasm", - bridge_proxy::ContractBuilder, - ); - blockchain -} - -#[test] -fn bridge_proxy_rs() { - world().run("scenarios/bridge-proxy.scen.json"); -} diff --git a/bridge-proxy/wasm/Cargo.lock b/bridge-proxy/wasm/Cargo.lock index 0b278dad..c43b87e1 100644 --- a/bridge-proxy/wasm/Cargo.lock +++ b/bridge-proxy/wasm/Cargo.lock @@ -35,6 +35,7 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" name = "bridge-proxy" version = "0.0.0" dependencies = [ + "eth-address", "multiversx-sc", "transaction", ] diff --git a/bridge-proxy/wasm/src/lib.rs b/bridge-proxy/wasm/src/lib.rs index 89af2cdb..757dc9cd 100644 --- a/bridge-proxy/wasm/src/lib.rs +++ b/bridge-proxy/wasm/src/lib.rs @@ -22,7 +22,7 @@ multiversx_sc_wasm_adapter::endpoints! { deposit => deposit executeWithAsnyc => execute_with_async refundTransactions => refund_transactions - setupMultiTransfer => setup_multi_transfer + setupMultiTransfer => set_multi_transfer_contract_address getMultiTransferAddress => multi_transfer_address getEthTransactionList => eth_transaction_list getEthFailedTransactionList => eth_failed_transaction_list From b22ab53198ffab3829e2c711264ca305028e529a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Mon, 14 Aug 2023 00:30:01 +0300 Subject: [PATCH 2/4] Rename mandos -> scenarios --- .../add_wrapped_token.scen.json | 0 .../blacklist_token.scen.json | 0 .../remove_wrapped_token.scen.json | 0 .../{mandos => scenarios}/setup.scen.json | 0 .../unwrap_token.scen.json | 0 .../whitelist_token.scen.json | 0 .../wrap_token.scen.json | 0 .../tests/scenario_go_test.rs | 35 +++++++++----- common/eth-address/src/lib.rs | 5 +- common/transaction/src/lib.rs | 4 +- .../add_refund_batch.scen.json | 0 .../create_another_tx_ok.scen.json | 0 ...te_another_tx_too_late_for_batch.scen.json | 0 .../create_transaction_ok.scen.json | 0 ...eate_transaction_over_max_amount.scen.json | 0 .../distribute_fees.scen.json | 0 .../execute_batch_both_rejected.scen.json | 0 .../execute_batch_both_success.scen.json | 0 ...e_batch_one_success_one_rejected.scen.json | 0 .../execute_transaction_rejected.scen.json | 0 .../execute_transaction_success.scen.json | 0 .../get_next_pending_tx.scen.json | 0 .../get_next_tx_batch.scen.json | 0 .../get_next_tx_batch_too_early.scen.json | 0 .../setup_accounts.scen.json | 0 .../{mandos => scenarios}/zero_fees.scen.json | 0 esdt-safe/tests/scenario_go_test.rs | 46 +++++++++++++------ .../batch_transfer_both_executed.scen.json | 0 .../batch_transfer_both_failed.scen.json | 0 ...transfer_one_executed_one_failed.scen.json | 0 ...batch_transfer_to_frozen_account.scen.json | 0 .../batch_transfer_with_wrapping.scen.json | 0 .../setup_accounts.scen.json | 0 .../transfer_ok.scen.json | 0 .../two_transfers_same_token.scen.json | 0 multi-transfer-esdt/tests/scenario_go_test.rs | 25 +++++++--- multi-transfer-esdt/wasm/Cargo.lock | 1 + .../change_token_config.scen.json | 0 ...eate_elrond_to_ethereum_tx_batch.scen.json | 0 .../ethereum_to_elrond_tx_batch_ok.scen.json | 0 ...reum_to_elrond_tx_batch_rejected.scen.json | 0 ...cute_elrond_to_ethereum_tx_batch.scen.json | 0 .../get_empty_batch.scen.json | 0 ...ject_elrond_to_ethereum_tx_batch.scen.json | 0 .../{mandos => scenarios}/setup.scen.json | 0 .../{mandos => scenarios}/unstake.scen.json | 0 multisig/tests/scenario_go_test.rs | 37 +++++++++------ multisig/wasm/Cargo.lock | 1 + .../{mandos => scenarios}/deploy.scen.json | 0 .../get_latest_price_feed.scen.json | 0 ...acle_gwei_in_eth_and_egld_submit.scen.json | 0 .../oracle_submit.scen.json | 0 52 files changed, 101 insertions(+), 53 deletions(-) rename bridged-tokens-wrapper/{mandos => scenarios}/add_wrapped_token.scen.json (100%) rename bridged-tokens-wrapper/{mandos => scenarios}/blacklist_token.scen.json (100%) rename bridged-tokens-wrapper/{mandos => scenarios}/remove_wrapped_token.scen.json (100%) rename bridged-tokens-wrapper/{mandos => scenarios}/setup.scen.json (100%) rename bridged-tokens-wrapper/{mandos => scenarios}/unwrap_token.scen.json (100%) rename bridged-tokens-wrapper/{mandos => scenarios}/whitelist_token.scen.json (100%) rename bridged-tokens-wrapper/{mandos => scenarios}/wrap_token.scen.json (100%) rename esdt-safe/{mandos => scenarios}/add_refund_batch.scen.json (100%) rename esdt-safe/{mandos => scenarios}/create_another_tx_ok.scen.json (100%) rename esdt-safe/{mandos => scenarios}/create_another_tx_too_late_for_batch.scen.json (100%) rename esdt-safe/{mandos => scenarios}/create_transaction_ok.scen.json (100%) rename esdt-safe/{mandos => scenarios}/create_transaction_over_max_amount.scen.json (100%) rename esdt-safe/{mandos => scenarios}/distribute_fees.scen.json (100%) rename esdt-safe/{mandos => scenarios}/execute_batch_both_rejected.scen.json (100%) rename esdt-safe/{mandos => scenarios}/execute_batch_both_success.scen.json (100%) rename esdt-safe/{mandos => scenarios}/execute_batch_one_success_one_rejected.scen.json (100%) rename esdt-safe/{mandos => scenarios}/execute_transaction_rejected.scen.json (100%) rename esdt-safe/{mandos => scenarios}/execute_transaction_success.scen.json (100%) rename esdt-safe/{mandos => scenarios}/get_next_pending_tx.scen.json (100%) rename esdt-safe/{mandos => scenarios}/get_next_tx_batch.scen.json (100%) rename esdt-safe/{mandos => scenarios}/get_next_tx_batch_too_early.scen.json (100%) rename esdt-safe/{mandos => scenarios}/setup_accounts.scen.json (100%) rename esdt-safe/{mandos => scenarios}/zero_fees.scen.json (100%) rename multi-transfer-esdt/{mandos => scenarios}/batch_transfer_both_executed.scen.json (100%) rename multi-transfer-esdt/{mandos => scenarios}/batch_transfer_both_failed.scen.json (100%) rename multi-transfer-esdt/{mandos => scenarios}/batch_transfer_one_executed_one_failed.scen.json (100%) rename multi-transfer-esdt/{mandos => scenarios}/batch_transfer_to_frozen_account.scen.json (100%) rename multi-transfer-esdt/{mandos => scenarios}/batch_transfer_with_wrapping.scen.json (100%) rename multi-transfer-esdt/{mandos => scenarios}/setup_accounts.scen.json (100%) rename multi-transfer-esdt/{mandos => scenarios}/transfer_ok.scen.json (100%) rename multi-transfer-esdt/{mandos => scenarios}/two_transfers_same_token.scen.json (100%) rename multisig/{mandos => scenarios}/change_token_config.scen.json (100%) rename multisig/{mandos => scenarios}/create_elrond_to_ethereum_tx_batch.scen.json (100%) rename multisig/{mandos => scenarios}/ethereum_to_elrond_tx_batch_ok.scen.json (100%) rename multisig/{mandos => scenarios}/ethereum_to_elrond_tx_batch_rejected.scen.json (100%) rename multisig/{mandos => scenarios}/execute_elrond_to_ethereum_tx_batch.scen.json (100%) rename multisig/{mandos => scenarios}/get_empty_batch.scen.json (100%) rename multisig/{mandos => scenarios}/reject_elrond_to_ethereum_tx_batch.scen.json (100%) rename multisig/{mandos => scenarios}/setup.scen.json (100%) rename multisig/{mandos => scenarios}/unstake.scen.json (100%) rename price-aggregator/{mandos => scenarios}/deploy.scen.json (100%) rename price-aggregator/{mandos => scenarios}/get_latest_price_feed.scen.json (100%) rename price-aggregator/{mandos => scenarios}/oracle_gwei_in_eth_and_egld_submit.scen.json (100%) rename price-aggregator/{mandos => scenarios}/oracle_submit.scen.json (100%) diff --git a/bridged-tokens-wrapper/mandos/add_wrapped_token.scen.json b/bridged-tokens-wrapper/scenarios/add_wrapped_token.scen.json similarity index 100% rename from bridged-tokens-wrapper/mandos/add_wrapped_token.scen.json rename to bridged-tokens-wrapper/scenarios/add_wrapped_token.scen.json diff --git a/bridged-tokens-wrapper/mandos/blacklist_token.scen.json b/bridged-tokens-wrapper/scenarios/blacklist_token.scen.json similarity index 100% rename from bridged-tokens-wrapper/mandos/blacklist_token.scen.json rename to bridged-tokens-wrapper/scenarios/blacklist_token.scen.json diff --git a/bridged-tokens-wrapper/mandos/remove_wrapped_token.scen.json b/bridged-tokens-wrapper/scenarios/remove_wrapped_token.scen.json similarity index 100% rename from bridged-tokens-wrapper/mandos/remove_wrapped_token.scen.json rename to bridged-tokens-wrapper/scenarios/remove_wrapped_token.scen.json diff --git a/bridged-tokens-wrapper/mandos/setup.scen.json b/bridged-tokens-wrapper/scenarios/setup.scen.json similarity index 100% rename from bridged-tokens-wrapper/mandos/setup.scen.json rename to bridged-tokens-wrapper/scenarios/setup.scen.json diff --git a/bridged-tokens-wrapper/mandos/unwrap_token.scen.json b/bridged-tokens-wrapper/scenarios/unwrap_token.scen.json similarity index 100% rename from bridged-tokens-wrapper/mandos/unwrap_token.scen.json rename to bridged-tokens-wrapper/scenarios/unwrap_token.scen.json diff --git a/bridged-tokens-wrapper/mandos/whitelist_token.scen.json b/bridged-tokens-wrapper/scenarios/whitelist_token.scen.json similarity index 100% rename from bridged-tokens-wrapper/mandos/whitelist_token.scen.json rename to bridged-tokens-wrapper/scenarios/whitelist_token.scen.json diff --git a/bridged-tokens-wrapper/mandos/wrap_token.scen.json b/bridged-tokens-wrapper/scenarios/wrap_token.scen.json similarity index 100% rename from bridged-tokens-wrapper/mandos/wrap_token.scen.json rename to bridged-tokens-wrapper/scenarios/wrap_token.scen.json diff --git a/bridged-tokens-wrapper/tests/scenario_go_test.rs b/bridged-tokens-wrapper/tests/scenario_go_test.rs index 4bbc4b02..a3d6e919 100644 --- a/bridged-tokens-wrapper/tests/scenario_go_test.rs +++ b/bridged-tokens-wrapper/tests/scenario_go_test.rs @@ -1,29 +1,40 @@ +use multiversx_sc_scenario::*; + +fn world() -> ScenarioWorld { + ScenarioWorld::vm_go() +} + #[test] -fn unwrap_token_go() { - multiversx_sc_scenario::run_go("mandos/unwrap_token.scen.json"); +fn add_wrapped_token_go() { + world().run("scenarios/add_wrapped_token.scen.json"); } #[test] -fn wrap_token_go() { - multiversx_sc_scenario::run_go("mandos/wrap_token.scen.json"); +fn blacklist_token_go() { + world().run("scenarios/blacklist_token.scen.json"); } #[test] -fn whitelist_token_go() { - multiversx_sc_scenario::run_go("mandos/whitelist_token.scen.json"); +fn remove_wrapped_token_go() { + world().run("scenarios/remove_wrapped_token.scen.json"); } #[test] -fn blacklist_token_go() { - multiversx_sc_scenario::run_go("mandos/blacklist_token.scen.json"); +fn setup_go() { + world().run("scenarios/setup.scen.json"); } #[test] -fn add_wrapped_token_go() { - multiversx_sc_scenario::run_go("mandos/add_wrapped_token.scen.json"); +fn unwrap_token_go() { + world().run("scenarios/unwrap_token.scen.json"); } #[test] -fn remove_wrapped_token_go() { - multiversx_sc_scenario::run_go("mandos/remove_wrapped_token.scen.json"); +fn whitelist_token_go() { + world().run("scenarios/whitelist_token.scen.json"); +} + +#[test] +fn wrap_token_go() { + world().run("scenarios/wrap_token.scen.json"); } diff --git a/common/eth-address/src/lib.rs b/common/eth-address/src/lib.rs index 0e4e6a53..878d94ab 100644 --- a/common/eth-address/src/lib.rs +++ b/common/eth-address/src/lib.rs @@ -9,7 +9,7 @@ use multiversx_sc::{ pub const ETH_ADDRESS_LEN: usize = 20; /// Wrapper over a 20-byte array -#[derive(TypeAbi, TopEncode, TopDecode, NestedEncode, NestedDecode, Clone, ManagedVecItem)] +#[derive(TypeAbi, TopEncode, TopDecode, NestedEncode, NestedDecode, Clone, ManagedVecItem, PartialEq)] pub struct EthAddress { pub raw_addr: ManagedByteArray, } @@ -24,4 +24,5 @@ impl EthAddress { pub fn as_managed_buffer(&self) -> &ManagedBuffer { self.raw_addr.as_managed_buffer() } -} + +} \ No newline at end of file diff --git a/common/transaction/src/lib.rs b/common/transaction/src/lib.rs index c2098019..68d3a2a8 100644 --- a/common/transaction/src/lib.rs +++ b/common/transaction/src/lib.rs @@ -26,7 +26,7 @@ pub type TxAsMultiValue = MultiValue6< pub type PaymentsVec = ManagedVec>; pub type TxBatchSplitInFields = MultiValue2>>; -#[derive(TopEncode, TopDecode, NestedEncode, NestedDecode, TypeAbi, ManagedVecItem, Clone)] +#[derive(TopEncode, TopDecode, NestedEncode, NestedDecode, TypeAbi, ManagedVecItem, Clone, PartialEq)] pub struct EthTransaction { pub from: EthAddress, pub to: ManagedAddress, @@ -47,7 +47,7 @@ pub type EthTxAsMultiValue = MultiValue7< u64, >; -#[derive(TopEncode, TopDecode, NestedEncode, NestedDecode, TypeAbi, ManagedVecItem, Clone)] +#[derive(TopEncode, TopDecode, NestedEncode, NestedDecode, TypeAbi, ManagedVecItem, Clone, PartialEq)] pub struct EthTransactionPayment { pub token_id: TokenIdentifier, pub nonce: u64, diff --git a/esdt-safe/mandos/add_refund_batch.scen.json b/esdt-safe/scenarios/add_refund_batch.scen.json similarity index 100% rename from esdt-safe/mandos/add_refund_batch.scen.json rename to esdt-safe/scenarios/add_refund_batch.scen.json diff --git a/esdt-safe/mandos/create_another_tx_ok.scen.json b/esdt-safe/scenarios/create_another_tx_ok.scen.json similarity index 100% rename from esdt-safe/mandos/create_another_tx_ok.scen.json rename to esdt-safe/scenarios/create_another_tx_ok.scen.json diff --git a/esdt-safe/mandos/create_another_tx_too_late_for_batch.scen.json b/esdt-safe/scenarios/create_another_tx_too_late_for_batch.scen.json similarity index 100% rename from esdt-safe/mandos/create_another_tx_too_late_for_batch.scen.json rename to esdt-safe/scenarios/create_another_tx_too_late_for_batch.scen.json diff --git a/esdt-safe/mandos/create_transaction_ok.scen.json b/esdt-safe/scenarios/create_transaction_ok.scen.json similarity index 100% rename from esdt-safe/mandos/create_transaction_ok.scen.json rename to esdt-safe/scenarios/create_transaction_ok.scen.json diff --git a/esdt-safe/mandos/create_transaction_over_max_amount.scen.json b/esdt-safe/scenarios/create_transaction_over_max_amount.scen.json similarity index 100% rename from esdt-safe/mandos/create_transaction_over_max_amount.scen.json rename to esdt-safe/scenarios/create_transaction_over_max_amount.scen.json diff --git a/esdt-safe/mandos/distribute_fees.scen.json b/esdt-safe/scenarios/distribute_fees.scen.json similarity index 100% rename from esdt-safe/mandos/distribute_fees.scen.json rename to esdt-safe/scenarios/distribute_fees.scen.json diff --git a/esdt-safe/mandos/execute_batch_both_rejected.scen.json b/esdt-safe/scenarios/execute_batch_both_rejected.scen.json similarity index 100% rename from esdt-safe/mandos/execute_batch_both_rejected.scen.json rename to esdt-safe/scenarios/execute_batch_both_rejected.scen.json diff --git a/esdt-safe/mandos/execute_batch_both_success.scen.json b/esdt-safe/scenarios/execute_batch_both_success.scen.json similarity index 100% rename from esdt-safe/mandos/execute_batch_both_success.scen.json rename to esdt-safe/scenarios/execute_batch_both_success.scen.json diff --git a/esdt-safe/mandos/execute_batch_one_success_one_rejected.scen.json b/esdt-safe/scenarios/execute_batch_one_success_one_rejected.scen.json similarity index 100% rename from esdt-safe/mandos/execute_batch_one_success_one_rejected.scen.json rename to esdt-safe/scenarios/execute_batch_one_success_one_rejected.scen.json diff --git a/esdt-safe/mandos/execute_transaction_rejected.scen.json b/esdt-safe/scenarios/execute_transaction_rejected.scen.json similarity index 100% rename from esdt-safe/mandos/execute_transaction_rejected.scen.json rename to esdt-safe/scenarios/execute_transaction_rejected.scen.json diff --git a/esdt-safe/mandos/execute_transaction_success.scen.json b/esdt-safe/scenarios/execute_transaction_success.scen.json similarity index 100% rename from esdt-safe/mandos/execute_transaction_success.scen.json rename to esdt-safe/scenarios/execute_transaction_success.scen.json diff --git a/esdt-safe/mandos/get_next_pending_tx.scen.json b/esdt-safe/scenarios/get_next_pending_tx.scen.json similarity index 100% rename from esdt-safe/mandos/get_next_pending_tx.scen.json rename to esdt-safe/scenarios/get_next_pending_tx.scen.json diff --git a/esdt-safe/mandos/get_next_tx_batch.scen.json b/esdt-safe/scenarios/get_next_tx_batch.scen.json similarity index 100% rename from esdt-safe/mandos/get_next_tx_batch.scen.json rename to esdt-safe/scenarios/get_next_tx_batch.scen.json diff --git a/esdt-safe/mandos/get_next_tx_batch_too_early.scen.json b/esdt-safe/scenarios/get_next_tx_batch_too_early.scen.json similarity index 100% rename from esdt-safe/mandos/get_next_tx_batch_too_early.scen.json rename to esdt-safe/scenarios/get_next_tx_batch_too_early.scen.json diff --git a/esdt-safe/mandos/setup_accounts.scen.json b/esdt-safe/scenarios/setup_accounts.scen.json similarity index 100% rename from esdt-safe/mandos/setup_accounts.scen.json rename to esdt-safe/scenarios/setup_accounts.scen.json diff --git a/esdt-safe/mandos/zero_fees.scen.json b/esdt-safe/scenarios/zero_fees.scen.json similarity index 100% rename from esdt-safe/mandos/zero_fees.scen.json rename to esdt-safe/scenarios/zero_fees.scen.json diff --git a/esdt-safe/tests/scenario_go_test.rs b/esdt-safe/tests/scenario_go_test.rs index 205306a5..7dcd7957 100644 --- a/esdt-safe/tests/scenario_go_test.rs +++ b/esdt-safe/tests/scenario_go_test.rs @@ -1,69 +1,85 @@ +use multiversx_sc_scenario::*; + +fn world() -> ScenarioWorld { + ScenarioWorld::vm_go() +} + #[test] -fn claim_fees_go() { - multiversx_sc_scenario::run_go("mandos/distribute_fees.scen.json"); +fn add_refund_batch_go() { + world().run("scenarios/add_refund_batch.scen.json"); } #[test] fn create_another_tx_ok_go() { - multiversx_sc_scenario::run_go("mandos/create_another_tx_ok.scen.json"); + world().run("scenarios/create_another_tx_ok.scen.json"); } #[test] fn create_another_tx_too_late_for_batch_go() { - multiversx_sc_scenario::run_go("mandos/create_another_tx_too_late_for_batch.scen.json"); + world().run("scenarios/create_another_tx_too_late_for_batch.scen.json"); } #[test] fn create_transaction_ok_go() { - multiversx_sc_scenario::run_go("mandos/create_transaction_ok.scen.json"); + world().run("scenarios/create_transaction_ok.scen.json"); +} + +#[test] +fn create_transaction_over_max_amount_go() { + world().run("scenarios/create_transaction_over_max_amount.scen.json"); +} + +#[test] +fn distribute_fees_go() { + world().run("scenarios/distribute_fees.scen.json"); } #[test] fn execute_batch_both_rejected_go() { - multiversx_sc_scenario::run_go("mandos/execute_batch_both_rejected.scen.json"); + world().run("scenarios/execute_batch_both_rejected.scen.json"); } #[test] fn execute_batch_both_success_go() { - multiversx_sc_scenario::run_go("mandos/execute_batch_both_success.scen.json"); + world().run("scenarios/execute_batch_both_success.scen.json"); } #[test] fn execute_batch_one_success_one_rejected_go() { - multiversx_sc_scenario::run_go("mandos/execute_batch_one_success_one_rejected.scen.json"); + world().run("scenarios/execute_batch_one_success_one_rejected.scen.json"); } #[test] fn execute_transaction_rejected_go() { - multiversx_sc_scenario::run_go("mandos/execute_transaction_rejected.scen.json"); + world().run("scenarios/execute_transaction_rejected.scen.json"); } #[test] fn execute_transaction_success_go() { - multiversx_sc_scenario::run_go("mandos/execute_transaction_success.scen.json"); + world().run("scenarios/execute_transaction_success.scen.json"); } #[test] fn get_next_pending_tx_go() { - multiversx_sc_scenario::run_go("mandos/get_next_pending_tx.scen.json"); + world().run("scenarios/get_next_pending_tx.scen.json"); } #[test] fn get_next_tx_batch_go() { - multiversx_sc_scenario::run_go("mandos/get_next_tx_batch.scen.json"); + world().run("scenarios/get_next_tx_batch.scen.json"); } #[test] fn get_next_tx_batch_too_early_go() { - multiversx_sc_scenario::run_go("mandos/get_next_tx_batch_too_early.scen.json"); + world().run("scenarios/get_next_tx_batch_too_early.scen.json"); } #[test] fn setup_accounts_go() { - multiversx_sc_scenario::run_go("mandos/setup_accounts.scen.json"); + world().run("scenarios/setup_accounts.scen.json"); } #[test] fn zero_fees_go() { - multiversx_sc_scenario::run_go("mandos/zero_fees.scen.json"); + world().run("scenarios/zero_fees.scen.json"); } diff --git a/multi-transfer-esdt/mandos/batch_transfer_both_executed.scen.json b/multi-transfer-esdt/scenarios/batch_transfer_both_executed.scen.json similarity index 100% rename from multi-transfer-esdt/mandos/batch_transfer_both_executed.scen.json rename to multi-transfer-esdt/scenarios/batch_transfer_both_executed.scen.json diff --git a/multi-transfer-esdt/mandos/batch_transfer_both_failed.scen.json b/multi-transfer-esdt/scenarios/batch_transfer_both_failed.scen.json similarity index 100% rename from multi-transfer-esdt/mandos/batch_transfer_both_failed.scen.json rename to multi-transfer-esdt/scenarios/batch_transfer_both_failed.scen.json diff --git a/multi-transfer-esdt/mandos/batch_transfer_one_executed_one_failed.scen.json b/multi-transfer-esdt/scenarios/batch_transfer_one_executed_one_failed.scen.json similarity index 100% rename from multi-transfer-esdt/mandos/batch_transfer_one_executed_one_failed.scen.json rename to multi-transfer-esdt/scenarios/batch_transfer_one_executed_one_failed.scen.json diff --git a/multi-transfer-esdt/mandos/batch_transfer_to_frozen_account.scen.json b/multi-transfer-esdt/scenarios/batch_transfer_to_frozen_account.scen.json similarity index 100% rename from multi-transfer-esdt/mandos/batch_transfer_to_frozen_account.scen.json rename to multi-transfer-esdt/scenarios/batch_transfer_to_frozen_account.scen.json diff --git a/multi-transfer-esdt/mandos/batch_transfer_with_wrapping.scen.json b/multi-transfer-esdt/scenarios/batch_transfer_with_wrapping.scen.json similarity index 100% rename from multi-transfer-esdt/mandos/batch_transfer_with_wrapping.scen.json rename to multi-transfer-esdt/scenarios/batch_transfer_with_wrapping.scen.json diff --git a/multi-transfer-esdt/mandos/setup_accounts.scen.json b/multi-transfer-esdt/scenarios/setup_accounts.scen.json similarity index 100% rename from multi-transfer-esdt/mandos/setup_accounts.scen.json rename to multi-transfer-esdt/scenarios/setup_accounts.scen.json diff --git a/multi-transfer-esdt/mandos/transfer_ok.scen.json b/multi-transfer-esdt/scenarios/transfer_ok.scen.json similarity index 100% rename from multi-transfer-esdt/mandos/transfer_ok.scen.json rename to multi-transfer-esdt/scenarios/transfer_ok.scen.json diff --git a/multi-transfer-esdt/mandos/two_transfers_same_token.scen.json b/multi-transfer-esdt/scenarios/two_transfers_same_token.scen.json similarity index 100% rename from multi-transfer-esdt/mandos/two_transfers_same_token.scen.json rename to multi-transfer-esdt/scenarios/two_transfers_same_token.scen.json diff --git a/multi-transfer-esdt/tests/scenario_go_test.rs b/multi-transfer-esdt/tests/scenario_go_test.rs index cdda9c2b..099736dd 100644 --- a/multi-transfer-esdt/tests/scenario_go_test.rs +++ b/multi-transfer-esdt/tests/scenario_go_test.rs @@ -1,34 +1,45 @@ +use multiversx_sc_scenario::*; + +fn world() -> ScenarioWorld { + ScenarioWorld::vm_go() +} + #[test] fn batch_transfer_both_executed_go() { - multiversx_sc_scenario::run_go("mandos/batch_transfer_both_executed.scen.json"); + world().run("scenarios/batch_transfer_both_executed.scen.json"); } #[test] fn batch_transfer_both_failed_go() { - multiversx_sc_scenario::run_go("mandos/batch_transfer_both_failed.scen.json"); + world().run("scenarios/batch_transfer_both_failed.scen.json"); } #[test] fn batch_transfer_one_executed_one_failed_go() { - multiversx_sc_scenario::run_go("mandos/batch_transfer_one_executed_one_failed.scen.json"); + world().run("scenarios/batch_transfer_one_executed_one_failed.scen.json"); } #[test] fn batch_transfer_to_frozen_account_go() { - multiversx_sc_scenario::run_go("mandos/batch_transfer_to_frozen_account.scen.json"); + world().run("scenarios/batch_transfer_to_frozen_account.scen.json"); +} + +#[test] +fn batch_transfer_with_wrapping_go() { + world().run("scenarios/batch_transfer_with_wrapping.scen.json"); } #[test] fn setup_accounts_go() { - multiversx_sc_scenario::run_go("mandos/setup_accounts.scen.json"); + world().run("scenarios/setup_accounts.scen.json"); } #[test] fn transfer_ok_go() { - multiversx_sc_scenario::run_go("mandos/transfer_ok.scen.json"); + world().run("scenarios/transfer_ok.scen.json"); } #[test] fn two_transfers_same_token_go() { - multiversx_sc_scenario::run_go("mandos/two_transfers_same_token.scen.json"); + world().run("scenarios/two_transfers_same_token.scen.json"); } diff --git a/multi-transfer-esdt/wasm/Cargo.lock b/multi-transfer-esdt/wasm/Cargo.lock index 58967f4e..e4dc86a0 100644 --- a/multi-transfer-esdt/wasm/Cargo.lock +++ b/multi-transfer-esdt/wasm/Cargo.lock @@ -35,6 +35,7 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" name = "bridge-proxy" version = "0.0.0" dependencies = [ + "eth-address", "multiversx-sc", "transaction", ] diff --git a/multisig/mandos/change_token_config.scen.json b/multisig/scenarios/change_token_config.scen.json similarity index 100% rename from multisig/mandos/change_token_config.scen.json rename to multisig/scenarios/change_token_config.scen.json diff --git a/multisig/mandos/create_elrond_to_ethereum_tx_batch.scen.json b/multisig/scenarios/create_elrond_to_ethereum_tx_batch.scen.json similarity index 100% rename from multisig/mandos/create_elrond_to_ethereum_tx_batch.scen.json rename to multisig/scenarios/create_elrond_to_ethereum_tx_batch.scen.json diff --git a/multisig/mandos/ethereum_to_elrond_tx_batch_ok.scen.json b/multisig/scenarios/ethereum_to_elrond_tx_batch_ok.scen.json similarity index 100% rename from multisig/mandos/ethereum_to_elrond_tx_batch_ok.scen.json rename to multisig/scenarios/ethereum_to_elrond_tx_batch_ok.scen.json diff --git a/multisig/mandos/ethereum_to_elrond_tx_batch_rejected.scen.json b/multisig/scenarios/ethereum_to_elrond_tx_batch_rejected.scen.json similarity index 100% rename from multisig/mandos/ethereum_to_elrond_tx_batch_rejected.scen.json rename to multisig/scenarios/ethereum_to_elrond_tx_batch_rejected.scen.json diff --git a/multisig/mandos/execute_elrond_to_ethereum_tx_batch.scen.json b/multisig/scenarios/execute_elrond_to_ethereum_tx_batch.scen.json similarity index 100% rename from multisig/mandos/execute_elrond_to_ethereum_tx_batch.scen.json rename to multisig/scenarios/execute_elrond_to_ethereum_tx_batch.scen.json diff --git a/multisig/mandos/get_empty_batch.scen.json b/multisig/scenarios/get_empty_batch.scen.json similarity index 100% rename from multisig/mandos/get_empty_batch.scen.json rename to multisig/scenarios/get_empty_batch.scen.json diff --git a/multisig/mandos/reject_elrond_to_ethereum_tx_batch.scen.json b/multisig/scenarios/reject_elrond_to_ethereum_tx_batch.scen.json similarity index 100% rename from multisig/mandos/reject_elrond_to_ethereum_tx_batch.scen.json rename to multisig/scenarios/reject_elrond_to_ethereum_tx_batch.scen.json diff --git a/multisig/mandos/setup.scen.json b/multisig/scenarios/setup.scen.json similarity index 100% rename from multisig/mandos/setup.scen.json rename to multisig/scenarios/setup.scen.json diff --git a/multisig/mandos/unstake.scen.json b/multisig/scenarios/unstake.scen.json similarity index 100% rename from multisig/mandos/unstake.scen.json rename to multisig/scenarios/unstake.scen.json diff --git a/multisig/tests/scenario_go_test.rs b/multisig/tests/scenario_go_test.rs index 9605e9d4..f8cd6f03 100644 --- a/multisig/tests/scenario_go_test.rs +++ b/multisig/tests/scenario_go_test.rs @@ -1,46 +1,53 @@ +use multiversx_sc_scenario::*; + +fn world() -> ScenarioWorld { + ScenarioWorld::vm_go() +} + +*/ + + +#[test] +fn change_token_config_go() { + world().run("scenarios/change_token_config.scen.json"); +} + #[test] fn create_elrond_to_ethereum_tx_batch_go() { - multiversx_sc_scenario::run_go("mandos/create_elrond_to_ethereum_tx_batch.scen.json"); + world().run("scenarios/create_elrond_to_ethereum_tx_batch.scen.json"); } #[test] fn ethereum_to_elrond_tx_batch_ok_go() { - multiversx_sc_scenario::run_go("mandos/ethereum_to_elrond_tx_batch_ok.scen.json"); + world().run("scenarios/ethereum_to_elrond_tx_batch_ok.scen.json"); } #[test] fn ethereum_to_elrond_tx_batch_rejected_go() { - multiversx_sc_scenario::run_go("mandos/ethereum_to_elrond_tx_batch_rejected.scen.json"); + world().run("scenarios/ethereum_to_elrond_tx_batch_rejected.scen.json"); } #[test] fn execute_elrond_to_ethereum_tx_batch_go() { - multiversx_sc_scenario::run_go("mandos/execute_elrond_to_ethereum_tx_batch.scen.json"); + world().run("scenarios/execute_elrond_to_ethereum_tx_batch.scen.json"); } #[test] fn get_empty_batch_go() { - multiversx_sc_scenario::run_go("mandos/get_empty_batch.scen.json"); + world().run("scenarios/get_empty_batch.scen.json"); } #[test] fn reject_elrond_to_ethereum_tx_batch_go() { - multiversx_sc_scenario::run_go("mandos/reject_elrond_to_ethereum_tx_batch.scen.json"); + world().run("scenarios/reject_elrond_to_ethereum_tx_batch.scen.json"); } #[test] fn setup_go() { - multiversx_sc_scenario::run_go("mandos/setup.scen.json"); + world().run("scenarios/setup.scen.json"); } #[test] fn unstake_go() { - multiversx_sc_scenario::run_go("mandos/unstake.scen.json"); -} - -/* -#[test] -fn upgrade_child_sc_go() { - multiversx_sc_scenario::run_go("mandos/upgrade_child_sc.scen.json"); + world().run("scenarios/unstake.scen.json"); } -*/ diff --git a/multisig/wasm/Cargo.lock b/multisig/wasm/Cargo.lock index 036c6f9c..80816d3f 100644 --- a/multisig/wasm/Cargo.lock +++ b/multisig/wasm/Cargo.lock @@ -35,6 +35,7 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" name = "bridge-proxy" version = "0.0.0" dependencies = [ + "eth-address", "multiversx-sc", "transaction", ] diff --git a/price-aggregator/mandos/deploy.scen.json b/price-aggregator/scenarios/deploy.scen.json similarity index 100% rename from price-aggregator/mandos/deploy.scen.json rename to price-aggregator/scenarios/deploy.scen.json diff --git a/price-aggregator/mandos/get_latest_price_feed.scen.json b/price-aggregator/scenarios/get_latest_price_feed.scen.json similarity index 100% rename from price-aggregator/mandos/get_latest_price_feed.scen.json rename to price-aggregator/scenarios/get_latest_price_feed.scen.json diff --git a/price-aggregator/mandos/oracle_gwei_in_eth_and_egld_submit.scen.json b/price-aggregator/scenarios/oracle_gwei_in_eth_and_egld_submit.scen.json similarity index 100% rename from price-aggregator/mandos/oracle_gwei_in_eth_and_egld_submit.scen.json rename to price-aggregator/scenarios/oracle_gwei_in_eth_and_egld_submit.scen.json diff --git a/price-aggregator/mandos/oracle_submit.scen.json b/price-aggregator/scenarios/oracle_submit.scen.json similarity index 100% rename from price-aggregator/mandos/oracle_submit.scen.json rename to price-aggregator/scenarios/oracle_submit.scen.json From b8e9086874a5776bb29852e56660a89bc1210743 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Mon, 14 Aug 2023 15:10:07 +0300 Subject: [PATCH 3/4] Refactor bridge-proxy deposit test --- bridge-proxy/src/config.rs | 6 +- .../tests/bridge-proxy-blackbox-setup/mod.rs | 56 ------------------- .../tests/bridge_proxy_blackbox_test.rs | 29 +--------- 3 files changed, 6 insertions(+), 85 deletions(-) delete mode 100644 bridge-proxy/tests/bridge-proxy-blackbox-setup/mod.rs diff --git a/bridge-proxy/src/config.rs b/bridge-proxy/src/config.rs index f2c002e9..1cedabe2 100644 --- a/bridge-proxy/src/config.rs +++ b/bridge-proxy/src/config.rs @@ -1,7 +1,7 @@ multiversx_sc::imports!(); multiversx_sc::derive_imports!(); -use transaction::EthTransactionPayment; +use transaction::{EthTransactionPayment, EthTransaction}; #[multiversx_sc::module] pub trait ConfigModule { @@ -21,10 +21,10 @@ pub trait ConfigModule { } #[view(getEthTransactionById)] - fn get_eth_transaction_by_id(&self, id: u32) -> ManagedBuffer { + fn get_eth_transaction_by_id(&self, id: u32) -> EthTransaction { let eth_tx_list = self.eth_transaction_list(); match eth_tx_list.get_node_by_id(id) { - Some(tx) => tx.get_value_cloned().eth_tx.data, + Some(tx) => tx.get_value_cloned().eth_tx, None => sc_panic!("No transaction with this id!") } } diff --git a/bridge-proxy/tests/bridge-proxy-blackbox-setup/mod.rs b/bridge-proxy/tests/bridge-proxy-blackbox-setup/mod.rs deleted file mode 100644 index c2404b1f..00000000 --- a/bridge-proxy/tests/bridge-proxy-blackbox-setup/mod.rs +++ /dev/null @@ -1,56 +0,0 @@ - -use bridge_proxy::bridge_proxy::ConfigModule; - -use multiversx_sc::{ - api::ManagedTypeApi, - codec::multi_types::OptionalValue, - types::{Address, BigUint, BoxedBytes, CodeMetadata, ManagedBuffer, ManagedVec}, -}; -use multiversx_sc_scenario::{managed_address, rust_biguint, testing_framework::*, DebugApi}; - - -const BRIDGE_PROXY_WASM_PATH: &str = "bridge-proxy/output/bridge-proxy.wasm"; -const BRIDGE_TOKEN_ID: &[u8] = b"BRIDGE-123456"; - - -pub struct BridgeProxySetup -where - BridgeProxyObjBuilder: 'static + Copy + Fn() -> bridge_proxy::ContractObj, -{ - pub b_mock: BlockchainStateWrapper, - pub owner_address: Address, - pub bp_wrapper: ContractObjWrapper, BridgeProxyObjBuilder>, -} - -impl BridgeProxySetup -where - BridgeProxyObjBuilder: 'static + Copy + Fn() -> bridge_proxy::ContractObj, -{ - pub fn new(bp_builder: BridgeProxyObjBuilder) -> Self { - let rust_zero = rust_biguint!(0u64); - let mut b_mock = BlockchainStateWrapper::new(); - let owner_address = b_mock.create_user_account(&rust_zero); - - let bp_wrapper = b_mock.create_sc_account( - &rust_zero, - Some(&owner_address), - bp_builder, - BRIDGE_PROXY_PATH, - ); - b_mock - .execute_tx(&owner_address, &ms_wrapper, &rust_zero, |sc| { - let mut board_members = ManagedVec::new(); - board_members.push(managed_address!(&board_member_address)); - - sc.init(QUORUM_SIZE, board_members.into()); - sc.change_user_role(0, managed_address!(&proposer_address), UserRole::Proposer); - }) - .assert_ok(); - - Self { - b_mock, - owner_address, - bp_wrapper, - } - } -} \ No newline at end of file diff --git a/bridge-proxy/tests/bridge_proxy_blackbox_test.rs b/bridge-proxy/tests/bridge_proxy_blackbox_test.rs index 8a4e0f0d..1902f57f 100644 --- a/bridge-proxy/tests/bridge_proxy_blackbox_test.rs +++ b/bridge-proxy/tests/bridge_proxy_blackbox_test.rs @@ -25,16 +25,8 @@ use eth_address::*; use transaction::{EthTransaction, EthTransactionPayment}; const BRIDGE_TOKEN_ID: &[u8] = b"BRIDGE-123456"; -const MULTI_TRANSFER_CONTRACT_ADDRESS: &str = - "0x0000000000000000000000000000000000000000000000000000000000000000"; - -const USER_ETHEREUM_ADDRESS: &[u8] = b"0x0102030405060708091011121314151617181920"; - const GAS_LIMIT: u64 = 1_000_000; - const BRIDGE_PROXY_PATH_EXPR: &str = "file:output/bridge-proxy.wasm"; -// const MULTI_TRANSFER_PATH_EXPR: &str = "file:../multi-transfer-esdt/output/multi-transfer-esdt.wasm"; -// const ADDER_PATH_EXPR: &str = "file:test-contracts/adder.wasm"; fn world() -> ScenarioWorld { let mut blockchain = ScenarioWorld::new(); @@ -44,7 +36,7 @@ fn world() -> ScenarioWorld { } #[test] -fn basic_setup_test() { +fn deploy_deposit_test() { let mut test = BridgeProxyTestState::setup(); let bridge_token_id_expr = "str:BRIDGE-123456"; // when specifying the token transfer @@ -77,23 +69,8 @@ fn basic_setup_test() { ScQueryStep::new() .to(&test.bridge_proxy) .call(test.bridge_proxy.get_eth_transaction_by_id(1u32)) - .expect_value(eth_tx.data)); - // |tr| { - // let respose: LinkedList> = tr.result.unwrap(); - // let reponse_eth_tx = respose.pop_front(); - - // let eth_tx_payment = EthTransactionPayment { - // token_id: TokenIdentifier::from_esdt_bytes(BRIDGE_TOKEN_ID), - // nonce: 0u64, - // amount: BigUint::from(500u64), - // eth_tx, - // }; - // match reponse_eth_tx { - // Some(tx) => assert!(tx.eq(ð_tx_payment), "Transactions not equal!"), - // None => panic!("No transaction registered!"), - // } - // }, - // ); + .expect_value(eth_tx), + ); } type BridgeProxyContract = ContractInfo>; From 4c8596aaa58dc4a1813eaac94b5b7e47c2b6b367 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Mon, 14 Aug 2023 20:12:19 +0300 Subject: [PATCH 4/4] Add MultiTransferEsdt rust test --- bridge-proxy/wasm/src/lib.rs | 5 +- multi-transfer-esdt/Cargo.toml | 3 + .../tests/multi_transfer_blackbox_test.rs | 172 ++++++++++++++++++ multi-transfer-esdt/wasm/Cargo.lock | 1 + multisig/tests/scenario_go_test.rs | 4 - multisig/wasm/Cargo.lock | 1 + 6 files changed, 180 insertions(+), 6 deletions(-) create mode 100644 multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs diff --git a/bridge-proxy/wasm/src/lib.rs b/bridge-proxy/wasm/src/lib.rs index 757dc9cd..4cde9d5d 100644 --- a/bridge-proxy/wasm/src/lib.rs +++ b/bridge-proxy/wasm/src/lib.rs @@ -5,9 +5,9 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 7 +// Endpoints: 8 // Async Callback: 1 -// Total number of exported functions: 9 +// Total number of exported functions: 10 #![no_std] #![feature(lang_items)] @@ -23,6 +23,7 @@ multiversx_sc_wasm_adapter::endpoints! { executeWithAsnyc => execute_with_async refundTransactions => refund_transactions setupMultiTransfer => set_multi_transfer_contract_address + getEthTransactionById => get_eth_transaction_by_id getMultiTransferAddress => multi_transfer_address getEthTransactionList => eth_transaction_list getEthFailedTransactionList => eth_failed_transaction_list diff --git a/multi-transfer-esdt/Cargo.toml b/multi-transfer-esdt/Cargo.toml index 680fdc75..d8daabe6 100644 --- a/multi-transfer-esdt/Cargo.toml +++ b/multi-transfer-esdt/Cargo.toml @@ -13,6 +13,9 @@ path = "../common/transaction" [dependencies.tx-batch-module] path = "../common/tx-batch-module" +[dependencies.eth-address] +path = "../common/eth-address" + [dependencies.max-bridged-amount-module] path = "../common/max-bridged-amount-module" diff --git a/multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs b/multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs new file mode 100644 index 00000000..edbbf58d --- /dev/null +++ b/multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs @@ -0,0 +1,172 @@ +#![allow(unused)] + +use bridge_proxy::ProxyTrait as _; +use multi_transfer_esdt::ProxyTrait as _; + +use multiversx_sc::{ + api::ManagedTypeApi, + codec::multi_types::{MultiValueVec, OptionalValue}, + storage::mappers::SingleValue, + types::{ + Address, BigUint, CodeMetadata, ManagedAddress, ManagedBuffer, ManagedByteArray, + MultiValueEncoded, TokenIdentifier, + }, +}; +use multiversx_sc_scenario::{ + api::StaticApi, + scenario_format::interpret_trait::{InterpretableFrom, InterpreterContext}, + scenario_model::*, + ContractInfo, ScenarioWorld, +}; + +use eth_address::*; +use transaction::{EthTransaction, EthTransactionPayment}; + +const BRIDGE_TOKEN_ID: &[u8] = b"BRIDGE-123456"; +const USER_ETHEREUM_ADDRESS: &[u8] = b"0x0102030405060708091011121314151617181920"; + +const GAS_LIMIT: u64 = 1_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"; + +fn world() -> ScenarioWorld { + let mut blockchain = ScenarioWorld::new(); + + blockchain.register_contract( + MULTI_TRANSFER_PATH_EXPR, + multi_transfer_esdt::ContractBuilder, + ); + blockchain +} + +#[test] +fn basic_setup_test() { + let mut test = MultiTransferTestState::setup(); + let bridge_token_id_expr = "str:BRIDGE-123456"; // when specifying the token transfer + + test.multi_transfer_deploy(); + test.bridge_proxy_deploy(); + + test.world.set_state_step(SetStateStep::new().put_account( + &test.owner, + Account::new().esdt_balance(bridge_token_id_expr, 1_000u64), + )); + + let eth_tx = EthTransaction { + from: test.eth_user, + to: ManagedAddress::from_address(&test.user1.value), + token_id: TokenIdentifier::from_esdt_bytes(BRIDGE_TOKEN_ID), + amount: BigUint::from(500u64), + tx_nonce: 1u64, + data: ManagedBuffer::from("data"), + gas_limit: GAS_LIMIT, + }; + + test.world + .check_state_step(CheckStateStep::new().put_account( + &test.multi_transfer, + CheckAccount::new().check_storage("bridgeProxyContractAddress", "sc:bridge-proxy"), + )); + + let mut transfers = MultiValueEncoded::new(); + transfers.push(eth_tx); + + test.world.sc_call( + ScCallStep::new() + .from(&test.owner) + .to(&test.multi_transfer) + .call(test.multi_transfer.batch_transfer_esdt_token(1u32, transfers)) + // .esdt_transfer(bridge_token_id_expr, 0u64, 500u64), + ); + + // test.world.sc_query( + // ScQueryStep::new() + // .to(&test.multi_transfer) + // .call(test.multi_transfer.get_eth_transaction_by_id(1u32)) + // .expect_value(eth_tx), + // ); +} + +type MultiTransferContract = ContractInfo>; +type BridgeProxyContract = ContractInfo>; + +struct MultiTransferTestState { + world: ScenarioWorld, + owner: AddressValue, + user1: AddressValue, + user2: AddressValue, + eth_user: EthAddress, + multi_transfer: MultiTransferContract, + bridge_proxy: BridgeProxyContract, +} + +impl MultiTransferTestState { + fn setup() -> Self { + let world = world(); + let ic = &world.interpreter_context(); + + let mut state: MultiTransferTestState = MultiTransferTestState { + world, + owner: "address:owner".into(), + user1: "address:user1".into(), + user2: "address:user2".into(), + eth_user: EthAddress { + raw_addr: ManagedByteArray::default(), + }, + multi_transfer: MultiTransferContract::new("sc:multi_transfer"), + bridge_proxy: BridgeProxyContract::new("sc:bridge_proxy"), + }; + + state + .world + .set_state_step(SetStateStep::new().put_account(&state.owner, Account::new().nonce(1))); + + state + } + + fn multi_transfer_deploy(&mut self) -> &mut Self { + self.world.set_state_step( + SetStateStep::new() + .put_account(&self.owner, Account::new().nonce(1)) + .new_address(&self.owner, 1, &self.multi_transfer), + ); + + let ic = &self.world.interpreter_context(); + 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()) + .code(self.world.code_expression(MULTI_TRANSFER_PATH_EXPR)) + .call( + self.multi_transfer + .init(bridge_proxy_addr, ManagedAddress::zero()), + ), + ); + + self + } + + fn bridge_proxy_deploy(&mut self) -> &mut Self { + self.world.set_state_step( + SetStateStep::new() + .put_account(&self.owner, Account::new().nonce(1)) + .new_address(&self.owner, 1, &self.bridge_proxy), + ); + + let ic = &self.world.interpreter_context(); + self.world.sc_deploy( + ScDeployStep::new() + .from(self.owner.clone()) + .code(self.world.code_expression(BRIDGE_PROXY_PATH_EXPR)) + .call(self.bridge_proxy.init(ManagedAddress::zero())), + ); + + self + } +} diff --git a/multi-transfer-esdt/wasm/Cargo.lock b/multi-transfer-esdt/wasm/Cargo.lock index e4dc86a0..11823bb6 100644 --- a/multi-transfer-esdt/wasm/Cargo.lock +++ b/multi-transfer-esdt/wasm/Cargo.lock @@ -102,6 +102,7 @@ version = "0.0.0" dependencies = [ "bridge-proxy", "bridged-tokens-wrapper", + "eth-address", "max-bridged-amount-module", "multiversx-sc", "transaction", diff --git a/multisig/tests/scenario_go_test.rs b/multisig/tests/scenario_go_test.rs index f8cd6f03..0fc3e199 100644 --- a/multisig/tests/scenario_go_test.rs +++ b/multisig/tests/scenario_go_test.rs @@ -3,10 +3,6 @@ use multiversx_sc_scenario::*; fn world() -> ScenarioWorld { ScenarioWorld::vm_go() } - -*/ - - #[test] fn change_token_config_go() { world().run("scenarios/change_token_config.scen.json"); diff --git a/multisig/wasm/Cargo.lock b/multisig/wasm/Cargo.lock index 80816d3f..09074be0 100644 --- a/multisig/wasm/Cargo.lock +++ b/multisig/wasm/Cargo.lock @@ -123,6 +123,7 @@ version = "0.0.0" dependencies = [ "bridge-proxy", "bridged-tokens-wrapper", + "eth-address", "max-bridged-amount-module", "multiversx-sc", "transaction",