Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aurexav committed Dec 27, 2024
1 parent 447b568 commit 50e9d5c
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 46 deletions.
4 changes: 2 additions & 2 deletions node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ pub fn run() -> Result<()> {
#[cfg(feature = "runtime-benchmarks")]
Some(Subcommand::Benchmark(cmd)) => {
// darwinia
use dc_primitives::{Block, Hashing};
use dc_primitives::Hashing;
// polkadot-sdk
use cumulus_client_service::storage_proof_size::HostFunctions as ReclaimHostFunctions;
use frame_benchmarking_cli::{BenchmarkCmd, SUBSTRATE_REFERENCE_HARDWARE};
Expand All @@ -447,7 +447,7 @@ pub fn run() -> Result<()> {

match &**cmd {
BenchmarkCmd::Pallet(cmd) =>
runner.sync_run(|config| cmd.run::<Hashing, ReclaimHostFunctions>(config)),
runner.sync_run(|config| cmd.run_with_spec::<Hashing, ReclaimHostFunctions>(Some(config.chain_spec))),
BenchmarkCmd::Storage(cmd) => runner.sync_run(|config| {
construct_benchmark_partials!(config, cli, |partials| {
let db = partials.backend.expose_db();
Expand Down
2 changes: 1 addition & 1 deletion pallet/account-migration/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// darwinia
use crate::*;
// polkadot-sdk
use frame_benchmarking::v2;
use frame_benchmarking::v2::*;
use frame_system::RawOrigin;
use sp_std::prelude::*;

Expand Down
2 changes: 1 addition & 1 deletion pallet/deposit/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// darwinia
use crate::{Deposit, *};
// polkadot-sdk
use frame_benchmarking::v2;
use frame_benchmarking::v2::*;
use frame_system::RawOrigin;
use sp_std::prelude::*;

Expand Down
56 changes: 28 additions & 28 deletions pallet/deposit/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ fn migrate_should_work() {
]),
);

assert!(Deposit::deposit_of(1).is_some());
assert!(<Deposits<Runtime>>::get(1).is_some());
assert_ok!(Deposit::migrate_for(RuntimeOrigin::signed(1), 1));
assert!(Deposit::deposit_of(1).is_none());
assert!(<Deposits<Runtime>>::get(1).is_none());
});
}

Expand Down Expand Up @@ -68,67 +68,67 @@ fn on_idle_should_work() {
<Deposits<Runtime>>::insert(1, mock_deposits(512));
<Deposits<Runtime>>::insert(2, mock_deposits(512));
<Deposits<Runtime>>::insert(3, mock_deposits(512));
assert_eq!(Deposit::deposit_of(1).unwrap().len(), 512);
assert_eq!(Deposit::deposit_of(2).unwrap().len(), 512);
assert_eq!(Deposit::deposit_of(3).unwrap().len(), 512);
assert_eq!(<Deposits<Runtime>>::get(1).unwrap().len(), 512);
assert_eq!(<Deposits<Runtime>>::get(2).unwrap().len(), 512);
assert_eq!(<Deposits<Runtime>>::get(3).unwrap().len(), 512);

<Deposit as OnIdle<_>>::on_idle(0, Weight::zero());
assert_eq!(Deposit::deposit_of(1).unwrap().len(), 512);
assert_eq!(Deposit::deposit_of(2).unwrap().len(), 512);
assert_eq!(Deposit::deposit_of(3).unwrap().len(), 512);
assert_eq!(<Deposits<Runtime>>::get(1).unwrap().len(), 512);
assert_eq!(<Deposits<Runtime>>::get(2).unwrap().len(), 512);
assert_eq!(<Deposits<Runtime>>::get(3).unwrap().len(), 512);
<Deposit as OnIdle<_>>::on_idle(0, Weight::zero().add_ref_time(10));
assert_eq!(Deposit::deposit_of(1).unwrap().len(), 512);
assert_eq!(Deposit::deposit_of(2).unwrap().len(), 512);
assert_eq!(Deposit::deposit_of(3).unwrap().len(), 502);
assert_eq!(<Deposits<Runtime>>::get(1).unwrap().len(), 512);
assert_eq!(<Deposits<Runtime>>::get(2).unwrap().len(), 512);
assert_eq!(<Deposits<Runtime>>::get(3).unwrap().len(), 502);
<Deposit as OnIdle<_>>::on_idle(0, Weight::MAX);
assert_eq!(Deposit::deposit_of(1).unwrap().len(), 512);
assert_eq!(Deposit::deposit_of(2).unwrap().len(), 512);
assert_eq!(Deposit::deposit_of(3).unwrap().len(), 492);
assert_eq!(<Deposits<Runtime>>::get(1).unwrap().len(), 512);
assert_eq!(<Deposits<Runtime>>::get(2).unwrap().len(), 512);
assert_eq!(<Deposits<Runtime>>::get(3).unwrap().len(), 492);

(0..50).for_each(|_| {
<Deposit as OnIdle<_>>::on_idle(0, Weight::MAX);
});
assert_eq!(Deposit::deposit_of(1).unwrap().len(), 512);
assert_eq!(Deposit::deposit_of(2).unwrap().len(), 512);
assert!(Deposit::deposit_of(3).is_none());
assert_eq!(<Deposits<Runtime>>::get(1).unwrap().len(), 512);
assert_eq!(<Deposits<Runtime>>::get(2).unwrap().len(), 512);
assert!(<Deposits<Runtime>>::get(3).is_none());

(0..50).for_each(|_| {
<Deposit as OnIdle<_>>::on_idle(0, Weight::MAX);
});
assert_eq!(Deposit::deposit_of(1).unwrap().len(), 12);
assert_eq!(Deposit::deposit_of(2).unwrap().len(), 512);
assert!(Deposit::deposit_of(3).is_none());
assert_eq!(<Deposits<Runtime>>::get(1).unwrap().len(), 12);
assert_eq!(<Deposits<Runtime>>::get(2).unwrap().len(), 512);
assert!(<Deposits<Runtime>>::get(3).is_none());

System::reset_events();
(0..54).for_each(|_| {
<Deposit as OnIdle<_>>::on_idle(0, Weight::MAX);
});
assert_eq!(events().into_iter().count(), 54);
assert!(Deposit::deposit_of(1).is_none());
assert!(Deposit::deposit_of(2).is_none());
assert!(Deposit::deposit_of(3).is_none());
assert!(<Deposits<Runtime>>::get(1).is_none());
assert!(<Deposits<Runtime>>::get(2).is_none());
assert!(<Deposits<Runtime>>::get(3).is_none());
});
new_test_ext().execute_with(|| {
System::set_block_number(1);

let _ = Balances::deposit_creating(&0, 10_000);

<Deposits<Runtime>>::insert(1, mock_zero_deposits(512));
assert_eq!(Deposit::deposit_of(1).unwrap().len(), 512);
assert_eq!(<Deposits<Runtime>>::get(1).unwrap().len(), 512);

System::reset_events();
(0..52).for_each(|_| {
<Deposit as OnIdle<_>>::on_idle(0, Weight::MAX);
});
assert_eq!(events().into_iter().count(), 0);
assert!(Deposit::deposit_of(1).is_none());
assert!(<Deposits<Runtime>>::get(1).is_none());
});
new_test_ext().execute_with(|| {
<Deposits<Runtime>>::insert(1, mock_deposits(512));
assert_eq!(Deposit::deposit_of(1).unwrap().len(), 512);
assert_eq!(<Deposits<Runtime>>::get(1).unwrap().len(), 512);

<Deposit as OnIdle<_>>::on_idle(0, Weight::MAX);
assert!(Deposit::deposit_of(1).is_none());
assert_eq!(Deposit::migration_failure_of(1).unwrap().0.into_iter().count(), 512);
assert!(<Deposits<Runtime>>::get(1).is_none());
assert_eq!(<MigrationFailures<Runtime>>::get(1).unwrap().0.into_iter().count(), 512);
});
}
2 changes: 1 addition & 1 deletion pallet/staking/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// darwinia
use crate::*;
// polkadot-sdk
use frame_benchmarking::v2;
use frame_benchmarking::v2::*;
use frame_system::RawOrigin;
use sp_std::prelude::*;

Expand Down
15 changes: 13 additions & 2 deletions pallet/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ pub mod pallet {
#[pallet::storage]
pub type KtonStakingContract<T: Config> = StorageValue<_, T::AccountId>;

#[derive(DefaultNoBound)]
#[pallet::genesis_config]
pub struct GenesisConfig<T: Config> {
/// Current timestamp.
Expand All @@ -256,7 +255,19 @@ pub mod pallet {
#[allow(missing_docs)]
pub _marker: PhantomData<T>,
}

impl<T> Default for GenesisConfig<T>
where
T: Config,
{
fn default() -> Self {
Self {
now: Default::default(),
elapsed_time: Default::default(),
collator_count: 1,
_marker: Default::default(),
}
}
}
#[pallet::genesis_build]
impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
fn build(&self) {
Expand Down
2 changes: 1 addition & 1 deletion pallet/staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ frame_support::construct_runtime! {
pub enum Efflux {}
impl Efflux {
pub fn time(millis: Moment) {
Timestamp::set_timestamp(Timestamp::now() + millis);
Timestamp::set_timestamp(<pallet_timestamp::Now<Runtime>>::get() + millis);
}

pub fn block(number: BlockNumber) {
Expand Down
6 changes: 3 additions & 3 deletions pallet/staking/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ fn set_collator_count_should_work() {
);

assert_ok!(Staking::set_collator_count(RuntimeOrigin::root(), 1));
assert_eq!(Staking::collator_count(), 1);
assert_eq!(<CollatorCount<Runtime>>::get(), 1);
});
}

Expand All @@ -305,7 +305,7 @@ fn set_ring_staking_contract_should_work() {
);

assert_ok!(Staking::set_ring_staking_contract(RuntimeOrigin::root(), AccountId(1)));
assert_eq!(Staking::ring_staking_contract(), Some(AccountId(1)));
assert_eq!(<RingStakingContract<Runtime>>::get(), Some(AccountId(1)));
});
}

Expand All @@ -318,6 +318,6 @@ fn set_kton_staking_contract_should_work() {
);

assert_ok!(Staking::set_kton_staking_contract(RuntimeOrigin::root(), AccountId(1)));
assert_eq!(Staking::kton_staking_contract(), Some(AccountId(1)));
assert_eq!(<KtonStakingContract<Runtime>>::get(), Some(AccountId(1)));
});
}
14 changes: 7 additions & 7 deletions runtime/common/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ macro_rules! impl_account_migration_tests {
extra: (),
};

