Add a Decorated class, which will be offline decorated Metadata (#1463)

* Move Metadata to api-metadata

* Make tests in api-metadata pass

* Make tests in api-metadata pass

* Refactor fromMetadata into decorated

* Fix some linting

* Replace headers

* Fix all tests

* Small lint

* Fix tests

* Fix metadata docs scripts

* Fix import ordering

* Add line breaks

* Grumbles

* Fix forgotten import

* rpcMetadata everywhere

* Fixlint

* s/api-metadata/metadata

* Fix latest tests

* Fix lint

* Fix tests
This commit is contained in:
Amaury Martiny
2019-11-12 12:06:18 +01:00
committed by Jaco Greeff
parent c87ba33893
commit 16e0ea9315
152 changed files with 510 additions and 413 deletions
+23 -25
View File
@@ -7,15 +7,13 @@ import '@polkadot/types/injector';
import { Balance } from '@polkadot/types/interfaces';
import { Codec } from '@polkadot/types/types';
import fromMetadata from '@polkadot/api-metadata/storage/fromMetadata';
import { Storage } from '@polkadot/api-metadata/storage/types';
import Metadata from '@polkadot/types/Metadata';
import rpcMetadataV3 from '@polkadot/types/Metadata/v3/static';
import rpcMetadataV4 from '@polkadot/types/Metadata/v4/static';
import rpcMetadataV5 from '@polkadot/types/Metadata/v5/static';
import rpcMetadataV6 from '@polkadot/types/Metadata/v6/static';
import rpcMetadataV7 from '@polkadot/types/Metadata/v7/static';
import rpcMetadataV8 from '@polkadot/types/Metadata/v8/static';
import Metadata from '@polkadot/metadata';
import rpcMetadataV3 from '@polkadot/metadata/Metadata/v3/static';
import rpcMetadataV4 from '@polkadot/metadata/Metadata/v4/static';
import rpcMetadataV5 from '@polkadot/metadata/Metadata/v5/static';
import rpcMetadataV6 from '@polkadot/metadata/Metadata/v6/static';
import rpcMetadataV7 from '@polkadot/metadata/Metadata/v7/static';
import rpcMetadataV8 from '@polkadot/metadata/Metadata/v8/static';
import Api from '.';
@@ -27,7 +25,7 @@ const BALANCE_KEYS = [
];
const OPTION_BYTES_HEX = '0x210100000000000000000000000000000000000000000000000000000000000000000000000000000000011b4d03dd8c01f1049143cf9c4c817e4b167f1d1b83e5c6f0f10d89ba1e7bce';
function formattingTests (version: string, storage: Storage, encodedValues: [string, string, string]): void {
function formattingTests (version: string, decorated: Metadata, encodedValues: [string, string, string]): void {
const [ENC_ONE, ENC_TWO, CONTRACT_KEY] = encodedValues;
describe(`formatting with Metadata ${version}`, (): void => {
@@ -80,7 +78,7 @@ function formattingTests (version: string, storage: Storage, encodedValues: [str
it('encodes key (with params), decoding response', (done): void => {
api.state
.getStorage<Balance>([storage.balances.freeBalance, ADDR_ONE])
.getStorage<Balance>([decorated.query.balances.freeBalance, ADDR_ONE])
.subscribe((value): void => {
expect(
provider.send
@@ -95,7 +93,7 @@ function formattingTests (version: string, storage: Storage, encodedValues: [str
it('returns the fallback result on not-found values', (done): void => {
api.state
.getStorage([storage.system.accountNonce, ADDR_ONE])
.getStorage([decorated.query.system.accountNonce, ADDR_ONE])
.subscribe((value): void => {
expect(value.toHex()).toEqual('0x00000000');
done();
@@ -105,8 +103,8 @@ function formattingTests (version: string, storage: Storage, encodedValues: [str
it('encodes multiple keys, decoding multiple results', (done): void => {
api.state.subscribeStorage<[Balance, Balance]>(
[
[storage.balances.freeBalance, ADDR_ONE],
[storage.balances.freeBalance, ADDR_TWO]
[decorated.query.balances.freeBalance, ADDR_ONE],
[decorated.query.balances.freeBalance, ADDR_TWO]
]
).subscribe((value): void => {
// console.error(value);
@@ -131,8 +129,8 @@ function formattingTests (version: string, storage: Storage, encodedValues: [str
it('handles the case where Option<Bytes> are retrieved', (done): void => {
const call = Number(version.slice(1)) <= 5
? storage.contract.pristineCode
: storage.contracts.pristineCode;
? decorated.query.contract.pristineCode
: decorated.query.contracts.pristineCode;
api.state
.subscribeStorage([[call, '0x00']])
@@ -147,7 +145,7 @@ function formattingTests (version: string, storage: Storage, encodedValues: [str
});
it('handles fallbacks for linked heads (new metadata only)', (done): void => {
const headKey = storage.staking.validators && storage.staking.validators.headKey;
const headKey = decorated.query.staking.validators && decorated.query.staking.validators.headKey;
// skip for old
if (!headKey) {
@@ -165,7 +163,7 @@ function formattingTests (version: string, storage: Storage, encodedValues: [str
});
it('handles fallbacks for linked maps (new metadata only)', (done): void => {
const headKey = storage.staking.validators && storage.staking.validators.headKey;
const headKey = decorated.query.staking.validators && decorated.query.staking.validators.headKey;
// skip for old
if (!headKey) {
@@ -173,7 +171,7 @@ function formattingTests (version: string, storage: Storage, encodedValues: [str
}
api.state
.subscribeStorage([[storage.staking.validators, '0x00']])
.subscribeStorage([[decorated.query.staking.validators, '0x00']])
.subscribe(([value]: Codec[]): void => {
expect(value).toBeDefined();
// console.error('linked falklback', value);
@@ -184,37 +182,37 @@ function formattingTests (version: string, storage: Storage, encodedValues: [str
});
}
formattingTests('v3', fromMetadata(new Metadata(rpcMetadataV3)), [
formattingTests('v3', new Metadata(rpcMetadataV3), [
'0x4af2c53fce3ec33c6ccccf22e926f1a7',
'0x3e62f7ed6e788e1337bce2a97b68a12a',
'0x777519cd81f845abdb40d253923d6098'
]);
formattingTests('v4', fromMetadata(new Metadata(rpcMetadataV4)), [
formattingTests('v4', new Metadata(rpcMetadataV4), [
'0xec8f96437274a883afcac82d01a9defeb68209cd4f2c084632813692aa5e65ad',
'0x1dbb0224910f42a14e7f1406b24c6fe8157296691b02a78756e01946038fffab',
'0xc7879f4faa637a90d782070a3cb6be99a9fb0316e19a0454ce93c4f0a34712f1'
]);
formattingTests('v5', fromMetadata(new Metadata(rpcMetadataV5)), [
formattingTests('v5', new Metadata(rpcMetadataV5), [
'0xec8f96437274a883afcac82d01a9defeb68209cd4f2c084632813692aa5e65ad',
'0x1dbb0224910f42a14e7f1406b24c6fe8157296691b02a78756e01946038fffab',
'0xc7879f4faa637a90d782070a3cb6be99a9fb0316e19a0454ce93c4f0a34712f1'
]);
formattingTests('v6', fromMetadata(new Metadata(rpcMetadataV6)), [
formattingTests('v6', new Metadata(rpcMetadataV6), [
'0xec8f96437274a883afcac82d01a9defeb68209cd4f2c084632813692aa5e65ad',
'0x1dbb0224910f42a14e7f1406b24c6fe8157296691b02a78756e01946038fffab',
'0xc7879f4faa637a90d782070a3cb6be99a9fb0316e19a0454ce93c4f0a34712f1'
]);
formattingTests('v7', fromMetadata(new Metadata(rpcMetadataV7)), [
formattingTests('v7', new Metadata(rpcMetadataV7), [
'0xec8f96437274a883afcac82d01a9defeb68209cd4f2c084632813692aa5e65ad',
'0x1dbb0224910f42a14e7f1406b24c6fe8157296691b02a78756e01946038fffab',
'0xc7879f4faa637a90d782070a3cb6be99a9fb0316e19a0454ce93c4f0a34712f1'
]);
formattingTests('v8', fromMetadata(new Metadata(rpcMetadataV8)), [
formattingTests('v8', new Metadata(rpcMetadataV8), [
'0xec8f96437274a883afcac82d01a9defeb68209cd4f2c084632813692aa5e65ad',
'0x1dbb0224910f42a14e7f1406b24c6fe8157296691b02a78756e01946038fffab',
'0xc7879f4faa637a90d782070a3cb6be99a9fb0316e19a0454ce93c4f0a34712f1'