difftreelog
fix rust tests
in: master
8 files changed
pallets/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",
pallets/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, _)| {
pallets/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);
pallets/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"]
pallets/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"]
pallets/identity/src/tests.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// This file is part of Substrate.1920// Copyright (C) 2019-2022 Parity Technologies (UK) Ltd.21// SPDX-License-Identifier: Apache-2.02223// Licensed under the Apache License, Version 2.0 (the "License");24// you may not use this file except in compliance with the License.25// You may obtain a copy of the License at26//27// http://www.apache.org/licenses/LICENSE-2.028//29// Unless required by applicable law or agreed to in writing, software30// distributed under the License is distributed on an "AS IS" BASIS,31// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.32// See the License for the specific language governing permissions and33// limitations under the License.3435// Tests for Identity Pallet3637use super::*;38use crate as pallet_identity;3940use codec::{Decode, Encode};41use frame_support::{42 assert_noop, assert_ok, ord_parameter_types, parameter_types,43 traits::{ConstU32, ConstU64, EitherOfDiverse},44 BoundedVec,45};46use frame_system::{EnsureRoot, EnsureSignedBy};47use sp_core::H256;48use sp_runtime::{49 testing::Header,50 traits::{BadOrigin, BlakeTwo256, IdentityLookup},51};5253type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;54type Block = frame_system::mocking::MockBlock<Test>;5556frame_support::construct_runtime!(57 pub enum Test where58 Block = Block,59 NodeBlock = Block,60 UncheckedExtrinsic = UncheckedExtrinsic,61 {62 System: frame_system::{Pallet, Call, Config, Storage, Event<T>},63 Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},64 Identity: pallet_identity::{Pallet, Call, Storage, Event<T>},65 }66);6768parameter_types! {69 pub BlockWeights: frame_system::limits::BlockWeights =70 frame_system::limits::BlockWeights::simple_max(frame_support::weights::Weight::from_ref_time(1024));71}72impl frame_system::Config for Test {73 type BaseCallFilter = frame_support::traits::Everything;74 type BlockWeights = ();75 type BlockLength = ();76 type RuntimeOrigin = RuntimeOrigin;77 type Index = u64;78 type BlockNumber = u64;79 type Hash = H256;80 type RuntimeCall = RuntimeCall;81 type Hashing = BlakeTwo256;82 type AccountId = u64;83 type Lookup = IdentityLookup<Self::AccountId>;84 type Header = Header;85 type RuntimeEvent = RuntimeEvent;86 type BlockHashCount = ConstU64<250>;87 type DbWeight = ();88 type Version = ();89 type PalletInfo = PalletInfo;90 type AccountData = pallet_balances::AccountData<u64>;91 type OnNewAccount = ();92 type OnKilledAccount = ();93 type SystemWeightInfo = ();94 type SS58Prefix = ();95 type OnSetCode = ();96 type MaxConsumers = ConstU32<16>;97}9899impl pallet_balances::Config for Test {100 type Balance = u64;101 type RuntimeEvent = RuntimeEvent;102 type DustRemoval = ();103 type ExistentialDeposit = ConstU64<1>;104 type AccountStore = System;105 type MaxLocks = ();106 type MaxReserves = ();107 type ReserveIdentifier = [u8; 8];108 type WeightInfo = ();109}110111parameter_types! {112 pub const MaxAdditionalFields: u32 = 2;113 pub const MaxRegistrars: u32 = 20;114}115116ord_parameter_types! {117 pub const One: u64 = 1;118 pub const Two: u64 = 2;119}120type EnsureOneOrRoot = EitherOfDiverse<EnsureRoot<u64>, EnsureSignedBy<One, u64>>;121type EnsureTwoOrRoot = EitherOfDiverse<EnsureRoot<u64>, EnsureSignedBy<Two, u64>>;122impl pallet_identity::Config for Test {123 type RuntimeEvent = RuntimeEvent;124 type Currency = Balances;125 type Slashed = ();126 type BasicDeposit = ConstU64<10>;127 type FieldDeposit = ConstU64<10>;128 type SubAccountDeposit = ConstU64<10>;129 type MaxSubAccounts = ConstU32<2>;130 type MaxAdditionalFields = MaxAdditionalFields;131 type MaxRegistrars = MaxRegistrars;132 type RegistrarOrigin = EnsureOneOrRoot;133 type ForceOrigin = EnsureTwoOrRoot;134 type WeightInfo = ();135}136137pub fn new_test_ext() -> sp_io::TestExternalities {138 let mut t = frame_system::GenesisConfig::default()139 .build_storage::<Test>()140 .unwrap();141 pallet_balances::GenesisConfig::<Test> {142 balances: vec![(1, 10), (2, 10), (3, 10), (10, 100), (20, 100), (30, 100)],143 }144 .assimilate_storage(&mut t)145 .unwrap();146 t.into()147}148149fn ten() -> IdentityInfo<MaxAdditionalFields> {150 IdentityInfo {151 display: Data::Raw(b"ten".to_vec().try_into().unwrap()),152 legal: Data::Raw(b"The Right Ordinal Ten, Esq.".to_vec().try_into().unwrap()),153 ..Default::default()154 }155}156157fn twenty() -> IdentityInfo<MaxAdditionalFields> {158 IdentityInfo {159 display: Data::Raw(b"twenty".to_vec().try_into().unwrap()),160 legal: Data::Raw(161 b"The Right Ordinal Twenty, Esq."162 .to_vec()163 .try_into()164 .unwrap(),165 ),166 ..Default::default()167 }168}169170#[test]171fn editing_subaccounts_should_work() {172 new_test_ext().execute_with(|| {173 let data = |x| Data::Raw(vec![x; 1].try_into().unwrap());174175 assert_noop!(176 Identity::add_sub(RuntimeOrigin::signed(10), 20, data(1)),177 Error::<Test>::NoIdentity178 );179180 assert_ok!(Identity::set_identity(181 RuntimeOrigin::signed(10),182 Box::new(ten())183 ));184185 // first sub account186 assert_ok!(Identity::add_sub(RuntimeOrigin::signed(10), 1, data(1)));187 assert_eq!(SuperOf::<Test>::get(1), Some((10, data(1))));188 assert_eq!(Balances::free_balance(10), 80);189190 // second sub account191 assert_ok!(Identity::add_sub(RuntimeOrigin::signed(10), 2, data(2)));192 assert_eq!(SuperOf::<Test>::get(1), Some((10, data(1))));193 assert_eq!(SuperOf::<Test>::get(2), Some((10, data(2))));194 assert_eq!(Balances::free_balance(10), 70);195196 // third sub account is too many197 assert_noop!(198 Identity::add_sub(RuntimeOrigin::signed(10), 3, data(3)),199 Error::<Test>::TooManySubAccounts200 );201202 // rename first sub account203 assert_ok!(Identity::rename_sub(RuntimeOrigin::signed(10), 1, data(11)));204 assert_eq!(SuperOf::<Test>::get(1), Some((10, data(11))));205 assert_eq!(SuperOf::<Test>::get(2), Some((10, data(2))));206 assert_eq!(Balances::free_balance(10), 70);207208 // remove first sub account209 assert_ok!(Identity::remove_sub(RuntimeOrigin::signed(10), 1));210 assert_eq!(SuperOf::<Test>::get(1), None);211 assert_eq!(SuperOf::<Test>::get(2), Some((10, data(2))));212 assert_eq!(Balances::free_balance(10), 80);213214 // add third sub account215 assert_ok!(Identity::add_sub(RuntimeOrigin::signed(10), 3, data(3)));216 assert_eq!(SuperOf::<Test>::get(1), None);217 assert_eq!(SuperOf::<Test>::get(2), Some((10, data(2))));218 assert_eq!(SuperOf::<Test>::get(3), Some((10, data(3))));219 assert_eq!(Balances::free_balance(10), 70);220 });221}222223#[test]224fn resolving_subaccount_ownership_works() {225 new_test_ext().execute_with(|| {226 let data = |x| Data::Raw(vec![x; 1].try_into().unwrap());227228 assert_ok!(Identity::set_identity(229 RuntimeOrigin::signed(10),230 Box::new(ten())231 ));232 assert_ok!(Identity::set_identity(233 RuntimeOrigin::signed(20),234 Box::new(twenty())235 ));236237 // 10 claims 1 as a subaccount238 assert_ok!(Identity::add_sub(RuntimeOrigin::signed(10), 1, data(1)));239 assert_eq!(Balances::free_balance(1), 10);240 assert_eq!(Balances::free_balance(10), 80);241 assert_eq!(Balances::reserved_balance(10), 20);242 // 20 cannot claim 1 now243 assert_noop!(244 Identity::add_sub(RuntimeOrigin::signed(20), 1, data(1)),245 Error::<Test>::AlreadyClaimed246 );247 // 1 wants to be with 20 so it quits from 10248 assert_ok!(Identity::quit_sub(RuntimeOrigin::signed(1)));249 // 1 gets the 10 that 10 paid.250 assert_eq!(Balances::free_balance(1), 20);251 assert_eq!(Balances::free_balance(10), 80);252 assert_eq!(Balances::reserved_balance(10), 10);253 // 20 can claim 1 now254 assert_ok!(Identity::add_sub(RuntimeOrigin::signed(20), 1, data(1)));255 });256}257258#[test]259fn trailing_zeros_decodes_into_default_data() {260 let encoded = Data::Raw(b"Hello".to_vec().try_into().unwrap()).encode();261 assert!(<(Data, Data)>::decode(&mut &encoded[..]).is_err());262 let input = &mut &encoded[..];263 let (a, b) = <(Data, Data)>::decode(&mut AppendZerosInput::new(input)).unwrap();264 assert_eq!(a, Data::Raw(b"Hello".to_vec().try_into().unwrap()));265 assert_eq!(b, Data::None);266}267268#[test]269fn adding_registrar_should_work() {270 new_test_ext().execute_with(|| {271 assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));272 assert_ok!(Identity::set_fee(RuntimeOrigin::signed(3), 0, 10));273 let fields = IdentityFields(IdentityField::Display | IdentityField::Legal);274 assert_ok!(Identity::set_fields(RuntimeOrigin::signed(3), 0, fields));275 assert_eq!(276 Identity::registrars(),277 vec![Some(RegistrarInfo {278 account: 3,279 fee: 10,280 fields281 })]282 );283 });284}285286#[test]287fn amount_of_registrars_is_limited() {288 new_test_ext().execute_with(|| {289 for i in 1..MaxRegistrars::get() + 1 {290 assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), i as u64));291 }292 let last_registrar = MaxRegistrars::get() as u64 + 1;293 assert_noop!(294 Identity::add_registrar(RuntimeOrigin::signed(1), last_registrar),295 Error::<Test>::TooManyRegistrars296 );297 });298}299300#[test]301fn registration_should_work() {302 new_test_ext().execute_with(|| {303 assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));304 assert_ok!(Identity::set_fee(RuntimeOrigin::signed(3), 0, 10));305 let mut three_fields = ten();306 three_fields307 .additional308 .try_push(Default::default())309 .unwrap();310 three_fields311 .additional312 .try_push(Default::default())313 .unwrap();314 assert!(three_fields315 .additional316 .try_push(Default::default())317 .is_err());318 assert_ok!(Identity::set_identity(319 RuntimeOrigin::signed(10),320 Box::new(ten())321 ));322 assert_eq!(Identity::identity(10).unwrap().info, ten());323 assert_eq!(Balances::free_balance(10), 90);324 assert_ok!(Identity::clear_identity(RuntimeOrigin::signed(10)));325 assert_eq!(Balances::free_balance(10), 100);326 assert_noop!(327 Identity::clear_identity(RuntimeOrigin::signed(10)),328 Error::<Test>::NotNamed329 );330 });331}332333#[test]334fn uninvited_judgement_should_work() {335 new_test_ext().execute_with(|| {336 assert_noop!(337 Identity::provide_judgement(338 RuntimeOrigin::signed(3),339 0,340 10,341 Judgement::Reasonable,342 H256::random()343 ),344 Error::<Test>::InvalidIndex345 );346347 assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));348 assert_noop!(349 Identity::provide_judgement(350 RuntimeOrigin::signed(3),351 0,352 10,353 Judgement::Reasonable,354 H256::random()355 ),356 Error::<Test>::InvalidTarget357 );358359 assert_ok!(Identity::set_identity(360 RuntimeOrigin::signed(10),361 Box::new(ten())362 ));363 assert_noop!(364 Identity::provide_judgement(365 RuntimeOrigin::signed(3),366 0,367 10,368 Judgement::Reasonable,369 H256::random()370 ),371 Error::<Test>::JudgementForDifferentIdentity372 );373374 let identity_hash = BlakeTwo256::hash_of(&ten());375376 assert_noop!(377 Identity::provide_judgement(378 RuntimeOrigin::signed(10),379 0,380 10,381 Judgement::Reasonable,382 identity_hash383 ),384 Error::<Test>::InvalidIndex385 );386 assert_noop!(387 Identity::provide_judgement(388 RuntimeOrigin::signed(3),389 0,390 10,391 Judgement::FeePaid(1),392 identity_hash393 ),394 Error::<Test>::InvalidJudgement395 );396397 assert_ok!(Identity::provide_judgement(398 RuntimeOrigin::signed(3),399 0,400 10,401 Judgement::Reasonable,402 identity_hash403 ));404 assert_eq!(405 Identity::identity(10).unwrap().judgements,406 vec![(0, Judgement::Reasonable)]407 );408 });409}410411#[test]412fn clearing_judgement_should_work() {413 new_test_ext().execute_with(|| {414 assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));415 assert_ok!(Identity::set_identity(416 RuntimeOrigin::signed(10),417 Box::new(ten())418 ));419 assert_ok!(Identity::provide_judgement(420 RuntimeOrigin::signed(3),421 0,422 10,423 Judgement::Reasonable,424 BlakeTwo256::hash_of(&ten())425 ));426 assert_ok!(Identity::clear_identity(RuntimeOrigin::signed(10)));427 assert_eq!(Identity::identity(10), None);428 });429}430431#[test]432fn killing_slashing_should_work() {433 new_test_ext().execute_with(|| {434 assert_ok!(Identity::set_identity(435 RuntimeOrigin::signed(10),436 Box::new(ten())437 ));438 assert_noop!(439 Identity::kill_identity(RuntimeOrigin::signed(1), 10),440 BadOrigin441 );442 assert_ok!(Identity::kill_identity(RuntimeOrigin::signed(2), 10));443 assert_eq!(Identity::identity(10), None);444 assert_eq!(Balances::free_balance(10), 90);445 assert_noop!(446 Identity::kill_identity(RuntimeOrigin::signed(2), 10),447 Error::<Test>::NotNamed448 );449 });450}451452#[test]453fn setting_subaccounts_should_work() {454 new_test_ext().execute_with(|| {455 let mut subs = vec![(20, Data::Raw(vec![40; 1].try_into().unwrap()))];456 assert_noop!(457 Identity::set_subs(RuntimeOrigin::signed(10), subs.clone()),458 Error::<Test>::NotFound459 );460461 assert_ok!(Identity::set_identity(462 RuntimeOrigin::signed(10),463 Box::new(ten())464 ));465 assert_ok!(Identity::set_subs(RuntimeOrigin::signed(10), subs.clone()));466 assert_eq!(Balances::free_balance(10), 80);467 assert_eq!(Identity::subs_of(10), (10, vec![20].try_into().unwrap()));468 assert_eq!(469 Identity::super_of(20),470 Some((10, Data::Raw(vec![40; 1].try_into().unwrap())))471 );472473 // push another item and re-set it.474 subs.push((30, Data::Raw(vec![50; 1].try_into().unwrap())));475 assert_ok!(Identity::set_subs(RuntimeOrigin::signed(10), subs.clone()));476 assert_eq!(Balances::free_balance(10), 70);477 assert_eq!(478 Identity::subs_of(10),479 (20, vec![20, 30].try_into().unwrap())480 );481 assert_eq!(482 Identity::super_of(20),483 Some((10, Data::Raw(vec![40; 1].try_into().unwrap())))484 );485 assert_eq!(486 Identity::super_of(30),487 Some((10, Data::Raw(vec![50; 1].try_into().unwrap())))488 );489490 // switch out one of the items and re-set.491 subs[0] = (40, Data::Raw(vec![60; 1].try_into().unwrap()));492 assert_ok!(Identity::set_subs(RuntimeOrigin::signed(10), subs.clone()));493 assert_eq!(Balances::free_balance(10), 70); // no change in the balance494 assert_eq!(495 Identity::subs_of(10),496 (20, vec![40, 30].try_into().unwrap())497 );498 assert_eq!(Identity::super_of(20), None);499 assert_eq!(500 Identity::super_of(30),501 Some((10, Data::Raw(vec![50; 1].try_into().unwrap())))502 );503 assert_eq!(504 Identity::super_of(40),505 Some((10, Data::Raw(vec![60; 1].try_into().unwrap())))506 );507508 // clear509 assert_ok!(Identity::set_subs(RuntimeOrigin::signed(10), vec![]));510 assert_eq!(Balances::free_balance(10), 90);511 assert_eq!(Identity::subs_of(10), (0, BoundedVec::default()));512 assert_eq!(Identity::super_of(30), None);513 assert_eq!(Identity::super_of(40), None);514515 subs.push((20, Data::Raw(vec![40; 1].try_into().unwrap())));516 assert_noop!(517 Identity::set_subs(RuntimeOrigin::signed(10), subs.clone()),518 Error::<Test>::TooManySubAccounts519 );520 });521}522523#[test]524fn clearing_account_should_remove_subaccounts_and_refund() {525 new_test_ext().execute_with(|| {526 assert_ok!(Identity::set_identity(527 RuntimeOrigin::signed(10),528 Box::new(ten())529 ));530 assert_ok!(Identity::set_subs(531 RuntimeOrigin::signed(10),532 vec![(20, Data::Raw(vec![40; 1].try_into().unwrap()))]533 ));534 assert_ok!(Identity::clear_identity(RuntimeOrigin::signed(10)));535 assert_eq!(Balances::free_balance(10), 100);536 assert!(Identity::super_of(20).is_none());537 });538}539540#[test]541fn killing_account_should_remove_subaccounts_and_not_refund() {542 new_test_ext().execute_with(|| {543 assert_ok!(Identity::set_identity(544 RuntimeOrigin::signed(10),545 Box::new(ten())546 ));547 assert_ok!(Identity::set_subs(548 RuntimeOrigin::signed(10),549 vec![(20, Data::Raw(vec![40; 1].try_into().unwrap()))]550 ));551 assert_ok!(Identity::kill_identity(RuntimeOrigin::signed(2), 10));552 assert_eq!(Balances::free_balance(10), 80);553 assert!(Identity::super_of(20).is_none());554 });555}556557#[test]558fn cancelling_requested_judgement_should_work() {559 new_test_ext().execute_with(|| {560 assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));561 assert_ok!(Identity::set_fee(RuntimeOrigin::signed(3), 0, 10));562 assert_noop!(563 Identity::cancel_request(RuntimeOrigin::signed(10), 0),564 Error::<Test>::NoIdentity565 );566 assert_ok!(Identity::set_identity(567 RuntimeOrigin::signed(10),568 Box::new(ten())569 ));570 assert_ok!(Identity::request_judgement(571 RuntimeOrigin::signed(10),572 0,573 10574 ));575 assert_ok!(Identity::cancel_request(RuntimeOrigin::signed(10), 0));576 assert_eq!(Balances::free_balance(10), 90);577 assert_noop!(578 Identity::cancel_request(RuntimeOrigin::signed(10), 0),579 Error::<Test>::NotFound580 );581582 assert_ok!(Identity::provide_judgement(583 RuntimeOrigin::signed(3),584 0,585 10,586 Judgement::Reasonable,587 BlakeTwo256::hash_of(&ten())588 ));589 assert_noop!(590 Identity::cancel_request(RuntimeOrigin::signed(10), 0),591 Error::<Test>::JudgementGiven592 );593 });594}595596#[test]597fn requesting_judgement_should_work() {598 new_test_ext().execute_with(|| {599 assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));600 assert_ok!(Identity::set_fee(RuntimeOrigin::signed(3), 0, 10));601 assert_ok!(Identity::set_identity(602 RuntimeOrigin::signed(10),603 Box::new(ten())604 ));605 assert_noop!(606 Identity::request_judgement(RuntimeOrigin::signed(10), 0, 9),607 Error::<Test>::FeeChanged608 );609 assert_ok!(Identity::request_judgement(610 RuntimeOrigin::signed(10),611 0,612 10613 ));614 // 10 for the judgement request, 10 for the identity.615 assert_eq!(Balances::free_balance(10), 80);616617 // Re-requesting won't work as we already paid.618 assert_noop!(619 Identity::request_judgement(RuntimeOrigin::signed(10), 0, 10),620 Error::<Test>::StickyJudgement621 );622 assert_ok!(Identity::provide_judgement(623 RuntimeOrigin::signed(3),624 0,625 10,626 Judgement::Erroneous,627 BlakeTwo256::hash_of(&ten())628 ));629 // Registrar got their payment now.630 assert_eq!(Balances::free_balance(3), 20);631632 // Re-requesting still won't work as it's erroneous.633 assert_noop!(634 Identity::request_judgement(RuntimeOrigin::signed(10), 0, 10),635 Error::<Test>::StickyJudgement636 );637638 // Requesting from a second registrar still works.639 assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 4));640 assert_ok!(Identity::request_judgement(641 RuntimeOrigin::signed(10),642 1,643 10644 ));645646 // Re-requesting after the judgement has been reduced works.647 assert_ok!(Identity::provide_judgement(648 RuntimeOrigin::signed(3),649 0,650 10,651 Judgement::OutOfDate,652 BlakeTwo256::hash_of(&ten())653 ));654 assert_ok!(Identity::request_judgement(655 RuntimeOrigin::signed(10),656 0,657 10658 ));659 });660}661662#[test]663fn provide_judgement_should_return_judgement_payment_failed_error() {664 new_test_ext().execute_with(|| {665 assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));666 assert_ok!(Identity::set_fee(RuntimeOrigin::signed(3), 0, 10));667 assert_ok!(Identity::set_identity(668 RuntimeOrigin::signed(10),669 Box::new(ten())670 ));671 assert_ok!(Identity::request_judgement(672 RuntimeOrigin::signed(10),673 0,674 10675 ));676 // 10 for the judgement request, 10 for the identity.677 assert_eq!(Balances::free_balance(10), 80);678679 // This forces judgement payment failed error680 Balances::make_free_balance_be(&3, 0);681 assert_noop!(682 Identity::provide_judgement(683 RuntimeOrigin::signed(3),684 0,685 10,686 Judgement::Erroneous,687 BlakeTwo256::hash_of(&ten())688 ),689 Error::<Test>::JudgementPaymentFailed690 );691 });692}693694#[test]695fn field_deposit_should_work() {696 new_test_ext().execute_with(|| {697 assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));698 assert_ok!(Identity::set_fee(RuntimeOrigin::signed(3), 0, 10));699 assert_ok!(Identity::set_identity(700 RuntimeOrigin::signed(10),701 Box::new(IdentityInfo {702 additional: vec![703 (704 Data::Raw(b"number".to_vec().try_into().unwrap()),705 Data::Raw(10u32.encode().try_into().unwrap())706 ),707 (708 Data::Raw(b"text".to_vec().try_into().unwrap()),709 Data::Raw(b"10".to_vec().try_into().unwrap())710 ),711 ]712 .try_into()713 .unwrap(),714 ..Default::default()715 })716 ));717 assert_eq!(Balances::free_balance(10), 70);718 });719}720721#[test]722fn setting_account_id_should_work() {723 new_test_ext().execute_with(|| {724 assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));725 // account 4 cannot change the first registrar's identity since it's owned by 3.726 assert_noop!(727 Identity::set_account_id(RuntimeOrigin::signed(4), 0, 3),728 Error::<Test>::InvalidIndex729 );730 // account 3 can, because that's the registrar's current account.731 assert_ok!(Identity::set_account_id(RuntimeOrigin::signed(3), 0, 4));732 // account 4 can now, because that's their new ID.733 assert_ok!(Identity::set_account_id(RuntimeOrigin::signed(4), 0, 3));734 });735}736737#[test]738fn test_has_identity() {739 new_test_ext().execute_with(|| {740 assert_ok!(Identity::set_identity(741 RuntimeOrigin::signed(10),742 Box::new(ten())743 ));744 assert!(Identity::has_identity(&10, IdentityField::Display as u64));745 assert!(Identity::has_identity(&10, IdentityField::Legal as u64));746 assert!(Identity::has_identity(747 &10,748 IdentityField::Display as u64 | IdentityField::Legal as u64749 ));750 assert!(!Identity::has_identity(751 &10,752 IdentityField::Display as u64 | IdentityField::Legal as u64 | IdentityField::Web as u64753 ));754 });755}pallets/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(())
pallets/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