Add describeE2E (#1117)

* Add test

* Add describeE2E

* Make tests pass

* Make CC happy

* Add test:docker
This commit is contained in:
Amaury Martiny
2019-07-15 11:52:51 +02:00
committed by GitHub
parent 9cf0b3462d
commit d287b8de14
10 changed files with 147 additions and 93 deletions
+1
View File
@@ -22,6 +22,7 @@
"postinstall": "polkadot-dev-yarn-only",
"test": "jest --coverage --testPathIgnorePatterns e2e",
"test:all": "jest",
"test:docker": "WITH_DOCKER=1 jest packages/api/test/e2e",
"test:one": "jest",
"test:watch": "jest --coverage --watch"
},
@@ -2,22 +2,21 @@
// 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 { Extrinsic, SignedBlock } from '@polkadot/types';
import Api from './../../src/promise';
import ApiPromise from '../../src/promise';
import describeE2E from '../util/describeE2E';
// To run these tests locally you need to run a Alexander full archive node locally
describe.skip('alex archive queries (local)', (): void => {
let api: Api;
describeE2E({
only: [] // To run these tests locally you need to run a Alexander full archive node locally
})('alex archive queries (local)', (wsUrl): void => {
let api: ApiPromise;
beforeEach((): void => {
jest.setTimeout(30000);
});
beforeEach(async (done): Promise<void> => {
api = await ApiPromise.create(new WsProvider(wsUrl));
beforeEach(async (): Promise<Api> => {
api = await Api.create();
return api;
done();
});
// https://github.com/polkadot-js/api/issues/845
+10 -15
View File
@@ -2,27 +2,22 @@
// 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 { AccountId, EventRecord, Hash, Header, Option, Vector } from '@polkadot/types';
import Api from './../../src/promise';
import WsProvider from '@polkadot/rpc-provider/ws';
const WS_URL = 'wss://poc3-rpc.polkadot.io/';
// const WS_URL = 'wss://substrate-rpc.parity.io/';
import ApiPromise from '../../src/promise';
import describeE2E from '../util/describeE2E';
describe.skip('alex queries', (): void => {
let api: Api;
describeE2E({
only: ['remote-polkadot-alexander']
})('alex queries', (wsUrl): void => {
let api: ApiPromise;
beforeEach((): void => {
jest.setTimeout(30000);
});
beforeEach(async (done): Promise<void> => {
api = await ApiPromise.create(new WsProvider(wsUrl));
beforeEach(async (): Promise<Api> => {
api = await Api.create({
provider: new WsProvider(WS_URL)
});
return api;
done();
});
it('retrieves the list of validators', (done): Promise<() => void> => {
+9 -9
View File
@@ -3,20 +3,20 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import WsProvider from '@polkadot/rpc-provider/ws';
import { ApiPromise } from '@polkadot/api';
import { BlockNumber } from '@polkadot/types';
describe.skip('e2e consts', (): void => {
import ApiPromise from '../../src/promise';
import describeE2E from '../util/describeE2E';
describeE2E({
except: ['remote-substrate-1.0', 'substrate-1.0']
})('e2e consts', (wsUrl): void => {
let api: ApiPromise;
beforeEach((): Promise<ApiPromise> => {
api = new ApiPromise(new WsProvider('ws://127.0.0.1:9944'));
beforeEach(async (done): Promise<void> => {
api = await ApiPromise.create(new WsProvider(wsUrl));
return api.isReady;
});
beforeEach((): void => {
jest.setTimeout(30000);
done();
});
it('democracy.cooloffPeriod parameter type', (): void => {
+8 -15
View File
@@ -2,37 +2,30 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { KeyringPair } from '@polkadot/keyring/types';
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 flipperAbi from '../../../api-contract/test/contracts/flipper.json';
import { ApiPromise, SubmittableResult } from '../../src';
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');
describe.skip('Promise e2e contracts', (): void => {
describeE2E()('Promise e2e contracts', (wsUrl): void => {
let address: Address;
let codeHash: Hash;
let keyring: {
[index: string]: KeyringPair;
};
const keyring = testingPairs({ type: 'sr25519' });
let api: ApiPromise;
beforeEach(async (done): Promise<void> => {
if (!api) {
api = await ApiPromise.create();
api = await ApiPromise.create(new WsProvider(wsUrl));
keyring = testingPairs({ type: 'sr25519' });
}
jest.setTimeout(10000);
done();
});
+8 -13
View File
@@ -6,32 +6,27 @@ import BN from 'bn.js';
import { HeaderExtended } from '@polkadot/api-derive';
import { DerivedBalances } from '@polkadot/api-derive/types';
import WsProvider from '@polkadot/rpc-provider/ws';
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 Api from './../../src/promise';
import ApiPromise from '../../src/promise';
import describeE2E from '../util/describeE2E';
const ZERO = new BN(0);
const WS_URL = 'ws://127.0.0.1:9944';
// const WS_URL = 'wss://poc3-rpc.polkadot.io/';
describe.skip('Promise e2e queries', (): void => {
const keyring = testingPairs({ type: 'ed25519' });
let api: Api;
describeE2E()('Promise e2e queries', (wsUrl): void => {
let api: ApiPromise;
beforeEach(async (done): Promise<void> => {
if (!api) {
api = await Api.create({
provider: new WsProvider(WS_URL)
});
}
api = await ApiPromise.create(new WsProvider(wsUrl));
jest.setTimeout(30000);
done();
});
const keyring = testingPairs({ type: 'ed25519' });
it('makes the runtime, rpc, state & extrinsics available', (): void => {
expect(api.genesisHash).toBeDefined();
expect(api.runtimeMetadata).toBeDefined();
+21 -16
View File
@@ -4,14 +4,15 @@
import Keyring from '@polkadot/keyring';
import testingPairs from '@polkadot/keyring/testingPairs';
import { randomAsHex } from '@polkadot/util-crypto';
import WsProvider from '@polkadot/rpc-provider/ws';
import { EventRecord, ExtrinsicEra, Hash, Header, Index, SignedBlock } from '@polkadot/types';
import { randomAsHex } from '@polkadot/util-crypto';
import { Balance, EventRecord, ExtrinsicEra, Hash, Header, Index, SignedBlock } from '@polkadot/types';
import SingleAccountSigner from '../util/SingleAccountSigner';
import { SubmittableResult } from './../../src';
import ApiPromise from '../../src/promise';
import { Signer } from './../../src/types';
import Api from './../../src/promise';
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 =>
@@ -32,25 +33,18 @@ const logEvents = (done: () => {}): (r: SubmittableResult) => void =>
}
};
describe.skip('Promise e2e transactions', (): void => {
describeE2E({
except: ['remote-polkadot-alexander', 'remote-substrate-1.0']
})('Promise e2e transactions', (wsUrl): void => {
const keyring = testingPairs({ type: 'ed25519' });
let api: Api;
let api: ApiPromise;
beforeEach(async (done): Promise<void> => {
if (!api) {
api = await Api.create({
provider: new WsProvider('ws://127.0.0.1:9944')
});
}
api = await ApiPromise.create(new WsProvider(wsUrl));
jest.setTimeout(30000);
done();
});
afterEach((): void => {
jest.setTimeout(5000);
});
it('can submit an extrinsic from hex', async (done): Promise<() => void> => {
const nonce = await api.query.system.accountNonce(keyring.dave.address) as Index;
const hex = api.tx.balances
@@ -210,5 +204,16 @@ describe.skip('Promise e2e transactions', (): void => {
expect(hash.toHex()).toHaveLength(66);
done();
});
it('should fire an error with invalid transaction', async (done): Promise<Hash | void> => {
const aliceBalance = await api.query.balances.freeBalance(keyring.alice.address) as Balance;
return api.tx.balances
.transfer(keyring.bob.address, aliceBalance.muln(2))
.signAndSend(keyring.alice).catch((error): void => {
expect(error.message).toMatch(/1010: Invalid Transaction \(0\)/);
done();
});
});
});
});
+9 -5
View File
@@ -8,16 +8,20 @@ import { switchMap } from 'rxjs/operators';
import { Balance, Header } from '@polkadot/types';
import testingPairs from '@polkadot/keyring/testingPairs';
import WsProvider from '@polkadot/rpc-provider/ws';
import Api from '../../src/rx';
import ApiRx from '../../src/rx';
import describeE2E from '../util/describeE2E';
describe.skip('Rx e2e queries', (): void => {
describeE2E({
apiType: 'rxjs'
})('Rx e2e queries', (wsUrl): void => {
const keyring = testingPairs({ type: 'ed25519' });
let api: Api;
let api: ApiRx;
beforeEach(async (done): Promise<void> => {
api = await Api.create().toPromise();
jest.setTimeout(3000000);
api = await ApiRx.create(new WsProvider(wsUrl)).toPromise();
done();
});
+9 -9
View File
@@ -7,22 +7,22 @@ import { first, switchMap } from 'rxjs/operators';
import { Index } from '@polkadot/types';
import testingPairs from '@polkadot/keyring/testingPairs';
import WsProvider from '@polkadot/rpc-provider/ws';
import Api from './../../src/rx';
import ApiRx from './../../src/rx';
import { SubmittableResult } from './../../src';
import describeE2E from '../util/describeE2E';
describe.skip('Rx e2e transactions', (): void => {
describeE2E({
apiType: 'rxjs'
})('Rx e2e transactions', (wsUrl): void => {
const keyring = testingPairs({ type: 'ed25519' });
let api: Api;
let api: ApiRx;
beforeEach(async (done): Promise<void> => {
api = await Api.create().toPromise();
jest.setTimeout(30000);
done();
});
api = await ApiRx.create(new WsProvider(wsUrl)).toPromise();
afterEach((): void => {
jest.setTimeout(5000);
done();
});
it('makes a transfer', (done): void => {
+62
View File
@@ -0,0 +1,62 @@
// 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.
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/',
'remote-polkadot-alexander': 'wss://poc3-rpc.polkadot.io/',
'remote-substrate-1.0': 'wss://substrate-rpc.parity.io/'
};
type WsName = keyof typeof WS_ENDPOINTS;
interface Options {
except?: WsName[]; // Only one of the two keys `either` `only` should be set
only?: WsName[];
apiType?: 'promise' | 'rxjs';
}
// From the options and the WITH_DOCKER flag, calculate on which endpoints we
// should run the tests
function getWsEndpoints (options?: Options): WsName[] {
let wsEndpoints: WsName[] = []; // The ws endpoints to test
if (options && options.only) {
wsEndpoints = options.only;
} else {
wsEndpoints = (Object.keys(WS_ENDPOINTS) as 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;
}
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);
});
});
};
}