Skip to content

Commit

Permalink
XVM: replace MultiAddress with AccountId for ink! contracts (#1024)
Browse files Browse the repository at this point in the history
* XVM: replace MultiAddress with AccountId for ink! contracts.

* Remove unused feature in integration tests.
  • Loading branch information
shaunxw authored Sep 14, 2023
1 parent df73ca4 commit c6d4dfe
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
4 changes: 1 addition & 3 deletions pallets/xvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ use pallet_contracts_primitives::ReturnFlags;
use pallet_evm::GasWeightMapping;
use parity_scale_codec::Decode;
use sp_core::{H160, U256};
use sp_runtime::traits::StaticLookup;
use sp_std::{marker::PhantomData, prelude::*};

use astar_primitives::{
Expand Down Expand Up @@ -290,8 +289,7 @@ where

let dest = {
let error = CallFailure::revert(InvalidTarget, overheads);
let decoded = Decode::decode(&mut target.as_ref()).map_err(|_| error.clone())?;
T::Lookup::lookup(decoded).map_err(|_| error)
Decode::decode(&mut target.as_ref()).map_err(|_| error.clone())
}?;

// With overheads, less weight is available.
Expand Down
2 changes: 1 addition & 1 deletion pallets/xvm/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fn calling_into_same_vm_is_not_allowed() {
weight_limit: Weight::from_parts(1_000_000, 1_000_000),
};
let wasm_vm_id = VmId::Wasm;
let wasm_target = MultiAddress::<AccountId, ()>::Id(ALICE).encode();
let wasm_target = ALICE.encode();
let wasm_used_weight: Weight =
weights::SubstrateWeight::<TestRuntime>::wasm_call_overheads();
assert_noop!(
Expand Down
28 changes: 14 additions & 14 deletions tests/integration/src/xvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ fn wasm_payable_call_via_xvm_works() {
},
VmId::Wasm,
ALICE,
MultiAddress::<AccountId32, ()>::Id(wasm_payable_addr.clone()).encode(),
wasm_payable_addr.clone().encode(),
// Calling `deposit`
hex::decode("0000002a").expect("invalid selector hex"),
value,
Expand All @@ -255,10 +255,10 @@ fn calling_wasm_payable_from_evm_fails_if_caller_contract_balance_below_ed() {
RuntimeOrigin::root(),
alith(),
evm_caller_addr.clone(),
// to: 0x00a8f69d59df362b69a8d4acdb9001eb3e1b8d067b8fdaa70081aed945bde5c48c
// to: 0xa8f69d59df362b69a8d4acdb9001eb3e1b8d067b8fdaa70081aed945bde5c48c
// input: 0x0000002a (deposit)
// value: 1000000000
hex::decode("4012b914000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000003b9aca00000000000000000000000000000000000000000000000000000000000000002100a8f69d59df362b69a8d4acdb9001eb3e1b8d067b8fdaa70081aed945bde5c48c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000002a00000000000000000000000000000000000000000000000000000000").expect("invalid call input hex"),
hex::decode("4012b914000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000003b9aca000000000000000000000000000000000000000000000000000000000000000020a8f69d59df362b69a8d4acdb9001eb3e1b8d067b8fdaa70081aed945bde5c48c00000000000000000000000000000000000000000000000000000000000000040000002a00000000000000000000000000000000000000000000000000000000").expect("invalid call input hex"),
U256::from(value),
1_000_000,
U256::from(DefaultBaseFeePerGas::get()),
Expand Down Expand Up @@ -295,10 +295,10 @@ fn calling_wasm_payable_from_evm_works() {
RuntimeOrigin::root(),
alith(),
evm_caller_addr.clone(),
// to: 0x00a8f69d59df362b69a8d4acdb9001eb3e1b8d067b8fdaa70081aed945bde5c48c
// to: 0xa8f69d59df362b69a8d4acdb9001eb3e1b8d067b8fdaa70081aed945bde5c48c
// input: 0x0000002a (deposit)
// value: 1000000000
hex::decode("4012b914000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000003b9aca00000000000000000000000000000000000000000000000000000000000000002100a8f69d59df362b69a8d4acdb9001eb3e1b8d067b8fdaa70081aed945bde5c48c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000002a00000000000000000000000000000000000000000000000000000000").expect("invalid call input hex"),
hex::decode("4012b914000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000003b9aca000000000000000000000000000000000000000000000000000000000000000020a8f69d59df362b69a8d4acdb9001eb3e1b8d067b8fdaa70081aed945bde5c48c00000000000000000000000000000000000000000000000000000000000000040000002a00000000000000000000000000000000000000000000000000000000").expect("invalid call input hex"),
U256::from(value),
1_000_000,
U256::from(DefaultBaseFeePerGas::get()),
Expand Down Expand Up @@ -363,10 +363,10 @@ fn reentrance_not_allowed() {
let evm_caller_addr = deploy_evm_contract(CALL_WASM_PAYBLE);
let _ = deploy_wasm_contract(WASM_PAYABLE_NAME);

// to: 0x00a8f69d59df362b69a8d4acdb9001eb3e1b8d067b8fdaa70081aed945bde5c48c
// to: 0xa8f69d59df362b69a8d4acdb9001eb3e1b8d067b8fdaa70081aed945bde5c48c
// input: 0x0000002a (deposit)
// value: 1000000000
let call_wasm_payable_input = hex::decode("4012b914000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000003b9aca00000000000000000000000000000000000000000000000000000000000000002100a8f69d59df362b69a8d4acdb9001eb3e1b8d067b8fdaa70081aed945bde5c48c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000002a00000000000000000000000000000000000000000000000000000000").expect("invalid call input hex");
let call_wasm_payable_input = hex::decode("4012b914000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000003b9aca000000000000000000000000000000000000000000000000000000000000000020a8f69d59df362b69a8d4acdb9001eb3e1b8d067b8fdaa70081aed945bde5c48c00000000000000000000000000000000000000000000000000000000000000040000002a00000000000000000000000000000000000000000000000000000000").expect("invalid call input hex");
let input = hex::decode("0000002a")
.expect("invalid selector hex")
.iter()
Expand Down Expand Up @@ -522,7 +522,7 @@ fn wasm_call_via_xvm_fails_if_revert() {
},
VmId::Wasm,
ALICE,
MultiAddress::<AccountId32, ()>::Id(wasm_callee_addr.clone()).encode(),
wasm_callee_addr.clone().encode(),
input,
0,
None,
Expand All @@ -546,10 +546,10 @@ fn evm_caller_reverts_if_wasm_callee_reverted() {
let _ = deploy_wasm_contract(WASM_DUMMY_ERROR_NAME);
let evm_caller_addr = deploy_evm_contract(CALL_WASM_PAYBLE);

// to: 0x00a0565d335eb7545deeb25563471219e6f0c9b9bb504a112a5f26fe61237c5a23
// to: 0xa0565d335eb7545deeb25563471219e6f0c9b9bb504a112a5f26fe61237c5a23
// input: 0x0000002a (do_revert)
// value: 0
let input = hex::decode("4012b914000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002100a0565d335eb7545deeb25563471219e6f0c9b9bb504a112a5f26fe61237c5a230000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000002a00000000000000000000000000000000000000000000000000000000").expect("invalid call input hex");
let input = hex::decode("4012b914000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020a0565d335eb7545deeb25563471219e6f0c9b9bb504a112a5f26fe61237c5a2300000000000000000000000000000000000000000000000000000000000000040000002a00000000000000000000000000000000000000000000000000000000").expect("invalid call input hex");
let tx = CheckedEthereumTx {
target: evm_caller_addr.clone(),
input: EthereumTxInput::try_from(input).expect("input too large"),
Expand Down Expand Up @@ -666,7 +666,7 @@ fn wasm_call_via_xvm_fails_if_storage_deposit_limit_exhausted() {
},
VmId::Wasm,
ALICE,
MultiAddress::<AccountId32, ()>::Id(wasm_callee_addr.clone()).encode(),
wasm_callee_addr.clone().encode(),
input,
0,
Some(0)
Expand Down Expand Up @@ -696,7 +696,7 @@ fn wasm_call_via_xvm_call_works_if_sufficient_storage_deposit_limit() {
},
VmId::Wasm,
ALICE,
MultiAddress::<AccountId32, ()>::Id(wasm_callee_addr.clone()).encode(),
wasm_callee_addr.clone().encode(),
input,
0,
Some(UNIT)
Expand Down Expand Up @@ -742,11 +742,11 @@ fn calling_wasm_from_evm_works_if_sufficient_storage_deposit_limit() {
RuntimeOrigin::root(),
alith(),
evm_caller_addr.clone(),
// to: 0x000e0ddb5a5f0b99d7be468a3051a94073ec6b1900178316401a52b93415026999
// to: 0x0e0ddb5a5f0b99d7be468a3051a94073ec6b1900178316401a52b93415026999
// input: 0x0000002a (store)
// value: 0
// storage_deposit_limit: 1_000_000_000_000
hex::decode("2d9338da000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e8d4a510000000000000000000000000000000000000000000000000000000000000000021000e0ddb5a5f0b99d7be468a3051a94073ec6b1900178316401a52b934150269990000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000002a00000000000000000000000000000000000000000000000000000000").expect("invalid call input hex"),
hex::decode("2d9338da000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e8d4a5100000000000000000000000000000000000000000000000000000000000000000200e0ddb5a5f0b99d7be468a3051a94073ec6b1900178316401a52b9341502699900000000000000000000000000000000000000000000000000000000000000040000002a00000000000000000000000000000000000000000000000000000000").expect("invalid call input hex"),
U256::zero(),
1_000_000,
U256::from(DefaultBaseFeePerGas::get()),
Expand Down

0 comments on commit c6d4dfe

Please sign in to comment.