mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-21 06:21:01 +00:00
compact param in calls (#1499)
* impl #[codec(compact)] for param * update modules * test all and build runtime * Update srml/support/src/dispatch.rs Co-Authored-By: thiolliere <gui.thiolliere@gmail.com> * Update srml/support/src/dispatch.rs Co-Authored-By: thiolliere <gui.thiolliere@gmail.com> * delete wip comment * update param to use #[compact] instead of Cmpact<> * fmt * impl metadata * test metadata * add compact attr test * script buid * update test
This commit is contained in:
committed by
Bastian Köcher
parent
8f38593def
commit
2492931944
@@ -118,9 +118,8 @@ decl_module! {
|
||||
/// Retract the desire to stake for the transactor.
|
||||
///
|
||||
/// Effects will be felt at the beginning of the next era.
|
||||
fn unstake(origin, intentions_index: Compact<u32>) -> Result {
|
||||
fn unstake(origin, #[compact] intentions_index: u32) -> Result {
|
||||
let who = ensure_signed(origin)?;
|
||||
let intentions_index: u32 = intentions_index.into();
|
||||
// unstake fails in degenerate case of having too few existing staked parties
|
||||
if Self::intentions().len() <= Self::minimum_validator_count() as usize {
|
||||
return Err("cannot unstake when there are too few staked participants")
|
||||
@@ -149,9 +148,8 @@ decl_module! {
|
||||
|
||||
/// Will panic if called when source isn't currently nominating target.
|
||||
/// Updates Nominating, NominatorsFor and NominationBalance.
|
||||
fn unnominate(origin, target_index: Compact<u32>) {
|
||||
fn unnominate(origin, #[compact] target_index: u32) {
|
||||
let source = ensure_signed(origin)?;
|
||||
let target_index: u32 = target_index.into();
|
||||
let target_index = target_index as usize;
|
||||
|
||||
let target = <Nominating<T>>::get(&source).ok_or("Account must be nominating")?;
|
||||
@@ -182,11 +180,10 @@ decl_module! {
|
||||
/// An error (no-op) if `Self::intentions()[intentions_index] != origin`.
|
||||
fn register_preferences(
|
||||
origin,
|
||||
intentions_index: Compact<u32>,
|
||||
#[compact] intentions_index: u32,
|
||||
prefs: ValidatorPrefs<T::Balance>
|
||||
) {
|
||||
let who = ensure_signed(origin)?;
|
||||
let intentions_index: u32 = intentions_index.into();
|
||||
|
||||
if Self::intentions().get(intentions_index as usize) != Some(&who) {
|
||||
return Err("Invalid index")
|
||||
@@ -196,18 +193,17 @@ decl_module! {
|
||||
}
|
||||
|
||||
/// Set the number of sessions in an era.
|
||||
fn set_sessions_per_era(new: <T::BlockNumber as HasCompact>::Type) {
|
||||
<NextSessionsPerEra<T>>::put(new.into());
|
||||
fn set_sessions_per_era(#[compact] new: T::BlockNumber) {
|
||||
<NextSessionsPerEra<T>>::put(new);
|
||||
}
|
||||
|
||||
/// The length of the bonding duration in eras.
|
||||
fn set_bonding_duration(new: <T::BlockNumber as HasCompact>::Type) {
|
||||
<BondingDuration<T>>::put(new.into());
|
||||
fn set_bonding_duration(#[compact] new: T::BlockNumber) {
|
||||
<BondingDuration<T>>::put(new);
|
||||
}
|
||||
|
||||
/// The ideal number of validators.
|
||||
fn set_validator_count(new: Compact<u32>) {
|
||||
let new: u32 = new.into();
|
||||
fn set_validator_count(#[compact] new: u32) {
|
||||
<ValidatorCount<T>>::put(new);
|
||||
}
|
||||
|
||||
@@ -218,8 +214,7 @@ decl_module! {
|
||||
}
|
||||
|
||||
/// Set the offline slash grace period.
|
||||
fn set_offline_slash_grace(new: Compact<u32>) {
|
||||
let new: u32 = new.into();
|
||||
fn set_offline_slash_grace(#[compact] new: u32) {
|
||||
<OfflineSlashGrace<T>>::put(new);
|
||||
}
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ fn note_offline_grace_should_work() {
|
||||
with_externalities(&mut new_test_ext(0, 3, 3, 0, true, 10), || {
|
||||
Balances::set_free_balance(&10, 70);
|
||||
Balances::set_free_balance(&20, 70);
|
||||
assert_ok!(Staking::set_offline_slash_grace(1.into()));
|
||||
assert_ok!(Staking::set_offline_slash_grace(1));
|
||||
assert_eq!(Staking::offline_slash_grace(), 1);
|
||||
|
||||
assert_eq!(Staking::slash_count(&10), 0);
|
||||
@@ -145,7 +145,7 @@ fn note_offline_auto_unstake_session_change_should_work() {
|
||||
with_externalities(&mut new_test_ext(0, 3, 3, 0, true, 10), || {
|
||||
Balances::set_free_balance(&10, 7000);
|
||||
Balances::set_free_balance(&20, 7000);
|
||||
assert_ok!(Staking::register_preferences(Origin::signed(10), 0.into(), ValidatorPrefs { unstake_threshold: 1, validator_payment: 0 }));
|
||||
assert_ok!(Staking::register_preferences(Origin::signed(10), 0, ValidatorPrefs { unstake_threshold: 1, validator_payment: 0 }));
|
||||
|
||||
assert_eq!(Staking::intentions(), vec![10, 20]);
|
||||
|
||||
@@ -251,7 +251,7 @@ fn staking_should_work() {
|
||||
assert_eq!(Staking::validator_count(), 2);
|
||||
assert_eq!(Session::validators(), vec![10, 20]);
|
||||
|
||||
assert_ok!(Staking::set_bonding_duration(2.into()));
|
||||
assert_ok!(Staking::set_bonding_duration(2));
|
||||
assert_eq!(Staking::bonding_duration(), 2);
|
||||
|
||||
// Block 1: Add three validators. No obvious change.
|
||||
@@ -284,7 +284,7 @@ fn staking_should_work() {
|
||||
|
||||
// Block 5: Transfer stake from highest to lowest. No change yet.
|
||||
System::set_block_number(5);
|
||||
assert_ok!(Balances::transfer(Origin::signed(4), 1, 40.into()));
|
||||
assert_ok!(Balances::transfer(Origin::signed(4), 1, 40));
|
||||
Session::check_rotate_session(System::block_number());
|
||||
|
||||
// Block 6: Lowest now validator.
|
||||
@@ -327,7 +327,7 @@ fn nominating_and_rewards_should_work() {
|
||||
assert_eq!(Balances::total_balance(&4), 40);
|
||||
|
||||
System::set_block_number(2);
|
||||
assert_ok!(Staking::unnominate(Origin::signed(4), 0.into()));
|
||||
assert_ok!(Staking::unnominate(Origin::signed(4), 0));
|
||||
Session::check_rotate_session(System::block_number());
|
||||
assert_eq!(Staking::current_era(), 2);
|
||||
assert_eq!(Session::validators(), vec![3, 2]);
|
||||
@@ -460,7 +460,7 @@ fn staking_eras_work() {
|
||||
|
||||
// Block 3: Schedule an era length change; no visible changes.
|
||||
System::set_block_number(3);
|
||||
assert_ok!(Staking::set_sessions_per_era(3.into()));
|
||||
assert_ok!(Staking::set_sessions_per_era(3));
|
||||
Session::check_rotate_session(System::block_number());
|
||||
assert_eq!(Session::current_index(), 3);
|
||||
assert_eq!(Staking::sessions_per_era(), 2);
|
||||
@@ -506,7 +506,7 @@ fn staking_balance_transfer_when_bonded_should_not_work() {
|
||||
with_externalities(&mut new_test_ext(0, 1, 3, 1, false, 0), || {
|
||||
Balances::set_free_balance(&1, 111);
|
||||
assert_ok!(Staking::stake(Origin::signed(1)));
|
||||
assert_noop!(Balances::transfer(Origin::signed(1), 2, 69.into()), "cannot transfer illiquid funds");
|
||||
assert_noop!(Balances::transfer(Origin::signed(1), 2, 69), "cannot transfer illiquid funds");
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user