Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Deprecate Currency: Companion for #12951 (#6780)
Browse files Browse the repository at this point in the history
* Some renames

* Fix

* Fix build for new APIs

* Remove diener

* Fixes

* Fixes

* Fix integration tests

* Fixes

* fix nis issuance

* Update Cargo.toml

* Polkadot doesn't have freezes/holds yet

* No networks use freezes/holds

* update lockfile for {"substrate"}

* Fix tests

There are more failing tests; just starting with the easy ones.
Reserved balance does not count towards ED anymore, therefore reducing
all the reserves by ED (1).

Signed-off-by: Oliver Tale-Yazdi <[email protected]>

* Fixes for Polkadot pallets

* Fix parachains benchmarks

* Update Substrate

Signed-off-by: Oliver Tale-Yazdi <[email protected]>

---------

Signed-off-by: Oliver Tale-Yazdi <[email protected]>
Co-authored-by: parity-processbot <>
Co-authored-by: Oliver Tale-Yazdi <[email protected]>
  • Loading branch information
gavofyork and ggwpez authored Mar 20, 2023
1 parent 5feae5d commit 680c451
Show file tree
Hide file tree
Showing 33 changed files with 481 additions and 305 deletions.
372 changes: 186 additions & 186 deletions Cargo.lock

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions node/test/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,10 +395,11 @@ pub fn construct_transfer_extrinsic(
dest: sp_keyring::AccountKeyring,
value: Balance,
) -> UncheckedExtrinsic {
let function = polkadot_test_runtime::RuntimeCall::Balances(pallet_balances::Call::transfer {
dest: MultiSigner::from(dest.public()).into_account().into(),
value,
});
let function =
polkadot_test_runtime::RuntimeCall::Balances(pallet_balances::Call::transfer_allow_death {
dest: MultiSigner::from(dest.public()).into_account().into(),
value,
});

construct_extrinsic(client, function, origin, 0)
}
9 changes: 5 additions & 4 deletions node/test/service/tests/call-function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ async fn call_function_actually_work() {

let alice = run_validator_node(alice_config, None);

let function = polkadot_test_runtime::RuntimeCall::Balances(pallet_balances::Call::transfer {
dest: Charlie.to_account_id().into(),
value: 1,
});
let function =
polkadot_test_runtime::RuntimeCall::Balances(pallet_balances::Call::transfer_allow_death {
dest: Charlie.to_account_id().into(),
value: 1,
});
let output = alice.send_extrinsic(function, Bob).await.unwrap();

let res = output.result;
Expand Down
4 changes: 4 additions & 0 deletions runtime/common/src/assigned_slots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,10 @@ mod tests {
type MaxLocks = ();
type MaxReserves = ();
type ReserveIdentifier = [u8; 8];
type HoldIdentifier = ();
type FreezeIdentifier = ();
type MaxHolds = ConstU32<1>;
type MaxFreezes = ConstU32<1>;
}

impl parachains_configuration::Config for Test {
Expand Down
52 changes: 29 additions & 23 deletions runtime/common/src/auctions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ mod tests {
assert_noop, assert_ok, assert_storage_noop,
dispatch::DispatchError::BadOrigin,
ord_parameter_types, parameter_types,
traits::{EitherOfDiverse, OnFinalize, OnInitialize},
traits::{ConstU32, EitherOfDiverse, OnFinalize, OnInitialize},
};
use frame_system::{EnsureRoot, EnsureSignedBy};
use pallet_balances;
Expand Down Expand Up @@ -748,6 +748,10 @@ mod tests {
type MaxLocks = ();
type MaxReserves = MaxReserves;
type ReserveIdentifier = [u8; 8];
type HoldIdentifier = ();
type FreezeIdentifier = ();
type MaxHolds = ConstU32<1>;
type MaxFreezes = ConstU32<1>;
}

#[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Debug)]
Expand Down Expand Up @@ -1412,41 +1416,42 @@ mod tests {
let para_2 = ParaId::from(2_u32);

// Make a bid and reserve a balance
assert_ok!(Auctions::bid(RuntimeOrigin::signed(1), para_1, 1, 1, 4, 10));
assert_eq!(Balances::reserved_balance(1), 10);
assert_eq!(ReservedAmounts::<Test>::get((1, para_1)), Some(10));
assert_ok!(Auctions::bid(RuntimeOrigin::signed(1), para_1, 1, 1, 4, 9));
assert_eq!(Balances::reserved_balance(1), 9);
assert_eq!(ReservedAmounts::<Test>::get((1, para_1)), Some(9));
assert_eq!(Balances::reserved_balance(2), 0);
assert_eq!(ReservedAmounts::<Test>::get((2, para_2)), None);

// Bigger bid, reserves new balance and returns funds
assert_ok!(Auctions::bid(RuntimeOrigin::signed(2), para_2, 1, 1, 4, 20));
assert_ok!(Auctions::bid(RuntimeOrigin::signed(2), para_2, 1, 1, 4, 19));
assert_eq!(Balances::reserved_balance(1), 0);
assert_eq!(ReservedAmounts::<Test>::get((1, para_1)), None);
assert_eq!(Balances::reserved_balance(2), 20);
assert_eq!(ReservedAmounts::<Test>::get((2, para_2)), Some(20));
assert_eq!(Balances::reserved_balance(2), 19);
assert_eq!(ReservedAmounts::<Test>::get((2, para_2)), Some(19));
});
}

