mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 17:31:05 +00:00
Staking and nomination pools runtime API improvements (#13119)
* Adds StakingAPI_nominations_quota and NominationPoolsApi_balanceToPoint and NominationPoolsApi_pointsToBalance runtime APIs * Adds balance param to api_nominations_quota * Update frame/nomination-pools/src/lib.rs Co-authored-by: Anton <anton.kalyaev@gmail.com> * Update frame/nomination-pools/src/lib.rs Co-authored-by: Anton <anton.kalyaev@gmail.com> * Addresses comments - returns zero instead of error in runtime api * Update frame/staking/runtime-api/src/lib.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Update frame/staking/runtime-api/src/lib.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Addresses PR comments * Update frame/nomination-pools/runtime-api/Cargo.toml Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Fixes points_to_balance logic; adds tests * test comment fix * Update frame/nomination-pools/runtime-api/src/lib.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Update frame/nomination-pools/runtime-api/src/lib.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Fix block pruning (#13323) * Referendum proposal's metadata (#12568) * referenda metadata * todo comment * remove TODO, update rustdocs * referenda clear_metadata origin signed or root * referenda metadata unit tests * drop schema type for referenda metadata * remove metadata type * referenda metadata benches * note different preimages * metadata for democracy pallet * metadata democracy pallet tests and benches * fix cargo clippy * update docs * ".git/.scripts/bench-bot.sh" pallet dev pallet_democracy * ".git/.scripts/bench-bot.sh" pallet dev pallet_referenda * Update the doc frame/democracy/src/lib.rs Co-authored-by: Roman Useinov <roman.useinov@gmail.com> * Update the doc frame/democracy/src/lib.rs Co-authored-by: Anthony Alaribe <anthonyalaribe@gmail.com> * reference instead clone for take Co-authored-by: Anthony Alaribe <anthonyalaribe@gmail.com> * error rename BadMetadata to PreimageNotExist * clear metadata within internal_cancel_referendum fn * remove redundant clone * collapse metadata api into one set_metadata method * fmt * review fixes * not request preimage on set_metadata * rename events and update docs * ".git/.scripts/commands/bench/bench.sh" pallet dev pallet_democracy * ".git/.scripts/commands/bench/bench.sh" pallet dev pallet_referenda * rename reset_metadata to transfer_metadata --------- Co-authored-by: command-bot <> Co-authored-by: Roman Useinov <roman.useinov@gmail.com> Co-authored-by: Anthony Alaribe <anthonyalaribe@gmail.com> * Improve test coverage of the `Notifications` protocol (#13033) * Add handler and upgrade tests * Add tests for `behaviour.rs` * Apply review comments * Update dependencies * Apply suggestions from code review Co-authored-by: Dmitry Markin <dmitry@markin.tech> * Apply review comments * Fix clippy * Update mockall * Apply review comment --------- Co-authored-by: Dmitry Markin <dmitry@markin.tech> * refactors runtime API logic to own pallet impl block * removes unrelated changes * Fixes cargo doc comments lint * fixes node cargo * fixes comment * restart ci * restart ci * restart ci --------- Co-authored-by: Anton <anton.kalyaev@gmail.com> Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Co-authored-by: parity-processbot <> Co-authored-by: Arkadiy Paronyan <arkady.paronyan@gmail.com> Co-authored-by: Muharem Ismailov <ismailov.m.h@gmail.com> Co-authored-by: Roman Useinov <roman.useinov@gmail.com> Co-authored-by: Anthony Alaribe <anthonyalaribe@gmail.com> Co-authored-by: Aaro Altonen <48052676+altonen@users.noreply.github.com> Co-authored-by: Dmitry Markin <dmitry@markin.tech>
This commit is contained in:
@@ -195,6 +195,46 @@ mod bonded_pool {
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn api_points_to_balance_works() {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert!(BondedPool::<Runtime>::get(1).is_some());
|
||||
assert_eq!(Pallet::<Runtime>::api_points_to_balance(1, 10), 10);
|
||||
|
||||
// slash half of the pool's balance. expected result of `fn api_points_to_balance`
|
||||
// to be 1/2 of the pool's balance.
|
||||
StakingMock::set_bonded_balance(
|
||||
default_bonded_account(),
|
||||
Pools::depositor_min_bond() / 2,
|
||||
);
|
||||
assert_eq!(Pallet::<Runtime>::api_points_to_balance(1, 10), 5);
|
||||
|
||||
// if pool does not exist, points to balance ratio is 0.
|
||||
assert_eq!(BondedPool::<Runtime>::get(2), None);
|
||||
assert_eq!(Pallet::<Runtime>::api_points_to_balance(2, 10), 0);
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn api_balance_to_points_works() {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_eq!(Pallet::<Runtime>::api_balance_to_points(1, 0), 0);
|
||||
assert_eq!(Pallet::<Runtime>::api_balance_to_points(1, 10), 10);
|
||||
|
||||
// slash half of the pool's balance. expect result of `fn api_balance_to_points`
|
||||
// to be 2 * of the balance to add to the pool.
|
||||
StakingMock::set_bonded_balance(
|
||||
default_bonded_account(),
|
||||
Pools::depositor_min_bond() / 2,
|
||||
);
|
||||
assert_eq!(Pallet::<Runtime>::api_balance_to_points(1, 10), 20);
|
||||
|
||||
// if pool does not exist, balance to points ratio is 0.
|
||||
assert_eq!(BondedPool::<Runtime>::get(2), None);
|
||||
assert_eq!(Pallet::<Runtime>::api_points_to_balance(2, 10), 0);
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ok_to_join_with_works() {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
@@ -1305,51 +1345,51 @@ mod claim_payout {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
let ed = Balances::minimum_balance();
|
||||
|
||||
assert_eq!(Pools::pending_rewards(10), Some(0));
|
||||
assert_eq!(Pools::api_pending_rewards(10), Some(0));
|
||||
Balances::mutate_account(&default_reward_account(), |f| f.free += 30).unwrap();
|
||||
assert_eq!(Pools::pending_rewards(10), Some(30));
|
||||
assert_eq!(Pools::pending_rewards(20), None);
|
||||
assert_eq!(Pools::api_pending_rewards(10), Some(30));
|
||||
assert_eq!(Pools::api_pending_rewards(20), None);
|
||||
|
||||
Balances::make_free_balance_be(&20, ed + 10);
|
||||
assert_ok!(Pools::join(RuntimeOrigin::signed(20), 10, 1));
|
||||
|
||||
assert_eq!(Pools::pending_rewards(10), Some(30));
|
||||
assert_eq!(Pools::pending_rewards(20), Some(0));
|
||||
assert_eq!(Pools::api_pending_rewards(10), Some(30));
|
||||
assert_eq!(Pools::api_pending_rewards(20), Some(0));
|
||||
|
||||
Balances::mutate_account(&default_reward_account(), |f| f.free += 100).unwrap();
|
||||
|
||||
assert_eq!(Pools::pending_rewards(10), Some(30 + 50));
|
||||
assert_eq!(Pools::pending_rewards(20), Some(50));
|
||||
assert_eq!(Pools::pending_rewards(30), None);
|
||||
assert_eq!(Pools::api_pending_rewards(10), Some(30 + 50));
|
||||
assert_eq!(Pools::api_pending_rewards(20), Some(50));
|
||||
assert_eq!(Pools::api_pending_rewards(30), None);
|
||||
|
||||
Balances::make_free_balance_be(&30, ed + 10);
|
||||
assert_ok!(Pools::join(RuntimeOrigin::signed(30), 10, 1));
|
||||
|
||||
assert_eq!(Pools::pending_rewards(10), Some(30 + 50));
|
||||
assert_eq!(Pools::pending_rewards(20), Some(50));
|
||||
assert_eq!(Pools::pending_rewards(30), Some(0));
|
||||
assert_eq!(Pools::api_pending_rewards(10), Some(30 + 50));
|
||||
assert_eq!(Pools::api_pending_rewards(20), Some(50));
|
||||
assert_eq!(Pools::api_pending_rewards(30), Some(0));
|
||||
|
||||
Balances::mutate_account(&default_reward_account(), |f| f.free += 60).unwrap();
|
||||
|
||||
assert_eq!(Pools::pending_rewards(10), Some(30 + 50 + 20));
|
||||
assert_eq!(Pools::pending_rewards(20), Some(50 + 20));
|
||||
assert_eq!(Pools::pending_rewards(30), Some(20));
|
||||
assert_eq!(Pools::api_pending_rewards(10), Some(30 + 50 + 20));
|
||||
assert_eq!(Pools::api_pending_rewards(20), Some(50 + 20));
|
||||
assert_eq!(Pools::api_pending_rewards(30), Some(20));
|
||||
|
||||
// 10 should claim 10, 20 should claim nothing.
|
||||
assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10)));
|
||||
assert_eq!(Pools::pending_rewards(10), Some(0));
|
||||
assert_eq!(Pools::pending_rewards(20), Some(50 + 20));
|
||||
assert_eq!(Pools::pending_rewards(30), Some(20));
|
||||
assert_eq!(Pools::api_pending_rewards(10), Some(0));
|
||||
assert_eq!(Pools::api_pending_rewards(20), Some(50 + 20));
|
||||
assert_eq!(Pools::api_pending_rewards(30), Some(20));
|
||||
|
||||
assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(20)));
|
||||
assert_eq!(Pools::pending_rewards(10), Some(0));
|
||||
assert_eq!(Pools::pending_rewards(20), Some(0));
|
||||
assert_eq!(Pools::pending_rewards(30), Some(20));
|
||||
assert_eq!(Pools::api_pending_rewards(10), Some(0));
|
||||
assert_eq!(Pools::api_pending_rewards(20), Some(0));
|
||||
assert_eq!(Pools::api_pending_rewards(30), Some(20));
|
||||
|
||||
assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(30)));
|
||||
assert_eq!(Pools::pending_rewards(10), Some(0));
|
||||
assert_eq!(Pools::pending_rewards(20), Some(0));
|
||||
assert_eq!(Pools::pending_rewards(30), Some(0));
|
||||
assert_eq!(Pools::api_pending_rewards(10), Some(0));
|
||||
assert_eq!(Pools::api_pending_rewards(20), Some(0));
|
||||
assert_eq!(Pools::api_pending_rewards(30), Some(0));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user