Skip to content

Commit

Permalink
feat: update xvm integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ashutoshvarma committed Sep 13, 2023
1 parent dbffa3a commit 19dbd0a
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 24 deletions.
4 changes: 2 additions & 2 deletions runtime/local/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ impl pallet_utility::Config for Runtime {
impl pallet_account::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
type DefaultAddressMapping = <Self as pallet_evm::Config>::AddressMapping;
type DefaultAddressMapping = pallet_evm::HashedAddressMapping<BlakeTwo256>;
type DefaultAccountMapping = pallet_account::HashedAccountMapping<BlakeTwo256>;
type ClaimSignature = pallet_account::EIP712Signature<Self, ChainId>;
}
Expand Down Expand Up @@ -558,7 +558,7 @@ impl pallet_evm::Config for Runtime {
type BlockHashMapping = pallet_ethereum::EthereumBlockHashMapping<Runtime>;
type CallOrigin = pallet_evm::EnsureAddressRoot<AccountId>;
type WithdrawOrigin = pallet_evm::EnsureAddressTruncated;
type AddressMapping = pallet_evm::HashedAddressMapping<BlakeTwo256>;
type AddressMapping = Accounts;
type Currency = Balances;
type RuntimeEvent = RuntimeEvent;
type Runner = pallet_evm::runner::stack::Runner<Self>;
Expand Down
4 changes: 2 additions & 2 deletions runtime/shibuya/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ impl pallet_evm::Config for Runtime {
type BlockHashMapping = pallet_ethereum::EthereumBlockHashMapping<Runtime>;
type CallOrigin = pallet_evm::EnsureAddressRoot<AccountId>;
type WithdrawOrigin = pallet_evm::EnsureAddressTruncated;
type AddressMapping = pallet_evm::HashedAddressMapping<BlakeTwo256>;
type AddressMapping = Accounts;
type Currency = Balances;
type RuntimeEvent = RuntimeEvent;
type Runner = pallet_evm::runner::stack::Runner<Self>;
Expand Down Expand Up @@ -1226,7 +1226,7 @@ impl pallet_xc_asset_config::Config for Runtime {
impl pallet_account::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
type DefaultAddressMapping = <Self as pallet_evm::Config>::AddressMapping;
type DefaultAddressMapping = pallet_evm::HashedAddressMapping<BlakeTwo256>;
type DefaultAccountMapping = pallet_account::HashedAccountMapping<BlakeTwo256>;
type ClaimSignature = pallet_account::EIP712Signature<Self, EVMChainId>;
}
Expand Down
1 change: 1 addition & 0 deletions tests/integration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ sp-runtime = { workspace = true }

# astar dependencies
pallet-ethereum-checked = { workspace = true }
pallet-account = { workspace = true }
pallet-evm-precompile-assets-erc20 = { workspace = true }

astar-primitives = { workspace = true }
Expand Down
22 changes: 22 additions & 0 deletions tests/integration/src/account.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// This file is part of Astar.

// Copyright (C) 2019-2023 Stake Technologies Pte.Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later

// Astar is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Astar is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Astar. If not, see <http://www.gnu.org/licenses/>.

// use crate::setup::*;

#[test]
fn account_transfer_to_h160_via_lookup() {}
3 changes: 3 additions & 0 deletions tests/integration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ mod assets;

#[cfg(feature = "shibuya")]
mod xvm;

#[cfg(feature = "shibuya")]
mod account;
24 changes: 13 additions & 11 deletions tests/integration/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub use frame_support::{
traits::{OnFinalize, OnIdle, OnInitialize},
weights::Weight,
};
pub use pallet_account::AddressManager;
pub use pallet_evm::AddressMapping;
pub use sp_core::{H160, H256, U256};
pub use sp_runtime::{AccountId32, MultiAddress};
Expand All @@ -39,19 +40,11 @@ mod shibuya {
/// 1 SBY.
pub const UNIT: Balance = SBY;

// TODO: once Account Unification is finished, remove `alith` and `alicia`,
// which are mocks of two way account/address mapping.

/// H160 address mapped from `ALICE`.
/// H160 address mapped to `ALICE`.
pub fn alith() -> H160 {
h160_from(ALICE)
}

/// `AccountId32` mapped from `alith()`.
pub fn alicia() -> AccountId32 {
account_id_from(alith())
}

/// Convert `H160` to `AccountId32`.
pub fn account_id_from(address: H160) -> AccountId32 {
<Runtime as pallet_evm::Config>::AddressMapping::into_account_id(address)
Expand Down Expand Up @@ -112,6 +105,16 @@ mod shibuya {
assert_eq!(Balances::free_balance(&address), ExistentialDeposit::get(),);
address
}

pub fn claim_default_accounts(account: AccountId) {
let default_h160 = Accounts::to_default_address(&account);
assert_ok!(Accounts::claim_default_evm_account(RuntimeOrigin::signed(
account.clone()
)));
assert_eq!(Accounts::to_address(&account).unwrap(), default_h160);
// println!("{:?}", EVM::account_basic(&default_h160).0);
// println!("{} - {}", account_id_from(default_h160), ALICE);
}
}

#[cfg(feature = "shiden")]
Expand Down Expand Up @@ -175,6 +178,7 @@ impl ExtBuilder {

let mut ext = sp_io::TestExternalities::new(t);
ext.execute_with(|| System::set_block_number(1));
ext.execute_with(|| claim_default_accounts(ALICE));
ext
}
}
Expand All @@ -185,8 +189,6 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
(ALICE, INITIAL_AMOUNT),
(BOB, INITIAL_AMOUNT),
(CAT, INITIAL_AMOUNT),
#[cfg(feature = "shibuya")]
(alicia(), INITIAL_AMOUNT),
])
.build()
}
Expand Down
15 changes: 6 additions & 9 deletions tests/integration/src/xvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,8 @@ fn calling_evm_payable_from_wasm_works() {

let value = UNIT;

// TODO: after Account Unification finished, remove this mock account.
// It is needed now because currently the `AccountMapping` and `AddressMapping` are
// both one way mapping.
let mock_unified_wasm_account = account_id_from(h160_from(wasm_address.clone()));
let _ = Balances::deposit_creating(&mock_unified_wasm_account, value);
// claim the default mappings for wasm contract
claim_default_accounts(wasm_address.clone());

let evm_payable = evm_payable_addr.as_ref().to_vec();
let deposit_func = hex::decode("d0e30db0").expect("invalid deposit function hex");
Expand All @@ -328,10 +325,10 @@ fn calling_evm_payable_from_wasm_works() {
value
);

// TODO: after Account Unification finished, enable the wasm address balance check
// and remove the mock account balance check.
// assert_eq!(Balances::free_balance(&wasm_address), ExistentialDeposit::get());
assert_eq!(Balances::free_balance(&mock_unified_wasm_account), 0);
assert_eq!(
Balances::free_balance(&wasm_address),
ExistentialDeposit::get()
);
});
}

Expand Down

0 comments on commit 19dbd0a

Please sign in to comment.