git.delta.rocks / unique-network / refs/commits / 4b9c21e9505c

difftreelog

Resolve conflicts

Greg Zaitsev2021-07-27parents: #13a8824 #40e660f.patch.diff
in: master

2 files changed

modifiedCargo.lockdiffbeforeafterboth
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -5850,34 +5850,34 @@
 [[package]]
 name = "pallet-scheduler"
 version = "3.0.0"
+source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.7#9c572625f6557dfdb19f47474369a0327d51dfbc"
 dependencies = [
  "frame-benchmarking",
  "frame-support",
  "frame-system",
  "log",
  "parity-scale-codec 2.1.3",
- "serde",
- "sp-core",
  "sp-io",
  "sp-runtime",
  "sp-std",
- "substrate-test-utils",
- "up-sponsorship",
 ]
 
 [[package]]
 name = "pallet-scheduler"
 version = "3.0.0"
-source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.7#9c572625f6557dfdb19f47474369a0327d51dfbc"
 dependencies = [
  "frame-benchmarking",
  "frame-support",
  "frame-system",
  "log",
  "parity-scale-codec 2.1.3",
+ "serde",
+ "sp-core",
  "sp-io",
  "sp-runtime",
  "sp-std",
+ "substrate-test-utils",
+ "up-sponsorship",
 ]
 
 [[package]]
