Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve mock xcm #838

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions node/src/chain_specs/calamari.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,15 @@ fn calamari_dev_genesis(
candidates: invulnerables
.iter()
.cloned()
.map(|(account, _)| (account, 4_000_000 * KMA)) // TODO: Change to use constant from primitives
.map(|(account, _)| {
(
account,
calamari_runtime::staking::NORMAL_COLLATOR_MINIMUM_STAKE,
)
})
.collect(),
delegations,
inflation_config: calamari_runtime::currency::inflation_config::<
inflation_config: calamari_runtime::staking::inflation_config::<
calamari_runtime::Runtime,
>(),
},
Expand Down
13 changes: 5 additions & 8 deletions pallets/asset-manager/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,10 @@ use manta_primitives::{
ConcreteFungibleLedger,
},
constants::{ASSET_MANAGER_PALLET_ID, ASSET_STRING_LIMIT},
types::{AccountId, AssetId, Balance},
types::{AccountId, AssetId, Balance, BlockNumber, Header},
};
use sp_core::{H160, H256};
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
};
use sp_runtime::traits::{BlakeTwo256, IdentityLookup};
use sp_std::marker::PhantomData;
use xcm::{
prelude::{Parachain, X1},
Expand All @@ -47,7 +44,7 @@ use xcm::{

parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const SS58Prefix: u8 = 78;
pub const SS58Prefix: u8 = manta_primitives::constants::CALAMARI_SS58PREFIX;
}

impl system::Config for Runtime {
Expand All @@ -58,14 +55,14 @@ impl system::Config for Runtime {
type Origin = Origin;
type Call = Call;
type Index = u64;
type BlockNumber = u64;
type BlockNumber = BlockNumber;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = AccountId;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Event = Event;
type BlockHashCount = BlockHashCount;
type BlockHashCount = ConstU32<250>;
type Version = ();
type PalletInfo = PalletInfo;
type AccountData = pallet_balances::AccountData<Balance>;
Expand Down
1 change: 1 addition & 0 deletions pallets/collator-selection/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ sp-staking = { git = 'https://github.com/paritytech/substrate.git', default-feat
sp-std = { git = 'https://github.com/paritytech/substrate.git', default-features = false, branch = "polkadot-v0.9.26" }

[dev-dependencies]
manta-primitives = { path = "../../primitives/manta" }
pallet-aura = { git = 'https://github.com/paritytech/substrate.git', branch = "polkadot-v0.9.26" }
pallet-balances = { git = 'https://github.com/paritytech/substrate.git', branch = "polkadot-v0.9.26" }
pallet-timestamp = { git = 'https://github.com/paritytech/substrate.git', branch = "polkadot-v0.9.26" }
Expand Down
18 changes: 9 additions & 9 deletions pallets/collator-selection/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ use frame_support::{
},
PalletId,
};

use frame_system::EnsureSignedBy;
use manta_primitives::types::{BlockNumber, Header};
use sp_arithmetic::Percent;
use sp_core::H256;
use sp_runtime::{
testing::{Header, UintAuthorityId},
testing::UintAuthorityId,
traits::{BlakeTwo256, IdentityLookup, OpaqueKeys},
RuntimeAppPublic,
};
Expand Down Expand Up @@ -61,14 +61,14 @@ impl frame_system::Config for Test {
type Origin = Origin;
type Call = Call;
type Index = u64;
type BlockNumber = u64;
type BlockNumber = BlockNumber;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Event = Event;
type BlockHashCount = ConstU64<250>;
type BlockHashCount = ConstU32<250>;
type Version = ();
type PalletInfo = PalletInfo;
type AccountData = pallet_balances::AccountData<u64>;
Expand Down Expand Up @@ -147,16 +147,16 @@ impl pallet_session::SessionHandler<u64> for TestSessionHandler {
SessionHandlerCollators::set(keys.iter().map(|(a, _)| *a).collect::<Vec<_>>())
}
fn on_new_session<Ks: OpaqueKeys>(_: bool, keys: &[(u64, Ks)], _: &[(u64, Ks)]) {
SessionChangeBlock::set(System::block_number());
SessionChangeBlock::set(System::block_number() as u64);
SessionHandlerCollators::set(keys.iter().map(|(a, _)| *a).collect::<Vec<_>>())
}
fn on_before_session_ending() {}
fn on_disabled(_: u32) {}
}

parameter_types! {
pub const Offset: u64 = 0;
pub const Period: u64 = 10;
pub const Offset: BlockNumber = 0;
pub const Period: BlockNumber = 10;
}

impl pallet_session::Config for Test {
Expand Down Expand Up @@ -251,9 +251,9 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
t.into()
}

pub fn initialize_to_block(n: u64) {
pub fn initialize_to_block(n: BlockNumber) {
for i in System::block_number() + 1..=n {
System::set_block_number(i);
<AllPalletsReversedWithSystemFirst as frame_support::traits::OnInitialize<u64>>::on_initialize(i);
<AllPalletsReversedWithSystemFirst as frame_support::traits::OnInitialize<BlockNumber>>::on_initialize(i);
}
}
7 changes: 2 additions & 5 deletions pallets/manta-pay/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ use manta_primitives::{
ConcreteFungibleLedger,
},
constants::{ASSET_MANAGER_PALLET_ID, MANTA_PAY_PALLET_ID},
types::{AssetId, Balance},
types::{AssetId, Balance, BlockNumber, Header},
};
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
AccountId32,
};
Expand All @@ -58,11 +57,9 @@ frame_support::construct_runtime!(
}
);

type BlockNumber = u64;

parameter_types! {
pub const BlockHashCount: BlockNumber = 250;
pub const SS58Prefix: u8 = 42;
pub const SS58Prefix: u8 = manta_primitives::constants::CALAMARI_SS58PREFIX;
}

impl frame_system::Config for Test {
Expand Down
25 changes: 12 additions & 13 deletions pallets/parachain-staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,16 @@ use frame_support::{
traits::{Everything, GenesisBuild, LockIdentifier, OnFinalize, OnInitialize},
weights::Weight,
};
use manta_primitives::types::{BlockNumber, Header};
use sp_core::H256;
use sp_io;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
Perbill, Percent,
};

pub type AccountId = u64;
pub type Balance = u128;
pub type BlockNumber = u64;

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
Expand All @@ -57,11 +56,11 @@ construct_runtime!(
);

parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const BlockHashCount: BlockNumber = 250;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub const SS58Prefix: u8 = 42;
pub const SS58Prefix: u8 = manta_primitives::constants::CALAMARI_SS58PREFIX;
}
impl frame_system::Config for Test {
type BaseCallFilter = Everything;
Expand Down Expand Up @@ -212,7 +211,7 @@ impl pallet_session::SessionHandler<u64> for TestSessionHandler {
SessionHandlerCollators::set(keys.iter().map(|(a, _)| *a).collect::<Vec<_>>())
}
fn on_new_session<Ks: OpaqueKeys>(_: bool, keys: &[(u64, Ks)], _: &[(u64, Ks)]) {
SessionChangeBlock::set(System::block_number());
SessionChangeBlock::set(System::block_number() as u64);
SessionHandlerCollators::set(keys.iter().map(|(a, _)| *a).collect::<Vec<_>>())
}
fn on_before_session_ending() {}
Expand All @@ -233,8 +232,8 @@ impl From<UintAuthorityId> for MockSessionKeys {
}

parameter_types! {
pub const Offset: u64 = 0;
pub const Period: u64 = 10;
pub const Offset: BlockNumber = 0;
pub const Period: BlockNumber = 10;
}
impl pallet_session::Config for Test {
type Event = Event;
Expand Down Expand Up @@ -340,7 +339,7 @@ impl ExtBuilder {
}

/// Rolls forward one block. Returns the new block number.
pub(crate) fn roll_one_block() -> u64 {
pub(crate) fn roll_one_block() -> u32 {
Balances::on_finalize(System::block_number());
System::on_finalize(System::block_number());
System::set_block_number(System::block_number() + 1);
Expand All @@ -351,7 +350,7 @@ pub(crate) fn roll_one_block() -> u64 {
}

/// Rolls to the desired block. Returns the number of blocks played.
pub(crate) fn roll_to(n: u64) -> u64 {
pub(crate) fn roll_to(n: u32) -> u32 {
let mut num_blocks = 0;
let mut block = System::block_number();
while block < n {
Expand All @@ -364,15 +363,15 @@ pub(crate) fn roll_to(n: u64) -> u64 {
/// Rolls block-by-block to the beginning of the specified round.
/// This will complete the block in which the round change occurs.
/// Returns the number of blocks played.
pub(crate) fn roll_to_round_begin(round: u64) -> u64 {
let block = (round - 1) * DefaultBlocksPerRound::get() as u64;
pub(crate) fn roll_to_round_begin(round: u32) -> u32 {
let block = (round - 1) * DefaultBlocksPerRound::get();
roll_to(block)
}

/// Rolls block-by-block to the end of the specified round.
/// The block following will be the one in which the specified round change occurs.
pub(crate) fn roll_to_round_end(round: u64) -> u64 {
let block = round * DefaultBlocksPerRound::get() as u64 - 1;
pub(crate) fn roll_to_round_end(round: u32) -> u32 {
let block = round * DefaultBlocksPerRound::get() - 1;
roll_to(block)
}

Expand Down
26 changes: 13 additions & 13 deletions pallets/parachain-staking/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7376,11 +7376,11 @@ fn deferred_payment_steady_state_event_flow() {
.build()
.execute_with(|| {
// convenience to set the round points consistently
let set_round_points = |round: u64| {
set_author(round as u32, 1, 1);
set_author(round as u32, 2, 1);
set_author(round as u32, 3, 1);
set_author(round as u32, 4, 1);
let set_round_points = |round: u32| {
set_author(round, 1, 1);
set_author(round, 2, 1);
set_author(round, 3, 1);
set_author(round, 4, 1);
};

// grab initial issuance -- we will reset it before round issuance is calculated so that
Expand All @@ -7400,8 +7400,8 @@ fn deferred_payment_steady_state_event_flow() {
};

// fn to roll through the first RewardPaymentDelay rounds. returns new round index
let roll_through_initial_rounds = |mut round: u64| -> u64 {
while round < crate::mock::RewardPaymentDelay::get() as u64 + 1 {
let roll_through_initial_rounds = |mut round: u32| -> u32 {
while round < crate::mock::RewardPaymentDelay::get() + 1 {
set_round_points(round);

roll_to_round_end(round);
Expand All @@ -7415,7 +7415,7 @@ fn deferred_payment_steady_state_event_flow() {

// roll through a "steady state" round and make all of our assertions
// returns new round index
let roll_through_steady_state_round = |round: u64| -> u64 {
let roll_through_steady_state_round = |round: u32| -> u32 {
let num_rounds_rolled = roll_to_round_begin(round);
assert_eq!(
num_rounds_rolled, 1,
Expand All @@ -7424,28 +7424,28 @@ fn deferred_payment_steady_state_event_flow() {

let expected = vec![
Event::CollatorChosen {
round: round as u32,
round,
collator_account: 1,
total_exposed_amount: 400,
},
Event::CollatorChosen {
round: round as u32,
round,
collator_account: 2,
total_exposed_amount: 400,
},
Event::CollatorChosen {
round: round as u32,
round,
collator_account: 3,
total_exposed_amount: 400,
},
Event::CollatorChosen {
round: round as u32,
round,
collator_account: 4,
total_exposed_amount: 400,
},
Event::NewRound {
starting_block: (round - 1) * 5,
round: round as u32,
round,
selected_collators_number: 4,
total_balance: 1600,
},
Expand Down
15 changes: 6 additions & 9 deletions pallets/tx-pause/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,12 @@
#![cfg(test)]

use super::*;
use frame_support::{
construct_runtime, ord_parameter_types, parameter_types,
traits::{ConstU32, ConstU64},
};
use frame_support::{construct_runtime, ord_parameter_types, parameter_types, traits::ConstU32};
use frame_system::EnsureRoot;
use manta_primitives::types::Balance;
use manta_primitives::types::{Balance, BlockNumber, Header};

use sp_core::H256;
use sp_runtime::{testing::Header, traits::IdentityLookup};
use sp_runtime::traits::{BlakeTwo256, IdentityLookup};

pub type AccountId = u128;
pub const ALICE: AccountId = 1;
Expand All @@ -50,15 +47,15 @@ impl Contains<Call> for BaseFilter {
impl frame_system::Config for Runtime {
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
type BlockNumber = BlockNumber;
type Call = Call;
type Hash = H256;
type Hashing = ::sp_runtime::traits::BlakeTwo256;
type Hashing = BlakeTwo256;
type AccountId = AccountId;
type Lookup = IdentityLookup<AccountId>;
type Header = Header;
type Event = Event;
type BlockHashCount = ConstU64<250>;
type BlockHashCount = ConstU32<250>;
type BlockWeights = ();
type BlockLength = ();
type Version = ();
Expand Down
1 change: 1 addition & 0 deletions pallets/vesting/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ sp-std = { git = 'https://github.com/paritytech/substrate.git', default-features

[dev-dependencies]
chrono = "0.4"
manta-primitives = { path = "../../primitives/manta" }
pallet-balances = { git = 'https://github.com/paritytech/substrate.git', branch = "polkadot-v0.9.26" }
pallet-timestamp = { git = 'https://github.com/paritytech/substrate.git', branch = "polkadot-v0.9.26" }
sp-core = { git = 'https://github.com/paritytech/substrate.git', branch = "polkadot-v0.9.26" }
Expand Down
Loading