git.delta.rocks / unique-network / refs/commits / 1f6cb5bfa45d

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';20import privateKey from './substrate/privateKey';2122chai.use(chaiAsPromised);23const expect = chai.expect;2425describe('integration test: Inflation', () => {26  it('First year inflation is 10%', async () => {27    await usingApi(async (api) => {2829      // Make sure non-sudo can't start inflation30      const tx = api.tx.inflation.startInflation(1);31      const bob = privateKey('//Bob');32      await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.rejected;3334      // Start inflation on relay block 1 (Alice is sudo)35      const alice = privateKey('//Alice');36      const sudoTx = api.tx.sudo.sudo(tx as any);37      await submitTransactionAsync(alice, sudoTx);3839      const blockInterval = (api.consts.inflation.inflationBlockInterval).toBigInt();40      const totalIssuanceStart = (await api.query.inflation.startingYearTotalIssuance()).toBigInt();41      const blockInflation = (await api.query.inflation.blockInflation()).toBigInt();4243      const YEAR = 5259600n;  // 6-second block. Blocks in one year44      // const YEAR = 2629800n; // 12-second block. Blocks in one year4546      const totalExpectedInflation = totalIssuanceStart / 10n;47      const totalActualInflation = blockInflation * YEAR / blockInterval;4849      const tolerance = 0.00001; // Relative difference per year between theoretical and actual inflation50      const expectedInflation = totalExpectedInflation / totalActualInflation - 1n;5152      expect(Math.abs(Number(expectedInflation))).to.be.lessThanOrEqual(tolerance);53    });54  });5556});