From 014449755827cc28b9e94528a6b675789d11a2cc Mon Sep 17 00:00:00 2001 From: Peter White Date: Tue, 28 Jan 2025 12:32:55 -0700 Subject: [PATCH] test(integration): refactor RLP test to use OriginFor. Cleanup comments and unused imports --- integration-tests/public/rlp/e2e_tests.rs | 40 ++++++++++------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/integration-tests/public/rlp/e2e_tests.rs b/integration-tests/public/rlp/e2e_tests.rs index 27433085471..98a9fbb486e 100644 --- a/integration-tests/public/rlp/e2e_tests.rs +++ b/integration-tests/public/rlp/e2e_tests.rs @@ -1,13 +1,13 @@ use super::rlp::*; use ink_e2e::{ ContractsRegistry, - Keypair, }; -use ink_sandbox::{api::prelude::*, AccountId32, DefaultSandbox, Sandbox}; +use ink_sandbox::{api::prelude::*, DefaultSandbox, Sandbox}; use pallet_revive::ExecReturnValue; use ink::H160; -use ink::primitives::{AccountId, DepositLimit}; -use ink_e2e::subxt::tx::Signer; +use ink::primitives::{DepositLimit}; +use ink_sandbox::frame_system::pallet_prelude::OriginFor; + const STORAGE_DEPOSIT_LIMIT: DepositLimit = DepositLimit::Unchecked; #[test] @@ -15,8 +15,9 @@ fn call_rlp_encoded_message() { let built_contracts = ::ink_e2e::build_root_and_contract_dependencies(); let contracts = ContractsRegistry::new(built_contracts); - let mut sandbox = ink_e2e::DefaultSandbox::default(); + let mut sandbox = DefaultSandbox::default(); let caller = ink_e2e::alice(); + let origin = DefaultSandbox::convert_account_to_origin(DefaultSandbox::default_actor()); sandbox .mint_into( @@ -25,10 +26,8 @@ fn call_rlp_encoded_message() { ) .unwrap_or_else(|_| panic!("Failed to mint tokens")); - let origin = DefaultSandbox::convert_account_to_origin(AccountId32::from(caller.public_key().0)); sandbox.map_account(origin.clone()).expect("unable to map"); - // given let constructor = RlpRef::new(false); let params = constructor .endowment(0u32.into()) @@ -37,10 +36,8 @@ fn call_rlp_encoded_message() { .params(); let exec_input = params.exec_input(); - // TODO: could potentially simplify if helpers are exposed. - let code = contracts.load_code("rlp"); - let contract_addr = + let contract_addr = ::deploy_contract( &mut sandbox, code, @@ -48,7 +45,7 @@ fn call_rlp_encoded_message() { ink::scale::Encode::encode(&exec_input), // salt None, - origin, + origin.clone(), ::default_gas_limit(), STORAGE_DEPOSIT_LIMIT ) @@ -57,21 +54,21 @@ fn call_rlp_encoded_message() { let mut contract = ContractSandbox { sandbox, - contract_addr: contract_addr, + contract_addr, }; // set value - contract.call("set_value", true, caller.clone()); + contract.call("set_value", true, origin.clone()); // get value let value: bool = - contract.call_with_return_value("get_value", Vec::::new(), caller); + contract.call_with_return_value("get_value", Vec::::new(), origin); assert!(value, "value should have been set to true"); } struct ContractSandbox { - sandbox: ink_e2e::DefaultSandbox, + sandbox: DefaultSandbox, contract_addr: H160, } @@ -80,17 +77,17 @@ impl ContractSandbox { &mut self, message: &str, args: Args, - caller: Keypair, + origin: OriginFor<::Runtime>, ) -> Ret where Args: ink::rlp::Encodable, Ret: ink::rlp::Decodable, { - let result = self.call(message, args, caller); + let result = self.call(message, args, origin); ink::rlp::Decodable::decode(&mut &result[..]).expect("decode failed") } - fn call(&mut self, message: &str, args: Args, caller: Keypair) -> Vec + fn call(&mut self, message: &str, args: Args, origin: OriginFor<::Runtime>) -> Vec where Args: ink::rlp::Encodable, { @@ -99,16 +96,15 @@ impl ContractSandbox { ink::rlp::Encodable::encode(&args, &mut args_buf); data.append(&mut args_buf); - let result = self.call_raw(data, caller); + let result = self.call_raw(data, origin); assert!(!result.did_revert(), "'{message}' failed {:?}", result); result.data } - fn call_raw(&mut self, data: Vec, caller: Keypair) -> ExecReturnValue { - let origin = DefaultSandbox::convert_account_to_origin(AccountId32::from(caller.public_key().0)); + fn call_raw(&mut self, data: Vec, origin: OriginFor<::Runtime>) -> ExecReturnValue { let result = - + ::call_contract( &mut self.sandbox, self.contract_addr.clone(),