From 0342c8a267a23ce6b869e1b1a26e722a969a7c51 Mon Sep 17 00:00:00 2001 From: BiancaIalangi Date: Mon, 19 Aug 2024 13:02:30 +0300 Subject: [PATCH 1/3] proxy gen - add test for ManagedOption type name --- .../sc-config.toml | 3 + .../src/dummy_module.rs | 2 - .../rust-testing-framework-tester/src/lib.rs | 16 +- .../rust_testing_framework_tester_proxy.rs | 408 ++++++++++++++++++ .../tests/tester_blackbox_test.rs | 117 ++--- .../wasm/src/lib.rs | 5 +- 6 files changed, 491 insertions(+), 60 deletions(-) create mode 100644 contracts/feature-tests/rust-testing-framework-tester/src/rust_testing_framework_tester_proxy.rs diff --git a/contracts/feature-tests/rust-testing-framework-tester/sc-config.toml b/contracts/feature-tests/rust-testing-framework-tester/sc-config.toml index 330cdda658..c33c94d1ab 100644 --- a/contracts/feature-tests/rust-testing-framework-tester/sc-config.toml +++ b/contracts/feature-tests/rust-testing-framework-tester/sc-config.toml @@ -4,3 +4,6 @@ main = "rust-testing-framework-tester" # the only purpose of this config is to specify the allocator [contracts.rust-testing-framework-tester] allocator = "static64k" + +[[proxy]] +path = "src/rust_testing_framework_tester_proxy.rs" diff --git a/contracts/feature-tests/rust-testing-framework-tester/src/dummy_module.rs b/contracts/feature-tests/rust-testing-framework-tester/src/dummy_module.rs index 76721a8fc4..7db5c9379d 100644 --- a/contracts/feature-tests/rust-testing-framework-tester/src/dummy_module.rs +++ b/contracts/feature-tests/rust-testing-framework-tester/src/dummy_module.rs @@ -1,5 +1,3 @@ -multiversx_sc::imports!(); - #[multiversx_sc::module] pub trait DummyModule { fn some_function(&self) -> BigUint { diff --git a/contracts/feature-tests/rust-testing-framework-tester/src/lib.rs b/contracts/feature-tests/rust-testing-framework-tester/src/lib.rs index 4133f3f039..d40eac5613 100644 --- a/contracts/feature-tests/rust-testing-framework-tester/src/lib.rs +++ b/contracts/feature-tests/rust-testing-framework-tester/src/lib.rs @@ -1,11 +1,12 @@ #![no_std] -multiversx_sc::imports!(); -multiversx_sc::derive_imports!(); +use multiversx_sc::proxy_imports::*; pub mod dummy_module; +pub mod rust_testing_framework_tester_proxy; -#[derive(TopEncode, TopDecode, TypeAbi, Clone, Debug, PartialEq, Eq)] +#[type_abi] +#[derive(TopEncode, TopDecode, Clone, Debug, PartialEq, Eq)] pub struct NftDummyAttributes { pub creation_epoch: u64, pub cool_factor: u8, @@ -228,6 +229,15 @@ pub trait RustTestingFrameworkTester: dummy_module::DummyModule { sc_panic!("Oh no!"); } + /// Tests how is generated type name in proxy + #[endpoint] + fn type_managed_option( + &self, + managed_option: ManagedOption, + ) -> ManagedOption { + managed_option + } + fn get_val(&self) -> BigUint { self.total_value().get() } diff --git a/contracts/feature-tests/rust-testing-framework-tester/src/rust_testing_framework_tester_proxy.rs b/contracts/feature-tests/rust-testing-framework-tester/src/rust_testing_framework_tester_proxy.rs new file mode 100644 index 0000000000..13cb9b49e5 --- /dev/null +++ b/contracts/feature-tests/rust-testing-framework-tester/src/rust_testing_framework_tester_proxy.rs @@ -0,0 +1,408 @@ +// Code generated by the multiversx-sc proxy generator. DO NOT EDIT. + +//////////////////////////////////////////////////// +////////////////// AUTO-GENERATED ////////////////// +//////////////////////////////////////////////////// + +#![allow(dead_code)] +#![allow(clippy::all)] + +use multiversx_sc::proxy_imports::*; + +pub struct RustTestingFrameworkTesterProxy; + +impl TxProxyTrait for RustTestingFrameworkTesterProxy +where + Env: TxEnv, + From: TxFrom, + To: TxTo, + Gas: TxGas, +{ + type TxProxyMethods = RustTestingFrameworkTesterProxyMethods; + + fn proxy_methods(self, tx: Tx) -> Self::TxProxyMethods { + RustTestingFrameworkTesterProxyMethods { wrapped_tx: tx } + } +} + +pub struct RustTestingFrameworkTesterProxyMethods +where + Env: TxEnv, + From: TxFrom, + To: TxTo, + Gas: TxGas, +{ + wrapped_tx: Tx, +} + +#[rustfmt::skip] +impl RustTestingFrameworkTesterProxyMethods +where + Env: TxEnv, + Env::Api: VMApi, + From: TxFrom, + Gas: TxGas, +{ + pub fn init( + self, + ) -> TxTypedDeploy> { + self.wrapped_tx + .payment(NotPayable) + .raw_deploy() + .original_result() + } +} + +#[rustfmt::skip] +impl RustTestingFrameworkTesterProxyMethods +where + Env: TxEnv, + Env::Api: VMApi, + From: TxFrom, + To: TxTo, + Gas: TxGas, +{ + pub fn sum< + Arg0: ProxyArg>, + Arg1: ProxyArg>, + >( + self, + first: Arg0, + second: Arg1, + ) -> TxTypedCall> { + self.wrapped_tx + .payment(NotPayable) + .raw_call("sum") + .argument(&first) + .argument(&second) + .original_result() + } + + pub fn sum_sc_result< + Arg0: ProxyArg>, + Arg1: ProxyArg>, + >( + self, + first: Arg0, + second: Arg1, + ) -> TxTypedCall> { + self.wrapped_tx + .payment(NotPayable) + .raw_call("sum_sc_result") + .argument(&first) + .argument(&second) + .original_result() + } + + pub fn get_caller_legacy( + self, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("get_caller_legacy") + .original_result() + } + + pub fn get_egld_balance( + self, + ) -> TxTypedCall> { + self.wrapped_tx + .payment(NotPayable) + .raw_call("get_egld_balance") + .original_result() + } + + pub fn get_esdt_balance< + Arg0: ProxyArg>, + Arg1: ProxyArg, + >( + self, + token_id: Arg0, + nonce: Arg1, + ) -> TxTypedCall> { + self.wrapped_tx + .payment(NotPayable) + .raw_call("get_esdt_balance") + .argument(&token_id) + .argument(&nonce) + .original_result() + } + + pub fn receive_egld( + self, + ) -> TxTypedCall> { + self.wrapped_tx + .raw_call("receive_egld") + .original_result() + } + + pub fn recieve_egld_half( + self, + ) -> TxTypedCall { + self.wrapped_tx + .raw_call("recieve_egld_half") + .original_result() + } + + pub fn receive_esdt( + self, + ) -> TxTypedCall, BigUint)> { + self.wrapped_tx + .raw_call("receive_esdt") + .original_result() + } + + pub fn reject_payment( + self, + ) -> TxTypedCall { + self.wrapped_tx + .raw_call("reject_payment") + .original_result() + } + + pub fn receive_esdt_half( + self, + ) -> TxTypedCall { + self.wrapped_tx + .raw_call("receive_esdt_half") + .original_result() + } + + pub fn receive_multi_esdt( + self, + ) -> TxTypedCall>> { + self.wrapped_tx + .raw_call("receive_multi_esdt") + .original_result() + } + + pub fn send_nft< + Arg0: ProxyArg>, + Arg1: ProxyArg>, + Arg2: ProxyArg, + Arg3: ProxyArg>, + >( + self, + to: Arg0, + token_id: Arg1, + nft_nonce: Arg2, + amount: Arg3, + ) -> TxTypedCall { + self.wrapped_tx + .raw_call("send_nft") + .argument(&to) + .argument(&token_id) + .argument(&nft_nonce) + .argument(&amount) + .original_result() + } + + pub fn mint_esdt< + Arg0: ProxyArg>, + Arg1: ProxyArg, + Arg2: ProxyArg>, + >( + self, + token_id: Arg0, + nonce: Arg1, + amount: Arg2, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("mint_esdt") + .argument(&token_id) + .argument(&nonce) + .argument(&amount) + .original_result() + } + + pub fn burn_esdt< + Arg0: ProxyArg>, + Arg1: ProxyArg, + Arg2: ProxyArg>, + >( + self, + token_id: Arg0, + nonce: Arg1, + amount: Arg2, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("burn_esdt") + .argument(&token_id) + .argument(&nonce) + .argument(&amount) + .original_result() + } + + pub fn create_nft< + Arg0: ProxyArg>, + Arg1: ProxyArg>, + Arg2: ProxyArg, + >( + self, + token_id: Arg0, + amount: Arg1, + attributes: Arg2, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("create_nft") + .argument(&token_id) + .argument(&amount) + .argument(&attributes) + .original_result() + } + + pub fn get_block_epoch( + self, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("get_block_epoch") + .original_result() + } + + pub fn get_block_nonce( + self, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("get_block_nonce") + .original_result() + } + + pub fn get_block_timestamp( + self, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("get_block_timestamp") + .original_result() + } + + pub fn get_random_buffer_once< + Arg0: ProxyArg, + >( + self, + len: Arg0, + ) -> TxTypedCall> { + self.wrapped_tx + .payment(NotPayable) + .raw_call("get_random_buffer_once") + .argument(&len) + .original_result() + } + + pub fn get_random_buffer_twice< + Arg0: ProxyArg, + Arg1: ProxyArg, + >( + self, + len1: Arg0, + len2: Arg1, + ) -> TxTypedCall, ManagedBuffer)> { + self.wrapped_tx + .payment(NotPayable) + .raw_call("get_random_buffer_twice") + .argument(&len1) + .argument(&len2) + .original_result() + } + + pub fn call_other_contract_execute_on_dest< + Arg0: ProxyArg>, + >( + self, + other_sc_address: Arg0, + ) -> TxTypedCall> { + self.wrapped_tx + .payment(NotPayable) + .raw_call("call_other_contract_execute_on_dest") + .argument(&other_sc_address) + .original_result() + } + + pub fn call_other_contract_add_async_call< + Arg0: ProxyArg>, + Arg1: ProxyArg>, + >( + self, + other_sc_address: Arg0, + value: Arg1, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("call_other_contract_add_async_call") + .argument(&other_sc_address) + .argument(&value) + .original_result() + } + + pub fn get_total_value( + self, + ) -> TxTypedCall> { + self.wrapped_tx + .payment(NotPayable) + .raw_call("getTotalValue") + .original_result() + } + + pub fn execute_on_dest_add_value< + Arg0: ProxyArg>, + Arg1: ProxyArg>, + >( + self, + other_sc_address: Arg0, + value: Arg1, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("execute_on_dest_add_value") + .argument(&other_sc_address) + .argument(&value) + .original_result() + } + + pub fn add< + Arg0: ProxyArg>, + >( + self, + value: Arg0, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("addValue") + .argument(&value) + .original_result() + } + + pub fn panic( + self, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("panic") + .original_result() + } + + pub fn type_managed_option< + Arg0: ProxyArg>>, + >( + self, + managed_option: Arg0, + ) -> TxTypedCall>> { + self.wrapped_tx + .payment(NotPayable) + .raw_call("type_managed_option") + .argument(&managed_option) + .original_result() + } +} + +#[type_abi] +#[derive(TopEncode, TopDecode, Clone, Debug, PartialEq, Eq)] +pub struct NftDummyAttributes { + pub creation_epoch: u64, + pub cool_factor: u8, +} diff --git a/contracts/feature-tests/rust-testing-framework-tester/tests/tester_blackbox_test.rs b/contracts/feature-tests/rust-testing-framework-tester/tests/tester_blackbox_test.rs index afdabb5199..4ecb618355 100644 --- a/contracts/feature-tests/rust-testing-framework-tester/tests/tester_blackbox_test.rs +++ b/contracts/feature-tests/rust-testing-framework-tester/tests/tester_blackbox_test.rs @@ -1,76 +1,87 @@ use multiversx_sc_scenario::imports::*; use rust_testing_framework_tester::*; -const WASM_PATH_EXPR: &str = "mxsc:output/rust-testing-framework-tester.mxsc.json"; +const CODE_PATH: MxscPath = MxscPath::new("output/rust-testing-framework-tester.mxsc.json"); +const OWNER_ADDRESS: TestAddress = TestAddress::new("owner"); +const RUST_TESTING_FRAMEWORK_TESTER_ADDRESS: TestSCAddress = + TestSCAddress::new("rust-testing-framework-tester"); fn world() -> ScenarioWorld { let mut blockchain = ScenarioWorld::new(); - blockchain.register_contract( - WASM_PATH_EXPR, - rust_testing_framework_tester::ContractBuilder, - ); + blockchain.register_contract(CODE_PATH, rust_testing_framework_tester::ContractBuilder); blockchain } +fn deploy(world: &mut ScenarioWorld) -> (ManagedBuffer, Address) { + world.account(OWNER_ADDRESS).new_address( + OWNER_ADDRESS, + 0, + RUST_TESTING_FRAMEWORK_TESTER_ADDRESS, + ); + + world + .tx() + .from(OWNER_ADDRESS) + .typed(rust_testing_framework_tester_proxy::RustTestingFrameworkTesterProxy) + .init() + .code(CODE_PATH) + .returns(ReturnsResult) + .new_address(RUST_TESTING_FRAMEWORK_TESTER_ADDRESS) + .returns(ReturnsNewAddress) + .run() +} + #[test] -#[allow(deprecated)] fn tester_deploy_test() { let mut world = world(); - let code = world.code_expression(WASM_PATH_EXPR); - let owner_address = "address:owner"; - let mut adder_contract = - ContractInfo::>::new("sc:contract"); + world.start_trace(); - world - .start_trace() - .set_state_step( - SetStateStep::new() - .put_account(owner_address, Account::new()) - .new_address(owner_address, 0, &adder_contract), - ) - .sc_deploy_use_result( - ScDeployStep::new() - .from(owner_address) - .code(code) - .call(adder_contract.init()), - |address, tr: TypedResponse| { - assert_eq!(address, adder_contract.to_address()); - assert_eq!(tr.result.unwrap(), "constructor-result"); - }, - ) - .write_scenario_trace("scenarios/trace-deploy.scen.json"); + let (returned_value, contract_address) = deploy(&mut world); + + assert_eq!(returned_value.to_string(), "constructor-result"); + assert_eq!(contract_address, RUST_TESTING_FRAMEWORK_TESTER_ADDRESS); + + world.write_scenario_trace("scenarios/trace-deploy.scen.json"); +} + +#[test] +fn tester_managed_option_test() { + let mut world = world(); + + world.start_trace(); + + let (_, contract_address) = deploy(&mut world); + + let type_number: BigUint = BigUint::zero(); + let expected_type_managed_option: ManagedOption> = + ManagedOption::some(type_number); + + let output = world + .tx() + .from(OWNER_ADDRESS) + .to(contract_address) + .typed(rust_testing_framework_tester_proxy::RustTestingFrameworkTesterProxy) + .type_managed_option(expected_type_managed_option.clone()) + .returns(ReturnsResult) + .run(); + + assert_eq!(output, expected_type_managed_option); + world.write_scenario_trace("scenarios/trace-deploy.scen.json"); } #[test] -#[allow(deprecated)] fn tester_deploy_test_spawned_thread() { let handler = std::thread::spawn(|| { let mut world = world(); - let code = world.code_expression(WASM_PATH_EXPR); - - let owner_address = "address:owner"; - let mut adder_contract = - ContractInfo::>::new("sc:contract"); - - world - .start_trace() - .set_state_step( - SetStateStep::new() - .put_account(owner_address, Account::new()) - .new_address(owner_address, 0, &adder_contract), - ) - .sc_deploy_use_result( - ScDeployStep::new() - .from(owner_address) - .code(code) - .call(adder_contract.init()), - |address, tr: TypedResponse| { - assert_eq!(address, adder_contract.to_address()); - assert_eq!(tr.result.unwrap(), "constructor-result"); - }, - ) - .write_scenario_trace("scenarios/trace-deploy.scen.json"); + + world.start_trace(); + let (returned_value, contract_address) = deploy(&mut world); + + assert_eq!(returned_value.to_string(), "constructor-result"); + assert_eq!(contract_address, RUST_TESTING_FRAMEWORK_TESTER_ADDRESS); + + world.write_scenario_trace("scenarios/trace-deploy.scen.json"); }); handler.join().unwrap(); diff --git a/contracts/feature-tests/rust-testing-framework-tester/wasm/src/lib.rs b/contracts/feature-tests/rust-testing-framework-tester/wasm/src/lib.rs index 3943837d34..2c9fc57d28 100644 --- a/contracts/feature-tests/rust-testing-framework-tester/wasm/src/lib.rs +++ b/contracts/feature-tests/rust-testing-framework-tester/wasm/src/lib.rs @@ -5,9 +5,9 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 26 +// Endpoints: 27 // Async Callback: 1 -// Total number of exported functions: 28 +// Total number of exported functions: 29 #![no_std] @@ -44,6 +44,7 @@ multiversx_sc_wasm_adapter::endpoints! { execute_on_dest_add_value => execute_on_dest_add_value addValue => add panic => panic + type_managed_option => type_managed_option ) } From 581c4d41b88c075b2b120e4114d384e7be218b9e Mon Sep 17 00:00:00 2001 From: BiancaIalangi Date: Mon, 19 Aug 2024 15:28:48 +0300 Subject: [PATCH 2/3] proxy gen - move test to basic-features --- .../basic-features/sc-config.toml | 8 +++- .../src/basic_features_proxy.rs | 14 +++++++ .../basic-features/src/echo_managed.rs | 8 +++- .../basic_features_managed_option_test.rs | 41 +++++++++++++++++++ .../basic-features/wasm/src/lib.rs | 5 ++- .../rust-testing-framework-tester/src/lib.rs | 9 ---- .../rust_testing_framework_tester_proxy.rs | 13 ------ .../tests/tester_blackbox_test.rs | 25 ----------- .../wasm/src/lib.rs | 5 +-- 9 files changed, 74 insertions(+), 54 deletions(-) create mode 100644 contracts/feature-tests/basic-features/tests/basic_features_managed_option_test.rs diff --git a/contracts/feature-tests/basic-features/sc-config.toml b/contracts/feature-tests/basic-features/sc-config.toml index 82698d1dab..a2bf2ec189 100644 --- a/contracts/feature-tests/basic-features/sc-config.toml +++ b/contracts/feature-tests/basic-features/sc-config.toml @@ -12,4 +12,10 @@ kill_legacy_callback = true [[proxy]] path = "src/basic_features_proxy.rs" add-unlabelled = false -add-endpoints = ["init", "store_bytes", "load_bytes", "returns_egld_decimal"] +add-endpoints = [ + "init", + "store_bytes", + "load_bytes", + "returns_egld_decimal", + "echo_managed_option", +] diff --git a/contracts/feature-tests/basic-features/src/basic_features_proxy.rs b/contracts/feature-tests/basic-features/src/basic_features_proxy.rs index 469b2d3323..78e267f6bc 100644 --- a/contracts/feature-tests/basic-features/src/basic_features_proxy.rs +++ b/contracts/feature-tests/basic-features/src/basic_features_proxy.rs @@ -62,6 +62,20 @@ where To: TxTo, Gas: TxGas, { + /// This tests how is generated type name in proxy + pub fn echo_managed_option< + Arg0: ProxyArg>>, + >( + self, + mo: Arg0, + ) -> TxTypedCall>> { + self.wrapped_tx + .payment(NotPayable) + .raw_call("echo_managed_option") + .argument(&mo) + .original_result() + } + pub fn load_bytes( self, ) -> TxTypedCall> { diff --git a/contracts/feature-tests/basic-features/src/echo_managed.rs b/contracts/feature-tests/basic-features/src/echo_managed.rs index 62ee33a7a7..17084a26c8 100644 --- a/contracts/feature-tests/basic-features/src/echo_managed.rs +++ b/contracts/feature-tests/basic-features/src/echo_managed.rs @@ -1,4 +1,4 @@ -multiversx_sc::imports!(); +use multiversx_sc::imports::*; /// Test endpoint argument and result serialization. #[multiversx_sc::module] @@ -23,6 +23,12 @@ pub trait EchoManagedTypes { ma } + /// This tests how is generated type name in proxy + #[endpoint] + fn echo_managed_option(&self, mo: ManagedOption) -> ManagedOption { + mo + } + /// This tests that nested serialization of big ints within unmanaged types works. #[endpoint] fn echo_big_int_managed_vec(&self, x: ManagedVec) -> ManagedVec { diff --git a/contracts/feature-tests/basic-features/tests/basic_features_managed_option_test.rs b/contracts/feature-tests/basic-features/tests/basic_features_managed_option_test.rs new file mode 100644 index 0000000000..38d5730c03 --- /dev/null +++ b/contracts/feature-tests/basic-features/tests/basic_features_managed_option_test.rs @@ -0,0 +1,41 @@ +use imports::{MxscPath, ReturnsResult, TestAddress, TestSCAddress}; +use multiversx_sc::types::{BigUint, ManagedOption}; +use multiversx_sc_scenario::{api::StaticApi, imports, ScenarioTxRun, ScenarioWorld}; + +const OWNER_ADDRESS: TestAddress = TestAddress::new("owner"); +const BASIC_FEATURES_ADDRESS: TestSCAddress = TestSCAddress::new("basic-features"); +const BASIC_FEATURES_PATH: MxscPath = MxscPath::new("output/basic-features.mxsc.json"); + +fn world() -> ScenarioWorld { + let mut blockchain = ScenarioWorld::new(); + + blockchain.register_contract(BASIC_FEATURES_PATH, basic_features::ContractBuilder); + + blockchain.account(OWNER_ADDRESS).nonce(1); + blockchain + .account(BASIC_FEATURES_ADDRESS) + .nonce(1) + .code(BASIC_FEATURES_PATH); + + blockchain +} + +#[test] +fn managed_option_test() { + let mut world = world(); + + let type_number: BigUint = BigUint::zero(); + let expected_type_managed_option: ManagedOption> = + ManagedOption::some(type_number); + + let output = world + .tx() + .from(OWNER_ADDRESS) + .to(BASIC_FEATURES_ADDRESS) + .typed(basic_features::basic_features_proxy::BasicFeaturesProxy) + .echo_managed_option(expected_type_managed_option.clone()) + .returns(ReturnsResult) + .run(); + + assert_eq!(output, expected_type_managed_option); +} diff --git a/contracts/feature-tests/basic-features/wasm/src/lib.rs b/contracts/feature-tests/basic-features/wasm/src/lib.rs index 887b75bcd5..18cd29cd68 100644 --- a/contracts/feature-tests/basic-features/wasm/src/lib.rs +++ b/contracts/feature-tests/basic-features/wasm/src/lib.rs @@ -5,9 +5,9 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 403 +// Endpoints: 404 // Async Callback: 1 -// Total number of exported functions: 405 +// Total number of exported functions: 406 #![no_std] @@ -169,6 +169,7 @@ multiversx_sc_wasm_adapter::endpoints! { echo_big_int => echo_big_int echo_managed_buffer => echo_managed_buffer echo_managed_address => echo_managed_address + echo_managed_option => echo_managed_option echo_big_int_managed_vec => echo_big_int_managed_vec echo_big_int_tuple => echo_big_int_tuple echo_big_int_option => echo_big_int_option diff --git a/contracts/feature-tests/rust-testing-framework-tester/src/lib.rs b/contracts/feature-tests/rust-testing-framework-tester/src/lib.rs index d40eac5613..ad3766e123 100644 --- a/contracts/feature-tests/rust-testing-framework-tester/src/lib.rs +++ b/contracts/feature-tests/rust-testing-framework-tester/src/lib.rs @@ -229,15 +229,6 @@ pub trait RustTestingFrameworkTester: dummy_module::DummyModule { sc_panic!("Oh no!"); } - /// Tests how is generated type name in proxy - #[endpoint] - fn type_managed_option( - &self, - managed_option: ManagedOption, - ) -> ManagedOption { - managed_option - } - fn get_val(&self) -> BigUint { self.total_value().get() } diff --git a/contracts/feature-tests/rust-testing-framework-tester/src/rust_testing_framework_tester_proxy.rs b/contracts/feature-tests/rust-testing-framework-tester/src/rust_testing_framework_tester_proxy.rs index 13cb9b49e5..c2901b7b47 100644 --- a/contracts/feature-tests/rust-testing-framework-tester/src/rust_testing_framework_tester_proxy.rs +++ b/contracts/feature-tests/rust-testing-framework-tester/src/rust_testing_framework_tester_proxy.rs @@ -385,19 +385,6 @@ where .raw_call("panic") .original_result() } - - pub fn type_managed_option< - Arg0: ProxyArg>>, - >( - self, - managed_option: Arg0, - ) -> TxTypedCall>> { - self.wrapped_tx - .payment(NotPayable) - .raw_call("type_managed_option") - .argument(&managed_option) - .original_result() - } } #[type_abi] diff --git a/contracts/feature-tests/rust-testing-framework-tester/tests/tester_blackbox_test.rs b/contracts/feature-tests/rust-testing-framework-tester/tests/tester_blackbox_test.rs index 4ecb618355..8c16b5bd9e 100644 --- a/contracts/feature-tests/rust-testing-framework-tester/tests/tester_blackbox_test.rs +++ b/contracts/feature-tests/rust-testing-framework-tester/tests/tester_blackbox_test.rs @@ -45,31 +45,6 @@ fn tester_deploy_test() { world.write_scenario_trace("scenarios/trace-deploy.scen.json"); } -#[test] -fn tester_managed_option_test() { - let mut world = world(); - - world.start_trace(); - - let (_, contract_address) = deploy(&mut world); - - let type_number: BigUint = BigUint::zero(); - let expected_type_managed_option: ManagedOption> = - ManagedOption::some(type_number); - - let output = world - .tx() - .from(OWNER_ADDRESS) - .to(contract_address) - .typed(rust_testing_framework_tester_proxy::RustTestingFrameworkTesterProxy) - .type_managed_option(expected_type_managed_option.clone()) - .returns(ReturnsResult) - .run(); - - assert_eq!(output, expected_type_managed_option); - world.write_scenario_trace("scenarios/trace-deploy.scen.json"); -} - #[test] fn tester_deploy_test_spawned_thread() { let handler = std::thread::spawn(|| { diff --git a/contracts/feature-tests/rust-testing-framework-tester/wasm/src/lib.rs b/contracts/feature-tests/rust-testing-framework-tester/wasm/src/lib.rs index 2c9fc57d28..3943837d34 100644 --- a/contracts/feature-tests/rust-testing-framework-tester/wasm/src/lib.rs +++ b/contracts/feature-tests/rust-testing-framework-tester/wasm/src/lib.rs @@ -5,9 +5,9 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 27 +// Endpoints: 26 // Async Callback: 1 -// Total number of exported functions: 29 +// Total number of exported functions: 28 #![no_std] @@ -44,7 +44,6 @@ multiversx_sc_wasm_adapter::endpoints! { execute_on_dest_add_value => execute_on_dest_add_value addValue => add panic => panic - type_managed_option => type_managed_option ) } From d235aeb96d8752705c200ed5404db7af8473d0af Mon Sep 17 00:00:00 2001 From: BiancaIalangi Date: Mon, 19 Aug 2024 17:17:21 +0300 Subject: [PATCH 3/3] proxy gen - revert rust-testing-framework-tester upgrade --- .../sc-config.toml | 3 - .../src/dummy_module.rs | 2 + .../rust-testing-framework-tester/src/lib.rs | 7 +- .../rust_testing_framework_tester_proxy.rs | 395 ------------------ .../tests/tester_blackbox_test.rs | 88 ++-- 5 files changed, 56 insertions(+), 439 deletions(-) delete mode 100644 contracts/feature-tests/rust-testing-framework-tester/src/rust_testing_framework_tester_proxy.rs diff --git a/contracts/feature-tests/rust-testing-framework-tester/sc-config.toml b/contracts/feature-tests/rust-testing-framework-tester/sc-config.toml index c33c94d1ab..330cdda658 100644 --- a/contracts/feature-tests/rust-testing-framework-tester/sc-config.toml +++ b/contracts/feature-tests/rust-testing-framework-tester/sc-config.toml @@ -4,6 +4,3 @@ main = "rust-testing-framework-tester" # the only purpose of this config is to specify the allocator [contracts.rust-testing-framework-tester] allocator = "static64k" - -[[proxy]] -path = "src/rust_testing_framework_tester_proxy.rs" diff --git a/contracts/feature-tests/rust-testing-framework-tester/src/dummy_module.rs b/contracts/feature-tests/rust-testing-framework-tester/src/dummy_module.rs index 7db5c9379d..76721a8fc4 100644 --- a/contracts/feature-tests/rust-testing-framework-tester/src/dummy_module.rs +++ b/contracts/feature-tests/rust-testing-framework-tester/src/dummy_module.rs @@ -1,3 +1,5 @@ +multiversx_sc::imports!(); + #[multiversx_sc::module] pub trait DummyModule { fn some_function(&self) -> BigUint { diff --git a/contracts/feature-tests/rust-testing-framework-tester/src/lib.rs b/contracts/feature-tests/rust-testing-framework-tester/src/lib.rs index ad3766e123..4133f3f039 100644 --- a/contracts/feature-tests/rust-testing-framework-tester/src/lib.rs +++ b/contracts/feature-tests/rust-testing-framework-tester/src/lib.rs @@ -1,12 +1,11 @@ #![no_std] -use multiversx_sc::proxy_imports::*; +multiversx_sc::imports!(); +multiversx_sc::derive_imports!(); pub mod dummy_module; -pub mod rust_testing_framework_tester_proxy; -#[type_abi] -#[derive(TopEncode, TopDecode, Clone, Debug, PartialEq, Eq)] +#[derive(TopEncode, TopDecode, TypeAbi, Clone, Debug, PartialEq, Eq)] pub struct NftDummyAttributes { pub creation_epoch: u64, pub cool_factor: u8, diff --git a/contracts/feature-tests/rust-testing-framework-tester/src/rust_testing_framework_tester_proxy.rs b/contracts/feature-tests/rust-testing-framework-tester/src/rust_testing_framework_tester_proxy.rs deleted file mode 100644 index c2901b7b47..0000000000 --- a/contracts/feature-tests/rust-testing-framework-tester/src/rust_testing_framework_tester_proxy.rs +++ /dev/null @@ -1,395 +0,0 @@ -// Code generated by the multiversx-sc proxy generator. DO NOT EDIT. - -//////////////////////////////////////////////////// -////////////////// AUTO-GENERATED ////////////////// -//////////////////////////////////////////////////// - -#![allow(dead_code)] -#![allow(clippy::all)] - -use multiversx_sc::proxy_imports::*; - -pub struct RustTestingFrameworkTesterProxy; - -impl TxProxyTrait for RustTestingFrameworkTesterProxy -where - Env: TxEnv, - From: TxFrom, - To: TxTo, - Gas: TxGas, -{ - type TxProxyMethods = RustTestingFrameworkTesterProxyMethods; - - fn proxy_methods(self, tx: Tx) -> Self::TxProxyMethods { - RustTestingFrameworkTesterProxyMethods { wrapped_tx: tx } - } -} - -pub struct RustTestingFrameworkTesterProxyMethods -where - Env: TxEnv, - From: TxFrom, - To: TxTo, - Gas: TxGas, -{ - wrapped_tx: Tx, -} - -#[rustfmt::skip] -impl RustTestingFrameworkTesterProxyMethods -where - Env: TxEnv, - Env::Api: VMApi, - From: TxFrom, - Gas: TxGas, -{ - pub fn init( - self, - ) -> TxTypedDeploy> { - self.wrapped_tx - .payment(NotPayable) - .raw_deploy() - .original_result() - } -} - -#[rustfmt::skip] -impl RustTestingFrameworkTesterProxyMethods -where - Env: TxEnv, - Env::Api: VMApi, - From: TxFrom, - To: TxTo, - Gas: TxGas, -{ - pub fn sum< - Arg0: ProxyArg>, - Arg1: ProxyArg>, - >( - self, - first: Arg0, - second: Arg1, - ) -> TxTypedCall> { - self.wrapped_tx - .payment(NotPayable) - .raw_call("sum") - .argument(&first) - .argument(&second) - .original_result() - } - - pub fn sum_sc_result< - Arg0: ProxyArg>, - Arg1: ProxyArg>, - >( - self, - first: Arg0, - second: Arg1, - ) -> TxTypedCall> { - self.wrapped_tx - .payment(NotPayable) - .raw_call("sum_sc_result") - .argument(&first) - .argument(&second) - .original_result() - } - - pub fn get_caller_legacy( - self, - ) -> TxTypedCall { - self.wrapped_tx - .payment(NotPayable) - .raw_call("get_caller_legacy") - .original_result() - } - - pub fn get_egld_balance( - self, - ) -> TxTypedCall> { - self.wrapped_tx - .payment(NotPayable) - .raw_call("get_egld_balance") - .original_result() - } - - pub fn get_esdt_balance< - Arg0: ProxyArg>, - Arg1: ProxyArg, - >( - self, - token_id: Arg0, - nonce: Arg1, - ) -> TxTypedCall> { - self.wrapped_tx - .payment(NotPayable) - .raw_call("get_esdt_balance") - .argument(&token_id) - .argument(&nonce) - .original_result() - } - - pub fn receive_egld( - self, - ) -> TxTypedCall> { - self.wrapped_tx - .raw_call("receive_egld") - .original_result() - } - - pub fn recieve_egld_half( - self, - ) -> TxTypedCall { - self.wrapped_tx - .raw_call("recieve_egld_half") - .original_result() - } - - pub fn receive_esdt( - self, - ) -> TxTypedCall, BigUint)> { - self.wrapped_tx - .raw_call("receive_esdt") - .original_result() - } - - pub fn reject_payment( - self, - ) -> TxTypedCall { - self.wrapped_tx - .raw_call("reject_payment") - .original_result() - } - - pub fn receive_esdt_half( - self, - ) -> TxTypedCall { - self.wrapped_tx - .raw_call("receive_esdt_half") - .original_result() - } - - pub fn receive_multi_esdt( - self, - ) -> TxTypedCall>> { - self.wrapped_tx - .raw_call("receive_multi_esdt") - .original_result() - } - - pub fn send_nft< - Arg0: ProxyArg>, - Arg1: ProxyArg>, - Arg2: ProxyArg, - Arg3: ProxyArg>, - >( - self, - to: Arg0, - token_id: Arg1, - nft_nonce: Arg2, - amount: Arg3, - ) -> TxTypedCall { - self.wrapped_tx - .raw_call("send_nft") - .argument(&to) - .argument(&token_id) - .argument(&nft_nonce) - .argument(&amount) - .original_result() - } - - pub fn mint_esdt< - Arg0: ProxyArg>, - Arg1: ProxyArg, - Arg2: ProxyArg>, - >( - self, - token_id: Arg0, - nonce: Arg1, - amount: Arg2, - ) -> TxTypedCall { - self.wrapped_tx - .payment(NotPayable) - .raw_call("mint_esdt") - .argument(&token_id) - .argument(&nonce) - .argument(&amount) - .original_result() - } - - pub fn burn_esdt< - Arg0: ProxyArg>, - Arg1: ProxyArg, - Arg2: ProxyArg>, - >( - self, - token_id: Arg0, - nonce: Arg1, - amount: Arg2, - ) -> TxTypedCall { - self.wrapped_tx - .payment(NotPayable) - .raw_call("burn_esdt") - .argument(&token_id) - .argument(&nonce) - .argument(&amount) - .original_result() - } - - pub fn create_nft< - Arg0: ProxyArg>, - Arg1: ProxyArg>, - Arg2: ProxyArg, - >( - self, - token_id: Arg0, - amount: Arg1, - attributes: Arg2, - ) -> TxTypedCall { - self.wrapped_tx - .payment(NotPayable) - .raw_call("create_nft") - .argument(&token_id) - .argument(&amount) - .argument(&attributes) - .original_result() - } - - pub fn get_block_epoch( - self, - ) -> TxTypedCall { - self.wrapped_tx - .payment(NotPayable) - .raw_call("get_block_epoch") - .original_result() - } - - pub fn get_block_nonce( - self, - ) -> TxTypedCall { - self.wrapped_tx - .payment(NotPayable) - .raw_call("get_block_nonce") - .original_result() - } - - pub fn get_block_timestamp( - self, - ) -> TxTypedCall { - self.wrapped_tx - .payment(NotPayable) - .raw_call("get_block_timestamp") - .original_result() - } - - pub fn get_random_buffer_once< - Arg0: ProxyArg, - >( - self, - len: Arg0, - ) -> TxTypedCall> { - self.wrapped_tx - .payment(NotPayable) - .raw_call("get_random_buffer_once") - .argument(&len) - .original_result() - } - - pub fn get_random_buffer_twice< - Arg0: ProxyArg, - Arg1: ProxyArg, - >( - self, - len1: Arg0, - len2: Arg1, - ) -> TxTypedCall, ManagedBuffer)> { - self.wrapped_tx - .payment(NotPayable) - .raw_call("get_random_buffer_twice") - .argument(&len1) - .argument(&len2) - .original_result() - } - - pub fn call_other_contract_execute_on_dest< - Arg0: ProxyArg>, - >( - self, - other_sc_address: Arg0, - ) -> TxTypedCall> { - self.wrapped_tx - .payment(NotPayable) - .raw_call("call_other_contract_execute_on_dest") - .argument(&other_sc_address) - .original_result() - } - - pub fn call_other_contract_add_async_call< - Arg0: ProxyArg>, - Arg1: ProxyArg>, - >( - self, - other_sc_address: Arg0, - value: Arg1, - ) -> TxTypedCall { - self.wrapped_tx - .payment(NotPayable) - .raw_call("call_other_contract_add_async_call") - .argument(&other_sc_address) - .argument(&value) - .original_result() - } - - pub fn get_total_value( - self, - ) -> TxTypedCall> { - self.wrapped_tx - .payment(NotPayable) - .raw_call("getTotalValue") - .original_result() - } - - pub fn execute_on_dest_add_value< - Arg0: ProxyArg>, - Arg1: ProxyArg>, - >( - self, - other_sc_address: Arg0, - value: Arg1, - ) -> TxTypedCall { - self.wrapped_tx - .payment(NotPayable) - .raw_call("execute_on_dest_add_value") - .argument(&other_sc_address) - .argument(&value) - .original_result() - } - - pub fn add< - Arg0: ProxyArg>, - >( - self, - value: Arg0, - ) -> TxTypedCall { - self.wrapped_tx - .payment(NotPayable) - .raw_call("addValue") - .argument(&value) - .original_result() - } - - pub fn panic( - self, - ) -> TxTypedCall { - self.wrapped_tx - .payment(NotPayable) - .raw_call("panic") - .original_result() - } -} - -#[type_abi] -#[derive(TopEncode, TopDecode, Clone, Debug, PartialEq, Eq)] -pub struct NftDummyAttributes { - pub creation_epoch: u64, - pub cool_factor: u8, -} diff --git a/contracts/feature-tests/rust-testing-framework-tester/tests/tester_blackbox_test.rs b/contracts/feature-tests/rust-testing-framework-tester/tests/tester_blackbox_test.rs index 8c16b5bd9e..afdabb5199 100644 --- a/contracts/feature-tests/rust-testing-framework-tester/tests/tester_blackbox_test.rs +++ b/contracts/feature-tests/rust-testing-framework-tester/tests/tester_blackbox_test.rs @@ -1,62 +1,76 @@ use multiversx_sc_scenario::imports::*; use rust_testing_framework_tester::*; -const CODE_PATH: MxscPath = MxscPath::new("output/rust-testing-framework-tester.mxsc.json"); -const OWNER_ADDRESS: TestAddress = TestAddress::new("owner"); -const RUST_TESTING_FRAMEWORK_TESTER_ADDRESS: TestSCAddress = - TestSCAddress::new("rust-testing-framework-tester"); +const WASM_PATH_EXPR: &str = "mxsc:output/rust-testing-framework-tester.mxsc.json"; fn world() -> ScenarioWorld { let mut blockchain = ScenarioWorld::new(); - blockchain.register_contract(CODE_PATH, rust_testing_framework_tester::ContractBuilder); - blockchain -} - -fn deploy(world: &mut ScenarioWorld) -> (ManagedBuffer, Address) { - world.account(OWNER_ADDRESS).new_address( - OWNER_ADDRESS, - 0, - RUST_TESTING_FRAMEWORK_TESTER_ADDRESS, + blockchain.register_contract( + WASM_PATH_EXPR, + rust_testing_framework_tester::ContractBuilder, ); - - world - .tx() - .from(OWNER_ADDRESS) - .typed(rust_testing_framework_tester_proxy::RustTestingFrameworkTesterProxy) - .init() - .code(CODE_PATH) - .returns(ReturnsResult) - .new_address(RUST_TESTING_FRAMEWORK_TESTER_ADDRESS) - .returns(ReturnsNewAddress) - .run() + blockchain } #[test] +#[allow(deprecated)] fn tester_deploy_test() { let mut world = world(); + let code = world.code_expression(WASM_PATH_EXPR); - world.start_trace(); - - let (returned_value, contract_address) = deploy(&mut world); - - assert_eq!(returned_value.to_string(), "constructor-result"); - assert_eq!(contract_address, RUST_TESTING_FRAMEWORK_TESTER_ADDRESS); + let owner_address = "address:owner"; + let mut adder_contract = + ContractInfo::>::new("sc:contract"); - world.write_scenario_trace("scenarios/trace-deploy.scen.json"); + world + .start_trace() + .set_state_step( + SetStateStep::new() + .put_account(owner_address, Account::new()) + .new_address(owner_address, 0, &adder_contract), + ) + .sc_deploy_use_result( + ScDeployStep::new() + .from(owner_address) + .code(code) + .call(adder_contract.init()), + |address, tr: TypedResponse| { + assert_eq!(address, adder_contract.to_address()); + assert_eq!(tr.result.unwrap(), "constructor-result"); + }, + ) + .write_scenario_trace("scenarios/trace-deploy.scen.json"); } #[test] +#[allow(deprecated)] fn tester_deploy_test_spawned_thread() { let handler = std::thread::spawn(|| { let mut world = world(); + let code = world.code_expression(WASM_PATH_EXPR); - world.start_trace(); - let (returned_value, contract_address) = deploy(&mut world); - - assert_eq!(returned_value.to_string(), "constructor-result"); - assert_eq!(contract_address, RUST_TESTING_FRAMEWORK_TESTER_ADDRESS); + let owner_address = "address:owner"; + let mut adder_contract = + ContractInfo::>::new("sc:contract"); - world.write_scenario_trace("scenarios/trace-deploy.scen.json"); + world + .start_trace() + .set_state_step( + SetStateStep::new() + .put_account(owner_address, Account::new()) + .new_address(owner_address, 0, &adder_contract), + ) + .sc_deploy_use_result( + ScDeployStep::new() + .from(owner_address) + .code(code) + .call(adder_contract.init()), + |address, tr: TypedResponse| { + assert_eq!(address, adder_contract.to_address()); + assert_eq!(tr.result.unwrap(), "constructor-result"); + }, + ) + .write_scenario_trace("scenarios/trace-deploy.scen.json"); }); handler.join().unwrap();