1234567891011121314151617import type {IKeyringPair} from '@polkadot/types/types';18import {expect, itSub, usingPlaygrounds} from './util/index.js';1920const TREASURY = '5EYCAe5ijiYfyeZ2JJCGq56LmPyNRAKzpG4QkoQkkQNB5e6Z';212223describe('integration test: Inflation', () => {24 let superuser: IKeyringPair;2526 before(async () => {27 await usingPlaygrounds(async (helper, privateKey) => {28 superuser = await privateKey('//Alice');29 const api = helper.getApi();3031 const relayBlock = (await api.query.parachainSystem.lastRelayChainBlockNumber()).toNumber();32 await expect(helper.executeExtrinsic(superuser, 'api.tx.sudo.sudo', [helper.constructApiCall('api.tx.inflation.startInflation', [relayBlock])])).to.not.be.rejected;33 });34 });3536 itSub('First year inflation is 10%', async ({helper}) => {37 38 const [bob] = await helper.arrange.createAccounts([10n], superuser);3940 await expect(helper.executeExtrinsic(bob, 'api.tx.inflation.startInflation', [1])).to.be.rejectedWith(/BadOrigin/);4142 43 await expect(helper.executeExtrinsic(superuser, 'api.tx.inflation.startInflation', [1])).to.be.rejectedWith(/BadOrigin/);4445 const blockInterval = (helper.getApi().consts.inflation.inflationBlockInterval as any).toBigInt();46 const totalIssuanceStart = ((await helper.callRpc('api.query.inflation.startingYearTotalIssuance', [])) as any).toBigInt();47 const blockInflation = (await helper.callRpc('api.query.inflation.blockInflation', []) as any).toBigInt();4849 const YEAR = 5259600n; 50 5152 const totalExpectedInflation = totalIssuanceStart / 10n;53 const totalActualInflation = blockInflation * YEAR / blockInterval;5455 const tolerance = 0.00001; 56 const expectedInflation = totalExpectedInflation / totalActualInflation - 1n;5758 expect(Math.abs(Number(expectedInflation))).to.be.lessThanOrEqual(tolerance);59 });6061 62 itSub('Inflation happens after inflation block interval', async ({helper}) => {63 const api = helper.getApi();64 const blockInterval = api.consts.inflation.inflationBlockInterval.toNumber();6566 const relayBlock = 0; 67 68 const startBlock = (relayBlock + blockInterval) - (relayBlock % blockInterval) + 1;6970 await helper.wait.forRelayBlockNumber(startBlock);7172 const treasuryBalanceBefore = await helper.balance.getSubstrate(TREASURY);7374 await helper.wait.forRelayBlockNumber(startBlock + blockInterval + 1);7576 const treasuryBalanceAfter = await helper.balance.getSubstrate(TREASURY);77 expect(Number(treasuryBalanceAfter)).to.be.equal(Number(treasuryBalanceBefore)); 78 });79});