git.delta.rocks / unique-network / refs/commits / 5c283c1e8412

difftreelog

fix rust tests

Grigoriy Simonov2023-05-24parent: #e1a1068.patch.diff
in: master

8 files changed

modifiedpallets/collator-selection/Cargo.tomldiffbeforeafterboth
--- a/pallets/collator-selection/Cargo.toml
+++ b/pallets/collator-selection/Cargo.toml
@@ -55,9 +55,12 @@
 	"frame-system/std",
 	"log/std",
 	"pallet-authorship/std",
+	'pallet-aura/std',
+	'pallet-balances/std',
 	"pallet-session/std",
 	"rand/std",
 	"scale-info/std",
+	"sp-consensus-aura/std",
 	"sp-runtime/std",
 	"sp-staking/std",
 	"sp-std/std",
modifiedpallets/collator-selection/src/mock.rsdiffbeforeafterboth
--- a/pallets/collator-selection/src/mock.rs
+++ b/pallets/collator-selection/src/mock.rs
@@ -102,6 +102,8 @@
 parameter_types! {
 	pub const ExistentialDeposit: u64 = 5;
 	pub const MaxReserves: u32 = 50;
+	pub const MaxHolds: u32 = 2;
+	pub const MaxFreezes: u32 = 2;
 }
 
 impl pallet_balances::Config for Test {
@@ -114,6 +116,10 @@
 	type MaxLocks = ();
 	type MaxReserves = MaxReserves;
 	type ReserveIdentifier = [u8; 8];
+	type HoldIdentifier = [u8; 16];
+	type FreezeIdentifier = [u8; 16];
+	type MaxHolds = MaxHolds;
+	type MaxFreezes = MaxFreezes;
 }
 
 pub struct Author4;
@@ -209,6 +215,7 @@
 	pub const MaxXcmAllowedLocations: u32 = 16;
 	pub AppPromotionDailyRate: Perbill = Perbill::from_rational(5u32, 10_000);
 	pub const DayRelayBlocks: u32 = 1;
+	pub const LicenceBondIdentifier: [u8; 16] = *b"licenceidentifie";
 }
 
 impl pallet_configuration::Config for Test {
@@ -257,6 +264,7 @@
 	type ValidatorId = <Self as frame_system::Config>::AccountId;
 	type ValidatorIdOf = IdentityCollator;
 	type ValidatorRegistration = IsRegistered;
+	type LicenceBondIdentifier = LicenceBondIdentifier;
 	type WeightInfo = ();
 }
 
@@ -267,7 +275,9 @@
 		.unwrap();
 	let invulnerables = vec![1, 2];
 