modifiedpallets/inflation/src/tests.rsdiffbeforeafterboth
before · pallets/inflation/src/tests.rs
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::{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}3536frame_support::construct_runtime!(37	pub enum Test where38		Block = Block,39		NodeBlock = Block,40		UncheckedExtrinsic = UncheckedExtrinsic,41	{42		Balances: pallet_balances::{Pallet, Call, Storage},43		System: frame_system::{Pallet, Call, Config, Storage, Event<T>},44		Inflation: pallet_inflation::{Pallet, Call, Storage},45	}46);4748parameter_types! {49	pub const BlockHashCount: u64 = 250;50	pub BlockWeights: frame_system::limits::BlockWeights =51		frame_system::limits::BlockWeights::simple_max(1024);52	pub const SS58Prefix: u8 = 42;53}5455impl frame_system::Config for Test {56	type BaseCallFilter = ();57	type BlockWeights = ();58	type BlockLength = ();59	type DbWeight = ();60	type Origin = Origin;61	type Call = Call;62	type Index = u64;63	type BlockNumber = u64;64	type Hash = H256;65	type Hashing = BlakeTwo256;66	type AccountId = u64;67	type Lookup = IdentityLookup<Self::AccountId>;68	type Header = Header;69	type Event = ();70	type BlockHashCount = BlockHashCount;71	type Version = ();72	type PalletInfo = PalletInfo;73	type AccountData = pallet_balances::AccountData<u64>;74	type OnNewAccount = ();75	type OnKilledAccount = ();76	type SystemWeightInfo = ();77	type SS58Prefix = SS58Prefix;78	type OnSetCode = ();79}8081parameter_types! {82	pub TreasuryAccountId: u64 = 1234;83	pub const InflationBlockInterval: u32 = 100; // every time per how many blocks inflation is applied84}8586impl pallet_inflation::Config for Test {87	type Currency = Balances;88	type TreasuryAccountId = TreasuryAccountId;89	type InflationBlockInterval = InflationBlockInterval;90}9192pub fn new_test_ext() -> sp_io::TestExternalities {93	frame_system::GenesisConfig::default()94		.build_storage::<Test>()95		.unwrap()96		.into()97}9899#[test]100fn inflation_works() {101	new_test_ext().execute_with(|| {102		// Total issuance = 1_000_000_000103		let initial_issuance: u64 = 1_000_000_000;104		let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);105		assert_eq!(Balances::free_balance(1234), initial_issuance);106107		// BlockInflation should be set after 1st block and 108		// first inflation deposit should be equal to BlockInflation109		Inflation::on_initialize(1);110111		// SBP M2 review: Verify expected block inflation for year 1112		assert_eq!(Inflation::block_inflation(), 1901);113		assert_eq!(Balances::free_balance(1234) - initial_issuance, Inflation::block_inflation());114	});115}116117#[test]118fn inflation_second_deposit() {119	new_test_ext().execute_with(|| {120		// Total issuance = 1_000_000_000121		let initial_issuance: u64 = 1_000_000_000;122		let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);123		assert_eq!(Balances::free_balance(1234), initial_issuance);124		Inflation::on_initialize(1);125126		// Next inflation deposit happens when block is multiple of InflationBlockInterval127		let mut block: u32 = 2;128		let balance_before: u64 = Balances::free_balance(1234);129		while block % InflationBlockInterval::get() != 0 {130			Inflation::on_initialize(block as u64);131			block += 1;132		}133		let balance_just_before: u64 = Balances::free_balance(1234);134		assert_eq!(balance_before, balance_just_before);135136		// The block with inflation137		Inflation::on_initialize(block as u64);138		let balance_after: u64 = Balances::free_balance(1234);139		assert_eq!(140			balance_after - balance_just_before,141			Inflation::block_inflation()142		);143	});144}145146#[test]147fn inflation_in_1_year() {148	new_test_ext().execute_with(|| {149		// Total issuance = 1_000_000_000150		let initial_issuance: u64 = 1_000_000_000;151		let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);152		assert_eq!(Balances::free_balance(1234), initial_issuance);153		Inflation::on_initialize(1);154		let block_inflation_year_0 = Inflation::block_inflation();155156		// SBP M2 review: go through all the block inflations for year 1,157		// total issuance will be updated accordingly158		for block in (100..YEAR).step_by(100) {159			Inflation::on_initialize(block);160		}161		assert_eq!(162			initial_issuance + (1901 * (YEAR / 100)),163			<Balances as Currency<_>>::total_issuance()164		);165166		Inflation::on_initialize(YEAR);167		let block_inflation_year_1 = Inflation::block_inflation();168		// SBP M2 review: Verify expected block inflation for year 2169		assert_eq!(block_inflation_year_1, 1952);170171		// SBP M2 review: this is actually not true172		// Assert that year 1 inflation is less than year 0173		// assert!(block_inflation_year_0 > block_inflation_year_1);174	});175}176177#[test]178fn inflation_in_1_to_9_years() {179	new_test_ext().execute_with(|| {180		// Total issuance = 1_000_000_000181		let initial_issuance: u64 = 1_000_000_000;182		let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);183		assert_eq!(Balances::free_balance(1234), initial_issuance);184		Inflation::on_initialize(1);185186		for year in 1..=9 {187			let block_inflation_year_before = Inflation::block_inflation();188			Inflation::on_initialize(YEAR * year);189			let block_inflation_year_after = Inflation::block_inflation();190191			// SBP M2 review: this is actually not true (not for the first few years)192			// Assert that next year inflation is less than previous year inflation193			assert!(block_inflation_year_before > block_inflation_year_after);194		}195196	});197}198199#[test]200fn inflation_after_year_10_is_flat() {201	new_test_ext().execute_with(|| {202		// Total issuance = 1_000_000_000203		let initial_issuance: u64 = 1_000_000_000;204		let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);205		assert_eq!(Balances::free_balance(1234), initial_issuance);206		Inflation::on_initialize(YEAR * 9);207208		for year in 10..=20 {209			let block_inflation_year_before = Inflation::block_inflation();210			Inflation::on_initialize(YEAR * year);211			let block_inflation_year_after = Inflation::block_inflation();212213			// Assert that next year inflation is equal to previous year inflation214			assert_eq!(block_inflation_year_before, block_inflation_year_after);215		}216	});217}218219#[test]220fn inflation_rate_by_year() {221	new_test_ext().execute_with(|| {222		let payouts: u64 = YEAR / InflationBlockInterval::get() as u64;223224		// Inflation starts at 10% and does down by 2/3% every year until year 9 (included),225		// then it is flat.226		let payout_by_year: [u64; 11] = [1000, 933, 867, 800, 733, 667, 600, 533, 467, 400, 400];227228		// For accuracy total issuance = payout0 * payouts * 10;229		let initial_issuance: u64 = payout_by_year[0] * payouts * 10;230		let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);231		assert_eq!(Balances::free_balance(1234), initial_issuance);232233		for year in 0..=10 {234			// Year first block235			Inflation::on_initialize(year * YEAR);236			let mut actual_payout = Inflation::block_inflation();237			assert_eq!(actual_payout, payout_by_year[year as usize]);238239			// Year second block240			Inflation::on_initialize(year * YEAR + 1);241			actual_payout = Inflation::block_inflation();242			assert_eq!(actual_payout, payout_by_year[year as usize]);243244			// Year middle block245			Inflation::on_initialize(year * YEAR + YEAR / 2);246			actual_payout = Inflation::block_inflation();247			assert_eq!(actual_payout, payout_by_year[year as usize]);248249			// Year last block250			Inflation::on_initialize((year + 1) * YEAR - 1);251			actual_payout = Inflation::block_inflation();252			assert_eq!(actual_payout, payout_by_year[year as usize]);253		}254	});255}
after · pallets/inflation/src/tests.rs
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::{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}3536frame_support::construct_runtime!(37	pub enum Test where38		Block = Block,39		NodeBlock = Block,40		UncheckedExtrinsic = UncheckedExtrinsic,41	{42		Balances: pallet_balances::{Pallet, Call, Storage},43		System: frame_system::{Pallet, Call, Config, Storage, Event<T>},44		Inflation: pallet_inflation::{Pallet, Call, Storage},45	}46);4748parameter_types! {49	pub const BlockHashCount: u64 = 250;50	pub BlockWeights: frame_system::limits::BlockWeights =51		frame_system::limits::BlockWeights::simple_max(1024);52	pub const SS58Prefix: u8 = 42;53}5455impl frame_system::Config for Test {56	type BaseCallFilter = ();57	type BlockWeights = ();58	type BlockLength = ();59	type DbWeight = ();60	type Origin = Origin;61	type Call = Call;62	type Index = u64;63	type BlockNumber = u64;64	type Hash = H256;65	type Hashing = BlakeTwo256;66	type AccountId = u64;67	type Lookup = IdentityLookup<Self::AccountId>;68	type Header = Header;69	type Event = ();70	type BlockHashCount = BlockHashCount;71	type Version = ();72	type PalletInfo = PalletInfo;73	type AccountData = pallet_balances::AccountData<u64>;74	type OnNewAccount = ();75	type OnKilledAccount = ();76	type SystemWeightInfo = ();77	type SS58Prefix = SS58Prefix;78	type OnSetCode = ();79}8081parameter_types! {82	pub TreasuryAccountId: u64 = 1234;83	pub const InflationBlockInterval: u32 = 100; // every time per how many blocks inflation is applied84}8586impl pallet_inflation::Config for Test {87	type Currency = Balances;88	type TreasuryAccountId = TreasuryAccountId;89	type InflationBlockInterval = InflationBlockInterval;90}9192pub fn new_test_ext() -> sp_io::TestExternalities {93	frame_system::GenesisConfig::default()94		.build_storage::<Test>()95		.unwrap()96		.into()97}9899#[test]100fn inflation_works() {101	new_test_ext().execute_with(|| {102		// Total issuance = 1_000_000_000103		let initial_issuance: u64 = 1_000_000_000;104		let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);105		assert_eq!(Balances::free_balance(1234), initial_issuance);106107		// BlockInflation should be set after 1st block and108		// first inflation deposit should be equal to BlockInflation109		Inflation::on_initialize(1);110111		// SBP M2 review: Verify expected block inflation for year 1112		assert_eq!(Inflation::block_inflation(), 1901);113		assert_eq!(114			Balances::free_balance(1234) - initial_issuance,115			Inflation::block_inflation()116		);117	});118}119120#[test]121fn inflation_second_deposit() {122	new_test_ext().execute_with(|| {123		// Total issuance = 1_000_000_000124		let initial_issuance: u64 = 1_000_000_000;125		let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);126		assert_eq!(Balances::free_balance(1234), initial_issuance);127		Inflation::on_initialize(1);128129		// Next inflation deposit happens when block is multiple of InflationBlockInterval130		let mut block: u32 = 2;131		let balance_before: u64 = Balances::free_balance(1234);132		while block % InflationBlockInterval::get() != 0 {133			Inflation::on_initialize(block as u64);134			block += 1;135		}136		let balance_just_before: u64 = Balances::free_balance(1234);137		assert_eq!(balance_before, balance_just_before);138139		// The block with inflation140		Inflation::on_initialize(block as u64);141		let balance_after: u64 = Balances::free_balance(1234);142		assert_eq!(143			balance_after - balance_just_before,144			Inflation::block_inflation()145		);146	});147}148149#[test]150fn inflation_in_1_year() {151	new_test_ext().execute_with(|| {152		// Total issuance = 1_000_000_000153		let initial_issuance: u64 = 1_000_000_000;154		let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);155		assert_eq!(Balances::free_balance(1234), initial_issuance);156		Inflation::on_initialize(1);157		let block_inflation_year_0 = Inflation::block_inflation();158159		// SBP M2 review: go through all the block inflations for year 1,160		// total issuance will be updated accordingly161		for block in (100..YEAR).step_by(100) {162			Inflation::on_initialize(block);163		}164		assert_eq!(165			initial_issuance + (1901 * (YEAR / 100)),166			<Balances as Currency<_>>::total_issuance()167		);168169		Inflation::on_initialize(YEAR);170		let block_inflation_year_1 = Inflation::block_inflation();171		// SBP M2 review: Verify expected block inflation for year 2172		assert_eq!(block_inflation_year_1, 1952);173174		// SBP M2 review: this is actually not true175		// Assert that year 1 inflation is less than year 0176		// assert!(block_inflation_year_0 > block_inflation_year_1);177	});178}179180#[test]181fn inflation_in_1_to_9_years() {182	new_test_ext().execute_with(|| {183		// Total issuance = 1_000_000_000184		let initial_issuance: u64 = 1_000_000_000;185		let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);186		assert_eq!(Balances::free_balance(1234), initial_issuance);187		Inflation::on_initialize(1);188189		for year in 1..=9 {190			let block_inflation_year_before = Inflation::block_inflation();191			Inflation::on_initialize(YEAR * year);192			let block_inflation_year_after = Inflation::block_inflation();193194			// SBP M2 review: this is actually not true (not for the first few years)195			// Assert that next year inflation is less than previous year inflation196			assert!(block_inflation_year_before > block_inflation_year_after);197		}198	});199}200201#[test]202fn inflation_after_year_10_is_flat() {203	new_test_ext().execute_with(|| {204		// Total issuance = 1_000_000_000205		let initial_issuance: u64 = 1_000_000_000;206		let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);207		assert_eq!(Balances::free_balance(1234), initial_issuance);208		Inflation::on_initialize(YEAR * 9);209210		for year in 10..=20 {211			let block_inflation_year_before = Inflation::block_inflation();212			Inflation::on_initialize(YEAR * year);213			let block_inflation_year_after = Inflation::block_inflation();214215			// Assert that next year inflation is equal to previous year inflation216			assert_eq!(block_inflation_year_before, block_inflation_year_after);217		}218	});219}220221#[test]222fn inflation_rate_by_year() {223	new_test_ext().execute_with(|| {224		let payouts: u64 = YEAR / InflationBlockInterval::get() as u64;225226		// Inflation starts at 10% and does down by 2/3% every year until year 9 (included),227		// then it is flat.228		let payout_by_year: [u64; 11] = [1000, 933, 867, 800, 733, 667, 600, 533, 467, 400, 400];229230		// For accuracy total issuance = payout0 * payouts * 10;231		let initial_issuance: u64 = payout_by_year[0] * payouts * 10;232		let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);233		assert_eq!(Balances::free_balance(1234), initial_issuance);234235		for year in 0..=10 {236			// Year first block237			Inflation::on_initialize(year * YEAR);238			let mut actual_payout = Inflation::block_inflation();239			assert_eq!(actual_payout, payout_by_year[year as usize]);240241			// Year second block242			Inflation::on_initialize(year * YEAR + 1);243			actual_payout = Inflation::block_inflation();244			assert_eq!(actual_payout, payout_by_year[year as usize]);245246			// Year middle block247			Inflation::on_initialize(year * YEAR + YEAR / 2);248			actual_payout = Inflation::block_inflation();249			assert_eq!(actual_payout, payout_by_year[year as usize]);250251			// Year last block252			Inflation::on_initialize((year + 1) * YEAR - 1);253			actual_payout = Inflation::block_inflation();254			assert_eq!(actual_payout, payout_by_year[year as usize]);255		}256	});257}