Skip to content

Commit

Permalink
Merge branch 'master' into agustin-xcm-precompile-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzamontiel authored Jan 2, 2025
2 parents ea96231 + 7812654 commit 90fc581
Showing 1 changed file with 30 additions and 24 deletions.
54 changes: 30 additions & 24 deletions test/suites/smoke/test-staking-rewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,20 @@ describeSuite({
totalRoundIssuance = range.max;
}

const delayedPayout = (
await payment.rewardRound.firstBlockApi.query.parachainStaking.delayedPayouts(
payment.roundToPay.data.current
)
).unwrap();

// Validate round issuance calculation
expect(
delayedPayout.roundIssuance.eq(totalRoundIssuance),
`round issuance amounts do not match \
${delayedPayout.roundIssuance.toString()} != ${totalRoundIssuance.toString()} \
for round ${payment.roundToPay.data.current.toString()}`
).to.be.true;

const collatorCommissionRate =
await payment.rewardRound.priorBlockApi.query.parachainStaking.collatorCommission();

Expand Down Expand Up @@ -628,45 +642,37 @@ describeSuite({
payment.roundToPay.data.current
);

let percentage = 0;
let reservedReward = new BN(0);
// total expected staking reward minus the amount reserved for parachain bond
let totalStakingReward = totalRoundIssuance;
inflationDistributionConfig.forEach((config) => {
percentage += config.percent.toNumber();
const distribution = new Percent(config.percent.toBn()).of(totalRoundIssuance);
totalStakingReward = totalStakingReward.sub(distribution);
reservedReward = reservedReward.add(distribution);
});
const reservedPercentage = new Percent(percentage);
// total expected staking reward minus the amount reserved for parachain bond
const totalStakingReward = (() => {
const reservedReward = reservedPercentage.of(totalRoundIssuance);
if (!reservedInflation.isZero()) {
expect(
reservedReward.eq(reservedInflation),
`parachain bond amount does not match \
${reservedReward.toString()} != ${reservedInflation.toString()} \
for round ${payment.roundToPay.data.current.toString()}`
).to.be.true;
return totalRoundIssuance.sub(reservedReward);
}

return totalRoundIssuance;
})();
if (!reservedInflation.isZero()) {
expect(
reservedReward.eq(reservedInflation),
`parachain bond amount does not match \
${reservedReward.toString()} != ${reservedInflation.toString()} \
for round ${payment.roundToPay.data.current.toString()}`
).to.be.true;
}

const totalBondReward = totalStakingReward.sub(totalCollatorCommissionReward);

log(`
paidRoundNumber ${payment.roundToPay.data.current.toString()}
totalRoundIssuance ${totalRoundIssuance.toString()}
reservedInflation ${reservedInflation} \
(${reservedPercentage} * totalRoundIssuance)
reservedInflation ${reservedInflation}
totalCollatorCommissionReward ${totalCollatorCommissionReward.toString()} \
(${collatorCommissionRate} * totalRoundIssuance)
totalStakingReward ${totalStakingReward} \
(totalRoundIssuance - reservedInflation)
totalBondReward ${totalBondReward} \
(totalStakingReward - totalCollatorCommissionReward)`);

const delayedPayout = (
await payment.rewardRound.firstBlockApi.query.parachainStaking.delayedPayouts(
payment.roundToPay.data.current
)
).unwrap();
expect(
delayedPayout.totalStakingReward.eq(totalStakingReward),
`reward amounts do not match \
Expand Down

0 comments on commit 90fc581

Please sign in to comment.