diff --git a/contracts/feature-tests/composability/promises-features/sc-config.toml b/contracts/feature-tests/composability/promises-features/sc-config.toml index 79ef7a04a8..d3be3200f4 100644 --- a/contracts/feature-tests/composability/promises-features/sc-config.toml +++ b/contracts/feature-tests/composability/promises-features/sc-config.toml @@ -5,3 +5,6 @@ main = "promises-features" name = "promises-features" add-unlabelled = true ei = "1.3" # the whole point of this config is to explicitly specify that this contract needs EI 1.3/VM 1.5 + +[[proxy]] +path = "src/promises_feature_proxy.rs" diff --git a/contracts/feature-tests/composability/promises-features/src/promises_feature_proxy.rs b/contracts/feature-tests/composability/promises-features/src/promises_feature_proxy.rs new file mode 100644 index 0000000000..d5fb14bf19 --- /dev/null +++ b/contracts/feature-tests/composability/promises-features/src/promises_feature_proxy.rs @@ -0,0 +1,254 @@ +// 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 PromisesFeaturesProxy; + +impl TxProxyTrait for PromisesFeaturesProxy +where + Env: TxEnv, + From: TxFrom, + To: TxTo, + Gas: TxGas, +{ + type TxProxyMethods = PromisesFeaturesProxyMethods; + + fn proxy_methods(self, tx: Tx) -> Self::TxProxyMethods { + PromisesFeaturesProxyMethods { wrapped_tx: tx } + } +} + +pub struct PromisesFeaturesProxyMethods +where + Env: TxEnv, + From: TxFrom, + To: TxTo, + Gas: TxGas, +{ + wrapped_tx: Tx, +} + +#[rustfmt::skip] +impl PromisesFeaturesProxyMethods +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 PromisesFeaturesProxyMethods +where + Env: TxEnv, + Env::Api: VMApi, + From: TxFrom, + To: TxTo, + Gas: TxGas, +{ + pub fn callback_data( + self, + ) -> TxTypedCall>> { + self.wrapped_tx + .payment(NotPayable) + .raw_call("callback_data") + .original_result() + } + + pub fn callback_data_at_index< + Arg0: ProxyArg, + >( + self, + index: Arg0, + ) -> TxTypedCall, EgldOrEsdtTokenIdentifier, u64, BigUint, MultiValueManagedVec>>> { + self.wrapped_tx + .payment(NotPayable) + .raw_call("callback_data_at_index") + .argument(&index) + .original_result() + } + + pub fn clear_callback_data( + self, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("clear_callback_data") + .original_result() + } + + pub fn forward_promise_accept_funds< + Arg0: ProxyArg>, + >( + self, + to: Arg0, + ) -> TxTypedCall { + self.wrapped_tx + .raw_call("forward_promise_accept_funds") + .argument(&to) + .original_result() + } + + pub fn forward_promise_retrieve_funds< + Arg0: ProxyArg>, + Arg1: ProxyArg>, + Arg2: ProxyArg, + Arg3: ProxyArg>, + >( + self, + to: Arg0, + token: Arg1, + token_nonce: Arg2, + amount: Arg3, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("forward_promise_retrieve_funds") + .argument(&to) + .argument(&token) + .argument(&token_nonce) + .argument(&amount) + .original_result() + } + + pub fn promise_raw_single_token< + Arg0: ProxyArg>, + Arg1: ProxyArg>, + Arg2: ProxyArg, + Arg3: ProxyArg, + Arg4: ProxyArg>>, + >( + self, + to: Arg0, + endpoint_name: Arg1, + gas_limit: Arg2, + extra_gas_for_callback: Arg3, + args: Arg4, + ) -> TxTypedCall { + self.wrapped_tx + .raw_call("promise_raw_single_token") + .argument(&to) + .argument(&endpoint_name) + .argument(&gas_limit) + .argument(&extra_gas_for_callback) + .argument(&args) + .original_result() + } + + pub fn promise_raw_multi_transfer< + Arg0: ProxyArg>, + Arg1: ProxyArg>, + Arg2: ProxyArg, + Arg3: ProxyArg>>, + >( + self, + to: Arg0, + endpoint_name: Arg1, + extra_gas_for_callback: Arg2, + token_payment_args: Arg3, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("promise_raw_multi_transfer") + .argument(&to) + .argument(&endpoint_name) + .argument(&extra_gas_for_callback) + .argument(&token_payment_args) + .original_result() + } + + pub fn forward_sync_retrieve_funds_bt< + Arg0: ProxyArg>, + Arg1: ProxyArg>, + Arg2: ProxyArg, + Arg3: ProxyArg>, + >( + self, + to: Arg0, + token: Arg1, + token_nonce: Arg2, + amount: Arg3, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("forward_sync_retrieve_funds_bt") + .argument(&to) + .argument(&token) + .argument(&token_nonce) + .argument(&amount) + .original_result() + } + + pub fn forward_sync_retrieve_funds_bt_twice< + Arg0: ProxyArg>, + Arg1: ProxyArg>, + Arg2: ProxyArg, + Arg3: ProxyArg>, + >( + self, + to: Arg0, + token: Arg1, + token_nonce: Arg2, + amount: Arg3, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("forward_sync_retrieve_funds_bt_twice") + .argument(&to) + .argument(&token) + .argument(&token_nonce) + .argument(&amount) + .original_result() + } + + pub fn forward_promise_retrieve_funds_back_transfers< + Arg0: ProxyArg>, + Arg1: ProxyArg>, + Arg2: ProxyArg, + Arg3: ProxyArg>, + >( + self, + to: Arg0, + token: Arg1, + token_nonce: Arg2, + amount: Arg3, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("forward_promise_retrieve_funds_back_transfers") + .argument(&to) + .argument(&token) + .argument(&token_nonce) + .argument(&amount) + .original_result() + } +} + +#[type_abi] +#[derive(TopEncode, TopDecode)] +pub struct CallbackData +where + Api: ManagedTypeApi, +{ + pub callback_name: ManagedBuffer, + pub token_identifier: EgldOrEsdtTokenIdentifier, + pub token_nonce: u64, + pub token_amount: BigUint, + pub args: ManagedVec>, +} diff --git a/contracts/feature-tests/composability/promises-features/src/promises_main.rs b/contracts/feature-tests/composability/promises-features/src/promises_main.rs index 511b0d76d8..2387879943 100644 --- a/contracts/feature-tests/composability/promises-features/src/promises_main.rs +++ b/contracts/feature-tests/composability/promises-features/src/promises_main.rs @@ -6,6 +6,7 @@ mod fwd_call_promise_direct; mod fwd_call_promises; mod fwd_call_promises_bt; pub mod fwd_call_sync_bt; +pub mod promises_feature_proxy; pub mod vault_proxy; multiversx_sc::imports!(); diff --git a/contracts/feature-tests/composability/tests/promises_feature_blackbox_test.rs b/contracts/feature-tests/composability/tests/promises_feature_blackbox_test.rs index c7fa6600d2..4fd4f4d1cc 100644 --- a/contracts/feature-tests/composability/tests/promises_feature_blackbox_test.rs +++ b/contracts/feature-tests/composability/tests/promises_feature_blackbox_test.rs @@ -1,73 +1,47 @@ -#![allow(deprecated)] // TODO: unified syntax - use multiversx_sc::types::BigUint; use multiversx_sc_scenario::imports::*; -use promises_features::fwd_call_sync_bt::ProxyTrait; +use promises_features::promises_feature_proxy; -const USER_ADDRESS_EXPR: &str = "address:user"; -const PROMISES_FEATURE_ADDRESS_EXPR: &str = "sc:promises-feature"; -const PROMISES_FEATURES_PATH_EXPR: &str = - "mxsc:promises-features/output/promises-feature.mxsc.json"; -const VAULT_ADDRESS_EXPR: &str = "sc:vault"; -const VAULT_PATH_EXPR: &str = "mxsc:../vault/output/vault.mxsc.json"; +const USER_ADDRESS: TestAddress = TestAddress::new("user"); +const PROMISES_FEATURE_ADDRESS: TestSCAddress = TestSCAddress::new("promises-feature"); +const PROMISES_FEATURES_PATH: MxscPath = + MxscPath::new("promises-features/output/promises-feature.mxsc.json"); +const VAULT_ADDRESS: TestSCAddress = TestSCAddress::new("vault"); +const VAULT_PATH: MxscPath = MxscPath::new("../vault/output/vault.mxsc.json"); -const TOKEN_ID_EXPR: &str = "str:TOKEN-123456"; +const TOKEN_ID_EXPR: TestTokenIdentifier = TestTokenIdentifier::new("TOKEN-123456"); const TOKEN_ID: &[u8] = b"TOKEN-123456"; -type PromisesFeaturesContract = ContractInfo>; -type VaultContract = ContractInfo>; - fn world() -> ScenarioWorld { let mut blockchain = ScenarioWorld::new(); - blockchain.register_contract( - PROMISES_FEATURES_PATH_EXPR, - promises_features::ContractBuilder, - ); - blockchain.register_contract(VAULT_PATH_EXPR, vault::ContractBuilder); + blockchain.register_contract(PROMISES_FEATURES_PATH, promises_features::ContractBuilder); + blockchain.register_contract(VAULT_PATH, vault::ContractBuilder); blockchain } struct PromisesFeaturesTestState { world: ScenarioWorld, - promises_features_contract: PromisesFeaturesContract, - vault_contract: VaultContract, } impl PromisesFeaturesTestState { fn new() -> Self { let mut world = world(); - let promises_feature_code = world.code_expression(PROMISES_FEATURES_PATH_EXPR); - let vault_code = world.code_expression(VAULT_PATH_EXPR); - - world.set_state_step( - SetStateStep::new() - .put_account(USER_ADDRESS_EXPR, Account::new().nonce(1)) - .put_account( - PROMISES_FEATURE_ADDRESS_EXPR, - Account::new().nonce(1).code(promises_feature_code), - ) - .put_account( - VAULT_ADDRESS_EXPR, - Account::new() - .nonce(1) - .code(vault_code) - .esdt_balance(TOKEN_ID_EXPR, "1000"), - ), - ); - - let promises_features_contract = - PromisesFeaturesContract::new(PROMISES_FEATURE_ADDRESS_EXPR); - let vault_contract = VaultContract::new(VAULT_ADDRESS_EXPR); - - Self { - world, - promises_features_contract, - vault_contract, - } + world.account(USER_ADDRESS).nonce(1); + world + .account(PROMISES_FEATURE_ADDRESS) + .nonce(1) + .code(PROMISES_FEATURES_PATH); + world + .account(VAULT_ADDRESS) + .nonce(1) + .code(VAULT_PATH) + .esdt_balance(TOKEN_ID_EXPR, 1000); + + Self { world } } } @@ -76,25 +50,19 @@ fn test_back_transfers() { let mut state = PromisesFeaturesTestState::new(); let token_amount = BigUint::from(1000u64); - state.world.sc_call( - ScCallStep::new().from(USER_ADDRESS_EXPR).call( - state - .promises_features_contract - .forward_sync_retrieve_funds_bt( - state.vault_contract, - TOKEN_ID, - 0u64, - &token_amount, - ), - ), - ); + state + .world + .tx() + .from(USER_ADDRESS) + .to(PROMISES_FEATURE_ADDRESS) + .typed(promises_feature_proxy::PromisesFeaturesProxy) + .forward_sync_retrieve_funds_bt(VAULT_ADDRESS, TOKEN_ID, 0u64, &token_amount) + .run(); state .world - .check_state_step(CheckStateStep::new().put_account( - state.promises_features_contract, - CheckAccount::new().esdt_balance(TOKEN_ID_EXPR, token_amount), - )); + .check_account(PROMISES_FEATURE_ADDRESS) + .esdt_balance(TOKEN_ID_EXPR, token_amount); } #[test] @@ -102,25 +70,18 @@ fn test_multi_call_back_transfers() { let mut state = PromisesFeaturesTestState::new(); let token_amount = BigUint::from(1000u64); let half_token_amount = token_amount.clone() / 2u64; - let vault_address = state.vault_contract.to_address(); - - state.world.sc_call( - ScCallStep::new().from(USER_ADDRESS_EXPR).call( - state - .promises_features_contract - .forward_sync_retrieve_funds_bt_twice( - vault_address.clone(), - TOKEN_ID, - 0u64, - &half_token_amount, - ), - ), - ); state .world - .check_state_step(CheckStateStep::new().put_account( - state.promises_features_contract, - CheckAccount::new().esdt_balance(TOKEN_ID_EXPR, token_amount), - )); + .tx() + .from(USER_ADDRESS) + .to(PROMISES_FEATURE_ADDRESS) + .typed(promises_feature_proxy::PromisesFeaturesProxy) + .forward_sync_retrieve_funds_bt_twice(VAULT_ADDRESS, TOKEN_ID, 0u64, &half_token_amount) + .run(); + + state + .world + .check_account(PROMISES_FEATURE_ADDRESS) + .esdt_balance(TOKEN_ID_EXPR, token_amount); }