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

Add era to Unbonded event #11770

Merged
merged 5 commits into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion frame/nomination-pools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1349,7 +1349,7 @@ pub mod pallet {
/// pool.
/// - `points` is the number of points that are issued as a result of `balance` being
/// dissolved into the corresponding unbonding pool.
///
/// - `era` is the era in which the balance will be unbonded.
/// In the absence of slashing, these values will match. In the presence of slashing, the
/// number of points that are issued in the unbonding pool will be less than the amount
/// requested to be unbonded.
Expand All @@ -1358,6 +1358,7 @@ pub mod pallet {
pool_id: PoolId,
balance: BalanceOf<T>,
points: BalanceOf<T>,
era: EraIndex,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the docs to say what is era please? is it the era in which we unbonded, or the one in which we will be unlocked?

},
/// A member has withdrawn from their pool.
///
Expand Down Expand Up @@ -1683,6 +1684,7 @@ pub mod pallet {
pool_id: member.pool_id,
points: points_unbonded,
balance: unbonding_balance,
era: unbond_era,
});

// Now that we know everything has worked write the items to storage.
Expand Down
131 changes: 86 additions & 45 deletions frame/nomination-pools/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ mod claim_payout {
Event::Created { depositor: 10, pool_id: 1 },
Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true },
Event::Bonded { member: 11, pool_id: 1, bonded: 11, joined: true },
Event::Unbonded { member: 11, pool_id: 1, points: 11, balance: 11 }
Event::Unbonded { member: 11, pool_id: 1, points: 11, balance: 11, era: 3 }
]
);
});
Expand Down Expand Up @@ -1374,7 +1374,7 @@ mod claim_payout {
assert_eq!(
pool_events_since_last_call(),
vec![
Event::Unbonded { member: 20, pool_id: 1, balance: 10, points: 10 },
Event::Unbonded { member: 20, pool_id: 1, balance: 10, points: 10, era: 3 },
Event::PaidOut { member: 10, pool_id: 1, payout: 50 },
Event::PaidOut { member: 20, pool_id: 1, payout: 50 },
]
Expand Down Expand Up @@ -1808,12 +1808,12 @@ mod claim_payout {
Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true },
Event::Bonded { member: 20, pool_id: 1, bonded: 20, joined: true },
Event::Bonded { member: 30, pool_id: 1, bonded: 20, joined: true },
Event::Unbonded { member: 20, pool_id: 1, balance: 10, points: 10 },
Event::Unbonded { member: 20, pool_id: 1, balance: 10, points: 10, era: 3 },
Event::PaidOut { member: 30, pool_id: 1, payout: 15 },
Event::Unbonded { member: 30, pool_id: 1, balance: 10, points: 10 },
Event::Unbonded { member: 30, pool_id: 1, balance: 5, points: 5 },
Event::Unbonded { member: 30, pool_id: 1, balance: 10, points: 10, era: 3 },
Event::Unbonded { member: 30, pool_id: 1, balance: 5, points: 5, era: 3 },
Event::PaidOut { member: 20, pool_id: 1, payout: 7 },
Event::Unbonded { member: 20, pool_id: 1, balance: 5, points: 5 },
Event::Unbonded { member: 20, pool_id: 1, balance: 5, points: 5, era: 3 },
Event::PaidOut { member: 10, pool_id: 1, payout: 7 }
]
);
Expand Down Expand Up @@ -1865,10 +1865,10 @@ mod claim_payout {
pool_events_since_last_call(),
vec![
Event::StateChanged { pool_id: 1, new_state: PoolState::Destroying },
Event::Unbonded { member: 20, pool_id: 1, balance: 20, points: 20 },
Event::Unbonded { member: 20, pool_id: 1, balance: 20, points: 20, era: 3 },
Event::Withdrawn { member: 20, pool_id: 1, balance: 20, points: 20 },
Event::MemberRemoved { pool_id: 1, member: 20 },
Event::Unbonded { member: 10, pool_id: 1, balance: 10, points: 10 },
Event::Unbonded { member: 10, pool_id: 1, balance: 10, points: 10, era: 6 },
Event::Withdrawn { member: 10, pool_id: 1, balance: 10, points: 10 },
Event::MemberRemoved { pool_id: 1, member: 10 },
Event::Destroyed { pool_id: 1 }
Expand Down Expand Up @@ -2269,7 +2269,7 @@ mod unbond {
Event::Bonded { member: 40, pool_id: 1, bonded: 40, joined: true },
Event::Bonded { member: 550, pool_id: 1, bonded: 550, joined: true },
Event::PaidOut { member: 40, pool_id: 1, payout: 40 },
Event::Unbonded { member: 40, pool_id: 1, points: 6, balance: 6 }
Event::Unbonded { member: 40, pool_id: 1, points: 6, balance: 6, era: 3 }
]
);

Expand Down Expand Up @@ -2311,7 +2311,13 @@ mod unbond {
pool_events_since_last_call(),
vec![
Event::PaidOut { member: 550, pool_id: 1, payout: 550 },
Event::Unbonded { member: 550, pool_id: 1, points: 92, balance: 92 }
Event::Unbonded {
member: 550,
pool_id: 1,
points: 92,
balance: 92,
era: 3
}
]
);

Expand Down Expand Up @@ -2349,7 +2355,7 @@ mod unbond {
Event::Withdrawn { member: 550, pool_id: 1, points: 92, balance: 92 },
Event::MemberRemoved { pool_id: 1, member: 550 },
Event::PaidOut { member: 10, pool_id: 1, payout: 10 },
Event::Unbonded { member: 10, pool_id: 1, points: 2, balance: 2 }
Event::Unbonded { member: 10, pool_id: 1, points: 2, balance: 2, era: 6 }
]
);
});
Expand Down Expand Up @@ -2395,7 +2401,7 @@ mod unbond {
vec![
Event::Created { depositor: 10, pool_id: 1 },
Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true },
Event::Unbonded { member: 10, pool_id: 1, points: 10, balance: 10 }
Event::Unbonded { member: 10, pool_id: 1, points: 10, balance: 10, era: 9 }
]
);
});
Expand Down Expand Up @@ -2430,7 +2436,13 @@ mod unbond {
Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true },
Event::Bonded { member: 100, pool_id: 1, bonded: 100, joined: true },
Event::Bonded { member: 200, pool_id: 1, bonded: 200, joined: true },
Event::Unbonded { member: 100, pool_id: 1, points: 100, balance: 100 },
Event::Unbonded {
member: 100,
pool_id: 1,
points: 100,
balance: 100,
era: 3
},
]
);

