git.delta.rocks / unique-network / refs/commits / 504df77ef385

difftreelog

source

tests/src/inflation.test.ts2.4 KiBsourcehistory
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import chai from 'chai';18import chaiAsPromised from 'chai-as-promised';19import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';2021chai.use(chaiAsPromised);22const expect = chai.expect;2324describe('integration test: Inflation', () => {25  it('First year inflation is 10%', async () => {26    await usingApi(async (api, privateKeyWrapper) => {2728      // Make sure non-sudo can't start inflation29      const tx = api.tx.inflation.startInflation(1);30      const bob = privateKeyWrapper('//Bob');31      await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.rejected;3233      // Start inflation on relay block 1 (Alice is sudo)34      const alice = privateKeyWrapper('//Alice');35      const sudoTx = api.tx.sudo.sudo(tx as any);36      await submitTransactionAsync(alice, sudoTx);3738      const blockInterval = (api.consts.inflation.inflationBlockInterval).toBigInt();39      const totalIssuanceStart = (await api.query.inflation.startingYearTotalIssuance()).toBigInt();40      const blockInflation = (await api.query.inflation.blockInflation()).toBigInt();4142      const YEAR = 5259600n;  // 6-second block. Blocks in one year43      // const YEAR = 2629800n; // 12-second block. Blocks in one year4445      const totalExpectedInflation = totalIssuanceStart / 10n;46      const totalActualInflation = blockInflation * YEAR / blockInterval;4748      const tolerance = 0.00001; // Relative difference per year between theoretical and actual inflation49      const expectedInflation = totalExpectedInflation / totalActualInflation - 1n;5051      expect(Math.abs(Number(expectedInflation))).to.be.lessThanOrEqual(tolerance);52    });53  });5455});