Skip to content

Commit a217ac1

Browse files
committed
staking inflation rewards test
1 parent 58d6401 commit a217ac1

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

tests/staking/inflation.test.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { expect } from 'vitest'
2+
import { u16 } from '@polkadot/types'
3+
import { given } from '../../helpers'
4+
5+
given('astar')('Reward payouts based on inflation (decayed)', async ({ networks: { astar } }) => {
6+
const advanceNextEra = async () => {
7+
const state = await astar.api.query.dappStaking.activeProtocolState<any>()
8+
await astar.dev.newBlock({ count: 1, unsafeBlockHeight: state.nextEraStart.toNumber() })
9+
}
10+
11+
const palletVersion = (await astar.api.query.inflation.palletVersion<u16>()).toNumber()
12+
const config = (await astar.api.query.inflation.activeInflationConfig()).toJSON() as Record<string, any>
13+
14+
// Scenario 1: baseline, no decay
15+
// new parameter on version 2
16+
if (palletVersion >= 2) {
17+
config.decayRate = 1_000_000_000_000_000_000n; // 100%
18+
config.decayFactor = 1_000_000_000_000_000_000n; // 100%
19+
}
20+
21+
await astar.dev.setStorage({
22+
balances: {
23+
totalIssuance: 8_400_000_000_000_000_000_000_000_000n, // 8.4B
24+
},
25+
inflation: {
26+
activeInflationConfig: config,
27+
}
28+
});
29+
30+
await advanceNextEra()
31+
32+
const issuance_1 = (await astar.api.query.balances.totalIssuance()).toBigInt()
33+
expect(issuance_1).toBeGreaterThan(8_400_000_000_000_000_000_000_000_000n)
34+
35+
// Scenario 2: decayRate = 0%, expect no rewards
36+
if (palletVersion >= 2) {
37+
config.decayRate = 0n
38+
await astar.dev.setStorage({
39+
inflation: { activeInflationConfig: config },
40+
})
41+
42+
await advanceNextEra()
43+
44+
const activeConfig = (await astar.api.query.inflation.activeInflationConfig()).toJSON() as Record<string, any>
45+
const decay_factor = activeConfig.decayFactor
46+
expect(BigInt(decay_factor)).toBe(0n)
47+
48+
const issuance_2 = (await astar.api.query.balances.totalIssuance()).toBigInt()
49+
expect(issuance_2).toBe(issuance_1) // no increase
50+
}
51+
})

0 commit comments

Comments
 (0)