-	let balances = vec![(1, 100), (2, 100), (3, 100), (4, 100), (5, 100)];
+	let ed = <Test as pallet_balances::Config>::ExistentialDeposit::get();
+
+	let balances = vec![(1, 100), (2, 100), (3, 100), (4, 100), (5, 100), (33, ed)];
 	let keys = balances
 		.iter()
 		.map(|&(i, _)| {
modifiedpallets/collator-selection/src/tests.rsdiffbeforeafterboth
--- a/pallets/collator-selection/src/tests.rs
+++ b/pallets/collator-selection/src/tests.rs
@@ -34,16 +34,16 @@
 use crate::{mock::*, Error};
 use frame_support::{
 	assert_noop, assert_ok,
-	traits::{Currency, GenesisBuild, OnInitialize},
+	traits::{fungible, GenesisBuild, OnInitialize},
 };
 use frame_system::RawOrigin;
-use pallet_balances::Error as BalancesError;
-use sp_runtime::traits::BadOrigin;
+use sp_runtime::{traits::BadOrigin, TokenError};
 use pallet_configuration::{
 	CollatorSelectionDesiredCollatorsOverride as DesiredCollators,
 	CollatorSelectionKickThresholdOverride as KickThreshold,
 	CollatorSelectionLicenseBondOverride as LicenseBond,
 };
+use scale_info::prelude::*;
 
 fn get_license_and_onboard(account_id: <Test as frame_system::Config>::AccountId) {
 	assert_ok!(CollatorSelection::get_license(RuntimeOrigin::signed(
@@ -226,8 +226,9 @@
 #[test]
 fn cannot_obtain_license_if_poor() {
 	new_test_ext().execute_with(|| {
+		let ed = <Test as pallet_balances::Config>::ExistentialDeposit::get();
 		assert_eq!(Balances::free_balance(&3), 100);
-		assert_eq!(Balances::free_balance(&33), 0);
+		assert_eq!(Balances::free_balance(&33), ed);
 
 		// works
 		assert_ok!(CollatorSelection::get_license(RuntimeOrigin::signed(3)));
@@ -235,7 +236,7 @@
 		// poor
 		assert_noop!(
 			CollatorSelection::get_license(RuntimeOrigin::signed(33)),
-			BalancesError::<Test>::InsufficientBalance,
+			TokenError::FundsUnavailable,
 		);
 	});
 }
@@ -417,10 +418,7 @@
 fn authorship_event_handler() {
 	new_test_ext().execute_with(|| {
 		// put 100 in the pot + 5 for ED
-		<pallet_balances::Pallet<T> as fungible::Mutate<T::AccountId>>::set_balance(
-			&CollatorSelection::account_id(),
-			105,
-		);
+		<Balances as fungible::Mutate<_>>::set_balance(&CollatorSelection::account_id(), 105);
 
 		// 4 is the default author.
 		assert_eq!(Balances::free_balance(4), 100);
@@ -444,10 +442,7 @@
 		// Nothing panics, no reward when no ED in balance
 		Authorship::on_initialize(1);
 		// put some money into the pot at ED
-		<pallet_balances::Pallet<T> as fungible::Mutate<T::AccountId>>::set_balance(
-			&CollatorSelection::account_id(),
-			5,
-		);
+		<Balances as fungible::Mutate<_>>::set_balance(&CollatorSelection::account_id(), 5);
 		// 4 is the default author.
 		assert_eq!(Balances::free_balance(4), 100);
 		get_license_and_onboard(4);
modifiedpallets/foreign-assets/Cargo.tomldiffbeforeafterboth
--- a/pallets/foreign-assets/Cargo.toml
+++ b/pallets/foreign-assets/Cargo.toml
@@ -42,5 +42,6 @@
 	"sp-runtime/std",
 	"sp-std/std",
 	"up-data-structs/std",
+	"xcm-executor/std"
 ]
 try-runtime = ["frame-support/try-runtime"]
modifiedpallets/identity/Cargo.tomldiffbeforeafterboth
--- a/pallets/identity/Cargo.toml
+++ b/pallets/identity/Cargo.toml
@@ -46,5 +46,6 @@
 	"sp-io/std",
 	"sp-runtime/std",
 	"sp-std/std",
+	"pallet-balances/std",
 ]
 try-runtime = ["frame-support/try-runtime"]
modifiedpallets/identity/src/tests.rsdiffbeforeafterboth
--- a/pallets/identity/src/tests.rs
+++ b/pallets/identity/src/tests.rs
@@ -106,6 +106,10 @@
 	type MaxReserves = ();
 	type ReserveIdentifier = [u8; 8];
 	type WeightInfo = ();
+	type HoldIdentifier = ();
+	type FreezeIdentifier = ();
+	type MaxHolds = ();
+	type MaxFreezes = ();
 }
 
 parameter_types! {
modifiedpallets/inflation/src/lib.rsdiffbeforeafterboth
187 <NextInflationBlock<T>>::set(inflation_start_relay_block + block_interval.into());187 <NextInflationBlock<T>>::set(inflation_start_relay_block + block_interval.into());
188188
189 // First time deposit - create Treasury account so that we can call deposit_into_existing everywhere else189 // First time deposit - create Treasury account so that we can call deposit_into_existing everywhere else
190 let imbalance = T::Currency::deposit(190 let _ = T::Currency::deposit(
191 &T::TreasuryAccountId::get(),191 &T::TreasuryAccountId::get(),
192 <BlockInflation<T>>::get(),192 <BlockInflation<T>>::get(),
193 Precision::Exact,193 Precision::Exact,
194 )?;194 )?;
195 debug_assert!(imbalance.peek().is_zero());
196 }195 }
197196
198 Ok(())197 Ok(())
modifiedpallets/inflation/src/tests.rsdiffbeforeafterboth
--- a/pallets/inflation/src/tests.rs
+++ b/pallets/inflation/src/tests.rs
@@ -20,7 +20,7 @@
 
 use frame_support::{
 	assert_ok, parameter_types,
-	traits::{Currency, OnInitialize, Everything, ConstU32},
+	traits::{fungible::{Balanced, Inspect}, OnInitialize, Everything, ConstU32, tokens::Precision},
 	weights::Weight,
 };
 use frame_system::RawOrigin;
@@ -53,6 +53,10 @@
 	type MaxLocks = MaxLocks;
 	type MaxReserves = ();
 	type ReserveIdentifier = ();
+	type HoldIdentifier = ();
+	type FreezeIdentifier = ();
+	type MaxHolds = ();
+	type MaxFreezes = ();
 }
 
 frame_support::construct_runtime!(
@@ -141,7 +145,7 @@
 fn uninitialized_inflation() {
 	new_test_ext().execute_with(|| {
 		let initial_issuance: u64 = 1_000_000_000;
-		let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);
+		let _ = <Balances as Balanced<_>>::deposit(&1234, initial_issuance, Precision::Exact);
 		assert_eq!(Balances::free_balance(1234), initial_issuance);
 
 		// BlockInflation should be set after inflation is started
@@ -157,7 +161,7 @@
 	new_test_ext().execute_with(|| {
 		// Total issuance = 1_000_000_000
 		let initial_issuance: u64 = 1_000_000_000;
-		let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);
+		let _ = <Balances as Balanced<_>>::deposit(&1234, initial_issuance, Precision::Exact);
 		assert_eq!(Balances::free_balance(1234), initial_issuance);
 
 		// BlockInflation should be set after inflation is started
@@ -187,7 +191,7 @@
 	new_test_ext().execute_with(|| {
 		// Total issuance = 1_000_000_000
 		let initial_issuance: u64 = 1_000_000_000;
-		let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);
+		let _ = <Balances as Balanced<_>>::deposit(&1234, initial_issuance, Precision::Exact);
 		assert_eq!(Balances::free_balance(1234), initial_issuance);
 		MockBlockNumberProvider::set(1);
 
@@ -218,7 +222,7 @@
 	new_test_ext().execute_with(|| {
 		// Total issuance = 1_000_000_000
 		let initial_issuance: u64 = 1_000_000_000;
-		let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);
+		let _ = <Balances as Balanced<_>>::deposit(&1234, initial_issuance, Precision::Exact);
 		assert_eq!(Balances::free_balance(1234), initial_issuance);
 		MockBlockNumberProvider::set(1);
 
@@ -234,7 +238,7 @@
 		}
 		assert_eq!(
 			initial_issuance + (FIRST_YEAR_BLOCK_INFLATION * (YEAR / 100)),
-			<Balances as Currency<_>>::total_issuance()
+			<Balances as Inspect<_>>::total_issuance()
 		);
 
 		MockBlockNumberProvider::set(YEAR + 1);
@@ -254,7 +258,7 @@
 		// Total issuance = 1_000_000_000
 		let initial_issuance: u64 = 1_000_000_000;
 		let start_block: u64 = 10457457;
-		let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);
+		let _ = <Balances as Balanced<_>>::deposit(&1234, initial_issuance, Precision::Exact);
 		assert_eq!(Balances::free_balance(1234), initial_issuance);
 		MockBlockNumberProvider::set(start_block);
 
@@ -273,7 +277,7 @@
 		}
 		assert_eq!(
 			initial_issuance + (FIRST_YEAR_BLOCK_INFLATION * (YEAR / 100)),
-			<Balances as Currency<_>>::total_issuance()
+			<Balances as Inspect<_>>::total_issuance()
 		);
 
 		MockBlockNumberProvider::set(start_block + YEAR + 1);
@@ -292,7 +296,7 @@
 	new_test_ext().execute_with(|| {
 		// Total issuance = 1_000_000_000
 		let initial_issuance: u64 = 1_000_000_000;
-		let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);
+		let _ = <Balances as Balanced<_>>::deposit(&1234, initial_issuance, Precision::Exact);
 		assert_eq!(Balances::free_balance(1234), initial_issuance);
 		MockBlockNumberProvider::set(YEAR * 9 + 1);
 
@@ -327,7 +331,7 @@
 
 		// For accuracy total issuance = payout0 * payouts * 10;
 		let initial_issuance: u64 = payout_by_year[0] * payouts * 10;
-		let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);
+		let _ = <Balances as Balanced<_>>::deposit(&1234, initial_issuance, Precision::Exact);
 		assert_eq!(Balances::free_balance(1234), initial_issuance);
 
 		// Start inflation as sudo