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
before · pallets/collator-selection/Cargo.toml
1[package]2authors = ["Parity Technologies <admin@parity.io>", "Unique Network <support@uniquenetwork.io>"]3description = "Simple staking pallet with a fixed stake."4edition = "2021"5homepage = "https://unique.network"6license = "GPLv3"7name = "pallet-collator-selection"8repository = "https://github.com/UniqueNetwork/unique-chain"9version = "4.0.0"1011[package.metadata.docs.rs]12targets = ["x86_64-unknown-linux-gnu"]1314[dependencies]15# Note: `package = "parity-scale-codec"` must be supplied since the `Encode` macro searches for it.16codec = { workspace = true, package = "parity-scale-codec" }1718log = { workspace = true }19rand = { version = "0.8.5", features = ["std_rng"], default-features = false }20scale-info = { workspace = true }21serde = { workspace = true }2223frame-support = { workspace = true }24frame-system = { workspace = true }25pallet-authorship = { workspace = true }26pallet-configuration = { workspace = true }27pallet-session = { workspace = true }28sp-runtime = { workspace = true }29sp-staking = { workspace = true }30sp-std = { workspace = true }3132frame-benchmarking = { workspace = true, optional = true }3334[dev-dependencies]35pallet-aura = { workspace = true }36pallet-balances = { features = ["insecure_zero_ed"], workspace = true }37pallet-timestamp = { workspace = true }38sp-consensus-aura = { workspace = true }39sp-core = { workspace = true }40sp-io = { workspace = true }41sp-runtime = { workspace = true }42sp-tracing = { workspace = true }4344[features]45default = ["std"]46runtime-benchmarks = [47	"frame-benchmarking/runtime-benchmarks",48	"frame-support/runtime-benchmarks",49	"frame-system/runtime-benchmarks",50]51std = [52	"codec/std",53	"frame-benchmarking/std",54	"frame-support/std",55	"frame-system/std",56	"log/std",57	"pallet-authorship/std",58	"pallet-session/std",59	"rand/std",60	"scale-info/std",61	"sp-runtime/std",62	"sp-staking/std",63	"sp-std/std",64]6566try-runtime = ["frame-support/try-runtime"]
after · pallets/collator-selection/Cargo.toml
1[package]2authors = ["Parity Technologies <admin@parity.io>", "Unique Network <support@uniquenetwork.io>"]3description = "Simple staking pallet with a fixed stake."4edition = "2021"5homepage = "https://unique.network"6license = "GPLv3"7name = "pallet-collator-selection"8repository = "https://github.com/UniqueNetwork/unique-chain"9version = "4.0.0"1011[package.metadata.docs.rs]12targets = ["x86_64-unknown-linux-gnu"]1314[dependencies]15# Note: `package = "parity-scale-codec"` must be supplied since the `Encode` macro searches for it.16codec = { workspace = true, package = "parity-scale-codec" }1718log = { workspace = true }19rand = { version = "0.8.5", features = ["std_rng"], default-features = false }20scale-info = { workspace = true }21serde = { workspace = true }2223frame-support = { workspace = true }24frame-system = { workspace = true }25pallet-authorship = { workspace = true }26pallet-configuration = { workspace = true }27pallet-session = { workspace = true }28sp-runtime = { workspace = true }29sp-staking = { workspace = true }30sp-std = { workspace = true }3132frame-benchmarking = { workspace = true, optional = true }3334[dev-dependencies]35pallet-aura = { workspace = true }36pallet-balances = { features = ["insecure_zero_ed"], workspace = true }37pallet-timestamp = { workspace = true }38sp-consensus-aura = { workspace = true }39sp-core = { workspace = true }40sp-io = { workspace = true }41sp-runtime = { workspace = true }42sp-tracing = { workspace = true }4344[features]45default = ["std"]46runtime-benchmarks = [47	"frame-benchmarking/runtime-benchmarks",48	"frame-support/runtime-benchmarks",49	"frame-system/runtime-benchmarks",50]51std = [52	"codec/std",53	"frame-benchmarking/std",54	"frame-support/std",55	"frame-system/std",56	"log/std",57	"pallet-authorship/std",58	'pallet-aura/std',59	'pallet-balances/std',60	"pallet-session/std",61	"rand/std",62	"scale-info/std",63	"sp-consensus-aura/std",64	"sp-runtime/std",65	"sp-staking/std",66	"sp-std/std",67]6869try-runtime = ["frame-support/try-runtime"]
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
--- 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