Skip to content

Commit

Permalink
Augment precision for division and use divRound
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzamontiel committed Nov 29, 2024
1 parent c315e70 commit 2a9166b
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions test/suites/smoke/test-staking-rewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { rateLimiter, getPreviousRound, getNextRound } from "../../helpers";
import { AccountId20, Block } from "@polkadot/types/interfaces";

const limiter = rateLimiter();
const DIV_PRECISION = 1000;

interface RoundData {
data: PalletParachainStakingRoundInfo;
Expand Down Expand Up @@ -582,7 +583,12 @@ describeSuite({
).round.ideal;
const idealIssuance = new Perbill(idealInflation).of(totalIssuance);

totalRoundIssuance = roundDuration.mul(idealIssuance).div(idealDuration);
totalRoundIssuance = roundDuration
.mul(idealIssuance)
.mul(new BN(DIV_PRECISION))
.div(idealDuration)
.divRound(new BN(DIV_PRECISION));

} else {
// Always apply max inflation
// It works because the total staked amount is already 1000 times more than the max on
Expand Down Expand Up @@ -630,9 +636,9 @@ describeSuite({
payment.roundToPay.data.current
);

let percentage = 0;
let percentage = new BN(0);
inflationDistributionConfig.forEach((config) => {
percentage += config.percent.toNumber();
percentage = percentage.add(config.percent);
});
const reservedPercentage = new Percent(percentage);
// total expected staking reward minus the amount reserved for parachain bond
Expand Down

0 comments on commit 2a9166b

Please sign in to comment.