difftreelog
test fix build
in: master
9 files changed
pallets/collator-selection/src/mock.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617// Original license:18// Copyright (C) 2021 Parity Technologies (UK) Ltd.19// SPDX-License-Identifier: Apache-2.02021// Licensed under the Apache License, Version 2.0 (the "License");22// you may not use this file except in compliance with the License.23// You may obtain a copy of the License at24//25// http://www.apache.org/licenses/LICENSE-2.026//27// Unless required by applicable law or agreed to in writing, software28// distributed under the License is distributed on an "AS IS" BASIS,29// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.30// See the License for the specific language governing permissions and31// limitations under the License.3233use frame_support::{34 ord_parameter_types, parameter_types,35 traits::{ConstU32, FindAuthor, ValidatorRegistration},36 PalletId,37};38use frame_system as system;39use frame_system::EnsureSignedBy;40use sp_core::{ConstBool, H256};41use sp_runtime::{42 testing::UintAuthorityId,43 traits::{BlakeTwo256, IdentityLookup, OpaqueKeys},44 BuildStorage, Perbill, RuntimeAppPublic,45};4647use super::*;48use crate as collator_selection;4950type Block = frame_system::mocking::MockBlockU32<Test>;5152// Configure a mock runtime to test the pallet.53frame_support::construct_runtime!(54 pub enum Test {55 System: frame_system,56 Timestamp: pallet_timestamp,57 Session: pallet_session,58 Aura: pallet_aura,59 Balances: pallet_balances,60 CollatorSelection: collator_selection,61 Authorship: pallet_authorship,62 }63);6465parameter_types! {66 pub const BlockHashCount: u32 = 250;67 pub const SS58Prefix: u8 = 42;68}6970impl system::Config for Test {71 type BaseCallFilter = frame_support::traits::Everything;72 type Block = Block;73 type BlockWeights = ();74 type BlockLength = ();75 type DbWeight = ();76 type RuntimeOrigin = RuntimeOrigin;77 type RuntimeCall = RuntimeCall;78 type Nonce = u64;79 type Hash = H256;80 type Hashing = BlakeTwo256;81 type AccountId = u64;82 type Lookup = IdentityLookup<Self::AccountId>;83 type RuntimeEvent = RuntimeEvent;84 type BlockHashCount = BlockHashCount;85 type Version = ();86 type PalletInfo = PalletInfo;87 type AccountData = pallet_balances::AccountData<u64>;88 type OnNewAccount = ();89 type OnKilledAccount = ();90 type SystemWeightInfo = ();91 type SS58Prefix = SS58Prefix;92 type OnSetCode = ();93 type MaxConsumers = ConstU32<16>;94}9596parameter_types! {97 pub const ExistentialDeposit: u64 = 5;98 pub const MaxReserves: u32 = 50;99 pub const MaxHolds: u32 = 2;100 pub const MaxFreezes: u32 = 2;101}102103impl pallet_balances::Config for Test {104 type Balance = u64;105 type RuntimeEvent = RuntimeEvent;106 type DustRemoval = ();107 type ExistentialDeposit = ExistentialDeposit;108 type AccountStore = System;109 type WeightInfo = ();110 type MaxLocks = ();111 type MaxReserves = MaxReserves;112 type ReserveIdentifier = [u8; 8];113 type FreezeIdentifier = [u8; 16];114 type MaxHolds = MaxHolds;115 type MaxFreezes = MaxFreezes;116 type RuntimeHoldReason = RuntimeHoldReason;117}118119pub struct Author4;120impl FindAuthor<u64> for Author4 {121 fn find_author<'a, I>(_digests: I) -> Option<u64>122 where123 I: 'a + IntoIterator<Item = (frame_support::ConsensusEngineId, &'a [u8])>,124 {125 Some(4)126 }127}128129impl pallet_authorship::Config for Test {130 type FindAuthor = Author4;131 type EventHandler = CollatorSelection;132}133134parameter_types! {135 pub const MinimumPeriod: u64 = 1;136}137138impl pallet_timestamp::Config for Test {139 type Moment = u64;140 type OnTimestampSet = Aura;141 type MinimumPeriod = MinimumPeriod;142 type WeightInfo = ();143}144145impl pallet_aura::Config for Test {146 type AuthorityId = sp_consensus_aura::sr25519::AuthorityId;147 type MaxAuthorities = MaxAuthorities;148 type DisabledValidators = ();149 type AllowMultipleBlocksPerSlot = ConstBool<true>;150}151152sp_runtime::impl_opaque_keys! {153 pub struct MockSessionKeys {154 // a key for aura authoring155 pub aura: UintAuthorityId,156 }157}158159impl From<UintAuthorityId> for MockSessionKeys {160 fn from(aura: sp_runtime::testing::UintAuthorityId) -> Self {161 Self { aura }162 }163}164165parameter_types! {166 pub static SessionHandlerCollators: Vec<u64> = Vec::new();167 pub static SessionChangeBlock: u32 = 0;168}169170pub struct TestSessionHandler;171impl pallet_session::SessionHandler<u64> for TestSessionHandler {172 const KEY_TYPE_IDS: &'static [sp_runtime::KeyTypeId] = &[UintAuthorityId::ID];173 fn on_genesis_session<Ks: OpaqueKeys>(keys: &[(u64, Ks)]) {174 SessionHandlerCollators::set(keys.iter().map(|(a, _)| *a).collect::<Vec<_>>())175 }176 fn on_new_session<Ks: OpaqueKeys>(_: bool, keys: &[(u64, Ks)], _: &[(u64, Ks)]) {177 SessionChangeBlock::set(System::block_number());178 dbg!(keys.len());179 SessionHandlerCollators::set(keys.iter().map(|(a, _)| *a).collect::<Vec<_>>())180 }181 fn on_before_session_ending() {}182 fn on_disabled(_: u32) {}183}184185parameter_types! {186 pub const Offset: u32 = 0;187 pub const Period: u32 = 10;188}189190impl pallet_session::Config for Test {191 type RuntimeEvent = RuntimeEvent;192 type ValidatorId = <Self as frame_system::Config>::AccountId;193 // we don't have stash and controller, thus we don't need the convert as well.194 type ValidatorIdOf = IdentityCollator;195 type ShouldEndSession = pallet_session::PeriodicSessions<Period, Offset>;196 type NextSessionRotation = pallet_session::PeriodicSessions<Period, Offset>;197 type SessionManager = CollatorSelection;198 type SessionHandler = TestSessionHandler;199 type Keys = MockSessionKeys;200 type WeightInfo = ();201}202203parameter_types! {204 pub const MaxCollators: u32 = 5;205 pub const LicenseBond: u64 = 10;206 pub const KickThreshold: u32 = 10;207 // the following values do not matter and are meaningless, etc.208 pub const DefaultWeightToFeeCoefficient: u64 = 100_000;209 pub const DefaultMinGasPrice: u64 = 100_000;210 pub const MaxXcmAllowedLocations: u32 = 16;211 pub AppPromotionDailyRate: Perbill = Perbill::from_rational(5u32, 10_000);212 pub const DayRelayBlocks: u32 = 1;213 pub const LicenceBondIdentifier: [u8; 16] = *b"licenceidentifie";214}215216ord_parameter_types! {217 pub const RootAccount: u64 = 777;218}219220parameter_types! {221 pub const PotId: PalletId = PalletId(*b"PotStake");222 pub const MaxAuthorities: u32 = 100_000;223 pub const SlashRatio: Perbill = Perbill::one();224}225226pub struct IsRegistered;227impl ValidatorRegistration<u64> for IsRegistered {228 fn is_registered(id: &u64) -> bool {229 *id != 7u64230 }231}232233impl Config for Test {234 type RuntimeEvent = RuntimeEvent;235 type RuntimeHoldReason = RuntimeHoldReason;236 type UpdateOrigin = EnsureSignedBy<RootAccount, u64>;237 type PotId = PotId;238 type MaxCollators = MaxCollators;239 type SlashRatio = SlashRatio;240 type TreasuryAccountId = ();241 type ValidatorId = <Self as frame_system::Config>::AccountId;242 type ValidatorIdOf = IdentityCollator;243 type ValidatorRegistration = IsRegistered;244 type Currency = Balances;245 type DesiredCollators = MaxCollators;246 type LicenseBond = LicenseBond;247 type KickThreshold = KickThreshold;248 type WeightInfo = ();249}250251pub fn new_test_ext() -> sp_io::TestExternalities {252 sp_tracing::try_init_simple();253 let mut t = <frame_system::GenesisConfig<Test>>::default()254 .build_storage()255 .unwrap();256 let invulnerables = vec![1, 2];257258 let ed = <Test as pallet_balances::Config>::ExistentialDeposit::get();259260 let balances: Vec<(u64, u64)> = (1..=<Test as Config>::DesiredCollators::get() as u64 + 1)261 .map(|i| (i, 100))262 .chain(core::iter::once((33, ed)))263 .collect();264265 let keys = balances266 .iter()267 .map(|&(i, _)| {268 (269 i,270 i,271 MockSessionKeys {272 aura: UintAuthorityId(i),273 },274 )275 })276 .collect::<Vec<_>>();277 let collator_selection = collator_selection::GenesisConfig::<Test> { invulnerables };278 let session = pallet_session::GenesisConfig::<Test> { keys };279 pallet_balances::GenesisConfig::<Test> { balances }280 .assimilate_storage(&mut t)281 .unwrap();282 // collator selection must be initialized before session.283 collator_selection.assimilate_storage(&mut t).unwrap();284 session.assimilate_storage(&mut t).unwrap();285286 t.into()287}288289pub fn initialize_to_block(n: u32) {290 for i in System::block_number() + 1..=n {291 System::set_block_number(i);292 <AllPalletsWithSystem as frame_support::traits::OnInitialize<u32>>::on_initialize(i);293 }294}pallets/collator-selection/src/tests.rsdiffbeforeafterboth--- a/pallets/collator-selection/src/tests.rs
+++ b/pallets/collator-selection/src/tests.rs
@@ -32,10 +32,10 @@
use frame_support::{
assert_noop, assert_ok,
- traits::{fungible, GenesisBuild, OnInitialize},
+ traits::{fungible, OnInitialize},
};
use scale_info::prelude::*;
-use sp_runtime::{traits::BadOrigin, TokenError};
+use sp_runtime::{traits::BadOrigin, BuildStorage, TokenError};
use crate::{self as collator_selection, mock::*, Config, Error};
@@ -464,8 +464,8 @@
#[should_panic = "duplicate invulnerables in genesis."]
fn cannot_set_genesis_value_twice() {
sp_tracing::try_init_simple();
- let mut t = frame_system::GenesisConfig::default()
- .build_storage::<Test>()
+ let mut t = <frame_system::GenesisConfig<Test>>::default()
+ .build_storage()
.unwrap();
let invulnerables = vec![1, 1];
pallets/identity/src/tests.rsdiffbeforeafterboth--- a/pallets/identity/src/tests.rs
+++ b/pallets/identity/src/tests.rs
@@ -43,7 +43,6 @@
use parity_scale_codec::{Decode, Encode};
use sp_core::H256;
use sp_runtime::{
- testing::Header,
traits::{BadOrigin, BlakeTwo256, IdentityLookup},
BuildStorage,
};
@@ -51,8 +50,7 @@
use super::*;
use crate as pallet_identity;
-type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
-type Block = frame_system::mocking::MockBlock<Test>;
+type Block = frame_system::mocking::MockBlockU32<Test>;
frame_support::construct_runtime!(
pub enum Test {
@@ -79,7 +77,7 @@
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type RuntimeEvent = RuntimeEvent;
- type BlockHashCount = ConstU64<250>;
+ type BlockHashCount = ConstU32<250>;
type DbWeight = ();
type Version = ();
type PalletInfo = PalletInfo;
pallets/inflation/src/tests.rsdiffbeforeafterboth--- a/pallets/inflation/src/tests.rs
+++ b/pallets/inflation/src/tests.rs
@@ -34,12 +34,12 @@
use crate as pallet_inflation;
-type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
-type Block = frame_system::mocking::MockBlock<Test>;
+type Block = frame_system::mocking::MockBlockU32<Test>;
-const YEAR: u64 = 5_259_600; // 6-second blocks
- // const YEAR: u64 = 2_629_800; // 12-second blocks
- // Expected 100-block inflation for year 1 is 100 * 100_000_000 / YEAR = FIRST_YEAR_BLOCK_INFLATION
+// 6-second blocks
+// const YEAR: u32 = 2_629_800; // 12-second blocks
+// Expected 100-block inflation for year 1 is 100 * 100_000_000 / YEAR = FIRST_YEAR_BLOCK_INFLATION
+const YEAR: u32 = 5_259_600;
const FIRST_YEAR_BLOCK_INFLATION: u64 = 1901;
parameter_types! {
@@ -60,6 +60,7 @@
type FreezeIdentifier = ();
type MaxHolds = ();
type MaxFreezes = ();
+ type RuntimeHoldReason = RuntimeHoldReason;
}
frame_support::construct_runtime!(
@@ -71,7 +72,7 @@
);
parameter_types! {
- pub const BlockHashCount: u64 = 250;
+ pub const BlockHashCount: u32 = 250;
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(Weight::from_parts(1024, 0));
pub const SS58Prefix: u8 = 42;
@@ -79,6 +80,7 @@
impl frame_system::Config for Test {
type BaseCallFilter = Everything;
+ type Block = Block;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
@@ -187,7 +189,7 @@
fn inflation_second_deposit() {
new_test_ext().execute_with(|| {
// Total issuance = 1_000_000_000
- let initial_issuance: u64 = 1_000_000_000;
+ let initial_issuance = 1_000_000_000;
let _ = <Balances as Balanced<_>>::deposit(&1234, initial_issuance, Precision::Exact);
assert_eq!(Balances::free_balance(1234), initial_issuance);
MockBlockNumberProvider::set(1);
@@ -196,20 +198,20 @@
assert_ok!(Inflation::start_inflation(RawOrigin::Root.into(), 1));
// Next inflation deposit happens when block is greater then or equal to NextInflationBlock
- let mut block: u64 = 2;
- let balance_before: u64 = Balances::free_balance(1234);
+ let mut block = 2;
+ let balance_before = Balances::free_balance(1234);
while block < <pallet_inflation::NextInflationBlock<Test>>::get() {
- MockBlockNumberProvider::set(block as u64);
+ MockBlockNumberProvider::set(block);
Inflation::on_initialize(0);
block += 1;
}
- let balance_just_before: u64 = Balances::free_balance(1234);
+ let balance_just_before = Balances::free_balance(1234);
assert_eq!(balance_before, balance_just_before);
// The block with inflation
- MockBlockNumberProvider::set(block as u64);
+ MockBlockNumberProvider::set(block);
Inflation::on_initialize(0);
- let balance_after: u64 = Balances::free_balance(1234);
+ let balance_after = Balances::free_balance(1234);
assert_eq!(balance_after - balance_just_before, block_inflation!());
});
}
@@ -234,7 +236,7 @@
Inflation::on_initialize(0);
}
assert_eq!(
- initial_issuance + (FIRST_YEAR_BLOCK_INFLATION * (YEAR / 100)),
+ initial_issuance + (FIRST_YEAR_BLOCK_INFLATION * ((YEAR as u64) / 100)),
<Balances as Inspect<_>>::total_issuance()
);
@@ -243,8 +245,8 @@
let block_inflation_year_2 = block_inflation!();
// Expected 100-block inflation for year 2: 100 * 9.33% * initial issuance * 110% / YEAR == 1951
let expecter_year_2_inflation: u64 = (initial_issuance
- + FIRST_YEAR_BLOCK_INFLATION * YEAR / 100)
- * 933 * 100 / (10000 * YEAR);
+ + FIRST_YEAR_BLOCK_INFLATION * (YEAR as u64) / 100)
+ * 933 * 100 / (10000 * (YEAR as u64));
assert_eq!(block_inflation_year_2 / 10, expecter_year_2_inflation / 10); // divide by 10 for approx. equality
});
}
@@ -253,8 +255,8 @@
fn inflation_start_large_kusama_block() {
new_test_ext().execute_with(|| {
// Total issuance = 1_000_000_000
- let initial_issuance: u64 = 1_000_000_000;
- let start_block: u64 = 10457457;
+ let initial_issuance = 1_000_000_000;
+ let start_block = 10457457;
let _ = <Balances as Balanced<_>>::deposit(&1234, initial_issuance, Precision::Exact);
assert_eq!(Balances::free_balance(1234), initial_issuance);
MockBlockNumberProvider::set(start_block);
@@ -273,7 +275,7 @@
Inflation::on_initialize(0);
}
assert_eq!(
- initial_issuance + (FIRST_YEAR_BLOCK_INFLATION * (YEAR / 100)),
+ initial_issuance + (FIRST_YEAR_BLOCK_INFLATION * ((YEAR as u64) / 100)),
<Balances as Inspect<_>>::total_issuance()
);
@@ -282,8 +284,8 @@
let block_inflation_year_2 = block_inflation!();
// Expected 100-block inflation for year 2: 100 * 9.33% * initial issuance * 110% / YEAR == 1951
let expecter_year_2_inflation: u64 = (initial_issuance
- + FIRST_YEAR_BLOCK_INFLATION * YEAR / 100)
- * 933 * 100 / (10000 * YEAR);
+ + FIRST_YEAR_BLOCK_INFLATION * (YEAR as u64) / 100)
+ * 933 * 100 / (10000 * (YEAR as u64));
assert_eq!(block_inflation_year_2 / 10, expecter_year_2_inflation / 10); // divide by 10 for approx. equality
});
}
@@ -320,14 +322,14 @@
#[test]
fn inflation_rate_by_year() {
new_test_ext().execute_with(|| {
- let payouts: u64 = YEAR / InflationBlockInterval::get() as u64;
+ let payouts = (YEAR / InflationBlockInterval::get()) as u64;
// Inflation starts at 10% and does down by 2/3% every year until year 9 (included),
// then it is flat.
let payout_by_year: [u64; 11] = [1000, 933, 867, 800, 733, 667, 600, 533, 467, 400, 400];
// For accuracy total issuance = payout0 * payouts * 10;
- let initial_issuance: u64 = payout_by_year[0] * payouts * 10;
+ let initial_issuance = payout_by_year[0] * payouts * 10;
let _ = <Balances as Balanced<_>>::deposit(&1234, initial_issuance, Precision::Exact);
assert_eq!(Balances::free_balance(1234), initial_issuance);
runtime/common/tests/mod.rsdiffbeforeafterboth--- a/runtime/common/tests/mod.rs
+++ b/runtime/common/tests/mod.rs
@@ -19,7 +19,7 @@
use sp_runtime::{BuildStorage, Storage};
use up_common::types::AuraId;
-use crate::{BuildGenesisConfig, ParachainInfoConfig, Runtime, RuntimeEvent, System};
+use crate::{ParachainInfoConfig, Runtime, RuntimeEvent, RuntimeGenesisConfig, System};
pub type Balance = u128;
pub mod xcm;
@@ -51,8 +51,8 @@
fn new_test_ext(balances: Vec<(AccountId, Balance)>) -> sp_io::TestExternalities {
let mut storage = make_basic_storage();
- pallet_balances::BuildGenesisConfig::<Runtime> { balances }
- .build_storage(&mut storage)
+ pallet_balances::GenesisConfig::<Runtime> { balances }
+ .assimilate_storage(&mut storage)
.unwrap();
let mut ext = sp_io::TestExternalities::new(storage);
@@ -95,7 +95,7 @@
.map(|acc| get_account_id_from_seed::<sr25519::Public>(acc))
.collect::<Vec<_>>();
- let cfg = BuildGenesisConfig {
+ let cfg = RuntimeGenesisConfig {
collator_selection: CollatorSelectionConfig { invulnerables },
session: SessionConfig { keys },
parachain_info: ParachainInfoConfig {
@@ -112,7 +112,7 @@
fn make_basic_storage() -> Storage {
use crate::AuraConfig;
- let cfg = BuildGenesisConfig {
+ let cfg = RuntimeGenesisConfig {
aura: AuraConfig {
authorities: vec![
get_from_seed::<AuraId>("Alice"),
runtime/common/tests/xcm.rsdiffbeforeafterboth--- a/runtime/common/tests/xcm.rs
+++ b/runtime/common/tests/xcm.rs
@@ -52,9 +52,9 @@
let xcm_event = &last_events(1)[0];
match xcm_event {
- RuntimeEvent::PolkadotXcm(pallet_xcm::Event::<Runtime>::Attempted(
- Outcome::Incomplete(_weight, Error::NoPermission),
- )) => { /* Pass */ }
+ RuntimeEvent::PolkadotXcm(pallet_xcm::Event::<Runtime>::Attempted {
+ outcome: Outcome::Incomplete(_weight, Error::NoPermission),
+ }) => { /* Pass */ }
_ => panic!(
"Expected PolkadotXcm.Attempted(Incomplete(_weight, NoPermission)),\
found: {xcm_event:#?}"
runtime/tests/src/dispatch.rsdiffbeforeafterboth--- /dev/null
+++ b/runtime/tests/src/dispatch.rs
@@ -0,0 +1 @@
+../../common/dispatch.rs
\ No newline at end of file
runtime/tests/src/lib.rsdiffbeforeafterboth--- a/runtime/tests/src/lib.rs
+++ b/runtime/tests/src/lib.rs
@@ -33,23 +33,20 @@
use scale_info::TypeInfo;
use sp_core::{H160, H256, U256};
use sp_runtime::{
- testing::Header,
traits::{BlakeTwo256, IdentityLookup},
+ BuildStorage,
};
use up_data_structs::mapping::{CrossTokenAddressMapping, EvmTokenAddressMapping};
-#[path = "../../common/dispatch.rs"]
mod dispatch;
use dispatch::CollectionDispatchT;
-#[path = "../../common/weights/mod.rs"]
mod weights;
use weights::CommonWeights;
-type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
-type Block = frame_system::mocking::MockBlock<Test>;
+type Block = frame_system::mocking::MockBlockU32<Test>;
#[cfg(test)]
mod tests;
@@ -73,13 +70,14 @@
);
parameter_types! {
- pub const BlockHashCount: u64 = 250;
+ pub const BlockHashCount: u32 = 250;
pub const SS58Prefix: u8 = 42;
}
impl system::Config for Test {
type RuntimeEvent = RuntimeEvent;
type BaseCallFilter = Everything;
+ type Block = Block;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
@@ -120,6 +118,7 @@
type MaxFreezes = MaxLocks;
type FreezeIdentifier = [u8; 8];
type MaxHolds = MaxLocks;
+ type RuntimeHoldReason = RuntimeHoldReason;
}
parameter_types! {
@@ -232,6 +231,7 @@
type OnMethodCall = ();
type OnCreate = ();
type OnChargeTransaction = ();
+ type OnCheckEvmTransaction = ();
type FindAuthor = ();
type BlockHashMapping = SubstrateBlockHashMapping<Self>;
type Timestamp = Timestamp;
@@ -296,8 +296,8 @@
// Build genesis storage according to the mock runtime.
pub fn new_test_ext() -> sp_io::TestExternalities {
- system::GenesisConfig::default()
- .build_storage::<Test>()
+ <system::GenesisConfig<Test>>::default()
+ .build_storage()
.unwrap()
.into()
}
runtime/tests/src/weightsdiffbeforeafterboth--- /dev/null
+++ b/runtime/tests/src/weights
@@ -0,0 +1 @@
+../../common/weights
\ No newline at end of file