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
102parameter_types! {102parameter_types! {
103 pub const ExistentialDeposit: u64 = 5;103 pub const ExistentialDeposit: u64 = 5;
104 pub const MaxReserves: u32 = 50;104 pub const MaxReserves: u32 = 50;
105 pub const MaxHolds: u32 = 2;
106 pub const MaxFreezes: u32 = 2;
105}107}
106108
107impl pallet_balances::Config for Test {109impl pallet_balances::Config for Test {
114 type MaxLocks = ();116 type MaxLocks = ();
115 type MaxReserves = MaxReserves;117 type MaxReserves = MaxReserves;
116 type ReserveIdentifier = [u8; 8];118 type ReserveIdentifier = [u8; 8];
119 type HoldIdentifier = [u8; 16];
120 type FreezeIdentifier = [u8; 16];
121 type MaxHolds = MaxHolds;
122 type MaxFreezes = MaxFreezes;
117}123}
118124
119pub struct Author4;125pub struct Author4;
209 pub const MaxXcmAllowedLocations: u32 = 16;215 pub const MaxXcmAllowedLocations: u32 = 16;
210 pub AppPromotionDailyRate: Perbill = Perbill::from_rational(5u32, 10_000);216 pub AppPromotionDailyRate: Perbill = Perbill::from_rational(5u32, 10_000);
211 pub const DayRelayBlocks: u32 = 1;217 pub const DayRelayBlocks: u32 = 1;
218 pub const LicenceBondIdentifier: [u8; 16] = *b"licenceidentifie";
212}219}
213220
214impl pallet_configuration::Config for Test {221impl pallet_configuration::Config for Test {
257 type ValidatorId = <Self as frame_system::Config>::AccountId;264 type ValidatorId = <Self as frame_system::Config>::AccountId;
258 type ValidatorIdOf = IdentityCollator;265 type ValidatorIdOf = IdentityCollator;
259 type ValidatorRegistration = IsRegistered;266 type ValidatorRegistration = IsRegistered;
267 type LicenceBondIdentifier = LicenceBondIdentifier;
260 type WeightInfo = ();268 type WeightInfo = ();
261}269}
262270
267 .unwrap();275 .unwrap();
268 let invulnerables = vec![1, 2];276 let invulnerables = vec![1, 2];
277
278 let ed = <Test as pallet_balances::Config>::ExistentialDeposit::get();
269279
270 let balances = vec![(1, 100), (2, 100), (3, 100), (4, 100), (5, 100)];280 let balances = vec![(1, 100), (2, 100), (3, 100), (4, 100), (5, 100), (33, ed)];
271 let keys = balances281 let keys = balances
272 .iter()282 .iter()
273 .map(|&(i, _)| {283 .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
--- a/pallets/inflation/src/lib.rs
+++ b/pallets/inflation/src/lib.rs
@@ -187,12 +187,11 @@
 				<NextInflationBlock<T>>::set(inflation_start_relay_block + block_interval.into());
 
 				// First time deposit - create Treasury account so that we can call deposit_into_existing everywhere else
-				let imbalance = T::Currency::deposit(
+				let _ = T::Currency::deposit(
 					&T::TreasuryAccountId::get(),
 					<BlockInflation<T>>::get(),
 					Precision::Exact,
 				)?;
-				debug_assert!(imbalance.peek().is_zero());
 			}
 
 			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