Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorganize test setup #1132

Merged
merged 26 commits into from Jul 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
63aa15c
Moved all e2e tests to 'api' folder
Stefie Jul 12, 2019
c9f7dad
Moved metadata test
Stefie Jul 12, 2019
7771577
Merge branch 'master' into sd-reorganize-test-setup
Stefie Jul 15, 2019
6a01d77
fix imports
Stefie Jul 15, 2019
911db8c
Merge branch 'master' into sd-reorganize-test-setup
Stefie Jul 15, 2019
704a162
Add jest options for testing the different endpoint types separately
Stefie Jul 15, 2019
f0a99e5
Add check for empty test suites and return empt test to prevent jest …
Stefie Jul 15, 2019
303ac3f
Fix import paths
Stefie Jul 15, 2019
6c7d3d0
Fix const tests for polkadot chains
Stefie Jul 15, 2019
fdbb5ff
Update to latest Substrate 2.0 image
Stefie Jul 15, 2019
8248677
Move contract files for e2e testing to e2e tesing folder
Stefie Jul 15, 2019
6d4920b
reorder & fix promise query tests for all test nodes
Stefie Jul 15, 2019
0b0be01
Merge branch 'master' into sd-reorganize-test-setup
Stefie Jul 15, 2019
93dfec5
final fixes for promise query
Stefie Jul 15, 2019
86fbad1
eslint fixes
Stefie Jul 15, 2019
2eb566e
removed trailing space
Stefie Jul 15, 2019
a4796f6
fix linting errors
Stefie Jul 15, 2019
97d067a
Address codeclimate "Function getWsEndpoints has a Cognitive Complexi…
Stefie Jul 15, 2019
f495b55
Fix contract ABI import paths
Stefie Jul 15, 2019
5be1012
linter endpoint types
Stefie Jul 15, 2019
bae961f
replace alice with alice_stash
Stefie Jul 16, 2019
493e6ba
Merge branch 'master' into sd-reorganize-test-setup
Stefie Jul 16, 2019
dfd20f0
split off promise-queries file
Stefie Jul 16, 2019
25be21e
Remove apiType, smaller cleanups, added local to only: [] tests suites
Stefie Jul 16, 2019
0c3a8d2
relative paths changed to `@polkadot` import
Stefie Jul 16, 2019
7310900
moved contract wasm & abi's back to `api-contract`
Stefie Jul 16, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker-compose.yml
Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -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"
},
Expand Down
Empty file removed packages/api-derive/test/consts.ts
Empty file.
Expand Up @@ -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;
Expand Down
Expand Up @@ -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';
Expand Down
Expand Up @@ -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' });

Expand Down
Expand Up @@ -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> => {
Expand Down
Expand Up @@ -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> => {
Expand Down
Expand Up @@ -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> => {
Expand All @@ -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();
});
});
Expand Up @@ -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;
Expand Down
205 changes: 205 additions & 0 deletions 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<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);
});
});
});