Expand All @@ -2439,7 +2451,13 @@ mod unbond {

assert_eq!(
pool_events_since_last_call(),
vec![Event::Unbonded { member: 200, pool_id: 1, points: 200, balance: 200 }]
vec![Event::Unbonded {
member: 200,
pool_id: 1,
points: 200,
balance: 200,
era: 3
}]
);

assert_eq!(
Expand Down Expand Up @@ -2508,7 +2526,7 @@ mod unbond {
Event::Created { depositor: 10, pool_id: 1 },
Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true },
Event::Bonded { member: 100, pool_id: 1, bonded: 100, joined: true },
Event::Unbonded { member: 100, pool_id: 1, points: 100, balance: 100 }
Event::Unbonded { member: 100, pool_id: 1, points: 100, balance: 100, era: 3 }
]
);

Expand Down Expand Up @@ -2659,7 +2677,7 @@ mod unbond {
vec![
Event::Created { depositor: 10, pool_id: 1 },
Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true },
Event::Unbonded { member: 10, pool_id: 1, points: 1, balance: 1 }
Event::Unbonded { member: 10, pool_id: 1, points: 1, balance: 1, era: 3 }
]
);

Expand All @@ -2685,7 +2703,7 @@ mod unbond {
);
assert_eq!(
pool_events_since_last_call(),
vec![Event::Unbonded { member: 10, pool_id: 1, points: 5, balance: 5 }]
vec![Event::Unbonded { member: 10, pool_id: 1, points: 5, balance: 5, era: 3 }]
);

// when: casual further unbond, next era.
Expand All @@ -2712,7 +2730,7 @@ mod unbond {
);
assert_eq!(
pool_events_since_last_call(),
vec![Event::Unbonded { member: 10, pool_id: 1, points: 1, balance: 1 }]
vec![Event::Unbonded { member: 10, pool_id: 1, points: 1, balance: 1, era: 4 }]
);

