diff --git a/framework/scenario/src/api/impl_vh/static_api.rs b/framework/scenario/src/api/impl_vh/static_api.rs index 7e375a0c31..d4941a60db 100644 --- a/framework/scenario/src/api/impl_vh/static_api.rs +++ b/framework/scenario/src/api/impl_vh/static_api.rs @@ -55,7 +55,7 @@ impl StaticApi { /// /// This placeholder then needs to be converted to something useful. pub fn is_current_address_placeholder(address: &Address) -> bool { - address.as_array() == StaticApiVMHooksHandler::CURRENT_ADDRESS_PLACEHOLDER.as_array() + address == &StaticApiVMHooksHandler::CURRENT_ADDRESS_PLACEHOLDER } pub fn reset() { diff --git a/framework/scenario/src/facade/world_tx/scenario_exec_call.rs b/framework/scenario/src/facade/world_tx/scenario_exec_call.rs index ca09b9d318..9c1551111b 100644 --- a/framework/scenario/src/facade/world_tx/scenario_exec_call.rs +++ b/framework/scenario/src/facade/world_tx/scenario_exec_call.rs @@ -52,7 +52,7 @@ impl<'w> TxEnvMockDeployAddress for ScenarioEnvExec<'w> { .world .get_state() .accounts - .get(&from_value.to_vm_address()) + .get(&from_value.to_address()) .expect("sender does not exist") .nonce; let new_address_value = address_annotated(self, &new_address); diff --git a/framework/scenario/src/facade/world_tx/scenario_set_state.rs b/framework/scenario/src/facade/world_tx/scenario_set_state.rs index d036d647cd..3fd44d70b3 100644 --- a/framework/scenario/src/facade/world_tx/scenario_set_state.rs +++ b/framework/scenario/src/facade/world_tx/scenario_set_state.rs @@ -73,7 +73,7 @@ impl ScenarioWorld { let balance_value = big_uint_annotated(&env, &balance); let accounts = &mut self.get_mut_state().accounts; for (vm_address_key, account) in accounts.iter_mut() { - if vm_address_key == &address_value.to_vm_address() { + if vm_address_key == &address_value.to_address() { account.egld_balance.clone_from(&balance_value.value); } } @@ -88,8 +88,8 @@ impl ScenarioWorld { let address_value = address_annotated(&env, &address); let balance_value = big_uint_annotated(&env, &balance); let accounts = &mut self.get_mut_state().accounts; - for (vm_address, account) in accounts.iter_mut() { - if vm_address == &address_value.to_vm_address() { + for (address, account) in accounts.iter_mut() { + if address == &address_value.to_address() { account.esdt.set_esdt_balance( token_id.to_vec(), 0, @@ -129,8 +129,8 @@ impl ScenarioWorld { let mut esdt_attributes = Vec::new(); let _ = attributes.top_encode(&mut esdt_attributes); let accounts = &mut self.get_mut_state().accounts; - for (vm_address, account) in accounts.iter_mut() { - if vm_address == &address_value.to_vm_address() { + for (account_address, account) in accounts.iter_mut() { + if account_address == &address_value.to_address() { account.esdt.set_esdt_balance( token_id.to_vec(), nonce_value.value, @@ -138,7 +138,7 @@ impl ScenarioWorld { EsdtInstanceMetadata { creator: creator .as_ref() - .map(|c| address_annotated(&env, c).to_vm_address()), + .map(|c| address_annotated(&env, c).to_address()), attributes: esdt_attributes.clone(), royalties: royalties_value.value, name: name.unwrap_or_default().to_vec(), @@ -156,8 +156,8 @@ impl ScenarioWorld { BigUintValue: From, { let accounts = &mut self.get_mut_state().accounts; - for (vm_address, account) in accounts.iter_mut() { - if vm_address == &AddressKey::from(address).to_vm_address() { + for (account_address, account) in accounts.iter_mut() { + if account_address == &AddressKey::from(address).to_address() { account .developer_rewards .clone_from(&BigUintValue::from(developer_rewards).value); @@ -172,8 +172,8 @@ impl ScenarioWorld { let env = self.new_env_data(); let address_value = address_annotated(&env, &address); let accounts = &mut self.get_mut_state().accounts; - for (vm_address, account) in accounts.iter_mut() { - if vm_address == &address_value.to_vm_address() { + for (account_address, account) in accounts.iter_mut() { + if account_address == &address_value.to_address() { account.esdt.set_roles( token_id.to_vec(), roles @@ -231,7 +231,7 @@ impl<'w> SetStateBuilderBase<'w> { .vm_runner .blockchain_mock .state - .account_exists(&address.to_vm_address()), + .account_exists(&address.to_address()), "updating existing accounts currently not supported" ); diff --git a/framework/scenario/src/scenario/model/transaction/tx_response.rs b/framework/scenario/src/scenario/model/transaction/tx_response.rs index 547b381338..8215a60756 100644 --- a/framework/scenario/src/scenario/model/transaction/tx_response.rs +++ b/framework/scenario/src/scenario/model/transaction/tx_response.rs @@ -37,7 +37,7 @@ impl TxResponse { .result_logs .iter() .map(|tx_log| Log { - address: Address::from_slice(tx_log.address.as_bytes()), + address: tx_log.address.clone(), endpoint: tx_log.endpoint.to_string(), topics: tx_log.topics.clone(), data: tx_log.data.clone(), diff --git a/framework/scenario/src/scenario/model/value/address_key.rs b/framework/scenario/src/scenario/model/value/address_key.rs index f54e05b2f3..a5234d6a63 100644 --- a/framework/scenario/src/scenario/model/value/address_key.rs +++ b/framework/scenario/src/scenario/model/value/address_key.rs @@ -29,10 +29,6 @@ impl AddressKey { pub fn to_address(&self) -> Address { self.value.clone() } - - pub fn to_vm_address(&self) -> multiversx_chain_vm::types::VMAddress { - self.value.as_array().into() - } } impl Ord for AddressKey { diff --git a/framework/scenario/src/scenario/model/value/address_value.rs b/framework/scenario/src/scenario/model/value/address_value.rs index fdde631ede..8ef4e78a26 100644 --- a/framework/scenario/src/scenario/model/value/address_value.rs +++ b/framework/scenario/src/scenario/model/value/address_value.rs @@ -36,10 +36,6 @@ impl AddressValue { pub fn to_address(&self) -> Address { self.value.clone() } - - pub fn to_vm_address(&self) -> multiversx_chain_vm::types::VMAddress { - self.value.as_array().into() - } } impl fmt::Display for AddressValue { diff --git a/framework/scenario/src/scenario/run_vm/check_state.rs b/framework/scenario/src/scenario/run_vm/check_state.rs index abed0212cc..c1d8275c2b 100644 --- a/framework/scenario/src/scenario/run_vm/check_state.rs +++ b/framework/scenario/src/scenario/run_vm/check_state.rs @@ -23,7 +23,7 @@ impl ScenarioVMRunner { fn execute(state: &BlockchainState, accounts: &CheckAccounts) { for (expected_address, expected_account) in accounts.accounts.iter() { - if let Some(account) = state.accounts.get(&expected_address.to_vm_address()) { + if let Some(account) = state.accounts.get(&expected_address.to_address()) { assert!( expected_account.nonce.check(account.nonce), "bad account nonce. Address: {}. Want: {}. Have: {}", diff --git a/framework/scenario/src/scenario/run_vm/sc_call.rs b/framework/scenario/src/scenario/run_vm/sc_call.rs index 0a66578eaf..0cfad3aa62 100644 --- a/framework/scenario/src/scenario/run_vm/sc_call.rs +++ b/framework/scenario/src/scenario/run_vm/sc_call.rs @@ -86,8 +86,8 @@ impl ScenarioVMRunner { fn tx_input_from_call(sc_call_step: &ScCallStep) -> TxInput { let tx = &sc_call_step.tx; TxInput { - from: tx.from.to_vm_address(), - to: tx.to.to_vm_address(), + from: tx.from.to_address(), + to: tx.to.to_address(), egld_value: tx.egld_value.value.clone(), esdt_values: tx_esdt_transfers_from_scenario(tx.esdt_value.as_slice()), func_name: tx.function.clone().into(), diff --git a/framework/scenario/src/scenario/run_vm/sc_deploy.rs b/framework/scenario/src/scenario/run_vm/sc_deploy.rs index 11bb387a6b..4386a1ab5d 100644 --- a/framework/scenario/src/scenario/run_vm/sc_deploy.rs +++ b/framework/scenario/src/scenario/run_vm/sc_deploy.rs @@ -43,7 +43,7 @@ impl ScenarioVMRunner { tx_result.pending_calls.no_calls(), "Async calls from constructors are currently not supported" ); - (new_address.as_array().into(), tx_result) + (new_address, tx_result) } pub fn perform_sc_deploy_lambda_and_check( @@ -65,7 +65,7 @@ impl ScenarioVMRunner { fn tx_input_from_deploy(sc_deploy_step: &ScDeployStep) -> TxInput { let tx = &sc_deploy_step.tx; TxInput { - from: tx.from.to_vm_address(), + from: tx.from.to_address(), to: multiversx_chain_vm::types::VMAddress::zero(), egld_value: tx.egld_value.value.clone(), esdt_values: Vec::new(), diff --git a/framework/scenario/src/scenario/run_vm/sc_query.rs b/framework/scenario/src/scenario/run_vm/sc_query.rs index 1d3476ab4e..2e0c1cbdda 100644 --- a/framework/scenario/src/scenario/run_vm/sc_query.rs +++ b/framework/scenario/src/scenario/run_vm/sc_query.rs @@ -48,8 +48,8 @@ impl ScenarioVMRunner { fn tx_input_from_query(sc_query_step: &ScQueryStep) -> TxInput { TxInput { - from: sc_query_step.tx.to.to_vm_address(), - to: sc_query_step.tx.to.to_vm_address(), + from: sc_query_step.tx.to.to_address(), + to: sc_query_step.tx.to.to_address(), egld_value: BigUint::from(0u32), esdt_values: Vec::new(), func_name: sc_query_step.tx.function.clone().into(), diff --git a/framework/scenario/src/scenario/run_vm/set_state.rs b/framework/scenario/src/scenario/run_vm/set_state.rs index 8284d42422..42042ee1cc 100644 --- a/framework/scenario/src/scenario/run_vm/set_state.rs +++ b/framework/scenario/src/scenario/run_vm/set_state.rs @@ -35,7 +35,7 @@ fn execute(state: &mut BlockchainState, set_state_step: &SetStateStep) { ); state.validate_and_add_account(AccountData { - address: address.to_vm_address(), + address: address.to_address(), nonce: account .nonce .as_ref() @@ -65,7 +65,7 @@ fn execute(state: &mut BlockchainState, set_state_step: &SetStateStep) { contract_owner: account .owner .as_ref() - .map(|address_value| address_value.to_vm_address()), + .map(|address_value| address_value.to_address()), developer_rewards: account .developer_rewards .as_ref() @@ -79,9 +79,9 @@ fn execute(state: &mut BlockchainState, set_state_step: &SetStateStep) { "field should have SC format" ); state.put_new_address( - new_address.creator_address.to_vm_address(), + new_address.creator_address.to_address(), new_address.creator_nonce.value, - new_address.new_address.to_vm_address(), + new_address.new_address.to_address(), ) } for new_token_identifier in set_state_step.new_token_identifiers.iter().cloned() { @@ -155,7 +155,7 @@ fn convert_scenario_esdt_instance_to_world_mock( creator: scenario_esdt .creator .as_ref() - .map(|creator| creator.to_vm_address()), + .map(|creator| creator.to_address()), royalties: scenario_esdt .royalties .as_ref() diff --git a/framework/scenario/src/scenario/run_vm/transfer.rs b/framework/scenario/src/scenario/run_vm/transfer.rs index 0ecb89b7b8..a0fcc948dc 100644 --- a/framework/scenario/src/scenario/run_vm/transfer.rs +++ b/framework/scenario/src/scenario/run_vm/transfer.rs @@ -18,7 +18,7 @@ impl ScenarioVMRunner { pub fn perform_validator_reward(&mut self, validator_rewards_step: &ValidatorRewardStep) { self.blockchain_mock.state.increase_validator_reward( - &validator_rewards_step.tx.to.to_vm_address(), + &validator_rewards_step.tx.to.to_address(), &validator_rewards_step.tx.egld_value.value, ); } @@ -26,8 +26,8 @@ impl ScenarioVMRunner { fn tx_input_from_transfer(tx_transfer: &TxTransfer) -> TxInput { TxInput { - from: tx_transfer.from.to_vm_address(), - to: tx_transfer.to.to_vm_address(), + from: tx_transfer.from.to_address(), + to: tx_transfer.to.to_address(), egld_value: tx_transfer.egld_value.value.clone(), esdt_values: tx_esdt_transfers_from_scenario(tx_transfer.esdt_value.as_slice()), func_name: TxFunctionName::EMPTY, diff --git a/framework/scenario/src/whitebox_legacy/contract_obj_wrapper.rs b/framework/scenario/src/whitebox_legacy/contract_obj_wrapper.rs index b88377b98d..3ae56e5a61 100644 --- a/framework/scenario/src/whitebox_legacy/contract_obj_wrapper.rs +++ b/framework/scenario/src/whitebox_legacy/contract_obj_wrapper.rs @@ -13,10 +13,7 @@ use crate::{ ScenarioWorld, }; use multiversx_chain_scenario_format::interpret_trait::InterpretableFrom; -use multiversx_chain_vm::{ - tx_mock::{TxContext, TxContextStack, TxFunctionName, TxResult}, - types::VMAddress, -}; +use multiversx_chain_vm::tx_mock::{TxContext, TxContextStack, TxFunctionName, TxResult}; use multiversx_sc::types::{BigUint, H256}; use num_traits::Zero; @@ -89,7 +86,7 @@ impl BlockchainStateWrapper { } pub fn check_egld_balance(&self, address: &Address, expected_balance: &num_bigint::BigUint) { - let actual_balance = match &self.world.get_state().accounts.get(&to_vm_address(address)) { + let actual_balance = match &self.world.get_state().accounts.get(address) { Some(acc) => acc.egld_balance.clone(), None => num_bigint::BigUint::zero(), }; @@ -109,7 +106,7 @@ impl BlockchainStateWrapper { token_id: &[u8], expected_balance: &num_bigint::BigUint, ) { - let actual_balance = match &self.world.get_state().accounts.get(&to_vm_address(address)) { + let actual_balance = match &self.world.get_state().accounts.get(address) { Some(acc) => acc.esdt.get_esdt_balance(token_id, 0), None => num_bigint::BigUint::zero(), }; @@ -135,7 +132,7 @@ impl BlockchainStateWrapper { T: TopEncode + TopDecode + PartialEq + core::fmt::Debug, { let (actual_balance, actual_attributes_serialized) = - match &self.world.get_state().accounts.get(&to_vm_address(address)) { + match &self.world.get_state().accounts.get(address) { Some(acc) => { let esdt_data = acc.esdt.get_by_identifier_or_default(token_id); let opt_instance = esdt_data.instances.get_by_nonce(nonce); @@ -304,20 +301,19 @@ impl BlockchainStateWrapper { CB: ContractBase + CallableContract + 'static, ContractObjBuilder: 'static + Copy + Fn() -> CB, { - let deployer_vm_address = to_vm_address(deployer); let deployer_acc = self .world .get_state() .accounts - .get(&deployer_vm_address) + .get(deployer) .unwrap() .clone(); let new_sc_address = self.address_factory.new_sc_address(); self.world.get_mut_state().put_new_address( - deployer_vm_address, + deployer.clone(), deployer_acc.nonce, - to_vm_address(&new_sc_address), + new_sc_address.clone(), ); ContractObjWrapper::new(new_sc_address, obj_builder) @@ -493,8 +489,7 @@ impl BlockchainStateWrapper { } pub fn add_mandos_set_account(&mut self, address: &Address) { - let vm_address = to_vm_address(address); - if let Some(acc) = self.world.get_state().accounts.get(&vm_address).cloned() { + if let Some(acc) = self.world.get_state().accounts.get(address).cloned() { let opt_contract_path = self.address_to_code_path.get(address); if let Some(trace) = &mut self.world.get_mut_debugger_backend().trace { MandosGenerator::new(&mut trace.scenario_trace, &mut self.current_tx_id) @@ -504,8 +499,7 @@ impl BlockchainStateWrapper { } pub fn add_mandos_check_account(&mut self, address: &Address) { - let vm_address = to_vm_address(address); - if let Some(acc) = self.world.get_state().accounts.get(&vm_address).cloned() { + if let Some(acc) = self.world.get_state().accounts.get(address).cloned() { if let Some(trace) = &mut self.world.get_mut_debugger_backend().trace { MandosGenerator::new(&mut trace.scenario_trace, &mut self.current_tx_id) .check_account(&acc); @@ -662,7 +656,7 @@ impl BlockchainStateWrapper { impl BlockchainStateWrapper { pub fn get_egld_balance(&self, address: &Address) -> num_bigint::BigUint { - match self.world.get_state().accounts.get(&to_vm_address(address)) { + match self.world.get_state().accounts.get(address) { Some(acc) => acc.egld_balance.clone(), None => panic!( "get_egld_balance: Account {:?} does not exist", @@ -677,7 +671,7 @@ impl BlockchainStateWrapper { token_id: &[u8], token_nonce: u64, ) -> num_bigint::BigUint { - match self.world.get_state().accounts.get(&to_vm_address(address)) { + match self.world.get_state().accounts.get(address) { Some(acc) => acc.esdt.get_esdt_balance(token_id, token_nonce), None => panic!( "get_esdt_balance: Account {:?} does not exist", @@ -692,7 +686,7 @@ impl BlockchainStateWrapper { token_id: &[u8], token_nonce: u64, ) -> Option { - match self.world.get_state().accounts.get(&to_vm_address(address)) { + match self.world.get_state().accounts.get(address) { Some(acc) => match acc.esdt.get_by_identifier(token_id) { Some(esdt_data) => esdt_data .instances @@ -708,8 +702,8 @@ impl BlockchainStateWrapper { } pub fn dump_state(&self) { - for addr in self.world.get_state().accounts.keys() { - self.dump_state_for_account_hex_attributes(&to_framework_address(addr)); + for address in self.world.get_state().accounts.keys() { + self.dump_state_for_account_hex_attributes(address); println!(); } } @@ -725,8 +719,7 @@ impl BlockchainStateWrapper { &self, address: &Address, ) { - let vm_address = to_vm_address(address); - let account = match self.world.get_state().accounts.get(&vm_address) { + let account = match self.world.get_state().accounts.get(address) { Some(acc) => acc, None => panic!( "dump_state_for_account: Account {:?} does not exist", @@ -817,11 +810,3 @@ where let c_base = func(); Box::new(c_base) } - -fn to_vm_address(address: &Address) -> VMAddress { - address.as_array().into() -} - -fn to_framework_address(vm_address: &VMAddress) -> Address { - vm_address.as_array().into() -}