diff --git a/contracts/benchmarks/mappers/linked-list-repeat/sc-config.toml b/contracts/benchmarks/mappers/linked-list-repeat/sc-config.toml new file mode 100644 index 0000000000..b26db4379a --- /dev/null +++ b/contracts/benchmarks/mappers/linked-list-repeat/sc-config.toml @@ -0,0 +1,5 @@ +[[proxy]] +path = "src/linked_list_repeat_proxy.rs" +[[proxy.path-rename]] +from = "benchmark_common::example_struct" +to = "benchmark_common" diff --git a/contracts/benchmarks/mappers/linked-list-repeat/src/linked_list_repeat.rs b/contracts/benchmarks/mappers/linked-list-repeat/src/linked_list_repeat.rs index 640fcb3968..40dfcba638 100644 --- a/contracts/benchmarks/mappers/linked-list-repeat/src/linked_list_repeat.rs +++ b/contracts/benchmarks/mappers/linked-list-repeat/src/linked_list_repeat.rs @@ -3,6 +3,7 @@ multiversx_sc::imports!(); use benchmark_common::ExampleStruct; +pub mod linked_list_repeat_proxy; #[multiversx_sc::contract] pub trait LinkedListRepeat: benchmark_common::BenchmarkCommon { diff --git a/contracts/benchmarks/mappers/linked-list-repeat/src/linked_list_repeat_proxy.rs b/contracts/benchmarks/mappers/linked-list-repeat/src/linked_list_repeat_proxy.rs new file mode 100644 index 0000000000..100ff19071 --- /dev/null +++ b/contracts/benchmarks/mappers/linked-list-repeat/src/linked_list_repeat_proxy.rs @@ -0,0 +1,166 @@ +// 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 LinkedListRepeatProxy; + +impl TxProxyTrait for LinkedListRepeatProxy +where + Env: TxEnv, + From: TxFrom, + To: TxTo, + Gas: TxGas, +{ + type TxProxyMethods = LinkedListRepeatProxyMethods; + + fn proxy_methods(self, tx: Tx) -> Self::TxProxyMethods { + LinkedListRepeatProxyMethods { wrapped_tx: tx } + } +} + +pub struct LinkedListRepeatProxyMethods +where + Env: TxEnv, + From: TxFrom, + To: TxTo, + Gas: TxGas, +{ + wrapped_tx: Tx, +} + +#[rustfmt::skip] +impl LinkedListRepeatProxyMethods +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 LinkedListRepeatProxyMethods +where + Env: TxEnv, + Env::Api: VMApi, + From: TxFrom, + To: TxTo, + Gas: TxGas, +{ + pub fn add< + Arg0: ProxyArg, + Arg1: ProxyArg>, + >( + self, + num_repeats: Arg0, + value: Arg1, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("add") + .argument(&num_repeats) + .argument(&value) + .original_result() + } + + pub fn count< + Arg0: ProxyArg>, + >( + self, + value: Arg0, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("count") + .argument(&value) + .original_result() + } + + pub fn remove< + Arg0: ProxyArg, + >( + self, + num_repeats: Arg0, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("remove") + .argument(&num_repeats) + .original_result() + } + + pub fn bench( + self, + ) -> TxTypedCall>> { + self.wrapped_tx + .payment(NotPayable) + .raw_call("bench") + .original_result() + } + + pub fn add_struct< + Arg0: ProxyArg, + Arg1: ProxyArg>, + >( + self, + num_repeats: Arg0, + value: Arg1, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("add_struct") + .argument(&num_repeats) + .argument(&value) + .original_result() + } + + pub fn count_struct< + Arg0: ProxyArg>, + >( + self, + value: Arg0, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("count_struct") + .argument(&value) + .original_result() + } + + pub fn remove_struct< + Arg0: ProxyArg, + >( + self, + num_repeats: Arg0, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("remove_struct") + .argument(&num_repeats) + .original_result() + } + + pub fn bench_struct( + self, + ) -> TxTypedCall>> { + self.wrapped_tx + .payment(NotPayable) + .raw_call("bench_struct") + .original_result() + } +} diff --git a/contracts/benchmarks/mappers/linked-list-repeat/tests/linked_list_repeat_blackbox_test.rs b/contracts/benchmarks/mappers/linked-list-repeat/tests/linked_list_repeat_blackbox_test.rs index 15465791d4..aa2edf237f 100644 --- a/contracts/benchmarks/mappers/linked-list-repeat/tests/linked_list_repeat_blackbox_test.rs +++ b/contracts/benchmarks/mappers/linked-list-repeat/tests/linked_list_repeat_blackbox_test.rs @@ -1,78 +1,76 @@ -#![allow(deprecated)] // TODO: unified syntax - use benchmark_common::ExampleStruct; -use linked_list_repeat::ProxyTrait; +use linked_list_repeat::linked_list_repeat_proxy; use multiversx_sc_scenario::imports::*; -const WASM_PATH_EXPR: &str = "mxsc:output/linked-list-repeat.mxsc.json"; +const WASM_PATH: MxscPath = MxscPath::new("output/linked-list-repeat.mxsc.json"); +const LLR_ADDRESS: TestSCAddress = TestSCAddress::new("llr"); +const OWNER_ADDRESS: TestAddress = TestAddress::new("owner"); fn world() -> ScenarioWorld { let mut blockchain = ScenarioWorld::new(); - blockchain.register_contract(WASM_PATH_EXPR, linked_list_repeat::ContractBuilder); + blockchain.register_contract(WASM_PATH, linked_list_repeat::ContractBuilder); blockchain } fn setup() -> ScenarioWorld { let mut world = world(); - let llr_code = world.code_expression(WASM_PATH_EXPR); + world + .account(OWNER_ADDRESS) + .nonce(1) + .new_address(OWNER_ADDRESS, 1, LLR_ADDRESS); world - .set_state_step( - SetStateStep::new() - .put_account("address:owner", Account::new().nonce(1)) - .new_address("address:owner", 1, "sc:llr"), - ) - .sc_deploy( - ScDeployStep::new() - .from("address:owner") - .code(llr_code) - .expect(TxExpect::ok().no_result()), - ); + .tx() + .from(OWNER_ADDRESS) + .typed(linked_list_repeat_proxy::LinkedListRepeatProxy) + .init() + .code(WASM_PATH) + .run(); world } #[test] fn linked_list_repeat_blackbox_raw() { let mut world = setup(); - let mut contract = ContractInfo::>::new("sc:llr"); let num_repeats = 5usize; world - .sc_call( - ScCallStep::new() - .from("address:owner") - .to("sc:llr") - .call(contract.add(num_repeats, "test--")) - .expect(TxExpect::ok().no_result()), - ) - .sc_call( - ScCallStep::new() - .from("address:owner") - .to("sc:llr") - .call(contract.count("test--\x00\x00\x00\x04")) - .expect(TxExpect::ok().result("1")), - ) - .sc_query_use_result( - ScQueryStep::new().to("sc:llr").call(contract.bench()), - |tr: TypedResponse>| { - let result = tr.result.unwrap().into_iter().collect::>(); - assert_eq!(result.len(), num_repeats); - for (index, item) in result.iter().enumerate() { - let index_str = - String::from_utf8((index as u32).to_be_bytes().to_vec()).unwrap(); - let expected = format!("test--{}", index_str); - assert_eq!(item, &expected); - } - }, - ); + .tx() + .from(OWNER_ADDRESS) + .to(LLR_ADDRESS) + .typed(linked_list_repeat_proxy::LinkedListRepeatProxy) + .add(num_repeats, "test--") + .run(); + + world + .tx() + .from(OWNER_ADDRESS) + .to(LLR_ADDRESS) + .typed(linked_list_repeat_proxy::LinkedListRepeatProxy) + .count("test--\x00\x00\x00\x04") + .returns(ExpectValue(1u32)) + .run(); + + let items = world + .query() + .to(LLR_ADDRESS) + .typed(linked_list_repeat_proxy::LinkedListRepeatProxy) + .bench() + .returns(ReturnsResult) + .run(); + + for (index, item) in items.into_iter().enumerate() { + let index_str = String::from_utf8((index as u32).to_be_bytes().to_vec()).unwrap(); + let expected = format!("test--{}", index_str); + assert_eq!(item.to_string(), expected); + } } #[test] fn linked_list_repeat_struct_blackbox_raw() { let mut world = setup(); - let mut contract = ContractInfo::>::new("sc:llr"); let mut example = ExampleStruct { first_token_id: TokenIdentifier::from_esdt_bytes(b"str:TESTTOK-1234"), @@ -82,20 +80,22 @@ fn linked_list_repeat_struct_blackbox_raw() { second_token_nonce: 0, second_token_amount: multiversx_sc::types::BigUint::from(1_000_000_000_000_000_000u64), }; - world.sc_call( - ScCallStep::new() - .from("address:owner") - .to("sc:llr") - .call(contract.add_struct(5u32, example.clone())) - .expect(TxExpect::ok().no_result()), - ); + + world + .tx() + .from(OWNER_ADDRESS) + .to(LLR_ADDRESS) + .typed(linked_list_repeat_proxy::LinkedListRepeatProxy) + .add_struct(5u32, example.clone()) + .run(); example.first_token_nonce = 3; example.second_token_nonce = 3; - world.sc_call( - ScCallStep::new() - .from("address:owner") - .to("sc:llr") - .call(contract.count_struct(example)) - .expect(TxExpect::ok().result("1")), - ); + world + .tx() + .from(OWNER_ADDRESS) + .to(LLR_ADDRESS) + .typed(linked_list_repeat_proxy::LinkedListRepeatProxy) + .count_struct(example) + .returns(ExpectValue(1u32)) + .run(); } diff --git a/framework/base/src/types/interaction/tx.rs b/framework/base/src/types/interaction/tx.rs index 4ed8603734..905b9af8fc 100644 --- a/framework/base/src/types/interaction/tx.rs +++ b/framework/base/src/types/interaction/tx.rs @@ -818,7 +818,7 @@ where /// /// Whenever possible, use proxies instead. /// - /// Doesa not serialize, does not enforce type safety. + /// Does not serialize, does not enforce type safety. #[inline] pub fn arguments_raw(mut self, raw: ManagedArgBuffer) -> Self { self.data.arg_buffer = raw;