From d57dca53f4ae87b8cf18dc6b4fe16e9b378ea456 Mon Sep 17 00:00:00 2001 From: Stefanie Doll Date: Tue, 16 Jul 2019 16:03:53 +0200 Subject: [PATCH] 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` --- docker-compose.yml | 2 +- package.json | 4 +- packages/api-derive/test/consts.ts | 0 .../test/e2e/api-derive}/promise.spec.ts | 7 +- .../test/e2e/api-derive}/rx.spec.ts | 7 +- .../test/e2e/api-metadata}/transfer.spec.ts | 2 +- .../{ => api}/promise-alex-archive.spec.ts | 6 +- .../test/e2e/{ => api}/promise-alex.spec.ts | 8 +- .../test/e2e/{ => api}/promise-consts.spec.ts | 18 +- .../e2e/{ => api}/promise-contract.spec.ts | 10 +- .../test/e2e/api/promise-queries-dev.spec.ts | 205 +++++++++ .../e2e/api/promise-queries-doubleMap.spec.ts | 93 +++++ .../api/test/e2e/api/promise-queries.spec.ts | 141 +++++++ .../api/test/e2e/{ => api}/promise-tx.spec.ts | 10 +- .../api/test/e2e/{ => api}/rx-queries.spec.ts | 10 +- packages/api/test/e2e/{ => api}/rx-tx.spec.ts | 10 +- packages/api/test/e2e/promise-queries.spec.ts | 388 ------------------ .../test/e2e/rpc-core}/alexander.spec.ts | 2 +- .../test/e2e/rpc-core}/basics.spec.ts | 2 +- .../test/e2e/rpc-core}/chain.spec.ts | 2 +- .../test/e2e/rpc-core}/state.spec.ts | 6 +- .../test/e2e/rpc-core}/subscribe.spec.ts | 2 +- packages/api/test/util/describeE2E.ts | 67 +-- 23 files changed, 533 insertions(+), 469 deletions(-) delete mode 100644 packages/api-derive/test/consts.ts rename packages/{api-derive/test/e2e => api/test/e2e/api-derive}/promise.spec.ts (97%) rename packages/{api-derive/test/e2e => api/test/e2e/api-derive}/rx.spec.ts (98%) rename packages/{api-metadata/src/extrinsics/test/e2e => api/test/e2e/api-metadata}/transfer.spec.ts (96%) rename packages/api/test/e2e/{ => api}/promise-alex-archive.spec.ts (91%) rename packages/api/test/e2e/{ => api}/promise-alex.spec.ts (92%) rename packages/api/test/e2e/{ => api}/promise-consts.spec.ts (58%) rename packages/api/test/e2e/{ => api}/promise-contract.spec.ts (89%) create mode 100644 packages/api/test/e2e/api/promise-queries-dev.spec.ts create mode 100644 packages/api/test/e2e/api/promise-queries-doubleMap.spec.ts create mode 100644 packages/api/test/e2e/api/promise-queries.spec.ts rename packages/api/test/e2e/{ => api}/promise-tx.spec.ts (97%) rename packages/api/test/e2e/{ => api}/rx-queries.spec.ts (86%) rename packages/api/test/e2e/{ => api}/rx-tx.spec.ts (88%) delete mode 100644 packages/api/test/e2e/promise-queries.spec.ts rename packages/{rpc-core/test/e2e => api/test/e2e/rpc-core}/alexander.spec.ts (97%) rename packages/{rpc-core/test/e2e => api/test/e2e/rpc-core}/basics.spec.ts (96%) rename packages/{rpc-core/test/e2e => api/test/e2e/rpc-core}/chain.spec.ts (96%) rename packages/{rpc-core/test/e2e => api/test/e2e/rpc-core}/state.spec.ts (96%) rename packages/{rpc-core/test/e2e => api/test/e2e/rpc-core}/subscribe.spec.ts (95%) diff --git a/docker-compose.yml b/docker-compose.yml index ba3cfbc51b..830f99cc0d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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: diff --git a/package.json b/package.json index 6219fdd6fe..dbcd59fae1 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/packages/api-derive/test/consts.ts b/packages/api-derive/test/consts.ts deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/packages/api-derive/test/e2e/promise.spec.ts b/packages/api/test/e2e/api-derive/promise.spec.ts similarity index 97% rename from packages/api-derive/test/e2e/promise.spec.ts rename to packages/api/test/e2e/api-derive/promise.spec.ts index 8709dc0d8b..a8443dc354 100644 --- a/packages/api-derive/test/e2e/promise.spec.ts +++ b/packages/api/test/e2e/api-derive/promise.spec.ts @@ -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; diff --git a/packages/api-derive/test/e2e/rx.spec.ts b/packages/api/test/e2e/api-derive/rx.spec.ts similarity index 98% rename from packages/api-derive/test/e2e/rx.spec.ts rename to packages/api/test/e2e/api-derive/rx.spec.ts index 7f19bd3e8c..44e8112576 100644 --- a/packages/api-derive/test/e2e/rx.spec.ts +++ b/packages/api/test/e2e/api-derive/rx.spec.ts @@ -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'; diff --git a/packages/api-metadata/src/extrinsics/test/e2e/transfer.spec.ts b/packages/api/test/e2e/api-metadata/transfer.spec.ts similarity index 96% rename from packages/api-metadata/src/extrinsics/test/e2e/transfer.spec.ts rename to packages/api/test/e2e/api-metadata/transfer.spec.ts index 286c8169f2..c2dba0859c 100644 --- a/packages/api-metadata/src/extrinsics/test/e2e/transfer.spec.ts +++ b/packages/api/test/e2e/api-metadata/transfer.spec.ts @@ -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' }); diff --git a/packages/api/test/e2e/promise-alex-archive.spec.ts b/packages/api/test/e2e/api/promise-alex-archive.spec.ts similarity index 91% rename from packages/api/test/e2e/promise-alex-archive.spec.ts rename to packages/api/test/e2e/api/promise-alex-archive.spec.ts index 5ed3760b33..f8a0fe9d3d 100644 --- a/packages/api/test/e2e/promise-alex-archive.spec.ts +++ b/packages/api/test/e2e/api/promise-alex-archive.spec.ts @@ -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 => { diff --git a/packages/api/test/e2e/promise-alex.spec.ts b/packages/api/test/e2e/api/promise-alex.spec.ts similarity index 92% rename from packages/api/test/e2e/promise-alex.spec.ts rename to packages/api/test/e2e/api/promise-alex.spec.ts index 266574fe73..7b66bd0e62 100644 --- a/packages/api/test/e2e/promise-alex.spec.ts +++ b/packages/api/test/e2e/api/promise-alex.spec.ts @@ -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 => { diff --git a/packages/api/test/e2e/promise-consts.spec.ts b/packages/api/test/e2e/api/promise-consts.spec.ts similarity index 58% rename from packages/api/test/e2e/promise-consts.spec.ts rename to packages/api/test/e2e/api/promise-consts.spec.ts index 7ba5505856..45426757e6 100644 --- a/packages/api/test/e2e/promise-consts.spec.ts +++ b/packages/api/test/e2e/api/promise-consts.spec.ts @@ -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 => { @@ -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(); }); }); diff --git a/packages/api/test/e2e/promise-contract.spec.ts b/packages/api/test/e2e/api/promise-contract.spec.ts similarity index 89% rename from packages/api/test/e2e/promise-contract.spec.ts rename to packages/api/test/e2e/api/promise-contract.spec.ts index 00da342154..a838247df4 100644 --- a/packages/api/test/e2e/promise-contract.spec.ts +++ b/packages/api/test/e2e/api/promise-contract.spec.ts @@ -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; diff --git a/packages/api/test/e2e/api/promise-queries-dev.spec.ts b/packages/api/test/e2e/api/promise-queries-dev.spec.ts new file mode 100644 index 0000000000..4943f71c1f --- /dev/null +++ b/packages/api/test/e2e/api/promise-queries-dev.spec.ts @@ -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 => { + 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 => { + 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 => { + 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 => { + 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 => { + // 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 => { + const hash = await api.query.balances.freeBalance.hash(keyring.alice.address); + + expect(hash).toBeDefined(); + }); + + it('gets correct key', async (): Promise => { + // 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; + 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 => { + // 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 => { + const size = await api.query.balances.freeBalance.size(keyring.alice_stash.address); + + expect(size.toNumber()).not.toEqual(0); + }); + }); +}); diff --git a/packages/api/test/e2e/api/promise-queries-doubleMap.spec.ts b/packages/api/test/e2e/api/promise-queries-doubleMap.spec.ts new file mode 100644 index 0000000000..92f479a629 --- /dev/null +++ b/packages/api/test/e2e/api/promise-queries-doubleMap.spec.ts @@ -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 => { + 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 => { + const eventTopics = await api.query.system.eventTopics(KEY1, KEY2); + + expect(eventTopics.toJSON()).toEqual([]); + }); + + it('queries correct value at a specified block', async (): Promise => { + 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 => { + const hash = await api.query.system.eventTopics(KEY1, KEY2); + + expect(hash).toBeDefined(); + }); + + it('gets correct key', async (): Promise => { + const key = api.query.system.eventTopics.key(KEY1, KEY2); + const eventTopicsData = await api.rpc.state.getStorage(key) as Option; + + expect(eventTopicsData.unwrapOr(undefined)).toEqual(undefined); + }); + + it('queries multiple results', async (): Promise => { + 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 => { + const size = await api.query.system.eventTopics.size(KEY1, KEY2); + + expect(size.toNumber()).toEqual(0); + }); + }); +}); diff --git a/packages/api/test/e2e/api/promise-queries.spec.ts b/packages/api/test/e2e/api/promise-queries.spec.ts new file mode 100644 index 0000000000..17162a95b3 --- /dev/null +++ b/packages/api/test/e2e/api/promise-queries.spec.ts @@ -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 => { + 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 => { + 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 => { + const header = await api.rpc.chain.getHeader() as Header; + const events = await api.query.system.events.at(header.hash) as Vector; + + 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 => { + const sessionIndex = await api.query.session.currentIndex() as SessionIndex; + + expect(sessionIndex.toNumber()).toBeGreaterThanOrEqual(0); + }); + + it('queries correct value at a specified block', async (): Promise => { + 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 => { + const hash: Hash = await api.query.session.currentIndex.hash(); + + expect(hash).toBeDefined(); + }); + + it('gets correct key', async (): Promise => { + const key = api.query.session.currentIndex.key(); + const sessionIndexData = await api.rpc.state.getStorage(key) as Option; + const sessionIndexRPC = new SessionIndex(sessionIndexData.unwrapOr(undefined)); + + expect(sessionIndexRPC.toNumber()).toBeGreaterThanOrEqual(0); + }); + + it('queries correct size', async (): Promise => { + const size = await api.query.session.currentIndex.size(); + + expect(size).not.toHaveLength(0); + expect(size.toNumber()).toBeGreaterThanOrEqual(0); + }); + }); +}); diff --git a/packages/api/test/e2e/promise-tx.spec.ts b/packages/api/test/e2e/api/promise-tx.spec.ts similarity index 97% rename from packages/api/test/e2e/promise-tx.spec.ts rename to packages/api/test/e2e/api/promise-tx.spec.ts index e9a4c48385..b7a05f420a 100644 --- a/packages/api/test/e2e/promise-tx.spec.ts +++ b/packages/api/test/e2e/api/promise-tx.spec.ts @@ -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 => diff --git a/packages/api/test/e2e/rx-queries.spec.ts b/packages/api/test/e2e/api/rx-queries.spec.ts similarity index 86% rename from packages/api/test/e2e/rx-queries.spec.ts rename to packages/api/test/e2e/api/rx-queries.spec.ts index c63700074f..90326ea30b 100644 --- a/packages/api/test/e2e/rx-queries.spec.ts +++ b/packages/api/test/e2e/api/rx-queries.spec.ts @@ -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(); diff --git a/packages/api/test/e2e/rx-tx.spec.ts b/packages/api/test/e2e/api/rx-tx.spec.ts similarity index 88% rename from packages/api/test/e2e/rx-tx.spec.ts rename to packages/api/test/e2e/api/rx-tx.spec.ts index 557ebd9b84..0edf9aeecf 100644 --- a/packages/api/test/e2e/rx-tx.spec.ts +++ b/packages/api/test/e2e/api/rx-tx.spec.ts @@ -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; diff --git a/packages/api/test/e2e/promise-queries.spec.ts b/packages/api/test/e2e/promise-queries.spec.ts deleted file mode 100644 index 3933d877cd..0000000000 --- a/packages/api/test/e2e/promise-queries.spec.ts +++ /dev/null @@ -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 => { - 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 => { - 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 => { - 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 => { - 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 => { - const header = await api.rpc.chain.getHeader() as Header; - const events = await api.query.system.events.at(header.hash) as Vector; - - 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 => { - const sessionIndex = await api.query.session.currentIndex() as SessionIndex; - - expect(sessionIndex.toNumber()).toBeGreaterThanOrEqual(0); - }); - - it('queries correct value at a specified block', async (): Promise => { - 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 => { - const hash: Hash = await api.query.session.currentIndex.hash(); - - expect(hash).toBeDefined(); - }); - - it('gets correct key', async (): Promise => { - const key = api.query.session.currentIndex.key(); - const sessionIndexData = await api.rpc.state.getStorage(key) as Option; - const sessionIndexRPC = new SessionIndex(sessionIndexData.unwrapOr(undefined)); - - expect(sessionIndexRPC.toNumber()).toBeGreaterThanOrEqual(0); - }); - - it('queries correct size', async (): Promise => { - 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 => { - 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 => { - // 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 => { - const hash = await api.query.balances.freeBalance.hash(keyring.alice.address); - - expect(hash).toBeDefined(); - }); - - it('gets correct key', async (): Promise => { - // 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; - 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 => { - // 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 => { - 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 => { - const eventTopics = await api.query.system.eventTopics(KEY1, KEY2); - - expect(eventTopics.toJSON()).toEqual([]); - }); - - it('queries correct value at a specified block', async (): Promise => { - 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 => { - const hash = await api.query.system.eventTopics(KEY1, KEY2); - - expect(hash).toBeDefined(); - }); - - it('gets correct key', async (): Promise => { - const key = api.query.system.eventTopics.key(KEY1, KEY2); - const eventTopicsData = await api.rpc.state.getStorage(key) as Option; - - expect(eventTopicsData.unwrapOr(undefined)).toEqual(undefined); - }); - - it('queries multiple results', async (): Promise => { - 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 => { - const size = await api.query.system.eventTopics.size(KEY1, KEY2); - - expect(size.toNumber()).toEqual(0); - }); - }); -}); diff --git a/packages/rpc-core/test/e2e/alexander.spec.ts b/packages/api/test/e2e/rpc-core/alexander.spec.ts similarity index 97% rename from packages/rpc-core/test/e2e/alexander.spec.ts rename to packages/api/test/e2e/rpc-core/alexander.spec.ts index 729d10f177..0a1e5f9ae1 100644 --- a/packages/rpc-core/test/e2e/alexander.spec.ts +++ b/packages/api/test/e2e/rpc-core/alexander.spec.ts @@ -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'; diff --git a/packages/rpc-core/test/e2e/basics.spec.ts b/packages/api/test/e2e/rpc-core/basics.spec.ts similarity index 96% rename from packages/rpc-core/test/e2e/basics.spec.ts rename to packages/api/test/e2e/rpc-core/basics.spec.ts index a98e8cae53..ee5453e44c 100644 --- a/packages/rpc-core/test/e2e/basics.spec.ts +++ b/packages/api/test/e2e/rpc-core/basics.spec.ts @@ -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; diff --git a/packages/rpc-core/test/e2e/chain.spec.ts b/packages/api/test/e2e/rpc-core/chain.spec.ts similarity index 96% rename from packages/rpc-core/test/e2e/chain.spec.ts rename to packages/api/test/e2e/rpc-core/chain.spec.ts index b4d41522be..1796972414 100644 --- a/packages/rpc-core/test/e2e/chain.spec.ts +++ b/packages/api/test/e2e/rpc-core/chain.spec.ts @@ -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; diff --git a/packages/rpc-core/test/e2e/state.spec.ts b/packages/api/test/e2e/rpc-core/state.spec.ts similarity index 96% rename from packages/rpc-core/test/e2e/state.spec.ts rename to packages/api/test/e2e/rpc-core/state.spec.ts index 8ebdbcba4c..038187e699 100644 --- a/packages/rpc-core/test/e2e/state.spec.ts +++ b/packages/api/test/e2e/rpc-core/state.spec.ts @@ -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 => { - 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 = testingPairs({ type: 'sr25519' }); diff --git a/packages/rpc-core/test/e2e/subscribe.spec.ts b/packages/api/test/e2e/rpc-core/subscribe.spec.ts similarity index 95% rename from packages/rpc-core/test/e2e/subscribe.spec.ts rename to packages/api/test/e2e/rpc-core/subscribe.spec.ts index 494d7ee5b9..589cf9f768 100644 --- a/packages/rpc-core/test/e2e/subscribe.spec.ts +++ b/packages/api/test/e2e/rpc-core/subscribe.spec.ts @@ -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; diff --git a/packages/api/test/util/describeE2E.ts b/packages/api/test/util/describeE2E.ts index 13a5fe52ed..74d3e1d78a 100644 --- a/packages/api/test/util/describeE2E.ts +++ b/packages/api/test/util/describeE2E.ts @@ -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); + }); + }); + } }; }