Adjust known-types to use @polkadot/networks (#3138)

This commit is contained in:
Jaco Greeff
2021-02-02 11:06:52 +01:00
committed by GitHub
parent 89f16f3123
commit 41b4cd5c55
8 changed files with 79 additions and 39 deletions
+1
View File
@@ -13,6 +13,7 @@
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/types-known#readme",
"dependencies": {
"@babel/runtime": "^7.12.5",
"@polkadot/networks": "^5.5.1",
"@polkadot/types": "3.7.3-0",
"@polkadot/util": "^5.5.1",
"bn.js": "^4.11.9"
@@ -1,10 +1,48 @@
// Copyright 2017-2021 @polkadot/types-known authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { assert, u8aEq } from '@polkadot/util';
import all from '.';
describe('upgrades', (): void => {
it('is valid', (): void => {
expect(all).toBeDefined();
});
it('has a valid entries for Kusama', (): void => {
const kusama = all.find(({ network }) => network === 'kusama');
assert(kusama, 'Unable to find the entry for Kusama');
const version = kusama.versions[17];
expect(u8aEq(kusama.genesisHash, '0xb0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafe')).toBe(true);
expect(version.blockNumber.eqn(901442)).toBe(true);
expect(version.specVersion.eqn(1045)).toBe(true);
});
it('has a valid entries for Polkadot', (): void => {
const polkadot = all.find(({ network }) => network === 'polkadot');
assert(polkadot, 'Unable to find the entry for Polkadot');
const version = polkadot.versions[19];
expect(u8aEq(polkadot.genesisHash, '0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3')).toBe(true);
expect(version.blockNumber.eqn(2436698)).toBe(true);
expect(version.specVersion.eqn(26)).toBe(true);
});
it('has a valid entries for Westend', (): void => {
const westend = all.find(({ network }) => network === 'westend');
assert(westend, 'Unable to find the entry for Polkadot');
const version = westend.versions[23];
expect(u8aEq(westend.genesisHash, '0xe143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e')).toBe(true);
expect(version.blockNumber.eqn(4207800)).toBe(true);
expect(version.specVersion.eqn(48)).toBe(true);
});
});
+14 -2
View File
@@ -6,12 +6,20 @@ import type { ChainUpgradesRaw } from './types';
import BN from 'bn.js';
import networks from '@polkadot/networks';
import { assert, hexToU8a } from '@polkadot/util';
import kusama from './kusama';
import polkadot from './polkadot';
import westend from './westend';
// testnets are not available in the networks map
const NET_EXTRA: Record<string, { genesisHash: string[] }> = {
westend: {
genesisHash: ['0xe143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e']
}
};
/** @internal */
function checkOrder (network: string, versions: [number, number][]): [number, number][] {
const ooo = versions.filter((curr, index): boolean => {
@@ -28,9 +36,13 @@ function checkOrder (network: string, versions: [number, number][]): [number, nu
}
/** @internal */
function rawToFinal (network: string, { genesisHash, versions }: ChainUpgradesRaw): ChainUpgrades {
function rawToFinal (network: string, versions: ChainUpgradesRaw): ChainUpgrades {
const chain = networks.find((n) => n.network === network) || NET_EXTRA[network];
assert(chain, `Unable to find info for chain ${network}`);
return {
genesisHash: hexToU8a(genesisHash),
genesisHash: hexToU8a(chain.genesisHash[0]),
network,
versions: checkOrder(network, versions).map(([blockNumber, specVersion]) => ({
blockNumber: new BN(blockNumber),
+10 -13
View File
@@ -3,18 +3,15 @@
import type { ChainUpgradesRaw } from './types';
const upgrades: ChainUpgradesRaw = {
genesisHash: '0xb0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafe',
versions: [
[0, 1020], [26669, 1021], [38245, 1022], [54248, 1023], [59659, 1024],
[67651, 1025], [82191, 1027], [83238, 1028], [101503, 1029], [203466, 1030],
[295787, 1031], [461692, 1032], [504329, 1033], [569327, 1038], [587687, 1039],
[653183, 1040], [693488, 1042], [901442, 1045], [1375086, 1050], [1445458, 1051],
[1472960, 1052], [1475648, 1053], [1491596, 1054], [1574408, 1055], [2064961, 1058],
[2201991, 1062], [2671528, 2005], [2704202, 2007], [2728002, 2008], [2832534, 2011],
[2962294, 2012], [3240000, 2013], [3274408, 2015], [3323565, 2019], [3534175, 2022],
[3860281, 2023], [4143129, 2024], [4401242, 2025], [4841367, 2026], [5961600, 2027]
]
};
const upgrades: ChainUpgradesRaw = [
[0, 1020], [26669, 1021], [38245, 1022], [54248, 1023], [59659, 1024],
[67651, 1025], [82191, 1027], [83238, 1028], [101503, 1029], [203466, 1030],
[295787, 1031], [461692, 1032], [504329, 1033], [569327, 1038], [587687, 1039],
[653183, 1040], [693488, 1042], [901442, 1045], [1375086, 1050], [1445458, 1051],
[1472960, 1052], [1475648, 1053], [1491596, 1054], [1574408, 1055], [2064961, 1058],
[2201991, 1062], [2671528, 2005], [2704202, 2007], [2728002, 2008], [2832534, 2011],
[2962294, 2012], [3240000, 2013], [3274408, 2015], [3323565, 2019], [3534175, 2022],
[3860281, 2023], [4143129, 2024], [4401242, 2025], [4841367, 2026], [5961600, 2027]
];
export default upgrades;
@@ -3,14 +3,11 @@
import type { ChainUpgradesRaw } from './types';
const upgrades: ChainUpgradesRaw = {
genesisHash: '0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3',
versions: [
[0, 0], [29231, 1], [188836, 5], [199405, 6], [214264, 7],
[244358, 8], [303079, 9], [314201, 10], [342400, 11], [443963, 12],
[528470, 13], [687751, 14], [746085, 15], [787923, 16], [799302, 17],
[1205128, 18], [1603423, 23], [1733218, 24], [2005673, 25], [2436698, 26]
]
};
const upgrades: ChainUpgradesRaw = [
[0, 0], [29231, 1], [188836, 5], [199405, 6], [214264, 7],
[244358, 8], [303079, 9], [314201, 10], [342400, 11], [443963, 12],
[528470, 13], [687751, 14], [746085, 15], [787923, 16], [799302, 17],
[1205128, 18], [1603423, 23], [1733218, 24], [2005673, 25], [2436698, 26]
];
export default upgrades;
+1 -4
View File
@@ -1,7 +1,4 @@
// Copyright 2017-2021 @polkadot/types-known authors & contributors
// SPDX-License-Identifier: Apache-2.0
export interface ChainUpgradesRaw {
genesisHash: string;
versions: [number, number][];
}
export type ChainUpgradesRaw = [number, number][];
+7 -10
View File
@@ -3,15 +3,12 @@
import type { ChainUpgradesRaw } from './types';
const upgrades: ChainUpgradesRaw = {
genesisHash: '0xe143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e',
versions: [
[214356, 4], [392764, 7], [409740, 8], [809976, 20], [877581, 24],
[879238, 25], [889472, 26], [902937, 27], [932751, 28], [991142, 29],
[1030162, 31], [1119657, 32], [1199282, 33], [1342534, 34], [1392263, 35],
[1431703, 36], [1433369, 37], [1490972, 41], [2087397, 43], [2316688, 44],
[2549864, 45], [3925782, 46], [3925843, 47], [4207800, 48]
]
};
const upgrades: ChainUpgradesRaw = [
[214356, 4], [392764, 7], [409740, 8], [809976, 20], [877581, 24],
[879238, 25], [889472, 26], [902937, 27], [932751, 28], [991142, 29],
[1030162, 31], [1119657, 32], [1199282, 33], [1342534, 34], [1392263, 35],
[1431703, 36], [1433369, 37], [1490972, 41], [2087397, 43], [2316688, 44],
[2549864, 45], [3925782, 46], [3925843, 47], [4207800, 48]
];
export default upgrades;
+2 -1
View File
@@ -1786,7 +1786,7 @@ __metadata:
languageName: unknown
linkType: soft
"@polkadot/networks@npm:5.5.1":
"@polkadot/networks@npm:5.5.1, @polkadot/networks@npm:^5.5.1":
version: 5.5.1
resolution: "@polkadot/networks@npm:5.5.1"
dependencies:
@@ -1869,6 +1869,7 @@ __metadata:
resolution: "@polkadot/types-known@workspace:packages/types-known"
dependencies:
"@babel/runtime": ^7.12.5
"@polkadot/networks": ^5.5.1
"@polkadot/types": 3.7.3-0
"@polkadot/util": ^5.5.1
"@types/bn.js": ^4.11.6