difftreelog
feat speedup inflation pallet
in: master
4 files changed
js-packages/tests/creditFeesToTreasury.seqtest.tsdiffbeforeafterboth--- a/js-packages/tests/creditFeesToTreasury.seqtest.ts
+++ b/js-packages/tests/creditFeesToTreasury.seqtest.ts
@@ -33,7 +33,7 @@
const blockInterval = inflationBlockInterval.toNumber();
const unsubscribe = await api.rpc.chain.subscribeNewHeads(head => {
const currentBlock = head.number.toNumber();
- if(currentBlock % blockInterval < blockInterval - 10) {
+ if(currentBlock % blockInterval < blockInterval - 2) {
unsubscribe();
resolve();
} else {
js-packages/tests/inflation.seqtest.tsdiffbeforeafterboth--- a/js-packages/tests/inflation.seqtest.ts
+++ b/js-packages/tests/inflation.seqtest.ts
@@ -17,6 +17,8 @@
import type {IKeyringPair} from '@polkadot/types/types';
import {expect, itSub, usingPlaygrounds} from './util/index.js';
+const TREASURY = '5EYCAe5ijiYfyeZ2JJCGq56LmPyNRAKzpG4QkoQkkQNB5e6Z';
+
// todo:playgrounds requires sudo, look into on the later stage
describe('integration test: Inflation', () => {
let superuser: IKeyringPair;
@@ -55,4 +57,23 @@
expect(Math.abs(Number(expectedInflation))).to.be.lessThanOrEqual(tolerance);
});
+
+ itSub('Inflation happens after inflation block interval', async ({helper}) => {
+ const api = helper.getApi();
+ const blockInterval = await api.consts.inflation.inflationBlockInterval.toNumber();
+
+ const relayBlock = (await api.query.parachainSystem.lastRelayChainBlockNumber()).toNumber();
+ await helper.executeExtrinsic(superuser, 'api.tx.sudo.sudo', [helper.constructApiCall('api.tx.inflation.startInflation', [relayBlock])]);
+ const blockInflation = (await helper.callRpc('api.query.inflation.blockInflation', []) as any).toBigInt();
+ const startBlock = (relayBlock + blockInterval) - (relayBlock % blockInterval) + 1;
+
+ await helper.wait.forRelayBlockNumber(startBlock);
+
+ const treasuryBalanceBefore = await helper.balance.getSubstrate(TREASURY);
+
+ await helper.wait.forRelayBlockNumber(startBlock + blockInterval);
+
+ const treasuryBalanceAfter = await helper.balance.getSubstrate(TREASURY);
+ expect(Number(treasuryBalanceAfter)).to.be.eqls(Number(treasuryBalanceBefore + blockInflation));
+ });
});
pallets/inflation/src/tests.rsdiffbeforeafterboth106106107parameter_types! {107parameter_types! {108 pub TreasuryAccountId: u64 = 1234;108 pub TreasuryAccountId: u64 = 1234;109 pub const InflationBlockInterval: u32 = 100; // every time per how many blocks inflation is applied109 pub const InflationBlockInterval: u32 = 10; // every time per how many blocks inflation is applied110 pub static MockBlockNumberProvider: u32 = 0;110 pub static MockBlockNumberProvider: u32 = 0;111}111}112112runtime/common/config/pallets/mod.rsdiffbeforeafterboth--- a/runtime/common/config/pallets/mod.rs
+++ b/runtime/common/config/pallets/mod.rs
@@ -102,7 +102,7 @@
}
parameter_types! {
- pub const InflationBlockInterval: BlockNumber = 100; // every time per how many blocks inflation is applied
+ pub const InflationBlockInterval: BlockNumber = 10; // every time per how many blocks inflation is applied
}
/// Pallet-inflation needs block number in on_initialize, where there is no `validation_data` exists yet