difftreelog
test fix mocks
in: master
3 files changed
pallets/inflation/src/tests.rsdiffbeforeafterboth1#![cfg(test)]2#![allow(clippy::from_over_into)]3use crate as pallet_inflation;45use frame_support::{6 traits::{Currency},7 parameter_types,8};9use frame_support::{traits::OnInitialize};10use sp_core::H256;11use sp_runtime::{12 traits::{BlakeTwo256, IdentityLookup},13 testing::Header,14};1516type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;17type Block = frame_system::mocking::MockBlock<Test>;1819const YEAR: u64 = 5_259_600;2021parameter_types! {22 pub const ExistentialDeposit: u64 = 1;23 pub const MaxLocks: u32 = 50;24}2526impl pallet_balances::Config for Test {27 type AccountStore = System;28 type Balance = u64;29 type DustRemoval = ();30 type Event = ();31 type ExistentialDeposit = ExistentialDeposit;32 type WeightInfo = ();33 type MaxLocks = MaxLocks;34 type MaxReserves = ();35 type ReserveIdentifier = ();36}3738frame_support::construct_runtime!(39 pub enum Test where40 Block = Block,41 NodeBlock = Block,42 UncheckedExtrinsic = UncheckedExtrinsic,43 {44 Balances: pallet_balances::{Pallet, Call, Storage},45 System: frame_system::{Pallet, Call, Config, Storage, Event<T>},46 Inflation: pallet_inflation::{Pallet, Call, Storage},47 }48);4950parameter_types! {51 pub const BlockHashCount: u64 = 250;52 pub BlockWeights: frame_system::limits::BlockWeights =53 frame_system::limits::BlockWeights::simple_max(1024);54 pub const SS58Prefix: u8 = 42;55}5657impl frame_system::Config for Test {58 type BaseCallFilter = ();59 type BlockWeights = ();60 type BlockLength = ();61 type DbWeight = ();62 type Origin = Origin;63 type Call = Call;64 type Index = u64;65 type BlockNumber = u64;66 type Hash = H256;67 type Hashing = BlakeTwo256;68 type AccountId = u64;69 type Lookup = IdentityLookup<Self::AccountId>;70 type Header = Header;71 type Event = ();72 type BlockHashCount = BlockHashCount;73 type Version = ();74 type PalletInfo = PalletInfo;75 type AccountData = pallet_balances::AccountData<u64>;76 type OnNewAccount = ();77 type OnKilledAccount = ();78 type SystemWeightInfo = ();79 type SS58Prefix = SS58Prefix;80 type OnSetCode = ();81}8283parameter_types! {84 pub TreasuryAccountId: u64 = 1234;85 pub const InflationBlockInterval: u32 = 100; // every time per how many blocks inflation is applied86}8788impl pallet_inflation::Config for Test {89 type Currency = Balances;90 type TreasuryAccountId = TreasuryAccountId;91 type InflationBlockInterval = InflationBlockInterval;92}9394pub fn new_test_ext() -> sp_io::TestExternalities {95 frame_system::GenesisConfig::default()96 .build_storage::<Test>()97 .unwrap()98 .into()99}100101#[test]102fn inflation_works() {103 new_test_ext().execute_with(|| {104 // Total issuance = 1_000_000_000105 let initial_issuance: u64 = 1_000_000_000;106 let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);107 assert_eq!(Balances::free_balance(1234), initial_issuance);108109 // BlockInflation should be set after 1st block and110 // first inflation deposit should be equal to BlockInflation111 Inflation::on_initialize(1);112113 // SBP M2 review: Verify expected block inflation for year 1114 assert_eq!(Inflation::block_inflation(), 1901);115 assert_eq!(116 Balances::free_balance(1234) - initial_issuance,117 Inflation::block_inflation()118 );119 });120}121122#[test]123fn inflation_second_deposit() {124 new_test_ext().execute_with(|| {125 // Total issuance = 1_000_000_000126 let initial_issuance: u64 = 1_000_000_000;127 let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);128 assert_eq!(Balances::free_balance(1234), initial_issuance);129 Inflation::on_initialize(1);130131 // Next inflation deposit happens when block is multiple of InflationBlockInterval132 let mut block: u32 = 2;133 let balance_before: u64 = Balances::free_balance(1234);134 while block % InflationBlockInterval::get() != 0 {135 Inflation::on_initialize(block as u64);136 block += 1;137 }138 let balance_just_before: u64 = Balances::free_balance(1234);139 assert_eq!(balance_before, balance_just_before);140141 // The block with inflation142 Inflation::on_initialize(block as u64);143 let balance_after: u64 = Balances::free_balance(1234);144 assert_eq!(145 balance_after - balance_just_before,146 Inflation::block_inflation()147 );148 });149}150151#[test]152fn inflation_in_1_year() {153 new_test_ext().execute_with(|| {154 // Total issuance = 1_000_000_000155 let initial_issuance: u64 = 1_000_000_000;156 let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);157 assert_eq!(Balances::free_balance(1234), initial_issuance);158 Inflation::on_initialize(1);159 let block_inflation_year_0 = Inflation::block_inflation();160161 // SBP M2 review: go through all the block inflations for year 1,162 // total issuance will be updated accordingly163 for block in (100..YEAR).step_by(100) {164 Inflation::on_initialize(block);165 }166 assert_eq!(167 initial_issuance + (1901 * (YEAR / 100)),168 <Balances as Currency<_>>::total_issuance()169 );170171 Inflation::on_initialize(YEAR);172 let block_inflation_year_1 = Inflation::block_inflation();173 // SBP M2 review: Verify expected block inflation for year 2174 assert_eq!(block_inflation_year_1, 1952);175176 // SBP M2 review: this is actually not true177 // Assert that year 1 inflation is less than year 0178 // assert!(block_inflation_year_0 > block_inflation_year_1);179 });180}181182#[test]183fn inflation_in_1_to_9_years() {184 new_test_ext().execute_with(|| {185 // Total issuance = 1_000_000_000186 let initial_issuance: u64 = 1_000_000_000;187 let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);188 assert_eq!(Balances::free_balance(1234), initial_issuance);189 Inflation::on_initialize(1);190191 for year in 1..=9 {192 let block_inflation_year_before = Inflation::block_inflation();193 Inflation::on_initialize(YEAR * year);194 let block_inflation_year_after = Inflation::block_inflation();195196 // SBP M2 review: this is actually not true (not for the first few years)197 // Assert that next year inflation is less than previous year inflation198 assert!(block_inflation_year_before > block_inflation_year_after);199 }200 });201}202203#[test]204fn inflation_after_year_10_is_flat() {205 new_test_ext().execute_with(|| {206 // Total issuance = 1_000_000_000207 let initial_issuance: u64 = 1_000_000_000;208 let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);209 assert_eq!(Balances::free_balance(1234), initial_issuance);210 Inflation::on_initialize(YEAR * 9);211212 for year in 10..=20 {213 let block_inflation_year_before = Inflation::block_inflation();214 Inflation::on_initialize(YEAR * year);215 let block_inflation_year_after = Inflation::block_inflation();216217 // Assert that next year inflation is equal to previous year inflation218 assert_eq!(block_inflation_year_before, block_inflation_year_after);219 }220 });221}222223#[test]224fn inflation_rate_by_year() {225 new_test_ext().execute_with(|| {226 let payouts: u64 = YEAR / InflationBlockInterval::get() as u64;227228 // Inflation starts at 10% and does down by 2/3% every year until year 9 (included),229 // then it is flat.230 let payout_by_year: [u64; 11] = [1000, 933, 867, 800, 733, 667, 600, 533, 467, 400, 400];231232 // For accuracy total issuance = payout0 * payouts * 10;233 let initial_issuance: u64 = payout_by_year[0] * payouts * 10;234 let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);235 assert_eq!(Balances::free_balance(1234), initial_issuance);236237 for year in 0..=10 {238 // Year first block239 Inflation::on_initialize(year * YEAR);240 let mut actual_payout = Inflation::block_inflation();241 assert_eq!(actual_payout, payout_by_year[year as usize]);242243 // Year second block244 Inflation::on_initialize(year * YEAR + 1);245 actual_payout = Inflation::block_inflation();246 assert_eq!(actual_payout, payout_by_year[year as usize]);247248 // Year middle block249 Inflation::on_initialize(year * YEAR + YEAR / 2);250 actual_payout = Inflation::block_inflation();251 assert_eq!(actual_payout, payout_by_year[year as usize]);252253 // Year last block254 Inflation::on_initialize((year + 1) * YEAR - 1);255 actual_payout = Inflation::block_inflation();256 assert_eq!(actual_payout, payout_by_year[year as usize]);257 }258 });259}1#![cfg(test)]2#![allow(clippy::from_over_into)]3use crate as pallet_inflation;45use frame_support::{6 traits::{Currency},7 parameter_types,8};9use frame_support::{10 traits::{OnInitialize, Everything},11};12use sp_core::H256;13use sp_runtime::{14 traits::{BlakeTwo256, IdentityLookup},15 testing::Header,16};1718type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;19type Block = frame_system::mocking::MockBlock<Test>;2021const YEAR: u64 = 5_259_600;2223parameter_types! {24 pub const ExistentialDeposit: u64 = 1;25 pub const MaxLocks: u32 = 50;26}2728impl pallet_balances::Config for Test {29 type AccountStore = System;30 type Balance = u64;31 type DustRemoval = ();32 type Event = ();33 type ExistentialDeposit = ExistentialDeposit;34 type WeightInfo = ();35 type MaxLocks = MaxLocks;36 type MaxReserves = ();37 type ReserveIdentifier = ();38}3940frame_support::construct_runtime!(41 pub enum Test where42 Block = Block,43 NodeBlock = Block,44 UncheckedExtrinsic = UncheckedExtrinsic,45 {46 Balances: pallet_balances::{Pallet, Call, Storage},47 System: frame_system::{Pallet, Call, Config, Storage, Event<T>},48 Inflation: pallet_inflation::{Pallet, Call, Storage},49 }50);5152parameter_types! {53 pub const BlockHashCount: u64 = 250;54 pub BlockWeights: frame_system::limits::BlockWeights =55 frame_system::limits::BlockWeights::simple_max(1024);56 pub const SS58Prefix: u8 = 42;57}5859impl frame_system::Config for Test {60 type BaseCallFilter = Everything;61 type BlockWeights = ();62 type BlockLength = ();63 type DbWeight = ();64 type Origin = Origin;65 type Call = Call;66 type Index = u64;67 type BlockNumber = u64;68 type Hash = H256;69 type Hashing = BlakeTwo256;70 type AccountId = u64;71 type Lookup = IdentityLookup<Self::AccountId>;72 type Header = Header;73 type Event = ();74 type BlockHashCount = BlockHashCount;75 type Version = ();76 type PalletInfo = PalletInfo;77 type AccountData = pallet_balances::AccountData<u64>;78 type OnNewAccount = ();79 type OnKilledAccount = ();80 type SystemWeightInfo = ();81 type SS58Prefix = SS58Prefix;82 type OnSetCode = ();83}8485parameter_types! {86 pub TreasuryAccountId: u64 = 1234;87 pub const InflationBlockInterval: u32 = 100; // every time per how many blocks inflation is applied88}8990impl pallet_inflation::Config for Test {91 type Currency = Balances;92 type TreasuryAccountId = TreasuryAccountId;93 type InflationBlockInterval = InflationBlockInterval;94}9596pub fn new_test_ext() -> sp_io::TestExternalities {97 frame_system::GenesisConfig::default()98 .build_storage::<Test>()99 .unwrap()100 .into()101}102103#[test]104fn inflation_works() {105 new_test_ext().execute_with(|| {106 // Total issuance = 1_000_000_000107 let initial_issuance: u64 = 1_000_000_000;108 let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);109 assert_eq!(Balances::free_balance(1234), initial_issuance);110111 // BlockInflation should be set after 1st block and112 // first inflation deposit should be equal to BlockInflation113 Inflation::on_initialize(1);114115 // SBP M2 review: Verify expected block inflation for year 1116 assert_eq!(Inflation::block_inflation(), 1901);117 assert_eq!(118 Balances::free_balance(1234) - initial_issuance,119 Inflation::block_inflation()120 );121 });122}123124#[test]125fn inflation_second_deposit() {126 new_test_ext().execute_with(|| {127 // Total issuance = 1_000_000_000128 let initial_issuance: u64 = 1_000_000_000;129 let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);130 assert_eq!(Balances::free_balance(1234), initial_issuance);131 Inflation::on_initialize(1);132133 // Next inflation deposit happens when block is multiple of InflationBlockInterval134 let mut block: u32 = 2;135 let balance_before: u64 = Balances::free_balance(1234);136 while block % InflationBlockInterval::get() != 0 {137 Inflation::on_initialize(block as u64);138 block += 1;139 }140 let balance_just_before: u64 = Balances::free_balance(1234);141 assert_eq!(balance_before, balance_just_before);142143 // The block with inflation144 Inflation::on_initialize(block as u64);145 let balance_after: u64 = Balances::free_balance(1234);146 assert_eq!(147 balance_after - balance_just_before,148 Inflation::block_inflation()149 );150 });151}152153#[test]154fn inflation_in_1_year() {155 new_test_ext().execute_with(|| {156 // Total issuance = 1_000_000_000157 let initial_issuance: u64 = 1_000_000_000;158 let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);159 assert_eq!(Balances::free_balance(1234), initial_issuance);160 Inflation::on_initialize(1);161 let block_inflation_year_0 = Inflation::block_inflation();162163 // SBP M2 review: go through all the block inflations for year 1,164 // total issuance will be updated accordingly165 for block in (100..YEAR).step_by(100) {166 Inflation::on_initialize(block);167 }168 assert_eq!(169 initial_issuance + (1901 * (YEAR / 100)),170 <Balances as Currency<_>>::total_issuance()171 );172173 Inflation::on_initialize(YEAR);174 let block_inflation_year_1 = Inflation::block_inflation();175 // SBP M2 review: Verify expected block inflation for year 2176 assert_eq!(block_inflation_year_1, 1952);177178 // SBP M2 review: this is actually not true179 // Assert that year 1 inflation is less than year 0180 // assert!(block_inflation_year_0 > block_inflation_year_1);181 });182}183184#[test]185fn inflation_in_1_to_9_years() {186 new_test_ext().execute_with(|| {187 // Total issuance = 1_000_000_000188 let initial_issuance: u64 = 1_000_000_000;189 let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);190 assert_eq!(Balances::free_balance(1234), initial_issuance);191 Inflation::on_initialize(1);192193 for year in 1..=9 {194 let block_inflation_year_before = Inflation::block_inflation();195 Inflation::on_initialize(YEAR * year);196 let block_inflation_year_after = Inflation::block_inflation();197198 // SBP M2 review: this is actually not true (not for the first few years)199 // Assert that next year inflation is less than previous year inflation200 assert!(block_inflation_year_before > block_inflation_year_after);201 }202 });203}204205#[test]206fn inflation_after_year_10_is_flat() {207 new_test_ext().execute_with(|| {208 // Total issuance = 1_000_000_000209 let initial_issuance: u64 = 1_000_000_000;210 let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);211 assert_eq!(Balances::free_balance(1234), initial_issuance);212 Inflation::on_initialize(YEAR * 9);213214 for year in 10..=20 {215 let block_inflation_year_before = Inflation::block_inflation();216 Inflation::on_initialize(YEAR * year);217 let block_inflation_year_after = Inflation::block_inflation();218219 // Assert that next year inflation is equal to previous year inflation220 assert_eq!(block_inflation_year_before, block_inflation_year_after);221 }222 });223}224225#[test]226fn inflation_rate_by_year() {227 new_test_ext().execute_with(|| {228 let payouts: u64 = YEAR / InflationBlockInterval::get() as u64;229230 // Inflation starts at 10% and does down by 2/3% every year until year 9 (included),231 // then it is flat.232 let payout_by_year: [u64; 11] = [1000, 933, 867, 800, 733, 667, 600, 533, 467, 400, 400];233234 // For accuracy total issuance = payout0 * payouts * 10;235 let initial_issuance: u64 = payout_by_year[0] * payouts * 10;236 let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);237 assert_eq!(Balances::free_balance(1234), initial_issuance);238239 for year in 0..=10 {240 // Year first block241 Inflation::on_initialize(year * YEAR);242 let mut actual_payout = Inflation::block_inflation();243 assert_eq!(actual_payout, payout_by_year[year as usize]);244245 // Year second block246 Inflation::on_initialize(year * YEAR + 1);247 actual_payout = Inflation::block_inflation();248 assert_eq!(actual_payout, payout_by_year[year as usize]);249250 // Year middle block251 Inflation::on_initialize(year * YEAR + YEAR / 2);252 actual_payout = Inflation::block_inflation();253 assert_eq!(actual_payout, payout_by_year[year as usize]);254255 // Year last block256 Inflation::on_initialize((year + 1) * YEAR - 1);257 actual_payout = Inflation::block_inflation();258 assert_eq!(actual_payout, payout_by_year[year as usize]);259 }260 });261}pallets/nft/src/mock.rsdiffbeforeafterboth--- a/pallets/nft/src/mock.rs
+++ b/pallets/nft/src/mock.rs
@@ -2,7 +2,7 @@
use crate as pallet_template;
use sp_core::H256;
-use frame_support::{parameter_types, weights::IdentityFee};
+use frame_support::{parameter_types, traits::Everything, weights::IdentityFee};
use sp_runtime::{
traits::{BlakeTwo256, IdentityLookup},
testing::Header,
@@ -12,6 +12,7 @@
use pallet_evm::AddressMapping;
use crate::{EvmBackwardsAddressMapping, CrossAccountId};
use codec::{Encode, Decode};
+use scale_info::TypeInfo;
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
@@ -35,7 +36,7 @@
}
impl system::Config for Test {
- type BaseCallFilter = ();
+ type BaseCallFilter = Everything;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
@@ -79,6 +80,7 @@
parameter_types! {
pub const TransactionByteFee: u64 = 1;
+ pub const OperationalFeeMultiplier: u8 = 5;
}
impl pallet_transaction_payment::Config for Test {
@@ -86,6 +88,7 @@
type TransactionByteFee = TransactionByteFee;
type WeightToFee = IdentityFee<u64>;
type FeeMultiplierUpdate = ();
+ type OperationalFeeMultiplier = OperationalFeeMultiplier;
}
parameter_types! {
@@ -118,7 +121,7 @@
}
}
-#[derive(Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]
+#[derive(Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, TypeInfo)]
pub struct TestCrossAccountId(u64, sp_core::H160);
impl CrossAccountId<u64> for TestCrossAccountId {
fn from_sub(sub: u64) -> Self {
pallets/scheduler/src/lib.rsdiffbeforeafterboth--- a/pallets/scheduler/src/lib.rs
+++ b/pallets/scheduler/src/lib.rs
@@ -796,7 +796,7 @@
use frame_support::{
Hashable, assert_err, assert_noop, assert_ok, ord_parameter_types, parameter_types,
- traits::{Contains, Filter, OnFinalize, OnInitialize},
+ traits::{Contains, OnFinalize, OnInitialize},
weights::constants::RocksDbWeight,
};
use sp_core::H256;
@@ -873,7 +873,7 @@
pub struct BaseFilter;
impl Contains<Call> for BaseFilter {
fn contains(call: &Call) -> bool {
- !matches!(call, Call::Logger(logger::Call::log(_, _)))
+ !matches!(call, Call::Logger(logger::Call::log { .. }))
}
}