// when: unbonding more than our active: error
Expand Down Expand Up @@ -2747,7 +2765,7 @@ mod unbond {
);
assert_eq!(
pool_events_since_last_call(),
vec![Event::Unbonded { member: 10, pool_id: 1, points: 3, balance: 3 }]
vec![Event::Unbonded { member: 10, pool_id: 1, points: 3, balance: 3, era: 4 }]
);
});
}
Expand Down Expand Up @@ -2792,9 +2810,9 @@ mod unbond {
Event::Created { depositor: 10, pool_id: 1 },
Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true },
Event::Bonded { member: 20, pool_id: 1, bonded: 20, joined: true },
Event::Unbonded { member: 20, pool_id: 1, balance: 2, points: 2 },
Event::Unbonded { member: 20, pool_id: 1, balance: 3, points: 3 },
Event::Unbonded { member: 20, pool_id: 1, balance: 1, points: 1 }
Event::Unbonded { member: 20, pool_id: 1, points: 2, balance: 2, era: 3 },
Event::Unbonded { member: 20, pool_id: 1, points: 3, balance: 3, era: 4 },
Event::Unbonded { member: 20, pool_id: 1, points: 1, balance: 1, era: 5 }
]
);
})
Expand Down Expand Up @@ -2827,7 +2845,7 @@ mod unbond {
vec![
Event::Created { depositor: 10, pool_id: 1 },
Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true },
Event::Unbonded { member: 10, pool_id: 1, points: 3, balance: 3 }
Event::Unbonded { member: 10, pool_id: 1, points: 3, balance: 3, era: 3 }
]
);
});
Expand Down Expand Up @@ -2873,7 +2891,7 @@ mod unbond {
Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true },
Event::Bonded { member: 20, pool_id: 1, bonded: 20, joined: true },
Event::PaidOut { member: 20, pool_id: 1, payout: 10 },
Event::Unbonded { member: 20, pool_id: 1, balance: 2, points: 2 }
Event::Unbonded { member: 20, pool_id: 1, balance: 2, points: 2, era: 3 }
]
);

Expand All @@ -2889,7 +2907,7 @@ mod unbond {
vec![
// 2/3 of ed, which is 20's share.
Event::PaidOut { member: 20, pool_id: 1, payout: 6 },
Event::Unbonded { member: 20, pool_id: 1, points: 3, balance: 3 }
Event::Unbonded { member: 20, pool_id: 1, points: 3, balance: 3, era: 4 }
]
);

Expand All @@ -2904,7 +2922,7 @@ mod unbond {
pool_events_since_last_call(),
vec![
Event::PaidOut { member: 20, pool_id: 1, payout: 3 },
Event::Unbonded { member: 20, pool_id: 1, points: 5, balance: 5 }
Event::Unbonded { member: 20, pool_id: 1, points: 5, balance: 5, era: 5 }
]
);

Expand Down Expand Up @@ -3003,16 +3021,21 @@ mod withdraw_unbonded {
with_era: Default::default()
}
);