assert!(AccountMigration::account_of(&account_id_32).is_none());
assert!(AccountMigration::kton_account_of(&account_id_32).is_none());
assert!(<darwinia_account_migration::Accounts<Runtime>>::get(&account_id_32).is_none());
assert!(<darwinia_account_migration::KtonAccounts<Runtime>>::get(&account_id_32).is_none());

<pallet_balances::TotalIssuance<Runtime, _>>::put(RING_AMOUNT);
<darwinia_account_migration::Accounts<Runtime>>::insert(
Expand All @@ -132,8 +132,8 @@ macro_rules! impl_account_migration_tests {
&Blake2_128Concat::hash(account_id_32.as_ref()),
asset_account,
);
assert!(AccountMigration::account_of(&account_id_32).is_some());
assert!(AccountMigration::kton_account_of(&account_id_32).is_some());
assert!(<darwinia_account_migration::Accounts<Runtime>>::get(&account_id_32).is_some());
assert!(<darwinia_account_migration::KtonAccounts<Runtime>>::get(&account_id_32).is_some());
}

fn migrate(from: Pair, to: AccountId) -> Result<(), E> {
Expand Down Expand Up @@ -215,7 +215,7 @@ macro_rules! impl_account_migration_tests {
preset_state_of(&from);

assert_ok!(migrate(from, to));
assert_eq!(AccountMigration::account_of(from_pk), None);
assert_eq!(<darwinia_account_migration::Accounts<Runtime>>::get(from_pk), None);
assert_eq!(
System::account(to),
AccountInfo {
Expand Down Expand Up @@ -249,7 +249,7 @@ macro_rules! impl_account_migration_tests {

assert_ok!(migrate(from, to));
let asset_details = asset_details();
assert_eq!(AccountMigration::kton_account_of(from_pk), None);
assert_eq!(<darwinia_account_migration::KtonAccounts<Runtime>>::get(from_pk), None);
assert_eq!(Assets::maybe_balance(KTON_ID, to).unwrap(), KTON_AMOUNT);
assert_eq!(pre_asset_details.accounts + 1, asset_details.accounts);
assert_eq!(pre_asset_details.sufficients + 1, asset_details.sufficients);
Expand Down Expand Up @@ -305,7 +305,7 @@ macro_rules! impl_account_migration_tests {
assert_ok!(migrate(from, to));
assert_eq!(Balances::free_balance(to), 80);
assert_eq!(Balances::free_balance(&Treasury::account_id()), 20);
assert_eq!(Deposit::deposit_of(to).unwrap().len(), 2);
assert_eq!(<darwinia_deposit::Deposits<Runtime>>::get(to).unwrap().len(), 2);
assert_eq!(Assets::maybe_balance(KTON_ID, to).unwrap(), 100);
});
}
Expand Down
1 change: 1 addition & 0 deletions runtime/crab/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ impl ExtBuilder {
assets: vec![(KTON_ID, ROOT, true, 1)],
metadata: vec![(KTON_ID, b"Crab Commitment Token".to_vec(), b"CKTON".to_vec(), 18)],
accounts: self.assets_accounts.clone(),
next_asset_id: None,
}
.assimilate_storage(&mut t)
.unwrap();
Expand Down
1 change: 1 addition & 0 deletions runtime/darwinia/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ impl ExtBuilder {
assets: vec![(KTON_ID, ROOT, true, 1)],
metadata: vec![(KTON_ID, b"Darwinia Commitment Token".to_vec(), b"KTON".to_vec(), 18)],
accounts: self.assets_accounts.clone(),
next_asset_id: None,
}
.assimilate_storage(&mut t)
.unwrap();
Expand Down
1 change: 1 addition & 0 deletions runtime/koi/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ impl ExtBuilder {
assets: vec![(KTON_ID, ROOT, true, 1)],
metadata: vec![(KTON_ID, b"Koi Commitment Token".to_vec(), b"PKTON".to_vec(), 18)],
accounts: self.assets_accounts.clone(),
next_asset_id: None,
}
.assimilate_storage(&mut t)
.unwrap();
Expand Down

0 comments on commit 50e9d5c

Please sign in to comment.