mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-08 11:18:01 +00:00
2302898b8a
* Start adding weight info * More weightinfo * finish weight info * more fixes * inital update of node runtime * fix the rest of the compilation * update balances * add docs * fix balances tests * Fix more tests * Fix compile * Fix pallet-evm tests
173 lines
4.5 KiB
Rust
173 lines
4.5 KiB
Rust
#![cfg(test)]
|
|
|
|
use super::*;
|
|
|
|
use std::{str::FromStr, collections::BTreeMap};
|
|
use frame_support::{
|
|
assert_ok, impl_outer_origin, parameter_types, impl_outer_dispatch,
|
|
};
|
|
use sp_core::H256;
|
|
// The testing primitives are very useful for avoiding having to work with signatures
|
|
// or public keys. `u64` is used as the `AccountId` and no `Signature`s are required.
|
|
use sp_runtime::{
|
|
Perbill,
|
|
testing::Header,
|
|
traits::{BlakeTwo256, IdentityLookup},
|
|
};
|
|
|
|
impl_outer_origin! {
|
|
pub enum Origin for Test where system = frame_system {}
|
|
}
|
|
|
|
impl_outer_dispatch! {
|
|
pub enum OuterCall for Test where origin: Origin {
|
|
self::EVM,
|
|
}
|
|
}
|
|
|
|
// For testing the pallet, we construct most of a mock runtime. This means
|
|
// first constructing a configuration type (`Test`) which `impl`s each of the
|
|
// configuration traits of pallets we want to use.
|
|
#[derive(Clone, Eq, PartialEq)]
|
|
pub struct Test;
|
|
parameter_types! {
|
|
pub const BlockHashCount: u64 = 250;
|
|
pub const MaximumBlockWeight: Weight = 1024;
|
|
pub const MaximumBlockLength: u32 = 2 * 1024;
|
|
pub const AvailableBlockRatio: Perbill = Perbill::one();
|
|
}
|
|
impl frame_system::Trait for Test {
|
|
type BaseCallFilter = ();
|
|
type Origin = Origin;
|
|
type Index = u64;
|
|
type BlockNumber = u64;
|
|
type Hash = H256;
|
|
type Call = OuterCall;
|
|
type Hashing = BlakeTwo256;
|
|
type AccountId = H256;
|
|
type Lookup = IdentityLookup<Self::AccountId>;
|
|
type Header = Header;
|
|
type Event = ();
|
|
type BlockHashCount = BlockHashCount;
|
|
type MaximumBlockWeight = MaximumBlockWeight;
|
|
type DbWeight = ();
|
|
type BlockExecutionWeight = ();
|
|
type ExtrinsicBaseWeight = ();
|
|
type MaximumExtrinsicWeight = MaximumBlockWeight;
|
|
type MaximumBlockLength = MaximumBlockLength;
|
|
type AvailableBlockRatio = AvailableBlockRatio;
|
|
type Version = ();
|
|
type ModuleToIndex = ();
|
|
type AccountData = pallet_balances::AccountData<u64>;
|
|
type OnNewAccount = ();
|
|
type OnKilledAccount = ();
|
|
type SystemWeightInfo = ();
|
|
}
|
|
|
|
parameter_types! {
|
|
pub const ExistentialDeposit: u64 = 1;
|
|
}
|
|
impl pallet_balances::Trait for Test {
|
|
type Balance = u64;
|
|
type DustRemoval = ();
|
|
type Event = ();
|
|
type ExistentialDeposit = ExistentialDeposit;
|
|
type AccountStore = System;
|
|
type WeightInfo = ();
|
|
}
|
|
|
|
parameter_types! {
|
|
pub const MinimumPeriod: u64 = 1000;
|
|
}
|
|
impl pallet_timestamp::Trait for Test {
|
|
type Moment = u64;
|
|
type OnTimestampSet = ();
|
|
type MinimumPeriod = MinimumPeriod;
|
|
type WeightInfo = ();
|
|
}
|
|
|
|
/// Fixed gas price of `0`.
|
|
pub struct FixedGasPrice;
|
|
impl FeeCalculator for FixedGasPrice {
|
|
fn min_gas_price() -> U256 {
|
|
// Gas price is always one token per gas.
|
|
0.into()
|
|
}
|
|
}
|
|
parameter_types! {
|
|
pub const EVMModuleId: ModuleId = ModuleId(*b"py/evmpa");
|
|
}
|
|
impl Trait for Test {
|
|
type ChainId = SystemChainId;
|
|
type ModuleId = EVMModuleId;
|
|
type FeeCalculator = FixedGasPrice;
|
|
type ConvertAccountId = HashTruncateConvertAccountId<BlakeTwo256>;
|
|
type Currency = Balances;
|
|
type Event = Event<Test>;
|
|
type Precompiles = ();
|
|
}
|
|
|
|
type System = frame_system::Module<Test>;
|
|
type Balances = pallet_balances::Module<Test>;
|
|
type EVM = Module<Test>;
|
|
|
|
// This function basically just builds a genesis storage key/value store according to
|
|
// our desired mockup.
|
|
pub fn new_test_ext() -> sp_io::TestExternalities {
|
|
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
|
|
|
|
let mut accounts = BTreeMap::new();
|
|
accounts.insert(
|
|
H160::from_str("1000000000000000000000000000000000000001").unwrap(),
|
|
GenesisAccount {
|
|
nonce: U256::from(1),
|
|
balance: U256::from(1000000),
|
|
storage: Default::default(),
|
|
code: vec![
|
|
0x00, // STOP
|
|
],
|
|
}
|
|
);
|
|
accounts.insert(
|
|
H160::from_str("1000000000000000000000000000000000000002").unwrap(),
|
|
GenesisAccount {
|
|
nonce: U256::from(1),
|
|
balance: U256::from(1000000),
|
|
storage: Default::default(),
|
|
code: vec![
|
|
0xff, // INVALID
|
|
],
|
|
}
|
|
);
|
|
|
|
// We use default for brevity, but you can configure as desired if needed.
|
|
pallet_balances::GenesisConfig::<Test>::default().assimilate_storage(&mut t).unwrap();
|
|
GenesisConfig { accounts }.assimilate_storage(&mut t).unwrap();
|
|
t.into()
|
|
}
|
|
|
|
#[test]
|
|
fn fail_call_return_ok() {
|
|
new_test_ext().execute_with(|| {
|
|
assert_ok!(EVM::call(
|
|
Origin::signed(H256::default()),
|
|
H160::from_str("1000000000000000000000000000000000000001").unwrap(),
|
|
Vec::new(),
|
|
U256::default(),
|
|
1000000,
|
|
U256::default(),
|
|
None,
|
|
));
|
|
|
|
assert_ok!(EVM::call(
|
|
Origin::signed(H256::default()),
|
|
H160::from_str("1000000000000000000000000000000000000002").unwrap(),
|
|
Vec::new(),
|
|
U256::default(),
|
|
1000000,
|
|
U256::default(),
|
|
None,
|
|
));
|
|
});
|
|
}
|