assert_eq!(
pool_events_since_last_call(),
vec![
Event::Created { depositor: 10, pool_id: 1 },
Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true },
Event::Bonded { member: 40, pool_id: 1, bonded: 40, joined: true },
Event::Bonded { member: 550, pool_id: 1, bonded: 550, joined: true },
Event::Unbonded { member: 550, pool_id: 1, points: 550, balance: 550 },
Event::Unbonded { member: 40, pool_id: 1, points: 40, balance: 40 },
Event::Unbonded {
member: 550,
pool_id: 1,
points: 550,
balance: 550,
era: 3
},
Event::Unbonded { member: 40, pool_id: 1, points: 40, balance: 40, era: 3 },
]
);
assert_eq!(
Expand Down Expand Up @@ -3077,7 +3100,7 @@ mod withdraw_unbonded {
assert_eq!(
pool_events_since_last_call(),
vec![
Event::Unbonded { member: 10, pool_id: 1, balance: 5, points: 5 },
Event::Unbonded { member: 10, pool_id: 1, balance: 5, points: 5, era: 9 },
Event::Withdrawn { member: 10, pool_id: 1, balance: 5, points: 5 },
Event::MemberRemoved { pool_id: 1, member: 10 },
Event::Destroyed { pool_id: 1 }
Expand Down Expand Up @@ -3122,8 +3145,14 @@ mod withdraw_unbonded {
Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true },
Event::Bonded { member: 40, pool_id: 1, bonded: 40, joined: true },
Event::Bonded { member: 550, pool_id: 1, bonded: 550, joined: true },
Event::Unbonded { member: 40, pool_id: 1, balance: 20, points: 20 },
Event::Unbonded { member: 550, pool_id: 1, balance: 275, points: 275 },
Event::Unbonded { member: 40, pool_id: 1, balance: 20, points: 20, era: 3 },
Event::Unbonded {
member: 550,
pool_id: 1,
balance: 275,
points: 275,
era: 3,
}
]
);
assert_eq!(
Expand Down Expand Up @@ -3199,7 +3228,7 @@ mod withdraw_unbonded {
assert_eq!(
pool_events_since_last_call(),
vec![
Event::Unbonded { member: 10, pool_id: 1, points: 5, balance: 5 },
Event::Unbonded { member: 10, pool_id: 1, points: 5, balance: 5, era: 6 },
Event::Withdrawn { member: 10, pool_id: 1, points: 5, balance: 5 },
Event::MemberRemoved { pool_id: 1, member: 10 },
Event::Destroyed { pool_id: 1 }
Expand Down Expand Up @@ -3313,8 +3342,20 @@ mod withdraw_unbonded {
Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true },
Event::Bonded { member: 100, pool_id: 1, bonded: 100, joined: true },
Event::Bonded { member: 200, pool_id: 1, bonded: 200, joined: true },
Event::Unbonded { member: 100, pool_id: 1, points: 100, balance: 100 },
Event::Unbonded { member: 200, pool_id: 1, points: 200, balance: 200 }
Event::Unbonded {
member: 100,
pool_id: 1,
points: 100,
balance: 100,
era: 3
},
Event::Unbonded {
member: 200,
pool_id: 1,
points: 200,
balance: 200,
era: 3
}
]
);

Expand Down Expand Up @@ -3391,7 +3432,7 @@ mod withdraw_unbonded {
Event::Created { depositor: 10, pool_id: 1 },
Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true },
Event::Bonded { member: 100, pool_id: 1, bonded: 100, joined: true },
Event::Unbonded { member: 100, pool_id: 1, points: 100, balance: 100 },
Event::Unbonded { member: 100, pool_id: 1, points: 100, balance: 100, era: 3 },
Event::Withdrawn { member: 100, pool_id: 1, points: 100, balance: 100 },
Event::MemberRemoved { pool_id: 1, member: 100 }
]
Expand Down Expand Up @@ -3431,8 +3472,8 @@ mod withdraw_unbonded {
Event::Created { depositor: 10, pool_id: 1 },
Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true },
Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: false },
Event::Unbonded { member: 10, pool_id: 1, points: 6, balance: 6 },
Event::Unbonded { member: 10, pool_id: 1, points: 1, balance: 1 }
Event::Unbonded { member: 10, pool_id: 1, points: 6, balance: 6, era: 3 },
Event::Unbonded { member: 10, pool_id: 1, points: 1, balance: 1, era: 4 }
]
);

Expand Down Expand Up @@ -3518,8 +3559,8 @@ mod withdraw_unbonded {
Event::Created { depositor: 10, pool_id: 1 },
Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true },
Event::Bonded { member: 11, pool_id: 1, bonded: 10, joined: true },
Event::Unbonded { member: 11, pool_id: 1, points: 6, balance: 6 },
Event::Unbonded { member: 11, pool_id: 1, points: 1, balance: 1 }
Event::Unbonded { member: 11, pool_id: 1, points: 6, balance: 6, era: 3 },
Event::Unbonded { member: 11, pool_id: 1, points: 1, balance: 1, era: 4 }
]
);

Expand Down Expand Up @@ -3608,8 +3649,8 @@ mod withdraw_unbonded {
Event::Created { depositor: 10, pool_id: 1 },
Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true },
Event::Bonded { member: 100, pool_id: 1, bonded: 100, joined: true },
Event::Unbonded { member: 100, pool_id: 1, points: 75, balance: 75 },
Event::Unbonded { member: 100, pool_id: 1, points: 25, balance: 25 },
Event::Unbonded { member: 100, pool_id: 1, points: 75, balance: 75, era: 3 },
Event::Unbonded { member: 100, pool_id: 1, points: 25, balance: 25, era: 4 },
Event::Withdrawn { member: 100, pool_id: 1, points: 75, balance: 75 },
]
);
Expand Down Expand Up @@ -3680,9 +3721,9 @@ mod withdraw_unbonded {
Event::Created { depositor: 10, pool_id: 1 },
Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true },
Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: false },
Event::Unbonded { member: 10, pool_id: 1, balance: 7, points: 7 },
Event::Unbonded { member: 10, pool_id: 1, balance: 3, points: 3 },
Event::Unbonded { member: 10, pool_id: 1, balance: 10, points: 10 },
Event::Unbonded { member: 10, pool_id: 1, balance: 7, points: 7, era: 3 },
Event::Unbonded { member: 10, pool_id: 1, balance: 3, points: 3, era: 4 },
Event::Unbonded { member: 10, pool_id: 1, balance: 10, points: 10, era: 4 },
Event::Withdrawn { member: 10, pool_id: 1, balance: 7, points: 7 }
]
);
Expand Down
Loading