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..1cedabe2 100644 --- a/bridge-proxy/src/config.rs +++ b/bridge-proxy/src/config.rs @@ -1,19 +1,32 @@ multiversx_sc::imports!(); multiversx_sc::derive_imports!(); -use transaction::EthTransactionPayment; +use transaction::{EthTransactionPayment, EthTransaction}; #[multiversx_sc::module] 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) -> 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, + None => sc_panic!("No transaction with this id!") + } } #[view(getMultiTransferAddress)] 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..1902f57f --- /dev/null +++ b/bridge-proxy/tests/bridge_proxy_blackbox_test.rs @@ -0,0 +1,125 @@ +#![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 GAS_LIMIT: u64 = 1_000_000; +const BRIDGE_PROXY_PATH_EXPR: &str = "file:output/bridge-proxy.wasm"; + +fn world() -> ScenarioWorld { + let mut blockchain = ScenarioWorld::new(); + + blockchain.register_contract(BRIDGE_PROXY_PATH_EXPR, bridge_proxy::ContractBuilder); + blockchain +} + +#[test] +fn deploy_deposit_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), + ); +} + +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..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)] @@ -22,7 +22,8 @@ multiversx_sc_wasm_adapter::endpoints! { deposit => deposit executeWithAsnyc => execute_with_async refundTransactions => refund_transactions - setupMultiTransfer => setup_multi_transfer + 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/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/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/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/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/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..11823bb6 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", ] @@ -101,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/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..0fc3e199 100644 --- a/multisig/tests/scenario_go_test.rs +++ b/multisig/tests/scenario_go_test.rs @@ -1,46 +1,49 @@ +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..09074be0 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", ] @@ -122,6 +123,7 @@ version = "0.0.0" dependencies = [ "bridge-proxy", "bridged-tokens-wrapper", + "eth-address", "max-bridged-amount-module", "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