Upgrades with API list (#5164)
* Add runtime APIs to known list * First pass * Add generated * Rerun * tsconfig adjustments * Pass APIs through * Missing package.json entry
This commit is contained in:
@@ -207,7 +207,7 @@ export abstract class Init<ApiType extends ApiTypes> extends Decorate<ApiType> {
|
||||
const [firstVersion, lastVersion] = getUpgradeVersion(this._genesisHash, header.number);
|
||||
const version = this.registry.createType('RuntimeVersionPartial',
|
||||
(firstVersion && (lastVersion || firstVersion.specVersion.eq(this._runtimeVersion.specVersion)))
|
||||
? { specName: this._runtimeVersion.specName, specVersion: firstVersion.specVersion }
|
||||
? { apis: firstVersion.apis, specName: this._runtimeVersion.specName, specVersion: firstVersion.specVersion }
|
||||
: await firstValueFrom(this._rpcCore.state.getRuntimeVersion.raw(header.parentHash))
|
||||
);
|
||||
|
||||
|
||||
@@ -29,5 +29,8 @@
|
||||
"@polkadot/types-codec": "9.2.2-0-x",
|
||||
"@polkadot/types-create": "9.2.2-0-x",
|
||||
"@polkadot/util": "^10.1.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/api": "9.2.2-0-x"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
// Copyright 2017-2022 @polkadot/types-known authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { HexString } from '@polkadot/util/types';
|
||||
import type { ChainUpgradesGenerated } from '../types';
|
||||
|
||||
import fs from 'fs';
|
||||
|
||||
import { ApiPromise, WsProvider } from '@polkadot/api';
|
||||
|
||||
import * as allMan from '../manual';
|
||||
import * as allGen from '.';
|
||||
|
||||
const keys = <const> ['kusama', 'polkadot', 'westend'];
|
||||
const urls = {
|
||||
kusama: 'wss://kusama-rpc.polkadot.io',
|
||||
polkadot: 'wss://rpc.polkadot.io',
|
||||
westend: 'wss://westend-rpc.polkadot.io'
|
||||
};
|
||||
|
||||
describe.each(keys)('generate %s', (chain): void => {
|
||||
const avail = allGen[chain];
|
||||
const final: ChainUpgradesGenerated = [];
|
||||
let api: ApiPromise;
|
||||
|
||||
beforeAll(async (): Promise<void> => {
|
||||
api = await ApiPromise.create({ provider: new WsProvider(urls[chain]) });
|
||||
});
|
||||
|
||||
afterAll(async (): Promise<void> => {
|
||||
fs.writeFileSync(`packages/types-known/src/upgrades/e2e/${chain}.ts`, `// Copyright 2017-${new Date().getFullYear()} @polkadot/types-known authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Auto-generated from on-chain data & manual definitions, do not edit
|
||||
/* eslint-disable quotes, comma-spacing */
|
||||
|
||||
import type { ChainUpgradesGenerated } from '../types';
|
||||
|
||||
const upgrades: ChainUpgradesGenerated = ${JSON.stringify(final)};
|
||||
|
||||
export default upgrades;
|
||||
`);
|
||||
await api.disconnect();
|
||||
});
|
||||
|
||||
it.each(allMan[chain])('%s', async (blockNumber, specVersion): Promise<void> => {
|
||||
const found = avail.find(([n, s]) => n === blockNumber && s === specVersion);
|
||||
|
||||
if (found) {
|
||||
final.push(found);
|
||||
} else {
|
||||
const blockHash = await api.rpc.chain.getBlockHash(blockNumber + 1);
|
||||
const runtime = await api.rpc.state.getRuntimeVersion(blockHash);
|
||||
const apis = runtime.apis.map(([api, version]): [HexString, number] => [api.toHex(), version.toNumber()]);
|
||||
|
||||
final.push([blockNumber, specVersion, apis]);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,6 @@
|
||||
// Copyright 2017-2022 @polkadot/types-known authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export { default as kusama } from './kusama';
|
||||
export { default as polkadot } from './polkadot';
|
||||
export { default as westend } from './westend';
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -3,6 +3,8 @@
|
||||
|
||||
import { u8aEq } from '@polkadot/util';
|
||||
|
||||
import * as allGen from './e2e';
|
||||
import * as allMan from './manual';
|
||||
import all from '.';
|
||||
|
||||
interface TestDef {
|
||||
@@ -38,6 +40,27 @@ const TESTS: TestDef[] = [
|
||||
}
|
||||
];
|
||||
|
||||
describe('generated', (): void => {
|
||||
it('should have all the chains', (): void => {
|
||||
expect(Object.keys(allMan).sort()).toEqual(Object.keys(allGen).sort());
|
||||
});
|
||||
|
||||
describe.each(Object.keys(allMan))('%s', (chain): void => {
|
||||
it('should have all generated', (): void => {
|
||||
const missing = allMan[chain as keyof typeof allMan].filter(([na, sa]) =>
|
||||
!allGen[chain as keyof typeof allGen].some(([nb, sb]) =>
|
||||
nb === na &&
|
||||
sb === sa
|
||||
)
|
||||
);
|
||||
|
||||
if (missing.length !== 0) {
|
||||
throw new Error(`${chain}:: missing generated apis found, run yarn test:one packages/types-known/src/upgrades/e2e`);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('upgrades', (): void => {
|
||||
TESTS.forEach(({ genesisHash, network, versions }): void => {
|
||||
describe(network, (): void => {
|
||||
|
||||
@@ -2,16 +2,12 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ChainUpgrades } from '@polkadot/types/types';
|
||||
import type { ChainUpgradesRaw } from './types';
|
||||
import type { ChainUpgradesGenerated } from './types';
|
||||
|
||||
import { selectableNetworks } from '@polkadot/networks';
|
||||
import { BN, hexToU8a, stringify } from '@polkadot/util';
|
||||
|
||||
import kusama from './kusama';
|
||||
import polkadot from './polkadot';
|
||||
import westend from './westend';
|
||||
|
||||
const allKnown = { kusama, polkadot, westend };
|
||||
import * as allKnown from './e2e';
|
||||
|
||||
// testnets are not available in the networks map
|
||||
const NET_EXTRA: Record<string, { genesisHash: string[] }> = {
|
||||
@@ -21,7 +17,7 @@ const NET_EXTRA: Record<string, { genesisHash: string[] }> = {
|
||||
};
|
||||
|
||||
/** @internal */
|
||||
function checkOrder (network: string, versions: ChainUpgradesRaw): [number, number][] {
|
||||
function checkOrder (network: string, versions: ChainUpgradesGenerated): ChainUpgradesGenerated {
|
||||
const ooo = versions.filter((curr, index): boolean => {
|
||||
const prev = versions[index - 1];
|
||||
|
||||
@@ -38,7 +34,7 @@ function checkOrder (network: string, versions: ChainUpgradesRaw): [number, numb
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function mapRaw ([network, versions]: [string, ChainUpgradesRaw]): ChainUpgrades {
|
||||
function mapRaw ([network, versions]: [string, ChainUpgradesGenerated]): ChainUpgrades {
|
||||
const chain = selectableNetworks.find((n) => n.network === network) || NET_EXTRA[network];
|
||||
|
||||
if (!chain) {
|
||||
@@ -48,7 +44,8 @@ function mapRaw ([network, versions]: [string, ChainUpgradesRaw]): ChainUpgrades
|
||||
return {
|
||||
genesisHash: hexToU8a(chain.genesisHash[0]),
|
||||
network,
|
||||
versions: checkOrder(network, versions).map(([blockNumber, specVersion]) => ({
|
||||
versions: checkOrder(network, versions).map(([blockNumber, specVersion, apis]) => ({
|
||||
apis,
|
||||
blockNumber: new BN(blockNumber),
|
||||
specVersion: new BN(specVersion)
|
||||
}))
|
||||
@@ -56,6 +53,6 @@ function mapRaw ([network, versions]: [string, ChainUpgradesRaw]): ChainUpgrades
|
||||
}
|
||||
|
||||
// Type overrides for specific spec types & versions as given in runtimeVersion
|
||||
const upgrades = Object.entries(allKnown).map(mapRaw);
|
||||
const upgrades = Object.entries<ChainUpgradesGenerated>(allKnown).map(mapRaw);
|
||||
|
||||
export default upgrades;
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
// Copyright 2017-2022 @polkadot/types-known authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export { default as kusama } from './kusama';
|
||||
export { default as polkadot } from './polkadot';
|
||||
export { default as westend } from './westend';
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
// Copyright 2017-2022 @polkadot/types-known authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ChainUpgradesRaw } from './types';
|
||||
import type { ChainUpgradesManual } from '../types';
|
||||
|
||||
const upgrades: ChainUpgradesRaw = [
|
||||
const upgrades: ChainUpgradesManual = [
|
||||
[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],
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
// Copyright 2017-2022 @polkadot/types-known authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ChainUpgradesRaw } from './types';
|
||||
import type { ChainUpgradesManual } from '../types';
|
||||
|
||||
const upgrades: ChainUpgradesRaw = [
|
||||
const upgrades: ChainUpgradesManual = [
|
||||
[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],
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
// Copyright 2017-2022 @polkadot/types-known authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ChainUpgradesRaw } from './types';
|
||||
import type { ChainUpgradesManual } from '../types';
|
||||
|
||||
const upgrades: ChainUpgradesRaw = [
|
||||
const upgrades: ChainUpgradesManual = [
|
||||
[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],
|
||||
@@ -1,4 +1,10 @@
|
||||
// Copyright 2017-2022 @polkadot/types-known authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { HexString } from '@polkadot/util/types';
|
||||
|
||||
export type ChainUpgradesRaw = [number, number][];
|
||||
|
||||
export type ChainUpgradesGenerated = [number, number, [HexString, number][]][];
|
||||
|
||||
export type ChainUpgradesManual = [number, number][];
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
"outDir": "./build",
|
||||
"rootDir": "./src"
|
||||
},
|
||||
"exclude": [
|
||||
"**/*.spec.ts"
|
||||
],
|
||||
"references": [
|
||||
{ "path": "../types/tsconfig.build.json" },
|
||||
{ "path": "../types-codec/tsconfig.build.json" },
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"baseUrl": "..",
|
||||
"outDir": "./build",
|
||||
"rootDir": "./src",
|
||||
"emitDeclarationOnly": false,
|
||||
"resolveJsonModule": true,
|
||||
"noEmit": true
|
||||
},
|
||||
"include": [
|
||||
"**/*.spec.ts"
|
||||
],
|
||||
"references": [
|
||||
{ "path": "../api/tsconfig.build.json" },
|
||||
{ "path": "../types/tsconfig.build.json" },
|
||||
{ "path": "../types-codec/tsconfig.build.json" },
|
||||
{ "path": "../types-create/tsconfig.build.json" }
|
||||
]
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import type { Observable } from 'rxjs';
|
||||
import type { BitVec, Bool, bool, Bytes, F32, f32, F64, f64, I8, i8, I16, i16, I32, i32, I64, i64, I128, i128, I256, i256, Json, Null, OptionBool, Raw, Text, Type, U8, u8, U16, u16, U32, u32, U64, u64, U128, u128, U256, u256, USize, usize } from '@polkadot/types-codec';
|
||||
import type { RegistryTypes } from '@polkadot/types-codec/types';
|
||||
import type { BN } from '@polkadot/util';
|
||||
import type { HexString } from '@polkadot/util/types';
|
||||
import type { GenericExtrinsic, GenericExtrinsicEra, GenericExtrinsicPayload, GenericSignerPayload } from '../extrinsic';
|
||||
import type { ExtDef } from '../extrinsic/signedExtensions/types';
|
||||
import type { GenericCall } from '../generic';
|
||||
@@ -38,6 +39,7 @@ export interface InterfaceTypes {
|
||||
export type CodecHasher = (data: Uint8Array) => Uint8Array;
|
||||
|
||||
export interface ChainUpgradeVersion {
|
||||
apis: [HexString, number][];
|
||||
blockNumber: BN;
|
||||
specVersion: BN;
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
{ "path": "./packages/types-create/tsconfig.build.json" },
|
||||
{ "path": "./packages/types-create/tsconfig.spec.json" },
|
||||
{ "path": "./packages/types-known/tsconfig.build.json" },
|
||||
{ "path": "./packages/types-known/tsconfig.spec.json" },
|
||||
{ "path": "./packages/types-support/tsconfig.build.json" }
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user