#[test]
fn initialize_winners_in_ending_period_works() {
new_test_ext().execute_with(|| {
assert_eq!(<Test as pallet_balances::Config>::ExistentialDeposit::get(), 1);
run_to_block(1);
assert_ok!(Auctions::new_auction(RuntimeOrigin::signed(6), 9, 1));
let para_1 = ParaId::from(1_u32);
let para_2 = ParaId::from(2_u32);
let para_3 = ParaId::from(3_u32);

// Make bids
assert_ok!(Auctions::bid(RuntimeOrigin::signed(1), para_1, 1, 1, 4, 10));
assert_ok!(Auctions::bid(RuntimeOrigin::signed(2), para_2, 1, 3, 4, 20));
assert_ok!(Auctions::bid(RuntimeOrigin::signed(1), para_1, 1, 1, 4, 9));
assert_ok!(Auctions::bid(RuntimeOrigin::signed(2), para_2, 1, 3, 4, 19));

assert_eq!(
Auctions::auction_status(System::block_number()),
AuctionStatus::<u32>::StartingPeriod
);
let mut winning = [None; SlotRange::SLOT_RANGE_COUNT];
winning[SlotRange::ZeroThree as u8 as usize] = Some((1, para_1, 10));
winning[SlotRange::TwoThree as u8 as usize] = Some((2, para_2, 20));
winning[SlotRange::ZeroThree as u8 as usize] = Some((1, para_1, 9));
winning[SlotRange::TwoThree as u8 as usize] = Some((2, para_2, 19));
assert_eq!(Auctions::winning(0), Some(winning));

run_to_block(9);
Expand All @@ -1468,14 +1473,14 @@ mod tests {
AuctionStatus::<u32>::EndingPeriod(1, 0)
);
assert_eq!(Auctions::winning(1), Some(winning));
assert_ok!(Auctions::bid(RuntimeOrigin::signed(3), para_3, 1, 3, 4, 30));
assert_ok!(Auctions::bid(RuntimeOrigin::signed(3), para_3, 1, 3, 4, 29));

run_to_block(12);
assert_eq!(
Auctions::auction_status(System::block_number()),
AuctionStatus::<u32>::EndingPeriod(2, 0)
);
winning[SlotRange::TwoThree as u8 as usize] = Some((3, para_3, 30));
winning[SlotRange::TwoThree as u8 as usize] = Some((3, para_3, 29));
assert_eq!(Auctions::winning(2), Some(winning));
});
}
Expand Down Expand Up @@ -1542,6 +1547,7 @@ mod tests {
#[test]
fn less_winning_samples_work() {
new_test_ext().execute_with(|| {
assert_eq!(<Test as pallet_balances::Config>::ExistentialDeposit::get(), 1);
EndingPeriod::set(30);
SampleLength::set(10);

Expand All @@ -1552,16 +1558,16 @@ mod tests {
let para_3 = ParaId::from(3_u32);

// Make bids
assert_ok!(Auctions::bid(RuntimeOrigin::signed(1), para_1, 1, 11, 14, 10));
assert_ok!(Auctions::bid(RuntimeOrigin::signed(2), para_2, 1, 13, 14, 20));
assert_ok!(Auctions::bid(RuntimeOrigin::signed(1), para_1, 1, 11, 14, 9));
assert_ok!(Auctions::bid(RuntimeOrigin::signed(2), para_2, 1, 13, 14, 19));

assert_eq!(
Auctions::auction_status(System::block_number()),
AuctionStatus::<u32>::StartingPeriod
);
let mut winning = [None; SlotRange::SLOT_RANGE_COUNT];
winning[SlotRange::ZeroThree as u8 as usize] = Some((1, para_1, 10));
winning[SlotRange::TwoThree as u8 as usize] = Some((2, para_2, 20));
winning[SlotRange::ZeroThree as u8 as usize] = Some((1, para_1, 9));
winning[SlotRange::TwoThree as u8 as usize] = Some((2, para_2, 19));
assert_eq!(Auctions::winning(0), Some(winning));

run_to_block(9);
Expand All @@ -1578,8 +1584,8 @@ mod tests {
assert_eq!(Auctions::winning(0), Some(winning));

// New bids update the current winning
assert_ok!(Auctions::bid(RuntimeOrigin::signed(3), para_3, 1, 14, 14, 30));
winning[SlotRange::ThreeThree as u8 as usize] = Some((3, para_3, 30));
assert_ok!(Auctions::bid(RuntimeOrigin::signed(3), para_3, 1, 14, 14, 29));
winning[SlotRange::ThreeThree as u8 as usize] = Some((3, para_3, 29));
assert_eq!(Auctions::winning(0), Some(winning));

run_to_block(20);
Expand All @@ -1590,8 +1596,8 @@ mod tests {
assert_eq!(Auctions::winning(1), Some(winning));
run_to_block(25);
// Overbid mid sample
assert_ok!(Auctions::bid(RuntimeOrigin::signed(3), para_3, 1, 13, 14, 30));
winning[SlotRange::TwoThree as u8 as usize] = Some((3, para_3, 30));
assert_ok!(Auctions::bid(RuntimeOrigin::signed(3), para_3, 1, 13, 14, 29));
winning[SlotRange::TwoThree as u8 as usize] = Some((3, para_3, 29));
assert_eq!(Auctions::winning(1), Some(winning));

run_to_block(30);
Expand All @@ -1611,8 +1617,8 @@ mod tests {
assert_eq!(
leases(),
vec![
((3.into(), 13), LeaseData { leaser: 3, amount: 30 }),
((3.into(), 14), LeaseData { leaser: 3, amount: 30 }),
((3.into(), 13), LeaseData { leaser: 3, amount: 29 }),
((3.into(), 14), LeaseData { leaser: 3, amount: 29 }),
]
);
});
Expand Down
13 changes: 9 additions & 4 deletions runtime/common/src/claims.rs
Original file line number Diff line number Diff line change
Expand Up @@ -717,13 +717,14 @@ mod tests {
assert_err, assert_noop, assert_ok,
dispatch::{DispatchError::BadOrigin, GetDispatchInfo, Pays},
ord_parameter_types, parameter_types,
traits::{ExistenceRequirement, GenesisBuild, WithdrawReasons},
traits::{ConstU32, ExistenceRequirement, GenesisBuild, WithdrawReasons},
};
use pallet_balances;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, Identity, IdentityLookup},
transaction_validity::TransactionLongevity,
TokenError,
};

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
Expand Down Expand Up @@ -786,6 +787,10 @@ mod tests {
type MaxReserves = ();
type ReserveIdentifier = [u8; 8];
type WeightInfo = ();
type HoldIdentifier = ();
type FreezeIdentifier = ();
type MaxHolds = ConstU32<1>;
type MaxFreezes = ConstU32<1>;
}

parameter_types! {
Expand Down Expand Up @@ -1206,7 +1211,7 @@ mod tests {
180,
ExistenceRequirement::AllowDeath
),
pallet_balances::Error::<Test, _>::LiquidityRestrictions,
TokenError::Frozen,
);
});
}
Expand Down Expand Up @@ -1294,15 +1299,15 @@ mod tests {
#[test]
fn claiming_while_vested_doesnt_work() {
new_test_ext().execute_with(|| {
CurrencyOf::<Test>::make_free_balance_be(&69, total_claims());
assert_eq!(Balances::free_balance(69), total_claims());
// A user is already vested
assert_ok!(<Test as Config>::VestingSchedule::add_vesting_schedule(
&69,
total_claims(),
100,
10
));
CurrencyOf::<Test>::make_free_balance_be(&69, total_claims());
assert_eq!(Balances::free_balance(69), total_claims());
assert_ok!(Claims::mint_claim(
RuntimeOrigin::root(),
eth(&bob()),
Expand Down
18 changes: 13 additions & 5 deletions runtime/common/src/crowdloan/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ pub mod pallet {

let deposit = T::SubmissionDeposit::get();

frame_system::Pallet::<T>::inc_providers(&Self::fund_account_id(fund_index));
CurrencyOf::<T>::reserve(&depositor, deposit)?;

Funds::<T>::insert(
Expand Down Expand Up @@ -575,6 +576,7 @@ pub mod pallet {
// can take care of that.
debug_assert!(Self::contribution_iterator(fund.fund_index).count().is_zero());

frame_system::Pallet::<T>::dec_providers(&Self::fund_account_id(fund.fund_index))?;
CurrencyOf::<T>::unreserve(&fund.depositor, fund.deposit);
Funds::<T>::remove(index);
Self::deposit_event(Event::<T>::Dissolved { para_id: index });
Expand Down Expand Up @@ -861,7 +863,7 @@ mod tests {

use frame_support::{
assert_noop, assert_ok, parameter_types,
traits::{OnFinalize, OnInitialize},
traits::{ConstU32, OnFinalize, OnInitialize},
};
use primitives::Id as ParaId;
use sp_core::H256;
Expand Down Expand Up @@ -943,6 +945,10 @@ mod tests {
type MaxReserves = ();
type ReserveIdentifier = [u8; 8];
type WeightInfo = ();
type HoldIdentifier = ();
type FreezeIdentifier = ();
type MaxHolds = ConstU32<1>;
type MaxFreezes = ConstU32<1>;
}

#[derive(Copy, Clone, Eq, PartialEq, Debug)]
Expand Down Expand Up @@ -987,9 +993,10 @@ mod tests {
let fund = Funds::<Test>::get(para).unwrap();
let account_id = Crowdloan::fund_account_id(fund.fund_index);
if winner {
let ed = <Test as pallet_balances::Config>::ExistentialDeposit::get();
let free_balance = Balances::free_balance(&account_id);
Balances::reserve(&account_id, free_balance)
.expect("should be able to reserve free balance");
Balances::reserve(&account_id, free_balance - ed)
.expect("should be able to reserve free balance minus ED");
} else {
let reserved_balance = Balances::reserved_balance(&account_id);
Balances::unreserve(&account_id, reserved_balance);
Expand Down Expand Up @@ -1613,7 +1620,7 @@ mod tests {
let account_id = Crowdloan::fund_account_id(index);

// user sends the crowdloan funds trying to make an accounting error
assert_ok!(Balances::transfer(RuntimeOrigin::signed(1), account_id, 10));
assert_ok!(Balances::transfer_allow_death(RuntimeOrigin::signed(1), account_id, 10));

// overfunded now
assert_eq!(Balances::free_balance(&account_id), 110);
Expand Down Expand Up @@ -1782,6 +1789,7 @@ mod tests {
#[test]
fn withdraw_from_finished_works() {
new_test_ext().execute_with(|| {
assert_eq!(<Test as pallet_balances::Config>::ExistentialDeposit::get(), 1);
let para = new_para();
let index = NextFundIndex::<Test>::get();
let account_id = Crowdloan::fund_account_id(index);
Expand All @@ -1793,7 +1801,7 @@ mod tests {
assert_ok!(Crowdloan::contribute(RuntimeOrigin::signed(2), para, 100, None));
assert_ok!(Crowdloan::contribute(RuntimeOrigin::signed(3), para, 50, None));
// simulate the reserving of para's funds. this actually happens in the Slots pallet.
assert_ok!(Balances::reserve(&account_id, 150));
assert_ok!(Balances::reserve(&account_id, 149));

run_to_block(19);
assert_noop!(
Expand Down
14 changes: 11 additions & 3 deletions runtime/common/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,15 @@ pub fn era_payout(
mod tests {
use super::*;
use frame_support::{
dispatch::DispatchClass, parameter_types, traits::FindAuthor, weights::Weight, PalletId,
dispatch::DispatchClass,
parameter_types,
traits::{ConstU32, FindAuthor},
weights::Weight,
PalletId,
};
use frame_system::limits;
use primitives::AccountId;
use sp_core::H256;
use sp_core::{ConstU64, H256};
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
Expand Down Expand Up @@ -176,12 +180,16 @@ mod tests {
type Balance = u64;
type RuntimeEvent = RuntimeEvent;
type DustRemoval = ();
type ExistentialDeposit = ();
type ExistentialDeposit = ConstU64<1>;
type AccountStore = System;
type MaxLocks = ();
type MaxReserves = ();
type ReserveIdentifier = [u8; 8];
type WeightInfo = ();
type HoldIdentifier = ();
type FreezeIdentifier = ();
type MaxHolds = ConstU32<1>;
type MaxFreezes = ConstU32<1>;
}

parameter_types! {
Expand Down
6 changes: 5 additions & 1 deletion runtime/common/src/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::{
};
use frame_support::{
assert_noop, assert_ok, parameter_types,
traits::{Currency, GenesisBuild, OnFinalize, OnInitialize},
traits::{ConstU32, Currency, GenesisBuild, OnFinalize, OnInitialize},
weights::Weight,
PalletId,
};
Expand Down Expand Up @@ -178,6 +178,10 @@ impl pallet_balances::Config for Test {
type WeightInfo = ();
type MaxReserves = MaxReserves;
type ReserveIdentifier = [u8; 8];
type HoldIdentifier = ();
type FreezeIdentifier = ();
type MaxHolds = ConstU32<0>;
type MaxFreezes = ConstU32<0>;
}

impl configuration::Config for Test {
Expand Down
6 changes: 5 additions & 1 deletion runtime/common/src/paras_registrar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ mod tests {
assert_noop, assert_ok,
error::BadOrigin,
parameter_types,
traits::{GenesisBuild, OnFinalize, OnInitialize},
traits::{ConstU32, GenesisBuild, OnFinalize, OnInitialize},
};
use frame_system::limits;
use pallet_balances::Error as BalancesError;
Expand Down Expand Up @@ -750,6 +750,10 @@ mod tests {
type MaxReserves = ();
type ReserveIdentifier = [u8; 8];
type WeightInfo = ();
type HoldIdentifier = ();
type FreezeIdentifier = ();
type MaxHolds = ConstU32<1>;
type MaxFreezes = ConstU32<1>;
}

impl shared::Config for Test {}
Expand Down
Loading

0 comments on commit 680c451

Please sign in to comment.