diff --git a/.github/workflows/actions-nightly.yml b/.github/workflows/actions-nightly.yml index ecd275e033..1569c9a99c 100644 --- a/.github/workflows/actions-nightly.yml +++ b/.github/workflows/actions-nightly.yml @@ -19,7 +19,7 @@ jobs: rust-toolchain: nightly-2024-05-22 path-to-sc-meta: framework/meta enable-contracts-size-report: false - mx-scenario-go-version: v2.1.0-alpha + mx-scenario-go-version: v3.0.0 coverage-args: --ignore-filename-regex='meta/src' --ignore-filename-regex='wasm-adapter' --ignore-filename-regex='benchmarks/' --ignore-filename-regex='tests/' --output ./coverage.md secrets: token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index a5c3eb476f..225a894772 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -18,7 +18,7 @@ jobs: with: rust-toolchain: 1.82 path-to-sc-meta: framework/meta - mx-scenario-go-version: v2.1.0-alpha + mx-scenario-go-version: v3.0.0 coverage-args: --ignore-filename-regex='meta/src' --ignore-filename-regex='wasm-adapter' --ignore-filename-regex='benchmarks/' --ignore-filename-regex='tests/' --output ./coverage.md secrets: token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/template-test-current.yml b/.github/workflows/template-test-current.yml index d496bb7856..78594ed1d9 100644 --- a/.github/workflows/template-test-current.yml +++ b/.github/workflows/template-test-current.yml @@ -29,7 +29,7 @@ jobs: run: | cargo install wasm-opt cargo install --path framework/meta - sc-meta install mx-scenario-go --tag v2.0.0 + sc-meta install mx-scenario-go --tag v3.0.0 which wasm-opt which mx-scenario-go diff --git a/.github/workflows/template-test-released.yml b/.github/workflows/template-test-released.yml index 5a7ad019e3..5f68dea82d 100644 --- a/.github/workflows/template-test-released.yml +++ b/.github/workflows/template-test-released.yml @@ -29,7 +29,7 @@ jobs: run: | cargo install wasm-opt cargo install --path framework/meta - sc-meta install mx-scenario-go --tag v2.0.0 + sc-meta install mx-scenario-go --tag v3.0.0 which wasm-opt which mx-scenario-go diff --git a/Cargo.lock b/Cargo.lock index f3279b7569..3a07185582 100755 --- a/Cargo.lock +++ b/Cargo.lock @@ -262,6 +262,7 @@ dependencies = [ "clap", "multiversx-sc-snippets", "serde", + "serial_test", "tokio", "toml", ] @@ -2437,9 +2438,9 @@ dependencies = [ [[package]] name = "multiversx-chain-vm-executor" -version = "0.2.0" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b59072fa0624b55ae5ae3fa6bfa91515bbeb4ac440214bc4a509e2c8806d6e9f" +checksum = "51cce7ae386960fbf5e85afe40ca16d63f926f0620ed1a36b019212b28e17219" [[package]] name = "multiversx-price-aggregator-sc" @@ -3676,6 +3677,15 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "scc" +version = "2.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94b13f8ea6177672c49d12ed964cca44836f59621981b04a3e26b87e675181de" +dependencies = [ + "sdd", +] + [[package]] name = "scenario-tester" version = "0.0.0" @@ -3719,6 +3729,12 @@ dependencies = [ "sha2", ] +[[package]] +name = "sdd" +version = "3.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "478f121bb72bbf63c52c93011ea1791dca40140dfe13f8336c4c5ac952c33aa9" + [[package]] name = "second-contract" version = "0.0.0" @@ -3874,6 +3890,31 @@ dependencies = [ "serde", ] +[[package]] +name = "serial_test" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b258109f244e1d6891bf1053a55d63a5cd4f8f4c30cf9a1280989f80e7a1fa9" +dependencies = [ + "futures", + "log", + "once_cell", + "parking_lot", + "scc", + "serial_test_derive", +] + +[[package]] +name = "serial_test_derive" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d69265a08751de7844521fd15003ae0a888e035773ba05695c5c759a6f89eef" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.77", +] + [[package]] name = "set-repeat" version = "0.0.0" diff --git a/chain/core/src/types/flags/esdt_token_type.rs b/chain/core/src/types/flags/esdt_token_type.rs index 74db07c9a6..3668ca6fe6 100644 --- a/chain/core/src/types/flags/esdt_token_type.rs +++ b/chain/core/src/types/flags/esdt_token_type.rs @@ -13,7 +13,7 @@ const ESDT_TYPE_INVALID: &[u8] = &[]; // Note: In the current implementation, SemiFungible is never returned -#[derive(TopDecode, TopEncode, NestedDecode, NestedEncode, Clone, PartialEq, Eq, Debug)] +#[derive(TopDecode, TopEncode, NestedDecode, NestedEncode, Clone, Copy, PartialEq, Eq, Debug)] pub enum EsdtTokenType { Fungible, NonFungible, diff --git a/chain/vm/Cargo.toml b/chain/vm/Cargo.toml index 0d02932800..827d55e638 100644 --- a/chain/vm/Cargo.toml +++ b/chain/vm/Cargo.toml @@ -39,4 +39,4 @@ version = "=0.11.1" path = "../core" [dependencies.multiversx-chain-vm-executor] -version = "0.2.0" +version = "0.3.0" diff --git a/chain/vm/src/tx_execution/exec_general_tx.rs b/chain/vm/src/tx_execution/exec_general_tx.rs index 2100e3fb20..53ca60bc30 100644 --- a/chain/vm/src/tx_execution/exec_general_tx.rs +++ b/chain/vm/src/tx_execution/exec_general_tx.rs @@ -52,6 +52,18 @@ pub(crate) fn create_transfer_value_log(tx_input: &TxInput, call_type: CallType) let mut data = vec![call_type.to_log_bytes(), tx_input.func_name.to_bytes()]; data.append(&mut tx_input.args.clone()); + if tx_input.esdt_values.is_empty() + && !tx_input.callback_payments.egld_value.is_zero() + && tx_input.call_type == CallType::AsyncCallback + { + return TxLog { + address: tx_input.from.clone(), + endpoint: "transferValueOnly".into(), + topics: vec![b"".to_vec(), tx_input.to.to_vec()], + data, + }; + } + let egld_value = if tx_input.call_type == CallType::AsyncCallback { &tx_input.callback_payments.egld_value } else { diff --git a/chain/vm/src/tx_execution/system_sc/system_sc_unimplemented.rs b/chain/vm/src/tx_execution/system_sc/system_sc_unimplemented.rs index cf93be7727..a324f34900 100644 --- a/chain/vm/src/tx_execution/system_sc/system_sc_unimplemented.rs +++ b/chain/vm/src/tx_execution/system_sc/system_sc_unimplemented.rs @@ -3,8 +3,8 @@ use crate::tx_mock::{BlockchainUpdate, TxCache, TxInput, TxResult}; /// Every unimplemented fn will be implemented and moved to its corresponding file. +/// /// This file will be deleted. - pub fn register_meta_esdt(tx_input: TxInput, tx_cache: TxCache) -> (TxResult, BlockchainUpdate) { unimplemented!() } diff --git a/chain/vm/src/vm_hooks/vh_dispatcher.rs b/chain/vm/src/vm_hooks/vh_dispatcher.rs index 0dbfc54051..1af9bfbb6a 100644 --- a/chain/vm/src/vm_hooks/vh_dispatcher.rs +++ b/chain/vm/src/vm_hooks/vh_dispatcher.rs @@ -1859,4 +1859,53 @@ impl VMHooks for VMHooksDispatcher { ) -> i32 { panic!("Unavailable: elliptic_curve_get_values") } + + fn is_reserved_function_name(&self, name_handle: i32) -> i32 { + panic!("Unavailable: is_reserved_function_name") + } + + fn managed_get_original_caller_addr(&self, destination_handle: i32) { + panic!("Unavailable: managed_get_original_caller_addr") + } + + fn managed_get_relayer_addr(&self, destination_handle: i32) { + panic!("Unavailable: managed_get_relayer_addr") + } + + fn managed_multi_transfer_esdt_nft_execute_by_user( + &self, + user_handle: i32, + dst_handle: i32, + token_transfers_handle: i32, + gas_limit: i64, + function_handle: i32, + arguments_handle: i32, + ) -> i32 { + panic!("Unavailable: managed_multi_transfer_esdt_nft_execute_by_user") + } + + fn managed_verify_secp256r1( + &self, + key_handle: i32, + message_handle: i32, + sig_handle: i32, + ) -> i32 { + panic!("Unavailable: managed_verify_secp256r1") + } + fn managed_verify_blssignature_share( + &self, + key_handle: i32, + message_handle: i32, + sig_handle: i32, + ) -> i32 { + panic!("Unavailable: managed_verify_blssignature_share") + } + fn managed_verify_blsaggregated_signature( + &self, + key_handle: i32, + message_handle: i32, + sig_handle: i32, + ) -> i32 { + panic!("Unavailable: managed_verify_blsaggregated_signature") + } } diff --git a/contracts/core/price-aggregator/tests/price_aggregator_whitebox_test.rs b/contracts/core/price-aggregator/tests/price_aggregator_whitebox_test.rs index f44d9f76fc..a23edf113a 100644 --- a/contracts/core/price-aggregator/tests/price_aggregator_whitebox_test.rs +++ b/contracts/core/price-aggregator/tests/price_aggregator_whitebox_test.rs @@ -2,10 +2,7 @@ use multiversx_price_aggregator_sc::{ price_aggregator_data::{OracleStatus, TimestampedPrice, TokenPair}, PriceAggregator, MAX_ROUND_DURATION_SECONDS, }; -use multiversx_sc_modules::{ - pause::EndpointWrappers as PauseEndpointWrappers, - staking::{EndpointWrappers as StakingEndpointWrappers, StakingModule}, -}; +use multiversx_sc_modules::{pause::PauseModule, staking::StakingModule}; use multiversx_sc_scenario::imports::*; pub const DECIMALS: u8 = 0; @@ -73,7 +70,7 @@ fn test_price_aggregator_submit() { .from(OWNER_ADDRESS) .to(PRICE_AGGREGATOR_ADDRESS) .whitebox(multiversx_price_aggregator_sc::contract_obj, |sc| { - sc.call_unpause_endpoint(); + sc.unpause_endpoint(); }); // submit first timestamp too old @@ -197,7 +194,7 @@ fn test_price_aggregator_submit_round_ok() { .from(OWNER_ADDRESS) .to(PRICE_AGGREGATOR_ADDRESS) .whitebox(multiversx_price_aggregator_sc::contract_obj, |sc| { - sc.call_unpause_endpoint(); + sc.unpause_endpoint(); }); // submit first @@ -304,7 +301,7 @@ fn test_price_aggregator_discarded_round() { .from(OWNER_ADDRESS) .to(PRICE_AGGREGATOR_ADDRESS) .whitebox(multiversx_price_aggregator_sc::contract_obj, |sc| { - sc.call_unpause_endpoint(); + sc.unpause_endpoint(); }); // submit first @@ -380,7 +377,7 @@ fn test_price_aggregator_slashing() { .from(OWNER_ADDRESS) .to(PRICE_AGGREGATOR_ADDRESS) .whitebox(multiversx_price_aggregator_sc::contract_obj, |sc| { - sc.call_unpause_endpoint(); + sc.unpause_endpoint(); }); world @@ -489,7 +486,7 @@ fn setup() -> (ScenarioWorld, Vec
) { .to(PRICE_AGGREGATOR_ADDRESS) .egld(STAKE_AMOUNT) .whitebox(multiversx_price_aggregator_sc::contract_obj, |sc| { - sc.call_stake(); + sc.stake(); }); } diff --git a/contracts/core/wegld-swap/src/wegld.rs b/contracts/core/wegld-swap/src/wegld.rs index 23a4493494..1c9cf11a2a 100644 --- a/contracts/core/wegld-swap/src/wegld.rs +++ b/contracts/core/wegld-swap/src/wegld.rs @@ -39,10 +39,10 @@ pub trait EgldEsdtSwap: multiversx_sc_modules::pause::PauseModule { let (payment_token, payment_amount) = self.call_value().single_fungible_esdt(); let wrapped_egld_token_id = self.wrapped_egld_token_id().get(); - require!(payment_token == wrapped_egld_token_id, "Wrong esdt token"); - require!(payment_amount > 0u32, "Must pay more than 0 tokens!"); + require!(*payment_token == wrapped_egld_token_id, "Wrong esdt token"); + require!(*payment_amount > 0u32, "Must pay more than 0 tokens!"); require!( - payment_amount <= self.get_locked_egld_balance(), + *payment_amount <= self.get_locked_egld_balance(), "Contract does not have enough funds" ); @@ -51,7 +51,7 @@ pub trait EgldEsdtSwap: multiversx_sc_modules::pause::PauseModule { // 1 wrapped eGLD = 1 eGLD, so we pay back the same amount let caller = self.blockchain().get_caller(); - self.tx().to(&caller).egld(&payment_amount).transfer(); + self.tx().to(&caller).egld(&*payment_amount).transfer(); } #[view(getLockedEgldBalance)] diff --git a/contracts/examples/adder/interactor/Cargo.toml b/contracts/examples/adder/interactor/Cargo.toml index 06507f3b74..97fbe441ed 100644 --- a/contracts/examples/adder/interactor/Cargo.toml +++ b/contracts/examples/adder/interactor/Cargo.toml @@ -24,6 +24,7 @@ clap = { version = "4.4.7", features = ["derive"] } serde = { version = "1.0", features = ["derive"] } toml = "0.8.6" tokio = { version = "1.24" } +serial_test = { version = "3.2.0" } [features] chain-simulator-tests = [] diff --git a/contracts/examples/adder/interactor/set_state.json b/contracts/examples/adder/interactor/set_state.json new file mode 100644 index 0000000000..a5115b7781 --- /dev/null +++ b/contracts/examples/adder/interactor/set_state.json @@ -0,0 +1,82 @@ +[ + { + "address": "erd1uv40ahysflse896x4ktnh6ecx43u7cmy9wnxnvcyp7deg299a4sq6vaywa", + "nonce": 5947, + "balance": "491982310359999986", + "keys": { + "454c524f4e44657364745453542d363437383930": "1209004563918244f40000", + "454c524f4e446e6f6e636550544d2d353336666162": "01", + "454c524f4e446573647450544d2d35333666616201": "08021202000122ef0108011212546573742d5061696e742d486172766573741a20e32afedc904fe1939746ad973beb383563cf63642ba669b3040f9b9428a5ed6020c4132a2e516d57564239575362674b52655a64615a434344766b454b70705a6b4d696d397563736e7857565041414c6a4374324368747470733a2f2f697066732e696f2f697066732f516d57564239575362674b52655a64615a434344766b454b70705a6b4d696d397563736e7857565041414c6a43743a3d746167733a3b6d657461646174613a516d52635039346b5872357a5a6a52477669376d4a36756e374c7078556859565234523452706963787a67596b74", + "454c524f4e44726f6c656573647450544d2d353336666162": "0a1145534454526f6c654e46544372656174650a0f45534454526f6c654e46544275726e", + "454c524f4e44657364745453542d633565303835": "1209004563918244f40000", + "454c524f4e44657364745453542d346230653865": "1209004563918244f40000", + "454c524f4e44657364744c5453542d346638343965": "1209000de0b6b3a763fc19", + "454c524f4e44657364745453542d393864633566": "1209004563918244f40000", + "454c524f4e44657364745453542d396230323030": "1209004563918244f40000", + "454c524f4e44657364745453542d386564363538": "1209004563918244f40000", + "454c524f4e44657364745453542d643862306438": "12020064", + "454c524f4e44657364745453542d363835303064": "1209004563918244f40000", + "454c524f4e44657364745453542d323833633361": "12020064", + "454c524f4e44657364745453542d333331386638": "1209004563918244f40000", + "454c524f4e44657364745453542d303637373232": "1209004563918244f40000", + "454c524f4e44657364745745474c442d613238633539": "120900389351ce08f09e12", + "454c524f4e44657364745453542d343138613232": "1209004563918244f40000", + "454c524f4e44657364745453542d656338383735": "12020064", + "454c524f4e44657364745453542d333639646531": "1209004563918244f40000", + "454c524f4e44657364745453542d373639313337": "1209004563918244f40000", + "454c524f4e44657364745453542d363434633935": "12020064", + "454c524f4e44657364745453542d623830663863": "1209004563918244f40000", + "454c524f4e4465736474475245454e2d306531363163": "120b00152d02c7e14af67fffdc", + "454c524f4e4465736474424358535542542d33393264366172": "080112020001", + "454c524f4e44657364745453542d343562383235": "12020064", + "454c524f4e44657364745453542d613562663131": "12020064", + "454c524f4e44657364745453542d623130616461": "1209004563918244f40000", + "454c524f4e44657364745453542d633933336139": "1209004563918244f40000", + "454c524f4e44657364744c5453542d376266336431": "1209000de0b6b3a763fc19", + "454c524f4e44657364745453542d336339363762": "12020064", + "454c524f4e44657364745453542d623136363735": "1209004563918244f40000", + "454c524f4e44657364745453542d303362373664": "12020064", + "454c524f4e44657364745453542d353538616434": "12020064", + "454c524f4e44657364745453542d353966316165": "1209004563918244f40000", + "454c524f4e44657364745453542d306632306637": "12020064", + "454c524f4e446573647455544b2d313464353764": "120b0001e6ce88d5ebbfd00000", + "454c524f4e44657364745453542d633636666535": "1209004563918244f40000", + "454c524f4e44657364745453542d346634303238": "12020064", + "454c524f4e44657364745453542d643964336136": "1209004563918244f40000", + "454c524f4e44657364745453542d343265356138": "1209004563918244f40000", + "454c524f4e44657364745453542d393836646663": "12020064" + }, + "code": "", + "code_hash": "", + "root_hash": "2zSeJjLqgozEQmmgDU8L0/GidcKzJOlJgwoaTUqvDFg=", + "code_metadata": "", + "owner_address": "", + "developer_reward": "0" + }, + { + "address": "erd13x29rvmp4qlgn4emgztd8jgvyzdj0p6vn37tqxas3v9mfhq4dy7shalqrx", + "nonce": 1417, + "balance": "1753855617144056", + "keys": { + "454c524f4e4465736474424358535542542d3339326436616e": "080112020001", + "454c524f4e446573647442534b2d343736343730": "120b00021e19e0c9bab23fff7b", + "454c524f4e446573647445564e544e4f544946592d393634383835": "120b00152d02c7e14af6800000", + "454c524f4e4465736474494e5445524e532d63393332356601": "0801120b0013097d1fb962e12fff47", + "454c524f4e44657364744e455453432d623635306261": "120b00d137965aa7a731800000", + "454c524f4e44657364745745474c442d613238633539": "120800010593b233281b", + "454c524f4e446e6f6e6365494e5445524e532d633933323566": "01", + "454c524f4e446e6f6e63654d4554414e46542d643062623339": "01", + "454c524f4e44726f6c6565736474494e5445524e532d633933323566": "0a1145534454526f6c654e46544372656174650a1645534454526f6c654e46544164645175616e74697479", + "454c524f4e44657364744e4943552d393730323932": "120b00d3c21bcecceda1000000", + "454c524f4e44726f6c65657364744d4554414e46542d643062623339": "0a1145534454526f6c654e4654437265617465", + "454c524f4e4465736474424358535542542d3339326436616c": "080112020001", + "454c524f4e44657364744e45543253432d306438663962": "120f0004ee2d6d3f3d6bcc25c64dc00000" + }, + "code": "", + "code_hash": "", + "root_hash": "AJ2jyOcPXgZAl0kHAlbWZIlG3F1VDtcoLAHR6eqehBA=", + "code_metadata": "", + "owner_address": "", + "developer_reward": "0" + } +] \ No newline at end of file diff --git a/contracts/examples/adder/interactor/src/basic_interactor.rs b/contracts/examples/adder/interactor/src/basic_interactor.rs index 63d71de11a..fc08f50357 100644 --- a/contracts/examples/adder/interactor/src/basic_interactor.rs +++ b/contracts/examples/adder/interactor/src/basic_interactor.rs @@ -57,7 +57,7 @@ impl AdderInteract { let adder_owner_address = interactor.register_wallet(test_wallets::heidi()).await; let wallet_address = interactor.register_wallet(test_wallets::ivan()).await; - interactor.generate_blocks_until_epoch(1).await.unwrap(); + interactor.generate_blocks(30u64).await.unwrap(); AdderInteract { interactor, diff --git a/contracts/examples/adder/interactor/tests/basic_interactor_cs_test.rs b/contracts/examples/adder/interactor/tests/basic_interactor_cs_test.rs index 1f07ee4c87..b4e9747794 100644 --- a/contracts/examples/adder/interactor/tests/basic_interactor_cs_test.rs +++ b/contracts/examples/adder/interactor/tests/basic_interactor_cs_test.rs @@ -1,6 +1,9 @@ use basic_interactor::{AdderInteract, Config}; +use multiversx_sc_snippets::{imports::Bech32Address, sdk::gateway::SetStateAccount, test_wallets}; +use serial_test::serial; #[tokio::test] +#[serial] #[cfg_attr(not(feature = "chain-simulator-tests"), ignore)] async fn simulator_upgrade_test() { let mut basic_interact = AdderInteract::new(Config::chain_simulator_config()).await; @@ -33,3 +36,70 @@ async fn simulator_upgrade_test() { let sum = basic_interact.get_sum().await; assert_eq!(sum, 7u32.into()); } + +#[tokio::test] +#[serial] +#[cfg_attr(not(feature = "chain-simulator-tests"), ignore)] +async fn set_state_cs_test() { + let account_address = test_wallets::mike(); + + let real_chain_interact = AdderInteract::new(Config::load_config()).await; + let simulator_interact = AdderInteract::new(Config::chain_simulator_config()).await; + + let account = real_chain_interact + .interactor + .get_account(&account_address.to_address()) + .await; + let keys = real_chain_interact + .interactor + .get_account_storage(&account_address.to_address()) + .await; + + let set_state_account = SetStateAccount::from(account).with_keys(keys); + let vec_state = vec![set_state_account]; + + let set_state_response = simulator_interact.interactor.set_state(vec_state).await; + + simulator_interact + .interactor + .generate_blocks(2u64) + .await + .unwrap(); + + assert!(set_state_response.is_ok()); +} + +#[tokio::test] +#[serial] +#[cfg_attr(not(feature = "chain-simulator-tests"), ignore)] +async fn set_state_from_file_cs_test() { + let account_address = test_wallets::mike(); + let account_address_2 = test_wallets::ivan(); + + let mut real_chain_interact = AdderInteract::new(Config::load_config()).await; + let simulator_interact = AdderInteract::new(Config::chain_simulator_config()).await; + + // now we should have current mike account in the set state file + real_chain_interact + .interactor + .retrieve_account(&Bech32Address::from(&account_address.to_address())) + .await; + + real_chain_interact + .interactor + .retrieve_account(&Bech32Address::from(&account_address_2.to_address())) + .await; + + let set_state_response = simulator_interact + .interactor + .set_state_for_saved_accounts() + .await; + + simulator_interact + .interactor + .generate_blocks(2u64) + .await + .unwrap(); + + assert!(set_state_response.is_ok()); +} diff --git a/contracts/examples/bonding-curve-contract/src/bonding_curve_contract.rs b/contracts/examples/bonding-curve-contract/src/bonding_curve_contract.rs index 6ab29068d3..490eb4bb42 100644 --- a/contracts/examples/bonding-curve-contract/src/bonding_curve_contract.rs +++ b/contracts/examples/bonding-curve-contract/src/bonding_curve_contract.rs @@ -20,13 +20,13 @@ pub trait Contract: #[init] fn init(&self) {} - #[payable("*")] + #[payable] #[endpoint(sellToken)] fn sell_token_endpoint(&self) { self.sell_token::