From bb219c02ad2bc8b227a8587c441ebac6b30dfad7 Mon Sep 17 00:00:00 2001 From: Mihai Calin Luca Date: Fri, 22 Mar 2024 18:05:29 +0100 Subject: [PATCH 1/7] small gas fix and multisig unified syntax in interactor --- .../interact/src/multisig_interact.rs | 114 +++++++++--------- .../interact/src/multisig_interact_nfts.rs | 38 +++--- .../interact/src/multisig_interact_wegld.rs | 4 +- contracts/examples/multisig/src/multisig.rs | 2 +- .../examples/multisig/src/multisig_proxy.rs | 6 +- .../src/facade/world_tx/scenario_env_util.rs | 7 +- 6 files changed, 89 insertions(+), 82 deletions(-) diff --git a/contracts/examples/multisig/interact/src/multisig_interact.rs b/contracts/examples/multisig/interact/src/multisig_interact.rs index cf679c5a13..1de0b6f261 100644 --- a/contracts/examples/multisig/interact/src/multisig_interact.rs +++ b/contracts/examples/multisig/interact/src/multisig_interact.rs @@ -6,27 +6,26 @@ mod multisig_interact_wegld; use clap::Parser; use multisig::{ - multisig_perform::ProxyTrait as _, multisig_propose::ProxyTrait as _, - multisig_state::ProxyTrait as _, ProxyTrait as _, + multisig_perform::ProxyTrait as _, multisig_propose::ProxyTrait as _, multisig_proxy, + ProxyTrait as _, }; use multisig_interact_config::Config; use multisig_interact_state::State; -use multiversx_sc_modules::dns::ProxyTrait as _; use multiversx_sc_scenario::{ - mandos_system::ScenarioRunner, multiversx_sc::codec::multi_types::IgnoreValue, + mandos_system::ScenarioRunner, + multiversx_sc::types::{BigUint, ReturnsNewAddress, ReturnsSimilar}, scenario_format::interpret_trait::InterpretableFrom, - standalone::retrieve_account_as_scenario_set_state, test_wallets, + standalone::retrieve_account_as_scenario_set_state, + test_wallets, }; use multiversx_sc_snippets::{ dns_address_for_name, env_logger, - multiversx_sc::{ - codec::multi_types::MultiValueVec, storage::mappers::SingleValue, types::Address, - }, + multiversx_sc::{codec::multi_types::MultiValueVec, types::Address}, multiversx_sc_scenario::{ api::StaticApi, bech32, scenario_format::interpret_trait::InterpreterContext, scenario_model::*, ContractInfo, }, - tokio, Interactor, StepBuffer, + tokio, Interactor, InteractorPrepareAsync, StepBuffer, }; const SYSTEM_SC_BECH32: &str = "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u"; @@ -160,21 +159,17 @@ impl MultisigInteract { self.set_state().await; let board = self.board(); - let (new_address, _) = self + + let new_address = self .interactor - .sc_deploy_get_result::<_, IgnoreValue>( - ScDeployStep::new() - .call( - self.state - .default_multisig() - .init(Config::load_config().quorum(), board), - ) - .from(&self.wallet_address) - .code(&self.multisig_code) - .gas_limit("100,000,000") - .expect(TxExpect::ok().additional_error_message("deploy failed: ")), - ) - .await; + .tx() + .from(&self.wallet_address) + .typed(multisig_proxy::MultisigProxy) + .init(&Config::load_config().quorum(), board) + .code(&self.multisig_code) + .with_gas_limit(100_000_000u64) + .returns(ReturnsNewAddress) + .sync_call(); let new_address_bech32 = bech32::encode(&new_address); println!("new address: {new_address_bech32}"); @@ -243,33 +238,31 @@ impl MultisigInteract { } async fn feed_contract_egld(&mut self) { - let _ = self - .interactor - .transfer( - TransferStep::new() - .from(&self.wallet_address) - .to(self.state.multisig()) - .egld_value("0,050000000000000000"), - ) + self.interactor + .tx() + .from(&self.wallet_address) + .to(self.state.multisig().to_address()) + .egld(BigUint::from(5_000_000_000_000_000_0u64)) // 0,05 or 5 * 10^16 + .prepare_async() + .run() .await; } - async fn perform_action(&mut self, action_id: usize, gas_expr: &str) { + async fn perform_action(&mut self, action_id: usize, gas_expr: u64) { if !self.quorum_reached(action_id).await && !self.sign(action_id).await { return; } println!("quorum reached for action `{action_id}`"); self.interactor - .sc_call( - ScCallStep::new() - .call(self.state.multisig().perform_action_endpoint(action_id)) - .from(&self.wallet_address) - .gas_limit(gas_expr) - .expect(TxExpect::ok().additional_error_message(format!( - "perform action `{action_id}` failed with: " - ))), - ) + .tx() + .from(&self.wallet_address) + .to(self.state.multisig().to_address()) + .with_gas_limit(gas_expr) + .typed(multisig_proxy::MultisigProxy) + .perform_action_endpoint(action_id) + .prepare_async() + .run() .await; println!("successfully performed action `{action_id}`"); @@ -361,33 +354,46 @@ impl MultisigInteract { async fn dns_register(&mut self, name: &str) { let dns_address = dns_address_for_name(name); self.interactor - .sc_call( - ScCallStep::new() - .call(self.state.multisig().dns_register(dns_address, name)) - .from(&self.wallet_address) - .gas_limit("30,000,000") - .expect(TxExpect::ok().additional_error_message("dns register failed with: ")), - ) + .tx() + .from(&self.wallet_address) + .to(self.state.multisig().to_address()) + .with_gas_limit(30_000_000u64) + .typed(multisig_proxy::MultisigProxy) + .dns_register(dns_address, name) + .prepare_async() + .run() .await; println!("successfully registered dns"); } async fn print_quorum(&mut self) { - let quorum: SingleValue = self + let quorum = self .interactor - .quick_query(self.state.multisig().quorum()) + .query() + .to(self.state.multisig().to_address()) + .typed(multisig_proxy::MultisigProxy) + .quorum() + .returns(ReturnsSimilar::::new()) + .prepare_async() + .run() .await; - println!("quorum: {}", quorum.into()); + println!("quorum: {}", quorum); } async fn print_board(&mut self) { - let board: SingleValue = self + let board = self .interactor - .quick_query(self.state.multisig().num_board_members()) + .query() + .to(self.state.multisig().to_address()) + .typed(multisig_proxy::MultisigProxy) + .num_board_members() + .returns(ReturnsSimilar::::new()) + .prepare_async() + .run() .await; - println!("board: {}", board.into()); + println!("board: {}", board); } } diff --git a/contracts/examples/multisig/interact/src/multisig_interact_nfts.rs b/contracts/examples/multisig/interact/src/multisig_interact_nfts.rs index ab8fa001f7..d607b7816a 100644 --- a/contracts/examples/multisig/interact/src/multisig_interact_nfts.rs +++ b/contracts/examples/multisig/interact/src/multisig_interact_nfts.rs @@ -39,26 +39,24 @@ impl MultisigInteract { let system_sc_address = bech32::decode(SYSTEM_SC_BECH32); let action_id = self .interactor - .sc_call_get_result( - ScCallStep::new() - .call( - self.state.multisig().propose_async_call( - system_sc_address, - ISSUE_COST, - FunctionCall::new("registerAndSetAllRoles") - .argument(&COLLECTION_NAME) - .argument(&COLLECTION_TICKER) - .argument(&TOKEN_TYPE) - .argument(&0u32), - ), - ) - .from(&self.wallet_address) - .gas_limit("10,000,000") - .expect(TxExpect::ok().additional_error_message("failed to issue collection")), + .tx() + .from(&self.wallet_address) + .to(self.state.multisig().to_address()) + .with_gas_limit(10_000_000u64) + .typed(multisig_proxy::MultisigProxy) + .propose_async_call( + system_sc_address, + ISSUE_COST, + FunctionCall::new("registerAndSetAllRoles") + .argument(&COLLECTION_NAME) + .argument(&COLLECTION_TICKER) + .argument(&TOKEN_TYPE) + .argument(&0u32), ) - .await - .result - .unwrap(); + .returns(ReturnsSimilar::::new()) + .prepare_async() + .run() + .await; println!("successfully proposed issue colllection with roles all action `{action_id}`"); action_id @@ -186,7 +184,7 @@ impl MultisigInteract { let action_id = self.propose_set_special_role().await; println!("performing set special role action `{action_id}`..."); - self.perform_action(action_id, "80,000,000").await; + self.perform_action(action_id, 80_000_000u64).await; } pub async fn create_items(&mut self) { diff --git a/contracts/examples/multisig/interact/src/multisig_interact_wegld.rs b/contracts/examples/multisig/interact/src/multisig_interact_wegld.rs index e3c6009b95..bcfa959805 100644 --- a/contracts/examples/multisig/interact/src/multisig_interact_wegld.rs +++ b/contracts/examples/multisig/interact/src/multisig_interact_wegld.rs @@ -34,7 +34,7 @@ impl MultisigInteract { let action_id = self.propose_wrap_egld().await; println!("perfoming wrap egld action `{action_id}`..."); - self.perform_action(action_id, "15,000,000").await; + self.perform_action(action_id, 15_000_000u64).await; } pub async fn unwrap_egld(&mut self) { @@ -42,7 +42,7 @@ impl MultisigInteract { let action_id = self.propose_unwrap_egld().await; println!("perfoming unwrap egld action `{action_id}`..."); - self.perform_action(action_id, "15,000,000").await; + self.perform_action(action_id, 15_000_000u64).await; } pub async fn wegld_swap_set_state(&mut self) { diff --git a/contracts/examples/multisig/src/multisig.rs b/contracts/examples/multisig/src/multisig.rs index 75c13cb5dd..96d3d5cdfa 100644 --- a/contracts/examples/multisig/src/multisig.rs +++ b/contracts/examples/multisig/src/multisig.rs @@ -4,7 +4,7 @@ pub mod action; pub mod multisig_events; pub mod multisig_perform; pub mod multisig_propose; -// pub mod multisig_proxy; +pub mod multisig_proxy; pub mod multisig_state; pub mod user_role; diff --git a/contracts/examples/multisig/src/multisig_proxy.rs b/contracts/examples/multisig/src/multisig_proxy.rs index b0d42e16ef..265bc968ab 100644 --- a/contracts/examples/multisig/src/multisig_proxy.rs +++ b/contracts/examples/multisig/src/multisig_proxy.rs @@ -355,7 +355,7 @@ where (), Gas, FunctionCall, - OriginalResultMarker>, + OriginalResultMarker, > { self.wrapped_tx .raw_call() @@ -727,11 +727,11 @@ where Api: ManagedTypeApi, { pub action_id: usize, - pub action_data: Action, + pub action_data: Action, pub signers: ManagedVec>, } -#[derive(TopEncode, TopDecode)] +#[derive(TopEncode, TopDecode, NestedEncode, NestedDecode)] pub enum Action { Nothing, AddBoardMember, diff --git a/framework/scenario/src/facade/world_tx/scenario_env_util.rs b/framework/scenario/src/facade/world_tx/scenario_env_util.rs index 19776e9a0d..2de2e9ae6c 100644 --- a/framework/scenario/src/facade/world_tx/scenario_env_util.rs +++ b/framework/scenario/src/facade/world_tx/scenario_env_util.rs @@ -12,7 +12,7 @@ use crate::{ api::StaticApi, scenario_model::{ AddressValue, BigUintValue, BytesValue, ScCallStep, ScDeployStep, ScQueryStep, - TransferStep, TxResponse, + TransferStep, TxResponse, U64Value, }, RHListScenario, ScenarioEnvExec, ScenarioWorld, }; @@ -46,7 +46,7 @@ pub fn tx_to_sc_call_step( from: From, to: To, payment: Payment, - _gas: Gas, + gas: Gas, data: FunctionCall, ) -> ScCallStep where @@ -63,6 +63,9 @@ where for arg in data.arg_buffer.iter_buffers() { step.tx.arguments.push(arg.to_vec().into()); } + + let explicit_gas = gas.resolve_gas(env); + step.tx.gas_limit = U64Value::from(explicit_gas); let full_payment_data = payment.into_full_payment_data(); if let Some(annotated_egld_payment) = full_payment_data.egld { From 7a79ec9a73a94937ea66a0b4d30bc823737fa7a1 Mon Sep 17 00:00:00 2001 From: Mihai Calin Luca Date: Fri, 22 Mar 2024 18:19:33 +0100 Subject: [PATCH 2/7] regen proxy file --- contracts/examples/multisig/src/multisig_proxy.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/examples/multisig/src/multisig_proxy.rs b/contracts/examples/multisig/src/multisig_proxy.rs index 5b596c9836..a4f5c82bd7 100644 --- a/contracts/examples/multisig/src/multisig_proxy.rs +++ b/contracts/examples/multisig/src/multisig_proxy.rs @@ -497,7 +497,7 @@ where Api: ManagedTypeApi, { pub action_id: usize, - pub action_data: Action, + pub action_data: Action, pub signers: ManagedVec>, } From 67d22a659a582dea2a76ebbf84989246dbd498f7 Mon Sep 17 00:00:00 2001 From: Mihai Calin Luca Date: Fri, 22 Mar 2024 19:59:18 +0100 Subject: [PATCH 3/7] further impl unified syntax in multisig interact --- .../interact/src/multisig_interact.rs | 43 +++++++---- .../interact/src/multisig_interact_nfts.rs | 76 +++++++++++-------- .../interact/src/multisig_interact_wegld.rs | 50 ++++++------ 3 files changed, 97 insertions(+), 72 deletions(-) diff --git a/contracts/examples/multisig/interact/src/multisig_interact.rs b/contracts/examples/multisig/interact/src/multisig_interact.rs index 1de0b6f261..c068f09a0e 100644 --- a/contracts/examples/multisig/interact/src/multisig_interact.rs +++ b/contracts/examples/multisig/interact/src/multisig_interact.rs @@ -13,7 +13,7 @@ use multisig_interact_config::Config; use multisig_interact_state::State; use multiversx_sc_scenario::{ mandos_system::ScenarioRunner, - multiversx_sc::types::{BigUint, ReturnsNewAddress, ReturnsSimilar}, + multiversx_sc::types::{BigUint, ReturnsSimilar}, scenario_format::interpret_trait::InterpretableFrom, standalone::retrieve_account_as_scenario_set_state, test_wallets, @@ -158,18 +158,19 @@ impl MultisigInteract { async fn deploy(&mut self) { self.set_state().await; - let board = self.board(); + let _board = self.board(); - let new_address = self - .interactor - .tx() - .from(&self.wallet_address) - .typed(multisig_proxy::MultisigProxy) - .init(&Config::load_config().quorum(), board) - .code(&self.multisig_code) - .with_gas_limit(100_000_000u64) - .returns(ReturnsNewAddress) - .sync_call(); + let new_address = Address::zero(); + // let new_address = self + // .interactor + // .tx() + // .from(&self.wallet_address) + // .typed(multisig_proxy::MultisigProxy) + // .init(&Config::load_config().quorum(), board) + // .code(&self.multisig_code) + // .with_gas_limit(100_000_000u64) + // .returns(ReturnsNewAddress) + // .sync_call(); let new_address_bech32 = bech32::encode(&new_address); println!("new address: {new_address_bech32}"); @@ -242,7 +243,7 @@ impl MultisigInteract { .tx() .from(&self.wallet_address) .to(self.state.multisig().to_address()) - .egld(BigUint::from(5_000_000_000_000_000_0u64)) // 0,05 or 5 * 10^16 + .egld(BigUint::from(50_000_000_000_000_000u64)) // 0,05 or 5 * 10^16 .prepare_async() .run() .await; @@ -303,13 +304,25 @@ impl MultisigInteract { async fn quorum_reached(&mut self, action_id: usize) -> bool { self.interactor - .quick_query(self.state.multisig().quorum_reached(action_id)) + .query() + .to(self.state.multisig().to_address()) + .typed(multisig_proxy::MultisigProxy) + .quorum_reached(action_id) + .returns(ReturnsSimilar::::new()) + .prepare_async() + .run() .await } async fn signed(&mut self, signer: &Address, action_id: usize) -> bool { self.interactor - .quick_query(self.state.multisig().signed(signer, action_id)) + .query() + .to(self.state.multisig().to_address()) + .typed(multisig_proxy::MultisigProxy) + .signed(signer, action_id) + .returns(ReturnsSimilar::::new()) + .prepare_async() + .run() .await } diff --git a/contracts/examples/multisig/interact/src/multisig_interact_nfts.rs b/contracts/examples/multisig/interact/src/multisig_interact_nfts.rs index d607b7816a..bcf73645ad 100644 --- a/contracts/examples/multisig/interact/src/multisig_interact_nfts.rs +++ b/contracts/examples/multisig/interact/src/multisig_interact_nfts.rs @@ -73,6 +73,18 @@ impl MultisigInteract { } println!("quorum reached for action `{action_id}`"); + // let _ = self + // .interactor + // .tx() + // .from(&self.wallet_address) + // .to(&self.state.multisig().to_address()) + // .with_gas_limit(80_000_000u64) + // .typed(multisig_proxy::MultisigProxy) + // .perform_action_endpoint(action_id) + // .with_result(WithResultTokenIdentifier::new(|token_id| { + // self.collection_token_identifier = token_id.to_string() + // })); + let response: TypedResponse = self .interactor .sc_call_get_result( @@ -98,23 +110,22 @@ impl MultisigInteract { let system_sc_address = bech32::decode(SYSTEM_SC_BECH32); let action_id = self .interactor - .sc_call_get_result( - ScCallStep::new() - .call( - self.state.multisig().propose_async_call( - system_sc_address, - ISSUE_COST, - FunctionCall::new("issueNonFungible") - .argument(&COLLECTION_NAME) - .argument(&COLLECTION_TICKER), - ), - ) - .from(&self.wallet_address) - .gas_limit("10,000,000"), + .tx() + .from(&self.wallet_address) + .to(&self.state.multisig().to_address()) + .with_gas_limit(10_000_000u64) + .typed(multisig_proxy::MultisigProxy) + .propose_async_call( + system_sc_address, + ISSUE_COST, + FunctionCall::new("issueNonFungible") + .argument(&COLLECTION_NAME) + .argument(&COLLECTION_TICKER), ) - .await - .result - .unwrap(); + .returns(ReturnsSimilar::::new()) + .prepare_async() + .run() + .await; println!("successfully proposed issue colllection action `{action_id}`"); action_id @@ -156,24 +167,23 @@ impl MultisigInteract { let multisig_address = self.state.multisig().to_address(); let action_id = self .interactor - .sc_call_get_result( - ScCallStep::new() - .call( - self.state.multisig().propose_async_call( - &self.system_sc_address, - 0u64, - FunctionCall::new("setSpecialRole") - .argument(&self.collection_token_identifier) - .argument(&multisig_address) - .argument(&"ESDTRoleNFTCreate"), - ), - ) - .from(&self.wallet_address) - .gas_limit("10,000,000"), + .tx() + .from(&self.wallet_address) + .to(&self.state.multisig().to_address()) + .with_gas_limit(10_000_000u64) + .typed(multisig_proxy::MultisigProxy) + .propose_async_call( + &self.system_sc_address, + 0u64, + FunctionCall::new("setSpecialRole") + .argument(&self.collection_token_identifier) + .argument(&multisig_address) + .argument(&"ESDTRoleNFTCreate"), ) - .await - .result - .unwrap(); + .returns(ReturnsSimilar::::new()) + .prepare_async() + .run() + .await; println!("successfully proposed set special role with action `{action_id}`"); action_id diff --git a/contracts/examples/multisig/interact/src/multisig_interact_wegld.rs b/contracts/examples/multisig/interact/src/multisig_interact_wegld.rs index bcfa959805..ebd75faada 100644 --- a/contracts/examples/multisig/interact/src/multisig_interact_wegld.rs +++ b/contracts/examples/multisig/interact/src/multisig_interact_wegld.rs @@ -62,19 +62,20 @@ impl MultisigInteract { async fn propose_wrap_egld(&mut self) -> usize { let action_id = self .interactor - .sc_call_get_result( - ScCallStep::new() - .call(self.state.multisig().propose_async_call( - bech32::decode(WEGLD_SWAP_SC_BECH32), - WRAP_AMOUNT, - FunctionCall::new("wrapEgld"), - )) - .from(&self.wallet_address) - .gas_limit("10,000,000"), + .tx() + .from(&self.wallet_address) + .to(&self.state.multisig().to_address()) + .with_gas_limit(10_000_000u64) + .typed(multisig_proxy::MultisigProxy) + .propose_async_call( + bech32::decode(WEGLD_SWAP_SC_BECH32), + WRAP_AMOUNT, + FunctionCall::new("wrapEgld"), ) - .await - .result - .unwrap(); + .returns(ReturnsSimilar::::new()) + .prepare_async() + .run() + .await; println!("successfully proposed wrap egld action `{action_id}`"); action_id @@ -94,19 +95,20 @@ impl MultisigInteract { let action_id = self .interactor - .sc_call_get_result( - ScCallStep::new() - .call(self.state.multisig().propose_async_call( - contract_call.basic.to, - 0u64, - contract_call.basic.function_call, - )) - .from(&self.wallet_address) - .gas_limit("10,000,000"), + .tx() + .from(&self.wallet_address) + .to(&self.state.multisig().to_address()) + .with_gas_limit(10_000_000u64) + .typed(multisig_proxy::MultisigProxy) + .propose_async_call( + contract_call.basic.to, + 0u64, + contract_call.basic.function_call, ) - .await - .result - .unwrap(); + .returns(ReturnsSimilar::::new()) + .prepare_async() + .run() + .await; println!("successfully proposed unwrap egld action `{action_id}`"); action_id From c78d33451732e5ec459e68a79c59be2537320413 Mon Sep 17 00:00:00 2001 From: Mihai Calin Luca Date: Fri, 22 Mar 2024 20:24:57 +0100 Subject: [PATCH 4/7] returnsNewTokenIdentifier and further improvements to multisig interact --- .../interact/src/multisig_interact.rs | 33 ++++----- .../interact/src/multisig_interact_nfts.rs | 69 ++++++++----------- .../base/src/types/interaction/tx_rh_list.rs | 3 + .../returns_new_token_identifier.rs | 32 +++++++++ .../facade/world_tx/scenario_rh_list_item.rs | 19 ++++- 5 files changed, 96 insertions(+), 60 deletions(-) create mode 100644 framework/base/src/types/interaction/tx_rh_list/returns_new_token_identifier.rs diff --git a/contracts/examples/multisig/interact/src/multisig_interact.rs b/contracts/examples/multisig/interact/src/multisig_interact.rs index c068f09a0e..8f7c4ddd1b 100644 --- a/contracts/examples/multisig/interact/src/multisig_interact.rs +++ b/contracts/examples/multisig/interact/src/multisig_interact.rs @@ -13,7 +13,7 @@ use multisig_interact_config::Config; use multisig_interact_state::State; use multiversx_sc_scenario::{ mandos_system::ScenarioRunner, - multiversx_sc::types::{BigUint, ReturnsSimilar}, + multiversx_sc::types::{BigUint, ReturnsNewAddress, ReturnsSimilar}, scenario_format::interpret_trait::InterpretableFrom, standalone::retrieve_account_as_scenario_set_state, test_wallets, @@ -158,21 +158,22 @@ impl MultisigInteract { async fn deploy(&mut self) { self.set_state().await; - let _board = self.board(); - - let new_address = Address::zero(); - // let new_address = self - // .interactor - // .tx() - // .from(&self.wallet_address) - // .typed(multisig_proxy::MultisigProxy) - // .init(&Config::load_config().quorum(), board) - // .code(&self.multisig_code) - // .with_gas_limit(100_000_000u64) - // .returns(ReturnsNewAddress) - // .sync_call(); - - let new_address_bech32 = bech32::encode(&new_address); + let board = self.board(); + + let new_address = self + .interactor + .tx() + .from(&self.wallet_address) + .typed(multisig_proxy::MultisigProxy) + .init(&Config::load_config().quorum(), board) + .code(&self.multisig_code) + .with_gas_limit(100_000_000u64) + .returns(ReturnsNewAddress) + .prepare_async() + .run() + .await; + + let new_address_bech32 = bech32::encode(&new_address.to_address()); println!("new address: {new_address_bech32}"); let new_address_expr = format!("bech32:{new_address_bech32}"); diff --git a/contracts/examples/multisig/interact/src/multisig_interact_nfts.rs b/contracts/examples/multisig/interact/src/multisig_interact_nfts.rs index bcf73645ad..73f128c564 100644 --- a/contracts/examples/multisig/interact/src/multisig_interact_nfts.rs +++ b/contracts/examples/multisig/interact/src/multisig_interact_nfts.rs @@ -1,8 +1,8 @@ use std::time::Duration; use multiversx_sc_scenario::multiversx_sc::{ - codec::{multi_types::IgnoreValue, Empty}, - types::FunctionCall, + codec::Empty, + types::{FunctionCall, ReturnsNewTokenIdentidier}, }; use super::*; @@ -73,33 +73,20 @@ impl MultisigInteract { } println!("quorum reached for action `{action_id}`"); - // let _ = self - // .interactor - // .tx() - // .from(&self.wallet_address) - // .to(&self.state.multisig().to_address()) - // .with_gas_limit(80_000_000u64) - // .typed(multisig_proxy::MultisigProxy) - // .perform_action_endpoint(action_id) - // .with_result(WithResultTokenIdentifier::new(|token_id| { - // self.collection_token_identifier = token_id.to_string() - // })); - - let response: TypedResponse = self + let new_token_id = self .interactor - .sc_call_get_result( - ScCallStep::new() - .call(self.state.multisig().perform_action_endpoint(action_id)) - .from(&self.wallet_address) - .gas_limit("80,000,000") - .expect(TxExpect::ok().additional_error_message( - "perform issue collection with all roles failed: ", - )), - ) + .tx() + .from(&self.wallet_address) + .to(&self.state.multisig().to_address()) + .with_gas_limit(80_000_000u64) + .typed(multisig_proxy::MultisigProxy) + .perform_action_endpoint(action_id) + .returns(ReturnsNewTokenIdentidier) + .prepare_async() + .run() .await; - self.collection_token_identifier = response - .new_issued_token_identifier - .expect("new token identifier could not be retrieved"); + self.collection_token_identifier = new_token_id.to_string(); + println!( "collection token identifier: {}", self.collection_token_identifier @@ -141,22 +128,20 @@ impl MultisigInteract { return; } println!("quorum reached for action `{action_id}`"); + let new_token_id = self + .interactor + .tx() + .from(&self.wallet_address) + .to(&self.state.multisig().to_address()) + .with_gas_limit(80_000_000u64) + .typed(multisig_proxy::MultisigProxy) + .perform_action_endpoint(action_id) + .returns(ReturnsNewTokenIdentidier) + .prepare_async() + .run() + .await; + self.collection_token_identifier = new_token_id.to_string(); - let response: TypedResponse = - self.interactor - .sc_call_get_result( - ScCallStep::new() - .call(self.state.multisig().perform_action_endpoint(action_id)) - .from(&self.wallet_address) - .gas_limit("80,000,000") - .expect(TxExpect::ok().additional_error_message( - "perform issue collection with all failed: ", - )), - ) - .await; - self.collection_token_identifier = response - .new_issued_token_identifier - .expect("new token identifier could not be retrieved"); println!( "collection token identifier: {}", self.collection_token_identifier diff --git a/framework/base/src/types/interaction/tx_rh_list.rs b/framework/base/src/types/interaction/tx_rh_list.rs index 2cf4743ef2..b3dd278f12 100644 --- a/framework/base/src/types/interaction/tx_rh_list.rs +++ b/framework/base/src/types/interaction/tx_rh_list.rs @@ -3,6 +3,7 @@ mod returns_exact; mod returns_new_address; mod returns_raw; mod returns_similar; +mod returns_new_token_identifier; mod tx_rh_list_cons; mod tx_rh_list_item; mod with_result_exact; @@ -15,7 +16,9 @@ pub use returns_exact::*; pub use returns_new_address::*; pub use returns_raw::*; pub use returns_similar::*; +pub use returns_new_token_identifier::*; pub use tx_rh_list_cons::*; pub use tx_rh_list_item::*; pub use with_result_new_address::*; pub use with_result_similar::*; + diff --git a/framework/base/src/types/interaction/tx_rh_list/returns_new_token_identifier.rs b/framework/base/src/types/interaction/tx_rh_list/returns_new_token_identifier.rs new file mode 100644 index 0000000000..71d5751de1 --- /dev/null +++ b/framework/base/src/types/interaction/tx_rh_list/returns_new_token_identifier.rs @@ -0,0 +1,32 @@ +use crate::{ + contract_base::BlockchainWrapper, proxy_imports::TokenIdentifier, types::{ + interaction::tx_call_deploy::RHListItemDeploy, BackTransfers, ManagedAddress, + ManagedBuffer, ManagedVec, RHListItemSync, TxEnv, + } +}; + +use super::RHListItem; + +pub struct ReturnsNewTokenIdentidier; + +impl RHListItem for ReturnsNewTokenIdentidier +where + Env: TxEnv, +{ + type Returns = TokenIdentifier; +} + + +// impl RHListItemScenario for ReturnsNewTokenIdentidier +// where +// Env: TxEnv, +// { +// fn item_scenario_result(self, tx_response: &TxResponse) -> Self::Returns { +// let new_token_id = tx_response +// .new_issued_token_identifier +// .clone() +// .expect("missing returned token identifier"); + +// new_token_id.into() +// } +// } diff --git a/framework/scenario/src/facade/world_tx/scenario_rh_list_item.rs b/framework/scenario/src/facade/world_tx/scenario_rh_list_item.rs index 36440e0313..7ed940c6be 100644 --- a/framework/scenario/src/facade/world_tx/scenario_rh_list_item.rs +++ b/framework/scenario/src/facade/world_tx/scenario_rh_list_item.rs @@ -1,8 +1,9 @@ use multiversx_sc::{ codec::{CodecFrom, TopDecodeMulti, TopEncodeMulti}, types::{ - ManagedAddress, RHList, RHListItem, ReturnsExact, ReturnsNewAddress, ReturnsSimilar, TxEnv, - WithResultNewAddress, WithResultSimilar, + ManagedAddress, RHList, RHListItem, ReturnsExact, ReturnsNewAddress, + ReturnsNewTokenIdentidier, ReturnsSimilar, TokenIdentifier, TxEnv, WithResultNewAddress, + WithResultSimilar, }, }; @@ -77,6 +78,20 @@ where } } +impl RHListItemScenario for ReturnsNewTokenIdentidier +where + Env: TxEnv, +{ + fn item_scenario_result(self, tx_response: &TxResponse) -> Self::Returns { + let new_token_id = tx_response + .new_issued_token_identifier + .clone() + .expect("missing returned token identifier"); + + TokenIdentifier::from(new_token_id.as_str()) + } +} + impl RHListItemScenario for WithResultNewAddress where Env: TxEnv, From 80cb79bcade227e3e13a5f0cded2a25774a2caaf Mon Sep 17 00:00:00 2001 From: Mihai Calin Luca Date: Fri, 22 Mar 2024 21:57:29 +0100 Subject: [PATCH 5/7] fix after review, cleanup and fmt --- .../interact/src/multisig_interact_nfts.rs | 12 ++++----- .../interact/src/multisig_interact_wegld.rs | 6 ++--- .../base/src/types/interaction/tx_rh_list.rs | 5 ++-- .../returns_new_token_identifier.rs | 25 +++++-------------- .../src/facade/world_tx/scenario_env_util.rs | 2 +- .../facade/world_tx/scenario_rh_list_item.rs | 4 +-- 6 files changed, 20 insertions(+), 34 deletions(-) diff --git a/contracts/examples/multisig/interact/src/multisig_interact_nfts.rs b/contracts/examples/multisig/interact/src/multisig_interact_nfts.rs index 73f128c564..5d54205c8a 100644 --- a/contracts/examples/multisig/interact/src/multisig_interact_nfts.rs +++ b/contracts/examples/multisig/interact/src/multisig_interact_nfts.rs @@ -2,7 +2,7 @@ use std::time::Duration; use multiversx_sc_scenario::multiversx_sc::{ codec::Empty, - types::{FunctionCall, ReturnsNewTokenIdentidier}, + types::{FunctionCall, ReturnsExact, ReturnsNewTokenIdentifier}, }; use super::*; @@ -53,7 +53,7 @@ impl MultisigInteract { .argument(&TOKEN_TYPE) .argument(&0u32), ) - .returns(ReturnsSimilar::::new()) + .returns(ReturnsExact) .prepare_async() .run() .await; @@ -81,7 +81,7 @@ impl MultisigInteract { .with_gas_limit(80_000_000u64) .typed(multisig_proxy::MultisigProxy) .perform_action_endpoint(action_id) - .returns(ReturnsNewTokenIdentidier) + .returns(ReturnsNewTokenIdentifier) .prepare_async() .run() .await; @@ -109,7 +109,7 @@ impl MultisigInteract { .argument(&COLLECTION_NAME) .argument(&COLLECTION_TICKER), ) - .returns(ReturnsSimilar::::new()) + .returns(ReturnsExact) .prepare_async() .run() .await; @@ -136,7 +136,7 @@ impl MultisigInteract { .with_gas_limit(80_000_000u64) .typed(multisig_proxy::MultisigProxy) .perform_action_endpoint(action_id) - .returns(ReturnsNewTokenIdentidier) + .returns(ReturnsNewTokenIdentifier) .prepare_async() .run() .await; @@ -165,7 +165,7 @@ impl MultisigInteract { .argument(&multisig_address) .argument(&"ESDTRoleNFTCreate"), ) - .returns(ReturnsSimilar::::new()) + .returns(ReturnsExact) .prepare_async() .run() .await; diff --git a/contracts/examples/multisig/interact/src/multisig_interact_wegld.rs b/contracts/examples/multisig/interact/src/multisig_interact_wegld.rs index ebd75faada..cbfde97e3f 100644 --- a/contracts/examples/multisig/interact/src/multisig_interact_wegld.rs +++ b/contracts/examples/multisig/interact/src/multisig_interact_wegld.rs @@ -1,6 +1,6 @@ use std::time::Duration; -use multiversx_sc_scenario::multiversx_sc::types::{ContractCallBase, FunctionCall}; +use multiversx_sc_scenario::multiversx_sc::types::{ContractCallBase, FunctionCall, ReturnsExact}; #[allow(unused_imports)] use multiversx_sc_snippets::multiversx_sc::types::{ EsdtTokenPayment, MultiValueEncoded, TokenIdentifier, @@ -72,7 +72,7 @@ impl MultisigInteract { WRAP_AMOUNT, FunctionCall::new("wrapEgld"), ) - .returns(ReturnsSimilar::::new()) + .returns(ReturnsExact) .prepare_async() .run() .await; @@ -105,7 +105,7 @@ impl MultisigInteract { 0u64, contract_call.basic.function_call, ) - .returns(ReturnsSimilar::::new()) + .returns(ReturnsExact) .prepare_async() .run() .await; diff --git a/framework/base/src/types/interaction/tx_rh_list.rs b/framework/base/src/types/interaction/tx_rh_list.rs index b3dd278f12..4af293146a 100644 --- a/framework/base/src/types/interaction/tx_rh_list.rs +++ b/framework/base/src/types/interaction/tx_rh_list.rs @@ -1,9 +1,9 @@ mod returns_bt; mod returns_exact; mod returns_new_address; +mod returns_new_token_identifier; mod returns_raw; mod returns_similar; -mod returns_new_token_identifier; mod tx_rh_list_cons; mod tx_rh_list_item; mod with_result_exact; @@ -14,11 +14,10 @@ mod with_result_similar; pub use returns_bt::*; pub use returns_exact::*; pub use returns_new_address::*; +pub use returns_new_token_identifier::*; pub use returns_raw::*; pub use returns_similar::*; -pub use returns_new_token_identifier::*; pub use tx_rh_list_cons::*; pub use tx_rh_list_item::*; pub use with_result_new_address::*; pub use with_result_similar::*; - diff --git a/framework/base/src/types/interaction/tx_rh_list/returns_new_token_identifier.rs b/framework/base/src/types/interaction/tx_rh_list/returns_new_token_identifier.rs index 71d5751de1..c1a4af47d1 100644 --- a/framework/base/src/types/interaction/tx_rh_list/returns_new_token_identifier.rs +++ b/framework/base/src/types/interaction/tx_rh_list/returns_new_token_identifier.rs @@ -1,32 +1,19 @@ use crate::{ - contract_base::BlockchainWrapper, proxy_imports::TokenIdentifier, types::{ + contract_base::BlockchainWrapper, + proxy_imports::TokenIdentifier, + types::{ interaction::tx_call_deploy::RHListItemDeploy, BackTransfers, ManagedAddress, ManagedBuffer, ManagedVec, RHListItemSync, TxEnv, - } + }, }; use super::RHListItem; -pub struct ReturnsNewTokenIdentidier; +pub struct ReturnsNewTokenIdentifier; -impl RHListItem for ReturnsNewTokenIdentidier +impl RHListItem for ReturnsNewTokenIdentifier where Env: TxEnv, { type Returns = TokenIdentifier; } - - -// impl RHListItemScenario for ReturnsNewTokenIdentidier -// where -// Env: TxEnv, -// { -// fn item_scenario_result(self, tx_response: &TxResponse) -> Self::Returns { -// let new_token_id = tx_response -// .new_issued_token_identifier -// .clone() -// .expect("missing returned token identifier"); - -// new_token_id.into() -// } -// } diff --git a/framework/scenario/src/facade/world_tx/scenario_env_util.rs b/framework/scenario/src/facade/world_tx/scenario_env_util.rs index 3a67373bb5..e54c34b969 100644 --- a/framework/scenario/src/facade/world_tx/scenario_env_util.rs +++ b/framework/scenario/src/facade/world_tx/scenario_env_util.rs @@ -63,7 +63,7 @@ where for arg in data.arg_buffer.iter_buffers() { step.tx.arguments.push(arg.to_vec().into()); } - + let explicit_gas = gas.resolve_gas(env); step.tx.gas_limit = U64Value::from(explicit_gas); diff --git a/framework/scenario/src/facade/world_tx/scenario_rh_list_item.rs b/framework/scenario/src/facade/world_tx/scenario_rh_list_item.rs index 7ed940c6be..780f2f7dcb 100644 --- a/framework/scenario/src/facade/world_tx/scenario_rh_list_item.rs +++ b/framework/scenario/src/facade/world_tx/scenario_rh_list_item.rs @@ -2,7 +2,7 @@ use multiversx_sc::{ codec::{CodecFrom, TopDecodeMulti, TopEncodeMulti}, types::{ ManagedAddress, RHList, RHListItem, ReturnsExact, ReturnsNewAddress, - ReturnsNewTokenIdentidier, ReturnsSimilar, TokenIdentifier, TxEnv, WithResultNewAddress, + ReturnsNewTokenIdentifier, ReturnsSimilar, TokenIdentifier, TxEnv, WithResultNewAddress, WithResultSimilar, }, }; @@ -78,7 +78,7 @@ where } } -impl RHListItemScenario for ReturnsNewTokenIdentidier +impl RHListItemScenario for ReturnsNewTokenIdentifier where Env: TxEnv, { From e3ba39d5b40aa03bea18ad6170cefdd8d8fd3872 Mon Sep 17 00:00:00 2001 From: Mihai Calin Luca Date: Fri, 22 Mar 2024 22:15:29 +0100 Subject: [PATCH 6/7] gas fix for deploy and transfer --- .../scenario/src/facade/world_tx/scenario_env_util.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/framework/scenario/src/facade/world_tx/scenario_env_util.rs b/framework/scenario/src/facade/world_tx/scenario_env_util.rs index e54c34b969..8663e54852 100644 --- a/framework/scenario/src/facade/world_tx/scenario_env_util.rs +++ b/framework/scenario/src/facade/world_tx/scenario_env_util.rs @@ -79,7 +79,7 @@ pub fn tx_to_sc_deploy_step( env: &Env, from: From, payment: Payment, - _gas: Gas, + gas: Gas, data: DeployCall>, ) -> ScDeployStep where @@ -96,6 +96,9 @@ where step.tx.arguments.push(arg.to_vec().into()); } + let explicit_gas = gas.resolve_gas(env); + step.tx.gas_limit = U64Value::from(explicit_gas); + let full_payment_data = payment.into_full_payment_data(env); if let Some(annotated_egld_payment) = full_payment_data.egld { step.tx.egld_value = annotated_egld_payment.into(); @@ -124,7 +127,7 @@ pub fn tx_to_transfer_step( from: From, to: To, payment: Payment, - _gas: Gas, + gas: Gas, ) -> TransferStep where Env: TxEnv, @@ -137,6 +140,9 @@ where .from(address_annotated(env, from)) .to(address_annotated(env, to)); + let explicit_gas = gas.resolve_gas(env); + step.tx.gas_limit = U64Value::from(explicit_gas); + let full_payment_data = payment.into_full_payment_data(env); if let Some(annotated_egld_payment) = full_payment_data.egld { step.tx.egld_value = annotated_egld_payment.into(); From 335a54e8a5a93eed59df8e2880f1c842d9c672f2 Mon Sep 17 00:00:00 2001 From: Andrei Marinica Date: Wed, 27 Mar 2024 01:05:44 +0200 Subject: [PATCH 7/7] multisig interactor cleanup --- contracts/examples/multisig/interact/config.toml | 2 +- .../multisig/interact/src/multisig_interact.rs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/contracts/examples/multisig/interact/config.toml b/contracts/examples/multisig/interact/config.toml index 1a1e45429a..a3b733f73d 100644 --- a/contracts/examples/multisig/interact/config.toml +++ b/contracts/examples/multisig/interact/config.toml @@ -1,2 +1,2 @@ -gateway = 'https://testnet-gateway.multiversx.com' +gateway = 'https://devnet-gateway.multiversx.com' quorum = 2 diff --git a/contracts/examples/multisig/interact/src/multisig_interact.rs b/contracts/examples/multisig/interact/src/multisig_interact.rs index 60d4ad2359..c60d0c9fac 100644 --- a/contracts/examples/multisig/interact/src/multisig_interact.rs +++ b/contracts/examples/multisig/interact/src/multisig_interact.rs @@ -13,7 +13,7 @@ use multisig_interact_config::Config; use multisig_interact_state::State; use multiversx_sc_scenario::{ mandos_system::ScenarioRunner, - multiversx_sc::types::{BigUint, ReturnsNewAddress, ReturnsResultConv}, + multiversx_sc::types::{BigUint, ReturnsNewAddress, ReturnsResult}, scenario_format::interpret_trait::InterpretableFrom, standalone::retrieve_account_as_scenario_set_state, test_wallets, @@ -309,7 +309,7 @@ impl MultisigInteract { .to(self.state.multisig().to_address()) .typed(multisig_proxy::MultisigProxy) .quorum_reached(action_id) - .returns(ReturnsResultConv::::new()) + .returns(ReturnsResult) .prepare_async() .run() .await @@ -321,7 +321,7 @@ impl MultisigInteract { .to(self.state.multisig().to_address()) .typed(multisig_proxy::MultisigProxy) .signed(signer, action_id) - .returns(ReturnsResultConv::::new()) + .returns(ReturnsResult) .prepare_async() .run() .await @@ -388,7 +388,7 @@ impl MultisigInteract { .to(self.state.multisig().to_address()) .typed(multisig_proxy::MultisigProxy) .quorum() - .returns(ReturnsResultConv::::new()) + .returns(ReturnsResult) .prepare_async() .run() .await; @@ -403,7 +403,7 @@ impl MultisigInteract { .to(self.state.multisig().to_address()) .typed(multisig_proxy::MultisigProxy) .num_board_members() - .returns(ReturnsResultConv::::new()) + .returns(ReturnsResult) .prepare_async() .run() .await;