Reorganize test setup (#1132)
* Moved all e2e tests to 'api' folder * Moved metadata test * fix imports * Add jest options for testing the different endpoint types separately * Add check for empty test suites and return empt test to prevent jest from throwing an error * Fix import paths * Fix const tests for polkadot chains * Update to latest Substrate 2.0 image * Move contract files for e2e testing to e2e tesing folder * reorder & fix promise query tests for all test nodes * final fixes for promise query * eslint fixes * removed trailing space * fix linting errors * Address codeclimate "Function getWsEndpoints has a Cognitive Complexity of 7 (exceeds 5 allowed)." * Fix contract ABI import paths * linter endpoint types * replace alice with alice_stash * split off promise-queries file * Remove apiType, smaller cleanups, added local to only: [] tests suites * relative paths changed to `@polkadot` import * moved contract wasm & abi's back to `api-contract`
This commit is contained in:
+1
-1
@@ -47,7 +47,7 @@ services:
|
||||
- "--ws-external"
|
||||
|
||||
substrate-2.0:
|
||||
image: parity/substrate:2.0.0-f981856d4
|
||||
image: parity/substrate:2.0.0-b65c315a1
|
||||
ports:
|
||||
- "9947:9944"
|
||||
networks:
|
||||
|
||||
+3
-1
@@ -22,7 +22,9 @@
|
||||
"postinstall": "polkadot-dev-yarn-only",
|
||||
"test": "jest --coverage --testPathIgnorePatterns e2e",
|
||||
"test:all": "jest",
|
||||
"test:docker": "WITH_DOCKER=1 jest packages/api/test/e2e",
|
||||
"test:e2e": "jest packages/api/test/e2e",
|
||||
"test:e2e-docker": "TEST_DOCKER=1 jest packages/api/test/e2e",
|
||||
"test:e2e-remote": "TEST_REMOTE=1 jest packages/api/test/e2e",
|
||||
"test:one": "jest",
|
||||
"test:watch": "jest --coverage --watch"
|
||||
},
|
||||
|
||||
+3
-4
@@ -7,13 +7,12 @@ import testingPairs from '@polkadot/keyring/testingPairs';
|
||||
import { WsProvider } from '@polkadot/rpc-provider';
|
||||
import { RewardDestination } from '@polkadot/types';
|
||||
|
||||
import { HeaderExtended } from '../../src/type';
|
||||
import { DerivedBalances, DerivedFees, DerivedSessionInfo, DerivedStaking } from '../../src/types';
|
||||
import { SubmittableResult } from '../../../api/src';
|
||||
import { SubmittableResult } from '@polkadot/api';
|
||||
import { HeaderExtended } from '@polkadot/api-derive/type';
|
||||
import { DerivedBalances, DerivedFees, DerivedSessionInfo, DerivedStaking } from '@polkadot/api-derive/types';
|
||||
|
||||
const ALICE_STASH = testingPairs().alice_stash.address;
|
||||
const WS = 'ws://127.0.0.1:9944/';
|
||||
// const WS = 'wss://poc3-rpc.polkadot.io/';
|
||||
|
||||
describe.skip('derive e2e', (): void => {
|
||||
let api: ApiPromise;
|
||||
+2
-5
@@ -5,15 +5,12 @@
|
||||
import BN from 'bn.js';
|
||||
|
||||
import ApiRx from '@polkadot/api/rx/Api';
|
||||
import { HeaderExtended } from '@polkadot/api-derive';
|
||||
import { DerivedBalances, DerivedContractFees, DerivedFees, DerivedSessionInfo } from '@polkadot/api-derive/types';
|
||||
import { AccountId, AccountIndex, BlockNumber, Index } from '@polkadot/types';
|
||||
import { WsProvider } from '@polkadot/rpc-provider';
|
||||
|
||||
import { HeaderExtended } from '../../src/type';
|
||||
import { DerivedBalances, DerivedContractFees, DerivedFees, DerivedSessionInfo } from '../../src/types';
|
||||
|
||||
const WS = 'ws://127.0.0.1:9944/';
|
||||
// const WS = 'wss://poc3-rpc.polkadot.io/';
|
||||
// const WS = 'wss://substrate-rpc.parity.io/';
|
||||
|
||||
// Dev account Alice
|
||||
const ID = '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY';
|
||||
+1
-1
@@ -8,7 +8,7 @@ import Rpc from '@polkadot/rpc-core';
|
||||
import WsProvider from '@polkadot/rpc-provider/ws';
|
||||
import testingPairs from '@polkadot/keyring/testingPairs';
|
||||
|
||||
import extrinsics from './../../static';
|
||||
import extrinsics from '@polkadot/api-metadata/extrinsics/static';
|
||||
|
||||
const keyring = testingPairs({ type: 'ed25519' });
|
||||
|
||||
+3
-3
@@ -5,12 +5,12 @@
|
||||
import WsProvider from '@polkadot/rpc-provider/ws';
|
||||
import { Extrinsic, SignedBlock } from '@polkadot/types';
|
||||
|
||||
import ApiPromise from '../../src/promise';
|
||||
import describeE2E from '../util/describeE2E';
|
||||
import ApiPromise from '../../../src/promise';
|
||||
import describeE2E from '../../util/describeE2E';
|
||||
|
||||
describeE2E({
|
||||
only: [] // To run these tests locally you need to run a Alexander full archive node locally
|
||||
})('alex archive queries (local)', (wsUrl): void => {
|
||||
})('Promise e2e alex archive queries (local)', (wsUrl): void => {
|
||||
let api: ApiPromise;
|
||||
|
||||
beforeEach(async (done): Promise<void> => {
|
||||
+4
-4
@@ -6,12 +6,12 @@ import { AccountId, EventRecord, Hash, Header, Option, Vector } from '@polkadot/
|
||||
|
||||
import WsProvider from '@polkadot/rpc-provider/ws';
|
||||
|
||||
import ApiPromise from '../../src/promise';
|
||||
import describeE2E from '../util/describeE2E';
|
||||
import ApiPromise from '../../../src/promise';
|
||||
import describeE2E from '../../util/describeE2E';
|
||||
|
||||
describeE2E({
|
||||
only: ['remote-polkadot-alexander']
|
||||
})('alex queries', (wsUrl): void => {
|
||||
only: ['docker-polkadot-alexander', 'remote-polkadot-alexander']
|
||||
})('Promise e2e alex queries', (wsUrl): void => {
|
||||
let api: ApiPromise;
|
||||
|
||||
beforeEach(async (done): Promise<void> => {
|
||||
+13
-5
@@ -5,12 +5,17 @@
|
||||
import WsProvider from '@polkadot/rpc-provider/ws';
|
||||
import { BlockNumber } from '@polkadot/types';
|
||||
|
||||
import ApiPromise from '../../src/promise';
|
||||
import describeE2E from '../util/describeE2E';
|
||||
import ApiPromise from '../../../src/promise';
|
||||
import describeE2E from '../../util/describeE2E';
|
||||
|
||||
describeE2E({
|
||||
except: ['remote-substrate-1.0', 'substrate-1.0']
|
||||
})('e2e consts', (wsUrl): void => {
|
||||
only: [
|
||||
'local',
|
||||
'docker-polkadot-master',
|
||||
'docker-substrate-master',
|
||||
'docker-substrate-2.0'
|
||||
]
|
||||
})('Promise e2e consts', (wsUrl): void => {
|
||||
let api: ApiPromise;
|
||||
|
||||
beforeEach(async (done): Promise<void> => {
|
||||
@@ -21,6 +26,9 @@ describeE2E({
|
||||
|
||||
it('democracy.cooloffPeriod parameter type', (): void => {
|
||||
expect(api.consts.democracy.cooloffPeriod).toBeInstanceOf(BlockNumber);
|
||||
expect(api.consts.democracy.cooloffPeriod.eq(432000)).toBeTruthy();
|
||||
expect(
|
||||
api.consts.democracy.cooloffPeriod.eq(432000) || // Substrate
|
||||
api.consts.democracy.cooloffPeriod.eq(259200) // Polkadot
|
||||
).toBeTruthy();
|
||||
});
|
||||
});
|
||||
+5
-5
@@ -6,16 +6,16 @@ import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
import { Abi } from '@polkadot/api-contract';
|
||||
import flipperAbi from '@polkadot/api-contract/test/contracts/flipper.json';
|
||||
import testingPairs from '@polkadot/keyring/testingPairs';
|
||||
import WsProvider from '@polkadot/rpc-provider/ws';
|
||||
import { Address, Hash } from '@polkadot/types';
|
||||
|
||||
import { SubmittableResult } from '../../src';
|
||||
import ApiPromise from '../../src/promise';
|
||||
import describeE2E from '../util/describeE2E';
|
||||
import { SubmittableResult } from '../../../src';
|
||||
import ApiPromise from '../../../src/promise';
|
||||
import describeE2E from '../../util/describeE2E';
|
||||
|
||||
const flipperCode = fs.readFileSync(path.join(__dirname, '../../../api-contract/test/contracts/flipper-pruned.wasm')).toString('hex');
|
||||
import flipperAbi from '../../../../api-contract/test/contracts/flipper.json';
|
||||
const flipperCode = fs.readFileSync(path.join(__dirname, '../../../../api-contract/test/contracts//flipper-pruned.wasm')).toString('hex');
|
||||
|
||||
describeE2E()('Promise e2e contracts', (wsUrl): void => {
|
||||
let address: Address;
|
||||
@@ -0,0 +1,205 @@
|
||||
// Copyright 2017-2019 @polkadot/api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import BN from 'bn.js';
|
||||
|
||||
import { DerivedBalances } from '@polkadot/api-derive/types';
|
||||
import testingPairs from '@polkadot/keyring/testingPairs';
|
||||
import WsProvider from '@polkadot/rpc-provider/ws';
|
||||
import { Balance, Header, Index, Option, U32 } from '@polkadot/types';
|
||||
|
||||
import ApiPromise from '../../../src/promise';
|
||||
import describeE2E from '../../util/describeE2E';
|
||||
|
||||
const ZERO = new BN(0);
|
||||
|
||||
// The following tests require a development node with the default funded testing accounts
|
||||
describeE2E({
|
||||
except: [
|
||||
'remote-polkadot-alexander',
|
||||
'remote-substrate-1.0'
|
||||
]
|
||||
})('Promise e2e development queries', (wsUrl): void => {
|
||||
let api: ApiPromise;
|
||||
|
||||
beforeEach(async (done): Promise<void> => {
|
||||
api = await ApiPromise.create(new WsProvider(wsUrl));
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
const keyring = testingPairs({ type: 'ed25519' });
|
||||
|
||||
it('allows retrieval of an fallback entry (once-off query)', async (): Promise<void> => {
|
||||
const nonce = await api.query.system.accountNonce('5DSo5RVtfrtgHoz2c7jK7Tca7FgJgpCzFnxoRVDeYUQcKPng');
|
||||
|
||||
expect(nonce.toHex()).toEqual('0x0000000000000000');
|
||||
});
|
||||
|
||||
it('allows retrieval of fallback when at query is made', async (): Promise<void> => {
|
||||
const header = await api.rpc.chain.getHeader() as Header;
|
||||
const nonce = await api.query.system.accountNonce.at(header.hash, '5DSo5RVtfrtgHoz2c7jK7Tca7FgJgpCzFnxoRVDeYUQcKPng');
|
||||
|
||||
expect(nonce.toHex()).toEqual('0x0000000000000000');
|
||||
});
|
||||
|
||||
it('queries state for a balance', async (): Promise<() => void> => {
|
||||
return api.query.balances.freeBalance(keyring.alice_stash.address, (balance: Balance): void => {
|
||||
expect(balance).toBeInstanceOf(BN);
|
||||
expect(balance.isZero()).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
it('subscribes to queries', (done): Promise<() => void> => {
|
||||
return (
|
||||
api.query.system.accountNonce(keyring.ferdie.address, (nonce: Index): void => {
|
||||
expect(nonce instanceof BN).toBe(true);
|
||||
|
||||
done();
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('subscribes to queries (default)', (done): Promise<() => void> => {
|
||||
return (
|
||||
api.query.staking.minimumValidatorCount((defaultCount: U32): void => {
|
||||
expect(defaultCount.toNumber()).toBe(1);
|
||||
|
||||
done();
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('subscribes to multiple results (freeBalance.multi)', (done): Promise<() => void> => {
|
||||
return (
|
||||
api.query.balances.freeBalance.multi([
|
||||
keyring.alice.address,
|
||||
keyring.bob.address,
|
||||
'5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y',
|
||||
keyring.ferdie.address
|
||||
], (balances): void => {
|
||||
expect(balances).toHaveLength(4);
|
||||
|
||||
done();
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('subscribes to multiple results (api.queryMulti)', (done): Promise<() => void> => {
|
||||
return api.queryMulti([
|
||||
[api.query.balances.freeBalance, keyring.alice.address],
|
||||
[api.query.balances.freeBalance, keyring.bob.address],
|
||||
[api.query.balances.freeBalance, '5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y'],
|
||||
[api.query.balances.freeBalance, keyring.ferdie.address]
|
||||
], (balances: Balance[]): void => {
|
||||
expect(balances).toHaveLength(4);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('subscribes to derived balances (balances.all)', (done): Promise<() => void> => {
|
||||
return (
|
||||
api.derive.balances.all(
|
||||
keyring.bob_stash.address,
|
||||
(all: DerivedBalances): void => {
|
||||
expect(all.accountId.toString()).toEqual(keyring.bob_stash.address);
|
||||
|
||||
expect(all.freeBalance).toBeDefined();
|
||||
expect(all.freeBalance.gt(ZERO)).toBe(true);
|
||||
expect(all.availableBalance).toBeDefined();
|
||||
expect(all.availableBalance.gt(ZERO)).toBe(true);
|
||||
expect(all.reservedBalance).toBeDefined();
|
||||
expect(all.lockedBalance).toBeDefined();
|
||||
expect(all.vestedBalance).toBeDefined();
|
||||
done();
|
||||
}
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
describe('with map type', (): void => {
|
||||
it('queries correct value', async (): Promise<void> => {
|
||||
const balance = await api.query.balances.freeBalance(keyring.bob_stash.address) as Balance;
|
||||
|
||||
expect(balance.isZero()).toBe(false);
|
||||
});
|
||||
|
||||
it('queries correct value at a specified block', async (): Promise<void> => {
|
||||
// assume the account Alice is only used in test(the balance of Alice does not change in this test case)
|
||||
const balance = await api.query.balances.freeBalance(keyring.alice_stash.address);
|
||||
const header = await api.rpc.chain.getHeader() as Header;
|
||||
const balanceAt = await api.query.balances.freeBalance.at(header.hash, keyring.alice_stash.address) as Balance;
|
||||
|
||||
expect(balanceAt.isZero()).toBe(false);
|
||||
expect(balanceAt.toString()).toEqual(balance.toString());
|
||||
});
|
||||
|
||||
it('subscribes to query and get correct result', async (done): Promise<() => void> => {
|
||||
// assume the account Alice is only used in test(the balance of Alice does not change in this test case)
|
||||
const balance = await api.query.balances.freeBalance(keyring.alice_stash.address);
|
||||
|
||||
return api.query.balances.freeBalance(keyring.alice_stash.address, (balanceSubscribed: Balance): void => {
|
||||
expect(balanceSubscribed.isZero()).toBe(false);
|
||||
expect(balanceSubscribed.toString()).toEqual(balance.toString());
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('queries correct hash', async (): Promise<void> => {
|
||||
const hash = await api.query.balances.freeBalance.hash(keyring.alice.address);
|
||||
|
||||
expect(hash).toBeDefined();
|
||||
});
|
||||
|
||||
it('gets correct key', async (): Promise<void> => {
|
||||
// assume the account Alice is only used in test(the balance of Alice does not change in this test case)
|
||||
const key = api.query.balances.freeBalance.key(keyring.alice_stash.address);
|
||||
const balanceData = await api.rpc.state.getStorage(key) as Option<any>;
|
||||
const balanceRPC = new Balance(balanceData.unwrapOr(undefined));
|
||||
|
||||
const balance = await api.query.balances.freeBalance(keyring.alice_stash.address);
|
||||
|
||||
expect(balanceRPC.isZero()).toBe(false);
|
||||
expect(balanceRPC.toString()).toEqual(balance.toString());
|
||||
});
|
||||
|
||||
it('queries multiple results', async (): Promise<void> => {
|
||||
// assume the account Alice and Bob are only used in test(the balance of them do not change in this test case)
|
||||
const balanceAlice = await api.query.balances.freeBalance(keyring.alice.address);
|
||||
const balanceBob = await api.query.balances.freeBalance(keyring.bob.address);
|
||||
|
||||
const balances = await api.query.balances.freeBalance.multi([
|
||||
keyring.alice.address,
|
||||
keyring.bob.address
|
||||
]);
|
||||
|
||||
expect(balances).toHaveLength(2);
|
||||
expect((balances as any)[0].toString()).toEqual(balanceAlice.toString());
|
||||
expect((balances as any)[1].toString()).toEqual(balanceBob.toString());
|
||||
});
|
||||
|
||||
it('subscribes to multiple queries and get correct results', async (done): Promise<() => void> => {
|
||||
// assume the account Alice and Bob are only used in test(the balance of them do not change in this test case)
|
||||
const balanceAlice = await api.query.balances.freeBalance(keyring.alice.address);
|
||||
const balanceBob = await api.query.balances.freeBalance(keyring.bob.address);
|
||||
|
||||
return api.query.balances.freeBalance.multi([
|
||||
keyring.alice.address,
|
||||
keyring.bob.address
|
||||
], (balances): void => {
|
||||
expect(balances).toHaveLength(2);
|
||||
expect(balances[0].toString()).toEqual(balanceAlice.toString());
|
||||
expect(balances[1].toString()).toEqual(balanceBob.toString());
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('queries correct size', async (): Promise<void> => {
|
||||
const size = await api.query.balances.freeBalance.size(keyring.alice_stash.address);
|
||||
|
||||
expect(size.toNumber()).not.toEqual(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,93 @@
|
||||
// Copyright 2017-2019 @polkadot/api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import WsProvider from '@polkadot/rpc-provider/ws';
|
||||
import { Header, Option } from '@polkadot/types';
|
||||
|
||||
import ApiPromise from '../../../src/promise';
|
||||
import describeE2E from '../../util/describeE2E';
|
||||
|
||||
// The following tests only run on nodes that support doubleMapType introduced by metadata v5
|
||||
describeE2E({
|
||||
only: [
|
||||
'local',
|
||||
'docker-polkadot-master',
|
||||
'docker-substrate-master',
|
||||
'docker-substrate-2.0'
|
||||
]
|
||||
})('Promise e2e doubleMap queries (since Metadata v5)', (wsUrl): void => {
|
||||
let api: ApiPromise;
|
||||
|
||||
beforeEach(async (done): Promise<void> => {
|
||||
api = await ApiPromise.create(new WsProvider(wsUrl));
|
||||
|
||||
done();
|
||||
});
|
||||
// TODO Update ['any', '0x1234'] to the key of a known event topic and update EXPECTED_VALUE to the expected value
|
||||
describe('with double map type', (): void => {
|
||||
const KEY1 = 'any';
|
||||
const KEY2 = '0x1234';
|
||||
it('queries correct value', async (): Promise<void> => {
|
||||
const eventTopics = await api.query.system.eventTopics(KEY1, KEY2);
|
||||
|
||||
expect(eventTopics.toJSON()).toEqual([]);
|
||||
});
|
||||
|
||||
it('queries correct value at a specified block', async (): Promise<void> => {
|
||||
const header = await api.rpc.chain.getHeader() as Header;
|
||||
|
||||
// TODO check & fix: this will throw the error: Encoding for input doesn't match output, created 0x00 from 0x
|
||||
const eventTopicsAt = await api.query.system.eventTopics.at(header.hash, KEY1, KEY2);
|
||||
expect(eventTopicsAt.toJSON()).toEqual([]);
|
||||
|
||||
// const eventTopicsAt = await api.query.system.eventTopics.at(header.hash, KEY1, KEY2);
|
||||
// expect(eventTopicsAt.toJSON()).toEqual([]);
|
||||
});
|
||||
|
||||
it('subscribes to query and get correct result', async (done): Promise<() => void> => {
|
||||
return api.query.system.eventTopics(KEY1, KEY2, (eventTopicsAt): void => {
|
||||
expect(eventTopicsAt.toJSON()).toEqual([]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('queries correct hash', async (): Promise<void> => {
|
||||
const hash = await api.query.system.eventTopics(KEY1, KEY2);
|
||||
|
||||
expect(hash).toBeDefined();
|
||||
});
|
||||
|
||||
it('gets correct key', async (): Promise<void> => {
|
||||
const key = api.query.system.eventTopics.key(KEY1, KEY2);
|
||||
const eventTopicsData = await api.rpc.state.getStorage(key) as Option<any>;
|
||||
|
||||
expect(eventTopicsData.unwrapOr(undefined)).toEqual(undefined);
|
||||
});
|
||||
|
||||
it('queries multiple results', async (): Promise<void> => {
|
||||
const eventTopicsList = await api.query.system.eventTopics.multi([
|
||||
[KEY1, KEY2]
|
||||
]);
|
||||
|
||||
expect(eventTopicsList).toHaveLength(1);
|
||||
expect((eventTopicsList as any)[0].toJSON()).toEqual([]);
|
||||
});
|
||||
|
||||
it('subscribes to multiple queries and get correct results', async (done): Promise<() => void> => {
|
||||
return api.query.system.eventTopics.multi([
|
||||
[KEY1, KEY2]
|
||||
], (eventTopicsList): void => {
|
||||
expect(eventTopicsList).toHaveLength(1);
|
||||
expect(eventTopicsList[0].toJSON()).toEqual([]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('queries correct size', async (): Promise<void> => {
|
||||
const size = await api.query.system.eventTopics.size(KEY1, KEY2);
|
||||
|
||||
expect(size.toNumber()).toEqual(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,141 @@
|
||||
// Copyright 2017-2019 @polkadot/api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { HeaderExtended } from '@polkadot/api-derive';
|
||||
import WsProvider from '@polkadot/rpc-provider/ws';
|
||||
import { LinkageResult } from '@polkadot/types/codec/Linkage';
|
||||
import { EventRecord, Hash, Header, Option, SessionIndex, Vector } from '@polkadot/types';
|
||||
|
||||
import ApiPromise from '../../../src/promise';
|
||||
import describeE2E from '../../util/describeE2E';
|
||||
|
||||
describeE2E()('Promise e2e queries', (wsUrl): void => {
|
||||
let api: ApiPromise;
|
||||
|
||||
beforeEach(async (done): Promise<void> => {
|
||||
api = await ApiPromise.create(new WsProvider(wsUrl));
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
it('makes the runtime, rpc, state & extrinsics available', (): void => {
|
||||
expect(api.genesisHash).toBeDefined();
|
||||
expect(api.runtimeMetadata).toBeDefined();
|
||||
expect(api.runtimeVersion).toBeDefined();
|
||||
expect(api.rpc).toBeDefined();
|
||||
expect(api.query).toBeDefined();
|
||||
expect(api.tx).toBeDefined();
|
||||
expect(api.derive).toBeDefined();
|
||||
});
|
||||
|
||||
it('subscribes to rpc', (done): Promise<() => void> => {
|
||||
return (
|
||||
api.rpc.chain.subscribeNewHead((header: Header): void => {
|
||||
expect(header.blockNumber.isZero()).toBe(false);
|
||||
|
||||
done();
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('subscribes to finalized', (done): Promise<() => void> => {
|
||||
return (
|
||||
api.rpc.chain.subscribeFinalizedHeads((header: Header): void => {
|
||||
expect(header.blockNumber.isZero()).toBe(false);
|
||||
|
||||
done();
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('subscribes to derive', (done): Promise<() => void> => {
|
||||
return (
|
||||
api.derive.chain.subscribeNewHead((header: HeaderExtended): void => {
|
||||
expect(header.blockNumber.isZero()).toBe(false);
|
||||
|
||||
done();
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('subscribes to a linked map (staking.validators)', (done): Promise<() => void> => {
|
||||
return (
|
||||
api.query.staking.validators((prefs: LinkageResult): void => {
|
||||
expect(prefs instanceof LinkageResult).toBe(true);
|
||||
|
||||
done();
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('can retrive header by hash', async (): Promise<void> => {
|
||||
const latest = await api.rpc.chain.getHeader() as Header;
|
||||
const specific = await api.rpc.chain.getHeader(latest.hash) as Header;
|
||||
|
||||
expect(latest.hash).toEqual(specific.hash);
|
||||
});
|
||||
|
||||
it('makes a query at a latest block (specified)', async (): Promise<void> => {
|
||||
const header = await api.rpc.chain.getHeader() as Header;
|
||||
const events = await api.query.system.events.at(header.hash) as Vector<EventRecord>;
|
||||
|
||||
expect(events.length).not.toEqual(0);
|
||||
|
||||
events.forEach(({ event: { data, method, section }, phase, topics }: EventRecord): void => {
|
||||
console.error(phase.toString(), `: ${section}.${method}`, data.toString(), topics.toString());
|
||||
});
|
||||
});
|
||||
|
||||
it('subscribes to events', (done): Promise<() => void> => {
|
||||
return (
|
||||
api.query.system.events((events): void => {
|
||||
expect(events).not.toHaveLength(0);
|
||||
done();
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
describe('with plain type', (): void => {
|
||||
it('queries a correct value', async (): Promise<void> => {
|
||||
const sessionIndex = await api.query.session.currentIndex() as SessionIndex;
|
||||
|
||||
expect(sessionIndex.toNumber()).toBeGreaterThanOrEqual(0);
|
||||
});
|
||||
|
||||
it('queries correct value at a specified block', async (): Promise<void> => {
|
||||
const header = await api.rpc.chain.getHeader() as Header;
|
||||
const sessionIndex = await api.query.session.currentIndex.at(header.hash) as SessionIndex;
|
||||
|
||||
expect(sessionIndex.toNumber()).toBeGreaterThanOrEqual(0);
|
||||
});
|
||||
|
||||
it('subscribes to query and get correct result', (done): Promise<() => void> => {
|
||||
return api.query.session.currentIndex((sessionIndex: SessionIndex): void => {
|
||||
expect(sessionIndex.toNumber()).toBeGreaterThanOrEqual(0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('queries correct hash', async (): Promise<void> => {
|
||||
const hash: Hash = await api.query.session.currentIndex.hash();
|
||||
|
||||
expect(hash).toBeDefined();
|
||||
});
|
||||
|
||||
it('gets correct key', async (): Promise<void> => {
|
||||
const key = api.query.session.currentIndex.key();
|
||||
const sessionIndexData = await api.rpc.state.getStorage(key) as Option<any>;
|
||||
const sessionIndexRPC = new SessionIndex(sessionIndexData.unwrapOr(undefined));
|
||||
|
||||
expect(sessionIndexRPC.toNumber()).toBeGreaterThanOrEqual(0);
|
||||
});
|
||||
|
||||
it('queries correct size', async (): Promise<void> => {
|
||||
const size = await api.query.session.currentIndex.size();
|
||||
|
||||
expect(size).not.toHaveLength(0);
|
||||
expect(size.toNumber()).toBeGreaterThanOrEqual(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
+5
-5
@@ -8,11 +8,11 @@ import WsProvider from '@polkadot/rpc-provider/ws';
|
||||
import { randomAsHex } from '@polkadot/util-crypto';
|
||||
import { EventRecord, ExtrinsicEra, Hash, Header, Index, SignedBlock } from '@polkadot/types';
|
||||
|
||||
import { SubmittableResult } from './../../src';
|
||||
import ApiPromise from '../../src/promise';
|
||||
import { Signer } from './../../src/types';
|
||||
import describeE2E from '../util/describeE2E';
|
||||
import SingleAccountSigner from '../util/SingleAccountSigner';
|
||||
import { SubmittableResult } from '../../../src';
|
||||
import ApiPromise from '../../../src/promise';
|
||||
import { Signer } from '../../../src/types';
|
||||
import describeE2E from '../../util/describeE2E';
|
||||
import SingleAccountSigner from '../../util/SingleAccountSigner';
|
||||
|
||||
// log all events for the transfare, calling done() when finalized
|
||||
const logEvents = (done: () => {}): (r: SubmittableResult) => void =>
|
||||
+4
-6
@@ -10,12 +10,10 @@ import { Balance, Header } from '@polkadot/types';
|
||||
import testingPairs from '@polkadot/keyring/testingPairs';
|
||||
import WsProvider from '@polkadot/rpc-provider/ws';
|
||||
|
||||
import ApiRx from '../../src/rx';
|
||||
import describeE2E from '../util/describeE2E';
|
||||
import ApiRx from '../../../src/rx';
|
||||
import describeE2E from '../../util/describeE2E';
|
||||
|
||||
describeE2E({
|
||||
apiType: 'rxjs'
|
||||
})('Rx e2e queries', (wsUrl): void => {
|
||||
describeE2E()('Rx e2e queries', (wsUrl): void => {
|
||||
const keyring = testingPairs({ type: 'ed25519' });
|
||||
let api: ApiRx;
|
||||
|
||||
@@ -36,7 +34,7 @@ describeE2E({
|
||||
});
|
||||
|
||||
it('queries state for a balance', (done): void => {
|
||||
api.query.balances.freeBalance(keyring.alice.address).subscribe((balance): void => {
|
||||
api.query.balances.freeBalance(keyring.alice_stash.address).subscribe((balance): void => {
|
||||
expect(balance).toBeInstanceOf(BN);
|
||||
expect((balance as Balance).isZero()).toBe(false);
|
||||
done();
|
||||
@@ -9,13 +9,11 @@ import { Index } from '@polkadot/types';
|
||||
import testingPairs from '@polkadot/keyring/testingPairs';
|
||||
import WsProvider from '@polkadot/rpc-provider/ws';
|
||||
|
||||
import ApiRx from './../../src/rx';
|
||||
import { SubmittableResult } from './../../src';
|
||||
import describeE2E from '../util/describeE2E';
|
||||
import ApiRx from '../../../src/rx';
|
||||
import { SubmittableResult } from '../../../src';
|
||||
import describeE2E from '../../util/describeE2E';
|
||||
|
||||
describeE2E({
|
||||
apiType: 'rxjs'
|
||||
})('Rx e2e transactions', (wsUrl): void => {
|
||||
describeE2E()('Rx e2e transactions', (wsUrl): void => {
|
||||
const keyring = testingPairs({ type: 'ed25519' });
|
||||
let api: ApiRx;
|
||||
|
||||
@@ -1,388 +0,0 @@
|
||||
// Copyright 2017-2019 @polkadot/api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import BN from 'bn.js';
|
||||
|
||||
import { HeaderExtended } from '@polkadot/api-derive';
|
||||
import { DerivedBalances } from '@polkadot/api-derive/types';
|
||||
import testingPairs from '@polkadot/keyring/testingPairs';
|
||||
import WsProvider from '@polkadot/rpc-provider/ws';
|
||||
import { LinkageResult } from '@polkadot/types/codec/Linkage';
|
||||
import { Balance, EventRecord, Hash, Header, Index, Option, SessionIndex, ValidatorPrefs, Vector } from '@polkadot/types';
|
||||
|
||||
import ApiPromise from '../../src/promise';
|
||||
import describeE2E from '../util/describeE2E';
|
||||
|
||||
const ZERO = new BN(0);
|
||||
|
||||
describeE2E()('Promise e2e queries', (wsUrl): void => {
|
||||
let api: ApiPromise;
|
||||
|
||||
beforeEach(async (done): Promise<void> => {
|
||||
api = await ApiPromise.create(new WsProvider(wsUrl));
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
const keyring = testingPairs({ type: 'ed25519' });
|
||||
|
||||
it('makes the runtime, rpc, state & extrinsics available', (): void => {
|
||||
expect(api.genesisHash).toBeDefined();
|
||||
expect(api.runtimeMetadata).toBeDefined();
|
||||
expect(api.runtimeVersion).toBeDefined();
|
||||
expect(api.rpc).toBeDefined();
|
||||
expect(api.query).toBeDefined();
|
||||
expect(api.tx).toBeDefined();
|
||||
expect(api.derive).toBeDefined();
|
||||
});
|
||||
|
||||
it('allows retrieval of an fallback entry (once-off query)', async (): Promise<void> => {
|
||||
const nonce = await api.query.system.accountNonce('5DSo5RVtfrtgHoz2c7jK7Tca7FgJgpCzFnxoRVDeYUQcKPng');
|
||||
|
||||
expect(nonce.toHex()).toEqual('0x0000000000000000');
|
||||
});
|
||||
|
||||
it('allows retrieval of fallback when at query is made', async (): Promise<void> => {
|
||||
const header = await api.rpc.chain.getHeader() as Header;
|
||||
const nonce = await api.query.system.accountNonce.at(header.hash, '5DSo5RVtfrtgHoz2c7jK7Tca7FgJgpCzFnxoRVDeYUQcKPng');
|
||||
|
||||
expect(nonce.toHex()).toEqual('0x0000000000000000');
|
||||
});
|
||||
|
||||
it('queries state for a balance', async (): Promise<() => void> => {
|
||||
return api.query.balances.freeBalance(keyring.alice.address, (balance: Balance): void => {
|
||||
expect(balance).toBeInstanceOf(BN);
|
||||
expect(balance.isZero()).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
it('subscribes to rpc', (done): Promise<() => void> => {
|
||||
return (
|
||||
api.rpc.chain.subscribeNewHead((header: Header): void => {
|
||||
expect(header.blockNumber.isZero()).toBe(false);
|
||||
|
||||
done();
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('subscribes to finalized', (done): Promise<() => void> => {
|
||||
return (
|
||||
api.rpc.chain.subscribeFinalizedHeads((header: Header): void => {
|
||||
expect(header.blockNumber.isZero()).toBe(false);
|
||||
|
||||
done();
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('subscribes to derive', (done): Promise<() => void> => {
|
||||
return (
|
||||
api.derive.chain.subscribeNewHead((header: HeaderExtended): void => {
|
||||
expect(header.blockNumber.isZero()).toBe(false);
|
||||
|
||||
done();
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('subscribes to queries', (done): Promise<() => void> => {
|
||||
return (
|
||||
api.query.system.accountNonce(keyring.ferdie.address, (nonce: Index): void => {
|
||||
expect(nonce instanceof BN).toBe(true);
|
||||
|
||||
done();
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it.skip('subscribes to queries (default)', (done): Promise<() => void> => {
|
||||
return (
|
||||
api.query.staking.validators(keyring.ferdie.address, (prefs: ValidatorPrefs): void => {
|
||||
expect(prefs.unstakeThreshold.toNumber()).toBe(3);
|
||||
|
||||
done();
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('subscribes to a linked map (staking.validators)', (done): Promise<() => void> => {
|
||||
return (
|
||||
api.query.staking.validators((prefs: LinkageResult): void => {
|
||||
expect(prefs instanceof LinkageResult).toBe(true);
|
||||
|
||||
done();
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('subscribes to multiple results (freeBalance.multi)', (done): Promise<() => void> => {
|
||||
return (
|
||||
api.query.balances.freeBalance.multi([
|
||||
keyring.alice.address,
|
||||
keyring.bob.address,
|
||||
'5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y',
|
||||
keyring.ferdie.address
|
||||
], (balances): void => {
|
||||
expect(balances).toHaveLength(4);
|
||||
|
||||
done();
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('subscribes to multiple results (api.queryMulti)', (done): Promise<() => void> => {
|
||||
return api.queryMulti([
|
||||
[api.query.balances.freeBalance, keyring.alice.address],
|
||||
[api.query.balances.freeBalance, keyring.bob.address],
|
||||
[api.query.balances.freeBalance, '5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y'],
|
||||
[api.query.balances.freeBalance, keyring.ferdie.address]
|
||||
], (balances: Balance[]): void => {
|
||||
expect(balances).toHaveLength(4);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('subscribes to derived balances (balances.all)', (done): Promise<() => void> => {
|
||||
return (
|
||||
api.derive.balances.all(
|
||||
keyring.alice.address,
|
||||
(all: DerivedBalances): void => {
|
||||
expect(all.accountId.toString()).toEqual(keyring.alice.address);
|
||||
|
||||
expect(all.freeBalance).toBeDefined();
|
||||
expect(all.freeBalance.gt(ZERO)).toBe(true);
|
||||
expect(all.availableBalance).toBeDefined();
|
||||
expect(all.availableBalance.gt(ZERO)).toBe(true);
|
||||
expect(all.reservedBalance).toBeDefined();
|
||||
expect(all.lockedBalance).toBeDefined();
|
||||
expect(all.vestedBalance).toBeDefined();
|
||||
done();
|
||||
}
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
it('can retrive header by hash', async (): Promise<void> => {
|
||||
const latest = await api.rpc.chain.getHeader() as Header;
|
||||
const specific = await api.rpc.chain.getHeader(latest.hash) as Header;
|
||||
|
||||
expect(latest.hash).toEqual(specific.hash);
|
||||
});
|
||||
|
||||
it('makes a query at a latest block (specified)', async (): Promise<void> => {
|
||||
const header = await api.rpc.chain.getHeader() as Header;
|
||||
const events = await api.query.system.events.at(header.hash) as Vector<EventRecord>;
|
||||
|
||||
expect(events.length).not.toEqual(0);
|
||||
|
||||
events.forEach(({ event: { data, method, section }, phase, topics }: EventRecord): void => {
|
||||
console.error(phase.toString(), `: ${section}.${method}`, data.toString(), topics.toString());
|
||||
});
|
||||
});
|
||||
|
||||
it('subscribes to events', (done): Promise<() => void> => {
|
||||
return (
|
||||
api.query.system.events((events): void => {
|
||||
expect(events).not.toHaveLength(0);
|
||||
done();
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
describe('with plain type', (): void => {
|
||||
it('queries a correct value', async (): Promise<void> => {
|
||||
const sessionIndex = await api.query.session.currentIndex() as SessionIndex;
|
||||
|
||||
expect(sessionIndex.toNumber()).toBeGreaterThanOrEqual(0);
|
||||
});
|
||||
|
||||
it('queries correct value at a specified block', async (): Promise<void> => {
|
||||
const header = await api.rpc.chain.getHeader() as Header;
|
||||
const sessionIndex = await api.query.session.currentIndex.at(header.hash) as SessionIndex;
|
||||
|
||||
expect(sessionIndex.toNumber()).toBeGreaterThanOrEqual(0);
|
||||
});
|
||||
|
||||
it('subscribes to query and get correct result', (done): Promise<() => void> => {
|
||||
return api.query.session.currentIndex((sessionIndex: SessionIndex): void => {
|
||||
expect(sessionIndex.toNumber()).toBeGreaterThanOrEqual(0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('queries correct hash', async (): Promise<void> => {
|
||||
const hash: Hash = await api.query.session.currentIndex.hash();
|
||||
|
||||
expect(hash).toBeDefined();
|
||||
});
|
||||
|
||||
it('gets correct key', async (): Promise<void> => {
|
||||
const key = api.query.session.currentIndex.key();
|
||||
const sessionIndexData = await api.rpc.state.getStorage(key) as Option<any>;
|
||||
const sessionIndexRPC = new SessionIndex(sessionIndexData.unwrapOr(undefined));
|
||||
|
||||
expect(sessionIndexRPC.toNumber()).toBeGreaterThanOrEqual(0);
|
||||
});
|
||||
|
||||
it('queries correct size', async (): Promise<void> => {
|
||||
const size = await api.query.session.currentIndex.size();
|
||||
|
||||
expect(size).not.toHaveLength(0);
|
||||
expect(size.toNumber()).toBeGreaterThanOrEqual(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('with map type', (): void => {
|
||||
it('queries correct value', async (): Promise<void> => {
|
||||
const balance = await api.query.balances.freeBalance(keyring.alice.address) as Balance;
|
||||
|
||||
expect(balance.isZero()).toBe(false);
|
||||
});
|
||||
|
||||
it('queries correct value at a specified block', async (): Promise<void> => {
|
||||
// assume the account Alice is only used in test(the balance of Alice does not change in this test case)
|
||||
const balance = await api.query.balances.freeBalance(keyring.alice.address);
|
||||
const header = await api.rpc.chain.getHeader() as Header;
|
||||
const balanceAt = await api.query.balances.freeBalance.at(header.hash, keyring.alice.address) as Balance;
|
||||
|
||||
expect(balanceAt.isZero()).toBe(false);
|
||||
expect(balanceAt.toString()).toEqual(balance.toString());
|
||||
});
|
||||
|
||||
it('subscribes to query and get correct result', async (done): Promise<() => void> => {
|
||||
// assume the account Alice is only used in test(the balance of Alice does not change in this test case)
|
||||
const balance = await api.query.balances.freeBalance(keyring.alice.address);
|
||||
|
||||
return api.query.balances.freeBalance(keyring.alice.address, (balanceSubscribed: Balance): void => {
|
||||
expect(balanceSubscribed.isZero()).toBe(false);
|
||||
expect(balanceSubscribed.toString()).toEqual(balance.toString());
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('queries correct hash', async (): Promise<void> => {
|
||||
const hash = await api.query.balances.freeBalance.hash(keyring.alice.address);
|
||||
|
||||
expect(hash).toBeDefined();
|
||||
});
|
||||
|
||||
it('gets correct key', async (): Promise<void> => {
|
||||
// assume the account Alice is only used in test(the balance of Alice does not change in this test case)
|
||||
const key = api.query.balances.freeBalance.key(keyring.alice.address);
|
||||
const balanceData = await api.rpc.state.getStorage(key) as Option<any>;
|
||||
const balanceRPC = new Balance(balanceData.unwrapOr(undefined));
|
||||
|
||||
const balance = await api.query.balances.freeBalance(keyring.alice.address);
|
||||
|
||||
expect(balanceRPC.isZero()).toBe(false);
|
||||
expect(balanceRPC.toString()).toEqual(balance.toString());
|
||||
});
|
||||
|
||||
it('queries multiple results', async (): Promise<void> => {
|
||||
// assume the account Alice and Bob are only used in test(the balance of them do not change in this test case)
|
||||
const balanceAlice = await api.query.balances.freeBalance(keyring.alice.address);
|
||||
const balanceBob = await api.query.balances.freeBalance(keyring.bob.address);
|
||||
|
||||
const balances = await api.query.balances.freeBalance.multi([
|
||||
keyring.alice.address,
|
||||
keyring.bob.address
|
||||
]);
|
||||
|
||||
expect(balances).toHaveLength(2);
|
||||
expect((balances as any)[0].toString()).toEqual(balanceAlice.toString());
|
||||
expect((balances as any)[1].toString()).toEqual(balanceBob.toString());
|
||||
});
|
||||
|
||||
it('subscribes to multiple queries and get correct results', async (done): Promise<() => void> => {
|
||||
// assume the account Alice and Bob are only used in test(the balance of them do not change in this test case)
|
||||
const balanceAlice = await api.query.balances.freeBalance(keyring.alice.address);
|
||||
const balanceBob = await api.query.balances.freeBalance(keyring.bob.address);
|
||||
|
||||
return api.query.balances.freeBalance.multi([
|
||||
keyring.alice.address,
|
||||
keyring.bob.address
|
||||
], (balances): void => {
|
||||
expect(balances).toHaveLength(2);
|
||||
expect(balances[0].toString()).toEqual(balanceAlice.toString());
|
||||
expect(balances[1].toString()).toEqual(balanceBob.toString());
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('queries correct size', async (): Promise<void> => {
|
||||
const size = await api.query.balances.freeBalance.size(keyring.alice.address);
|
||||
|
||||
expect(size.toNumber()).not.toEqual(0);
|
||||
});
|
||||
});
|
||||
|
||||
// TODO Update ['any', '0x1234'] to the key of a known event topic and update EXPECTED_VALUE to the expected value
|
||||
describe('with double map type', (): void => {
|
||||
const KEY1 = 'any';
|
||||
const KEY2 = '0x1234';
|
||||
it('queries correct value', async (): Promise<void> => {
|
||||
const eventTopics = await api.query.system.eventTopics(KEY1, KEY2);
|
||||
|
||||
expect(eventTopics.toJSON()).toEqual([]);
|
||||
});
|
||||
|
||||
it('queries correct value at a specified block', async (): Promise<void> => {
|
||||
const header = await api.rpc.chain.getHeader() as Header;
|
||||
|
||||
// TODO check & fix: this will throw the error: Encoding for input doesn't match output, created 0x00 from 0x
|
||||
const eventTopicsAt = await api.query.system.eventTopics.at(header.hash, KEY1, KEY2);
|
||||
expect(eventTopicsAt.toJSON()).toEqual([]);
|
||||
|
||||
// const eventTopicsAt = await api.query.system.eventTopics.at(header.hash, KEY1, KEY2);
|
||||
// expect(eventTopicsAt.toJSON()).toEqual([]);
|
||||
});
|
||||
|
||||
it('subscribes to query and get correct result', async (done): Promise<() => void> => {
|
||||
return api.query.system.eventTopics(KEY1, KEY2, (eventTopicsAt): void => {
|
||||
expect(eventTopicsAt.toJSON()).toEqual([]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('queries correct hash', async (): Promise<void> => {
|
||||
const hash = await api.query.system.eventTopics(KEY1, KEY2);
|
||||
|
||||
expect(hash).toBeDefined();
|
||||
});
|
||||
|
||||
it('gets correct key', async (): Promise<void> => {
|
||||
const key = api.query.system.eventTopics.key(KEY1, KEY2);
|
||||
const eventTopicsData = await api.rpc.state.getStorage(key) as Option<any>;
|
||||
|
||||
expect(eventTopicsData.unwrapOr(undefined)).toEqual(undefined);
|
||||
});
|
||||
|
||||
it('queries multiple results', async (): Promise<void> => {
|
||||
const eventTopicsList = await api.query.system.eventTopics.multi([
|
||||
[KEY1, KEY2]
|
||||
]);
|
||||
|
||||
expect(eventTopicsList).toHaveLength(1);
|
||||
expect((eventTopicsList as any)[0].toJSON()).toEqual([]);
|
||||
});
|
||||
|
||||
it('subscribes to multiple queries and get correct results', async (done): Promise<() => void> => {
|
||||
return api.query.system.eventTopics.multi([
|
||||
[KEY1, KEY2]
|
||||
], (eventTopicsList): void => {
|
||||
expect(eventTopicsList).toHaveLength(1);
|
||||
expect(eventTopicsList[0].toJSON()).toEqual([]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('queries correct size', async (): Promise<void> => {
|
||||
const size = await api.query.system.eventTopics.size(KEY1, KEY2);
|
||||
|
||||
expect(size.toNumber()).toEqual(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
+1
-1
@@ -6,7 +6,7 @@ import storage from '@polkadot/api-metadata/storage/static';
|
||||
import WsProvider from '@polkadot/rpc-provider/ws';
|
||||
import { BlockNumber, Index, SignedBlock, StorageChangeSet } from '@polkadot/types';
|
||||
|
||||
import Rpc from '../../src';
|
||||
import Rpc from '@polkadot/rpc-core';
|
||||
|
||||
const randomAccount = '5HTqyWJHAVUieZnpb1V8gK4T1E4mnhkrUVSSzWBQd6kYgsVJ';
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
import { ChainProperties, PendingExtrinsics } from '@polkadot/types';
|
||||
import WsProvider from '@polkadot/rpc-provider/ws';
|
||||
|
||||
import Rpc from '../../src';
|
||||
import Rpc from '@polkadot/rpc-core';
|
||||
|
||||
describe.skip('e2e basics', (): void => {
|
||||
let rpc: Rpc;
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
import { Header, RuntimeVersion } from '@polkadot/types';
|
||||
import WsProvider from '@polkadot/rpc-provider/ws';
|
||||
|
||||
import Rpc from '../../src';
|
||||
import Rpc from '@polkadot/rpc-core';
|
||||
|
||||
describe.skip('e2e chain', (): void => {
|
||||
let rpc: Rpc;
|
||||
+3
-3
@@ -14,8 +14,8 @@ import { KeyringPair } from '@polkadot/keyring/types';
|
||||
import WsProvider from '@polkadot/rpc-provider/ws';
|
||||
import { Balance, Bytes, Hash, Metadata, Moment, StorageData, StorageKey } from '@polkadot/types';
|
||||
|
||||
import Rpc from '../../src';
|
||||
import flipperAbi from '../../../api-contract/test/contracts/flipper.json';
|
||||
import Rpc from '@polkadot/rpc-core';
|
||||
import flipperAbi from '../../../../api-contract/test/contracts/flipper.json';
|
||||
|
||||
const ALICE = '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY';
|
||||
const CODE = '0x3a636f6465'; // :code
|
||||
@@ -92,7 +92,7 @@ describe.skip('e2e state', (): void => {
|
||||
let codeHash: Hash;
|
||||
|
||||
beforeAll(async (done): Promise<Hash> => {
|
||||
const code: string = fs.readFileSync(path.join(__dirname, '../../../api-contract/test/contracts/flipper-pruned.wasm')).toString('hex');
|
||||
const code: string = fs.readFileSync(path.join(__dirname, '../../../../api-contract/test/contracts/flipper-pruned.wasm')).toString('hex');
|
||||
const abi = new Abi(flipperAbi);
|
||||
const apiPromise: ApiPromise = await ApiPromise.create(new WsProvider('ws://127.0.0.1:9944'));
|
||||
const keyring: Record<string, KeyringPair> = testingPairs({ type: 'sr25519' });
|
||||
+1
-1
@@ -6,7 +6,7 @@ import { StorageChangeSet } from '@polkadot/types';
|
||||
import WsProvider from '@polkadot/rpc-provider/ws';
|
||||
import storage from '@polkadot/api-metadata/storage/static';
|
||||
|
||||
import Rpc from '../../src';
|
||||
import Rpc from '@polkadot/rpc-core';
|
||||
|
||||
describe.skip('e2e subscriptions', (): void => {
|
||||
let rpc: Rpc;
|
||||
@@ -4,11 +4,11 @@
|
||||
|
||||
const WS_ENDPOINTS = {
|
||||
local: 'ws://127.0.0.1:9944/',
|
||||
'substrate-master': 'ws://127.0.0.1:9945/',
|
||||
'substrate-1.0': 'ws://127.0.0.1:9946/',
|
||||
'substrate-2.0': 'ws://127.0.0.1:9947/',
|
||||
'polkadot-master': 'ws://127.0.0.1:9948/',
|
||||
'polkadot-alexander': 'ws://127.0.0.1:9949/',
|
||||
'docker-substrate-master': 'ws://127.0.0.1:9945/',
|
||||
'docker-substrate-1.0': 'ws://127.0.0.1:9946/',
|
||||
'docker-substrate-2.0': 'ws://127.0.0.1:9947/',
|
||||
'docker-polkadot-master': 'ws://127.0.0.1:9948/',
|
||||
'docker-polkadot-alexander': 'ws://127.0.0.1:9949/',
|
||||
'remote-polkadot-alexander': 'wss://poc3-rpc.polkadot.io/',
|
||||
'remote-substrate-1.0': 'wss://substrate-rpc.parity.io/'
|
||||
};
|
||||
@@ -16,12 +16,22 @@ const WS_ENDPOINTS = {
|
||||
type WsName = keyof typeof WS_ENDPOINTS;
|
||||
|
||||
interface Options {
|
||||
except?: WsName[]; // Only one of the two keys `either` `only` should be set
|
||||
except?: WsName[]; // Only one of the two keys `except` `only` should be set
|
||||
only?: WsName[];
|
||||
apiType?: 'promise' | 'rxjs';
|
||||
}
|
||||
|
||||
// From the options and the WITH_DOCKER flag, calculate on which endpoints we
|
||||
function filterProcessEnv (wsEndpoints: WsName[]): WsName[] {
|
||||
// If there's a TEST_DOCKER flag, we only run tests to Docker endpoints
|
||||
// If there's a TEST_REMOTE flag, we only run tests to remote endpoints
|
||||
// If none of the two is present, we only run tests on local node
|
||||
return process.env.TEST_REMOTE || process.env.TEST_DOCKER
|
||||
? process.env.TEST_REMOTE
|
||||
? wsEndpoints.filter((wsName): boolean => wsName.startsWith('remote-'))
|
||||
: wsEndpoints.filter((wsName): boolean => wsName.startsWith('docker-'))
|
||||
: wsEndpoints.filter((wsName): boolean => wsName === 'local');
|
||||
}
|
||||
|
||||
// From the options and the TEST_DOCKER and TEST_REMOTE flags, calculate on which endpoints we
|
||||
// should run the tests
|
||||
function getWsEndpoints (options?: Options): WsName[] {
|
||||
let wsEndpoints: WsName[] = []; // The ws endpoints to test
|
||||
@@ -33,30 +43,31 @@ function getWsEndpoints (options?: Options): WsName[] {
|
||||
.filter((wsName): boolean => !options || !options.except || !options.except.includes(wsName));
|
||||
}
|
||||
|
||||
// If there's no WITH_DOCKER flag, we only run local node
|
||||
if (!process.env.WITH_DOCKER) {
|
||||
wsEndpoints = wsEndpoints.filter((wsName): boolean => wsName === 'local');
|
||||
}
|
||||
|
||||
return wsEndpoints;
|
||||
return filterProcessEnv(wsEndpoints);
|
||||
}
|
||||
|
||||
export default function describeE2E (options?: Options): (message: string, inner: (wsUrl: string) => void) => void {
|
||||
return function (message: string, inner: (wsUrl: string) => void): void {
|
||||
getWsEndpoints(options)
|
||||
.map((wsName): [string, string] => [wsName, WS_ENDPOINTS[wsName]])
|
||||
.forEach(([wsName, wsUrl]): void => {
|
||||
describe(`${message} on ${wsName}`, (): void => {
|
||||
beforeAll((): void => {
|
||||
jest.setTimeout(30000);
|
||||
});
|
||||
|
||||
afterAll((): void => {
|
||||
jest.setTimeout(5000);
|
||||
});
|
||||
|
||||
inner(wsUrl);
|
||||
});
|
||||
const wsEndpoints = getWsEndpoints(options);
|
||||
if (!wsEndpoints.length) {
|
||||
describe(`Empty test Suite:`, (): void => {
|
||||
it('No tests found for passed endpoints', (): void => {});
|
||||
});
|
||||
} else {
|
||||
wsEndpoints.map((wsName): [string, string] => [wsName, WS_ENDPOINTS[wsName]])
|
||||
.forEach(([wsName, wsUrl]): void => {
|
||||
describe(`${message} on ${wsName}`, (): void => {
|
||||
beforeAll((): void => {
|
||||
jest.setTimeout(15000);
|
||||
});
|
||||
|
||||
afterAll((): void => {
|
||||
jest.setTimeout(5000);
|
||||
});
|
||||
|
||||
inner(wsUrl);
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user