Additional mortal era tests (#2259)
* Additional moratl era tests * birth !== current (output the same)
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
.eslintrc.js
|
||||
**/build/*
|
||||
**/coverage/*
|
||||
**/node_modules/*
|
||||
|
||||
+2
-2
@@ -27,8 +27,8 @@
|
||||
"@babel/core": "^7.9.6",
|
||||
"@babel/register": "^7.9.0",
|
||||
"@babel/runtime": "^7.9.6",
|
||||
"@polkadot/dev": "^0.52.15",
|
||||
"@polkadot/ts": "^0.3.19",
|
||||
"@polkadot/dev": "^0.52.16",
|
||||
"@polkadot/ts": "^0.3.20",
|
||||
"@polkadot/typegen": "workspace:packages/typegen",
|
||||
"@types/jest": "^25.2.1",
|
||||
"@vuepress/plugin-search": "^1.4.1",
|
||||
|
||||
@@ -4,4 +4,11 @@
|
||||
|
||||
import BN from 'bn.js';
|
||||
|
||||
export const FALLBACK_MAX_HASH_COUNT = 250;
|
||||
|
||||
// default here to 5 min eras, adjusted based on the actual blocktime
|
||||
export const FALLBACK_PERIOD = new BN(6 * 1000);
|
||||
|
||||
export const MAX_FINALITY_LAG = new BN(5);
|
||||
|
||||
export const MORTAL_PERIOD = new BN(5 * 60 * 1000);
|
||||
|
||||
@@ -5,23 +5,19 @@
|
||||
import { Header, Index } from '@polkadot/types/interfaces';
|
||||
import { AnyNumber, Codec, IExtrinsicEra } from '@polkadot/types/types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { Observable, combineLatest, of } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { isNumber, isUndefined } from '@polkadot/util';
|
||||
|
||||
import { FALLBACK_PERIOD, MAX_FINALITY_LAG, MORTAL_PERIOD } from './constants';
|
||||
|
||||
interface Result {
|
||||
header: Header | null;
|
||||
mortalLength: number;
|
||||
nonce: Index;
|
||||
}
|
||||
|
||||
// default here to 5 min eras, adjusted based on the actual blocktime
|
||||
const FALLBACK_PERIOD = new BN(6 * 1000);
|
||||
const MAX_FINALITY_LAG = new BN(5);
|
||||
const MORTAL_PERIOD = new BN(5 * 60 * 1000);
|
||||
|
||||
function latestNonce (api: ApiInterfaceRx, address: string): Observable<Index> {
|
||||
return api.derive.balances.account(address).pipe(
|
||||
map(({ accountNonce }): Index => accountNonce)
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
"@polkadot/util": "^2.9.1",
|
||||
"@polkadot/util-crypto": "^2.9.1",
|
||||
"bn.js": "^5.1.1",
|
||||
"eventemitter3": "^4.0.0",
|
||||
"eventemitter3": "^4.0.1",
|
||||
"rxjs": "^6.5.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
"@polkadot/util": "^2.9.1",
|
||||
"@polkadot/util-crypto": "^2.9.1",
|
||||
"bn.js": "^5.1.1",
|
||||
"eventemitter3": "^4.0.0",
|
||||
"eventemitter3": "^4.0.1",
|
||||
"isomorphic-fetch": "^2.2.1",
|
||||
"websocket": "^1.0.31"
|
||||
},
|
||||
|
||||
@@ -45,4 +45,42 @@ describe('ExtrinsicEra', (): void => {
|
||||
expect(json).toEqual({ MortalEra: '0x4e9c' });
|
||||
expect(new ExtrinsicEra(registry, json).toU8a()).toEqual(u8a);
|
||||
});
|
||||
|
||||
it('creates from an actual valid era', (): void => {
|
||||
const currBlock = 2251519;
|
||||
const mortalEra = new ExtrinsicEra(registry, '0xc503').asMortalEra;
|
||||
|
||||
expect(mortalEra.period.toNumber()).toEqual(64);
|
||||
expect(mortalEra.phase.toNumber()).toEqual(60);
|
||||
expect(mortalEra.birth(currBlock)).toEqual(2251516);
|
||||
expect(mortalEra.death(currBlock)).toEqual(2251580);
|
||||
});
|
||||
|
||||
it('creates for an actual era (2)', (): void => {
|
||||
const mortalEra = new ExtrinsicEra(registry, '0x8502').asMortalEra;
|
||||
|
||||
expect(mortalEra.period.toNumber()).toEqual(64);
|
||||
expect(mortalEra.phase.toNumber()).toEqual(40);
|
||||
});
|
||||
|
||||
it('creates form an actual era (3)', (): void => {
|
||||
const mortalEra = new ExtrinsicEra(registry, '0x6502').asMortalEra;
|
||||
|
||||
expect(mortalEra.period.toNumber()).toEqual(64);
|
||||
expect(mortalEra.phase.toNumber()).toEqual(38);
|
||||
});
|
||||
|
||||
it('creates from an actual era, 100 block hash count', (): void => {
|
||||
const mortalEra = new ExtrinsicEra(registry, '0xd607').asMortalEra;
|
||||
|
||||
expect(mortalEra.period.toNumber()).toEqual(128);
|
||||
expect(mortalEra.phase.toNumber()).toEqual(125);
|
||||
});
|
||||
|
||||
it('creates from a actual 2400 block hash count', (): void => {
|
||||
const mortalEra = new ExtrinsicEra(registry, '0x9be3').asMortalEra;
|
||||
|
||||
expect(mortalEra.period.toNumber()).toEqual(4096);
|
||||
expect(mortalEra.phase.toNumber()).toEqual(3641);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user