From 7812654443e25f2661397f93f4365c55fdc484f8 Mon Sep 17 00:00:00 2001 From: Gonza Montiel Date: Thu, 2 Jan 2025 08:15:59 -0300 Subject: [PATCH] test(smoke): fix inflation distribution calculation (#3065) * Augment precision for division and use divRound * add: cases for opposing scenarios * test(smoke): fix inflation distribution calculation --------- Co-authored-by: Pablo Labarta Co-authored-by: Rodrigo Quelhas <22591718+RomarQ@users.noreply.github.com> Co-authored-by: Rodrigo Quelhas --- test/suites/smoke/test-staking-rewards.ts | 54 +++++++++++++---------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/test/suites/smoke/test-staking-rewards.ts b/test/suites/smoke/test-staking-rewards.ts index 5cf6b850ad..9392a52089 100644 --- a/test/suites/smoke/test-staking-rewards.ts +++ b/test/suites/smoke/test-staking-rewards.ts @@ -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(); @@ -628,33 +642,30 @@ 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} \ @@ -662,11 +673,6 @@ describeSuite({ 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 \