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 itSub('Inflation happens after inflation block interval', async ({helper}) => {62 const api = helper.getApi();63 const blockInterval = await api.consts.inflation.inflationBlockInterval.toNumber();6465 const relayBlock = (await api.query.parachainSystem.lastRelayChainBlockNumber()).toNumber();66 const blockInflation = (await helper.callRpc('api.query.inflation.blockInflation', []) as any).toBigInt();67 const startBlock = (relayBlock + blockInterval) - (relayBlock % blockInterval) + 1;6869 await helper.wait.forRelayBlockNumber(startBlock);7071 const treasuryBalanceBefore = await helper.balance.getSubstrate(TREASURY);7273 await helper.wait.forRelayBlockNumber(startBlock + blockInterval + 1);7475 const treasuryBalanceAfter = await helper.balance.getSubstrate(TREASURY);76 expect(Number(treasuryBalanceAfter)).to.be.eqls(Number(treasuryBalanceBefore + blockInflation));77 });78});