difftreelog
test fix unit tests
in: master
5 files changed
pallets/inflation/src/tests.rsdiffbeforeafterboth1#![cfg(test)]2#![allow(clippy::from_over_into)]3use crate as pallet_inflation;45use frame_support::{6 assert_ok, parameter_types,7 traits::{Currency, OnInitialize, Everything},8};9use frame_system::RawOrigin;10use sp_core::H256;11use sp_runtime::{12 traits::{BlakeTwo256, BlockNumberProvider, 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; // 6-second blocks20 // const YEAR: u64 = 2_629_800; // 12-second blocks21 // Expected 100-block inflation for year 1 is 100 * 100_000_000 / YEAR = FIRST_YEAR_BLOCK_INFLATION22const FIRST_YEAR_BLOCK_INFLATION: u64 = 1901;2324parameter_types! {25 pub const ExistentialDeposit: u64 = 1;26 pub const MaxLocks: u32 = 50;27}2829impl pallet_balances::Config for Test {30 type AccountStore = System;31 type Balance = u64;32 type DustRemoval = ();33 type Event = ();34 type ExistentialDeposit = ExistentialDeposit;35 type WeightInfo = ();36 type MaxLocks = MaxLocks;37 type MaxReserves = ();38 type ReserveIdentifier = ();39}4041frame_support::construct_runtime!(42 pub enum Test where43 Block = Block,44 NodeBlock = Block,45 UncheckedExtrinsic = UncheckedExtrinsic,46 {47 Balances: pallet_balances::{Pallet, Call, Storage},48 System: frame_system::{Pallet, Call, Config, Storage, Event<T>},49 Inflation: pallet_inflation::{Pallet, Call, Storage},50 }51);5253parameter_types! {54 pub const BlockHashCount: u64 = 250;55 pub BlockWeights: frame_system::limits::BlockWeights =56 frame_system::limits::BlockWeights::simple_max(1024);57 pub const SS58Prefix: u8 = 42;58}5960impl frame_system::Config for Test {61 type BaseCallFilter = Everything;62 type BlockWeights = ();63 type BlockLength = ();64 type DbWeight = ();65 type Origin = Origin;66 type Call = Call;67 type Index = u64;68 type BlockNumber = u64;69 type Hash = H256;70 type Hashing = BlakeTwo256;71 type AccountId = u64;72 type Lookup = IdentityLookup<Self::AccountId>;73 type Header = Header;74 type Event = ();75 type BlockHashCount = BlockHashCount;76 type Version = ();77 type PalletInfo = PalletInfo;78 type AccountData = pallet_balances::AccountData<u64>;79 type OnNewAccount = ();80 type OnKilledAccount = ();81 type SystemWeightInfo = ();82 type SS58Prefix = SS58Prefix;83 type OnSetCode = ();84}8586parameter_types! {87 pub TreasuryAccountId: u64 = 1234;88 pub const InflationBlockInterval: u32 = 100; // every time per how many blocks inflation is applied89 pub static MockBlockNumberProvider: u64 = 0;90}9192impl BlockNumberProvider for MockBlockNumberProvider {93 type BlockNumber = u64;9495 fn current_block_number() -> Self::BlockNumber {96 Self::get()97 }98}99100impl pallet_inflation::Config for Test {101 type Currency = Balances;102 type TreasuryAccountId = TreasuryAccountId;103 type InflationBlockInterval = InflationBlockInterval;104 type BlockNumberProvider = MockBlockNumberProvider;105}106107pub fn new_test_ext() -> sp_io::TestExternalities {108 frame_system::GenesisConfig::default()109 .build_storage::<Test>()110 .unwrap()111 .into()112}113114macro_rules! block_inflation {115 // Block inflation doesn't have any argumets116 () => {117 // Return BlockInflation state variable current value118 <pallet_inflation::BlockInflation<Test>>::get()119 };120}121122#[test]123fn uninitialized_inflation() {124 new_test_ext().execute_with(|| {125 let initial_issuance: u64 = 1_000_000_000;126 let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);127 assert_eq!(Balances::free_balance(1234), initial_issuance);128129 // BlockInflation should be set after inflation is started130 // first inflation deposit should be equal to BlockInflation131 MockBlockNumberProvider::set(1);132133 assert_eq!(block_inflation!(), 0);134 });135}136137#[test]138fn inflation_works() {139 new_test_ext().execute_with(|| {140 // Total issuance = 1_000_000_000141 let initial_issuance: u64 = 1_000_000_000;142 let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);143 assert_eq!(Balances::free_balance(1234), initial_issuance);144145 // BlockInflation should be set after inflation is started146 // first inflation deposit should be equal to BlockInflation147 MockBlockNumberProvider::set(1);148149 // Start inflation as sudo150 assert_ok!(Inflation::start_inflation(RawOrigin::Root.into(), 1));151 assert_eq!(block_inflation!(), FIRST_YEAR_BLOCK_INFLATION);152 assert_eq!(153 Balances::free_balance(1234) - initial_issuance,154 block_inflation!()155 );156157 // Trigger inflation158 MockBlockNumberProvider::set(102);159 Inflation::on_initialize(0);160 assert_eq!(161 Balances::free_balance(1234) - initial_issuance,162 2 * block_inflation!()163 );164 });165}166167#[test]168fn inflation_second_deposit() {169 new_test_ext().execute_with(|| {170 // Total issuance = 1_000_000_000171 let initial_issuance: u64 = 1_000_000_000;172 let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);173 assert_eq!(Balances::free_balance(1234), initial_issuance);174 MockBlockNumberProvider::set(1);175176 // Start inflation as sudo177 assert_ok!(Inflation::start_inflation(RawOrigin::Root.into(), 1));178179 // Next inflation deposit happens when block is greater then or equal to NextInflationBlock180 let mut block: u64 = 2;181 let balance_before: u64 = Balances::free_balance(1234);182 while block < <pallet_inflation::NextInflationBlock<Test>>::get() {183 MockBlockNumberProvider::set(block as u64);184 Inflation::on_initialize(0);185 block += 1;186 }187 let balance_just_before: u64 = Balances::free_balance(1234);188 assert_eq!(balance_before, balance_just_before);189190 // The block with inflation191 MockBlockNumberProvider::set(block as u64);192 Inflation::on_initialize(0);193 let balance_after: u64 = Balances::free_balance(1234);194 assert_eq!(balance_after - balance_just_before, block_inflation!());195 });196}197198#[test]199fn inflation_in_1_year() {200 new_test_ext().execute_with(|| {201 // Total issuance = 1_000_000_000202 let initial_issuance: u64 = 1_000_000_000;203 let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);204 assert_eq!(Balances::free_balance(1234), initial_issuance);205 MockBlockNumberProvider::set(1);206207 // Start inflation as sudo208 assert_ok!(Inflation::start_inflation(RawOrigin::Root.into(), 1));209210 // Go through all the block inflations for year 1,211 // total issuance will be updated accordingly212 // Inflation is set to start in block 1, so first iteration is block 101213 for block in (101..YEAR).step_by(100) {214 MockBlockNumberProvider::set(block);215 Inflation::on_initialize(0);216 }217 assert_eq!(218 initial_issuance + (FIRST_YEAR_BLOCK_INFLATION * (YEAR / 100)),219 <Balances as Currency<_>>::total_issuance()220 );221222 MockBlockNumberProvider::set(YEAR + 1);223 Inflation::on_initialize(0);224 let block_inflation_year_2 = block_inflation!();225 // Expected 100-block inflation for year 2: 100 * 9.33% * initial issuance * 110% / YEAR == 1951226 let expecter_year_2_inflation: u64 = (initial_issuance227 + FIRST_YEAR_BLOCK_INFLATION * YEAR / 100)228 * 933 * 100 / (10000 * YEAR);229 assert_eq!(block_inflation_year_2 / 10, expecter_year_2_inflation / 10); // divide by 10 for approx. equality230 });231}232233#[test]234fn inflation_start_large_kusama_block() {235 new_test_ext().execute_with(|| {236 // Total issuance = 1_000_000_000237 let initial_issuance: u64 = 1_000_000_000;238 let start_block: u64 = 10457457;239 let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);240 assert_eq!(Balances::free_balance(1234), initial_issuance);241 MockBlockNumberProvider::set(start_block);242243 // Start inflation as sudo244 assert_ok!(Inflation::start_inflation(245 RawOrigin::Root.into(),246 start_block247 ));248249 // Go through all the block inflations for year 1,250 // total issuance will be updated accordingly251 // Inflation is set to start in block 1, so first iteration is block 101252 for block in (101..YEAR).step_by(100) {253 MockBlockNumberProvider::set(start_block + block);254 Inflation::on_initialize(0);255 }256 assert_eq!(257 initial_issuance + (FIRST_YEAR_BLOCK_INFLATION * (YEAR / 100)),258 <Balances as Currency<_>>::total_issuance()259 );260261 MockBlockNumberProvider::set(start_block + YEAR + 1);262 Inflation::on_initialize(0);263 let block_inflation_year_2 = block_inflation!();264 // Expected 100-block inflation for year 2: 100 * 9.33% * initial issuance * 110% / YEAR == 1951265 let expecter_year_2_inflation: u64 = (initial_issuance266 + FIRST_YEAR_BLOCK_INFLATION * YEAR / 100)267 * 933 * 100 / (10000 * YEAR);268 assert_eq!(block_inflation_year_2 / 10, expecter_year_2_inflation / 10); // divide by 10 for approx. equality269 });270}271272#[test]273fn inflation_after_year_10_is_flat() {274 new_test_ext().execute_with(|| {275 // Total issuance = 1_000_000_000276 let initial_issuance: u64 = 1_000_000_000;277 let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);278 assert_eq!(Balances::free_balance(1234), initial_issuance);279 MockBlockNumberProvider::set(YEAR * 9 + 1);280281 // Start inflation as sudo282 assert_ok!(Inflation::start_inflation(RawOrigin::Root.into(), 1));283284 // Let inflation catch up285 for _year in 1..=9 {286 Inflation::on_initialize(0);287 }288289 for year in 10..=20 {290 let block_inflation_year_before = block_inflation!();291 MockBlockNumberProvider::set(YEAR * year + 1);292 Inflation::on_initialize(0);293 let block_inflation_year_after = block_inflation!();294295 // Assert that next year inflation is equal to previous year inflation296 assert_eq!(block_inflation_year_before, block_inflation_year_after);297 }298 });299}300301#[test]302fn inflation_rate_by_year() {303 new_test_ext().execute_with(|| {304 let payouts: u64 = YEAR / InflationBlockInterval::get() as u64;305306 // Inflation starts at 10% and does down by 2/3% every year until year 9 (included),307 // then it is flat.308 let payout_by_year: [u64; 11] = [1000, 933, 867, 800, 733, 667, 600, 533, 467, 400, 400];309310 // For accuracy total issuance = payout0 * payouts * 10;311 let initial_issuance: u64 = payout_by_year[0] * payouts * 10;312 let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);313 assert_eq!(Balances::free_balance(1234), initial_issuance);314315 // Start inflation as sudo316 assert_ok!(Inflation::start_inflation(RawOrigin::Root.into(), 1));317318 for year in 0..=10 {319 // Year first block320 MockBlockNumberProvider::set(YEAR * year + 1);321 Inflation::on_initialize(0);322 let mut actual_payout = block_inflation!();323 assert_eq!(actual_payout, payout_by_year[year as usize]);324325 // Year second block326 MockBlockNumberProvider::set(YEAR * year + 2);327 Inflation::on_initialize(0);328 actual_payout = block_inflation!();329 assert_eq!(actual_payout, payout_by_year[year as usize]);330331 // Year middle block332 MockBlockNumberProvider::set(year * YEAR + YEAR / 2);333 Inflation::on_initialize(0);334 actual_payout = block_inflation!();335 assert_eq!(actual_payout, payout_by_year[year as usize]);336337 // Year last block338 MockBlockNumberProvider::set((year + 1) * YEAR);339 Inflation::on_initialize(0);340 actual_payout = block_inflation!();341 assert_eq!(actual_payout, payout_by_year[year as usize]);342 }343 });344}pallets/scheduler/src/lib.rsdiffbeforeafterboth--- a/pallets/scheduler/src/lib.rs
+++ b/pallets/scheduler/src/lib.rs
@@ -674,7 +674,9 @@
use super::*;
use frame_support::{
- ord_parameter_types, parameter_types, traits::Contains, weights::constants::RocksDbWeight,
+ ord_parameter_types, parameter_types,
+ traits::{Contains, ConstU32, EnsureOneOf},
+ weights::constants::RocksDbWeight,
};
use sp_core::H256;
use sp_runtime::{
@@ -682,7 +684,7 @@
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
};
- use frame_system::{EnsureOneOf, EnsureRoot, EnsureSignedBy};
+ use frame_system::{EnsureRoot, EnsureSignedBy};
use crate as scheduler;
mod logger {
@@ -779,6 +781,7 @@
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
+ type MaxConsumers = ConstU32<16>;
}
impl logger::Config for Test {
type Event = Event;
@@ -797,7 +800,7 @@
type PalletsOrigin = OriginCaller;
type Call = Call;
type MaximumWeight = MaximumSchedulerWeight;
- type ScheduleOrigin = EnsureOneOf<u64, EnsureRoot<u64>, EnsureSignedBy<One, u64>>;
+ type ScheduleOrigin = EnsureOneOf<EnsureRoot<u64>, EnsureSignedBy<One, u64>>;
type MaxScheduledPerBlock = MaxScheduledPerBlock;
type WeightInfo = ();
type SponsorshipHandler = ();
pallets/unique/src/mock.rsdiffbeforeafterboth--- a/pallets/unique/src/mock.rs
+++ b/pallets/unique/src/mock.rs
@@ -9,10 +9,11 @@
};
use pallet_transaction_payment::{CurrencyAdapter};
use frame_system as system;
-use pallet_evm::AddressMapping;
+use pallet_evm::{AddressMapping, runner::stack::MaybeMirroredLog};
use pallet_common::account::{EvmBackwardsAddressMapping, CrossAccountId};
-use codec::{Encode, Decode};
+use codec::{Encode, Decode, MaxEncodedLen};
use scale_info::TypeInfo;
+use up_data_structs::ConstU32;
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
@@ -63,6 +64,7 @@
type SystemWeightInfo = ();
type SS58Prefix = SS58Prefix;
type OnSetCode = ();
+ type MaxConsumers = ConstU32<16>;
}
parameter_types! {
@@ -125,7 +127,7 @@
}
}
-#[derive(Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, TypeInfo)]
+#[derive(Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, TypeInfo, MaxEncodedLen)]
pub struct TestCrossAccountId(u64, sp_core::H160);
impl CrossAccountId<u64> for TestCrossAccountId {
fn as_sub(&self) -> &u64 {
@@ -161,7 +163,7 @@
fn submit_logs_transaction(
_source: H160,
_tx: pallet_ethereum::Transaction,
- _logs: Vec<pallet_ethereum::Log>,
+ _logs: Vec<MaybeMirroredLog>,
) {
}
}
pallets/unique/src/tests.rsdiffbeforeafterboth--- a/pallets/unique/src/tests.rs
+++ b/pallets/unique/src/tests.rs
@@ -41,9 +41,9 @@
let origin1 = Origin::signed(owner);
assert_ok!(TemplateModule::create_collection(
origin1,
- col_name1,
- col_desc1,
- token_prefix1,
+ col_name1.try_into().unwrap(),
+ col_desc1.try_into().unwrap(),
+ token_prefix1.try_into().unwrap(),
mode.clone()
));
@@ -131,9 +131,9 @@
assert_noop!(
TemplateModule::create_collection(
origin1,
- col_name1,
- col_desc1,
- token_prefix1,
+ col_name1.try_into().unwrap(),
+ col_desc1.try_into().unwrap(),
+ token_prefix1.try_into().unwrap(),
CollectionMode::Fungible(MAX_DECIMAL_POINTS + 1)
),
Error::<Test>::CollectionDecimalPointLimitExceeded
@@ -2271,9 +2271,9 @@
assert_noop!(
TemplateModule::create_collection(
origin1,
- col_name1,
- col_desc1,
- token_prefix1,
+ col_name1.try_into().unwrap(),
+ col_desc1.try_into().unwrap(),
+ token_prefix1.try_into().unwrap(),
CollectionMode::NFT
),
CommonError::<Test>::TotalCollectionsLimitExceeded
@@ -2372,7 +2372,7 @@
assert_ok!(TemplateModule::set_const_on_chain_schema(
origin1,
collection_id,
- b"test const on chain schema".to_vec()
+ b"test const on chain schema".to_vec().try_into().unwrap()
));
assert_eq!(
@@ -2399,7 +2399,10 @@
assert_ok!(TemplateModule::set_variable_on_chain_schema(
origin1,
collection_id,
- b"test variable on chain schema".to_vec()
+ b"test variable on chain schema"
+ .to_vec()
+ .try_into()
+ .unwrap()
));
assert_eq!(
@@ -2432,7 +2435,7 @@
origin1,
collection_id,
TokenId(1),
- variable_data.clone()
+ variable_data.clone().try_into().unwrap()
));
assert_eq!(
@@ -2459,7 +2462,7 @@
origin1,
collection_id,
TokenId(1),
- variable_data.clone()
+ variable_data.clone().try_into().unwrap()
));
assert_eq!(
@@ -2485,7 +2488,7 @@
origin1,
collection_id,
TokenId(0),
- variable_data
+ variable_data.try_into().unwrap()
)
.map_err(|e| e.error),
<pallet_fungible::Error<Test>>::FungibleItemsDontHaveData
@@ -2494,54 +2497,6 @@
}
#[test]
-fn set_variable_meta_data_on_nft_token_fails_for_big_data() {
- new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
-
- let origin1 = Origin::signed(1);
-
- let data = default_nft_data();
- create_test_item(collection_id, &data.into());
-
- let variable_data = b"test set_variable_meta_data method, bigger than limits.".to_vec();
- assert_noop!(
- TemplateModule::set_variable_meta_data(
- origin1,
- collection_id,
- TokenId(1),
- variable_data
- )
- .map_err(|e| e.error),
- CommonError::<Test>::TokenVariableDataLimitExceeded
- );
- });
-}
-
-#[test]
-fn set_variable_meta_data_on_re_fungible_token_fails_for_big_data() {
- new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));
-
- let origin1 = Origin::signed(1);
-
- let data = default_re_fungible_data();
- create_test_item(collection_id, &data.into());
-
- let variable_data = b"test set_variable_meta_data method, bigger than limits.".to_vec();
- assert_noop!(
- TemplateModule::set_variable_meta_data(
- origin1,
- collection_id,
- TokenId(1),
- variable_data
- )
- .map_err(|e| e.error),
- CommonError::<Test>::TokenVariableDataLimitExceeded
- );
- });
-}
-
-#[test]
fn set_variable_meta_data_on_nft_with_item_owner_permission_flag() {
new_test_ext().execute_with(|| {
//default_limits();
@@ -2564,7 +2519,7 @@
origin1,
collection_id,
TokenId(1),
- variable_data.clone()
+ variable_data.clone().try_into().unwrap()
));
assert_eq!(
@@ -2574,48 +2529,6 @@
variable_data
);
});
-}
-
-#[test]
-fn set_variable_meta_data_on_nft_with_item_owner_permission_flag_neg() {
- new_test_ext().execute_with(|| {
- let collection_id =
- create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));
-
- let origin1 = Origin::signed(1);
-
- assert_ok!(TemplateModule::set_mint_permission(
- origin1.clone(),
- collection_id,
- true
- ));
- assert_ok!(TemplateModule::add_to_allow_list(
- origin1.clone(),
- collection_id,
- account(1)
- ));
-
- let data = default_nft_data();
- create_test_item(collection_id, &data.into());
-
- assert_ok!(TemplateModule::set_meta_update_permission_flag(
- origin1.clone(),
- collection_id,
- MetaUpdatePermission::ItemOwner,
- ));
-
- let variable_data = b"1234567890123".to_vec();
- assert_noop!(
- TemplateModule::set_variable_meta_data(
- origin1,
- collection_id,
- TokenId(1),
- variable_data.clone()
- )
- .map_err(|e| e.error),
- CommonError::<Test>::TokenVariableDataLimitExceeded
- );
- })
}
#[test]
@@ -2712,7 +2625,7 @@
origin1,
collection_id,
TokenId(1),
- variable_data.clone()
+ variable_data.clone().try_into().unwrap()
));
assert_eq!(
@@ -2761,7 +2674,7 @@
origin1,
collection_id,
TokenId(1),
- variable_data.clone()
+ variable_data.try_into().unwrap()
)
.map_err(|e| e.error),
CommonError::<Test>::NoPermission
@@ -2819,7 +2732,7 @@
origin1.clone(),
collection_id,
TokenId(1),
- variable_data.clone()
+ variable_data.try_into().unwrap()
)
.map_err(|e| e.error),
CommonError::<Test>::NoPermission
runtime/src/lib.rsdiffbeforeafterboth--- a/runtime/src/lib.rs
+++ b/runtime/src/lib.rs
@@ -68,7 +68,6 @@
use codec::{Encode, Decode};
use pallet_evm::{Account as EVMAccount, FeeCalculator, GasWeightMapping, OnMethodCall};
use fp_rpc::TransactionStatus;
-use sp_core::crypto::Public;
use sp_runtime::{
traits::{BlockNumberProvider, Dispatchable, PostDispatchInfoOf},
transaction_validity::TransactionValidityError,