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,214 +0,0 @@
|
||||
// Copyright 2017-2019 @polkadot/api-derive 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 ApiPromise from '@polkadot/api/promise/Api';
|
||||
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';
|
||||
|
||||
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;
|
||||
|
||||
beforeAll((): void => {
|
||||
jest.setTimeout(30000);
|
||||
});
|
||||
|
||||
beforeEach(async (done): Promise<void> => {
|
||||
api = await ApiPromise.create(new WsProvider(WS));
|
||||
done();
|
||||
});
|
||||
|
||||
it('returns correct results', async (): Promise<void> => {
|
||||
// https://github.com/polkadot-js/api/issues/777
|
||||
const block1 = await api.derive.chain.bestNumber();
|
||||
|
||||
await new Promise((resolve): void => {
|
||||
setTimeout(resolve, 15000);
|
||||
});
|
||||
|
||||
const block2 = await api.derive.chain.bestNumber();
|
||||
|
||||
expect(block1.eq(block2)).toBe(false);
|
||||
});
|
||||
|
||||
it('subscribes to newHead, retrieving the actual validator', (done): Promise<() => void> => {
|
||||
return api.derive.chain.subscribeNewHead(({ author }: HeaderExtended): void => {
|
||||
console.log('author', author && author.toString());
|
||||
|
||||
if (author) {
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('retrieves the fees (api.queryMulti)', (done): Promise<() => void> => {
|
||||
return api.derive.balances.fees((fees: DerivedFees): void => {
|
||||
console.error('fees', JSON.stringify(fees));
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('retrieves the balances', (done): Promise<() => void> => {
|
||||
return api.derive.balances.all('5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y', (balance: DerivedBalances): void => {
|
||||
console.error(JSON.stringify(balance));
|
||||
|
||||
if (balance.freeBalance.gtn(1)) {
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('retrieves balances for a problematic account', (done): Promise<() => void> => {
|
||||
return api.derive.balances.all('5F7BJL6Z4m8RLtK7nXEqqpEqhBbd535Z3CZeYF6ccvaQAY6N', (balance: DerivedBalances): void => {
|
||||
console.error(JSON.stringify(balance));
|
||||
|
||||
if (balance.availableBalance.eqn(0)) {
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('retrieves all session info', (done): Promise<() => void> => {
|
||||
let count = 0;
|
||||
|
||||
return api.derive.session.info((info: DerivedSessionInfo): void => {
|
||||
console.error(JSON.stringify(info));
|
||||
|
||||
// 5 blocks only, then go our merry way
|
||||
if (++count === 5) {
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('staking', (): void => {
|
||||
it('retrieves all staking info (for controller)', (done): Promise<() => void> => {
|
||||
const accountId = '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY';
|
||||
|
||||
return api.derive.staking.info(accountId, (info: DerivedStaking): void => {
|
||||
console.error(JSON.stringify(info));
|
||||
|
||||
expect(info.accountId.eq(accountId)).toBe(true);
|
||||
expect(info.controllerId!.eq(accountId)).toBe(true);
|
||||
expect(info.stashId!.eq('5GNJqTPyNqANBkUVMN1LPPrxXnFouWXoe2wNSmmEoLctxiZY')).toBe(true);
|
||||
expect(info.stashId!.eq(info.stakingLedger!.stash)).toBe(true);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('retrieves all staking info (for stash)', (done): Promise<() => void> => {
|
||||
const accountId = '5GNJqTPyNqANBkUVMN1LPPrxXnFouWXoe2wNSmmEoLctxiZY';
|
||||
|
||||
return api.derive.staking.info(accountId, (info: DerivedStaking): void => {
|
||||
console.error(JSON.stringify(info));
|
||||
|
||||
if (!info.stashId || !info.controllerId || !info.stakingLedger) {
|
||||
done.fail(new Error('At least one of info.stashId, info.controllerId or info.stakingLedger is undefined.'));
|
||||
return;
|
||||
}
|
||||
|
||||
expect(info.accountId.eq(accountId)).toBe(true);
|
||||
expect(info.controllerId.eq('5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY')).toBe(true);
|
||||
expect(info.stashId.eq(accountId)).toBe(true);
|
||||
expect(info.stashId.eq(info.stakingLedger.stash)).toBe(true);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('verifies derive.staking.unlocking', (): void => {
|
||||
const UNBOND_VALUE = 1;
|
||||
const alicePair = testingPairs().alice;
|
||||
|
||||
it('unbonds dots for Alice (from Alice Stash)', (done): Promise<() => void> => {
|
||||
return api.tx.staking.unbond(UNBOND_VALUE)
|
||||
.signAndSend(alicePair, (result: SubmittableResult): void => {
|
||||
if (result.status.isFinalized) {
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('verifies that derive.staking.unlocking isn\'t empty/undefined', (): Promise<() => void> => {
|
||||
return api.derive.staking.info(ALICE_STASH, (info: DerivedStaking): void => {
|
||||
expect(info.unlocking).toBeDefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('verifies derive.staking.rewardDestination', (): void => {
|
||||
const PAYEE = 2;
|
||||
const alicePair = testingPairs().alice;
|
||||
|
||||
it('Set payee for ALICE to 2', (done): Promise<() => void> => {
|
||||
return api.tx.staking
|
||||
.setPayee(PAYEE)
|
||||
.signAndSend(alicePair, (result: SubmittableResult): void => {
|
||||
if (result.status.isFinalized) {
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('verifies payee for ALICE_STASH', (done): Promise<() => void> => {
|
||||
return api.derive.staking.info(ALICE_STASH, (info: DerivedStaking): void => {
|
||||
if (!info.rewardDestination) {
|
||||
return done.fail(new Error('rewardDestination is undefined.'));
|
||||
} else {
|
||||
expect(info.rewardDestination.toString()).toBe('Controller');
|
||||
}
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('staking.info updates itself after changing reward destination', async (done): Promise<void> => {
|
||||
const stashId = testingPairs().alice_stash.address;
|
||||
|
||||
// start by setting the reqred to Staked, so we have a common starting point
|
||||
await api.tx.staking
|
||||
.setPayee(new RewardDestination('Staked'))
|
||||
.signAndSend(testingPairs().alice, ({ status }): void => {
|
||||
if (status.isFinalized) {
|
||||
console.error('setPayee(Staked) isFinalized');
|
||||
}
|
||||
});
|
||||
|
||||
let count = 0; // The # of times we got a callback response from api.derive.staking.info
|
||||
|
||||
// Subscribe to staking.info
|
||||
api.derive.staking.info(stashId, (result): void => {
|
||||
++count;
|
||||
|
||||
console.error('***', count, JSON.stringify(result));
|
||||
|
||||
if (count >= 2 && result.rewardDestination!.toString() === 'Stash') {
|
||||
done();
|
||||
}
|
||||
}).catch(console.error);
|
||||
|
||||
// Wait a bit, and change reward destination
|
||||
setTimeout(async (): Promise<void> => {
|
||||
await api.tx.staking
|
||||
.setPayee(new RewardDestination('Stash'))
|
||||
.signAndSend(testingPairs().alice, ({ status }): void => {
|
||||
if (status.isFinalized) {
|
||||
console.error('setPayee(Stash) isFinalized');
|
||||
}
|
||||
});
|
||||
}, 5000);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,284 +0,0 @@
|
||||
// Copyright 2017-2019 @polkadot/api-derive 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 ApiRx from '@polkadot/api/rx/Api';
|
||||
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';
|
||||
const IX = 'F7Hs';
|
||||
|
||||
describe.skip('Api-RX derive e2e', (): void => {
|
||||
let api: ApiRx;
|
||||
|
||||
beforeAll((): void => {
|
||||
jest.setTimeout(10000);
|
||||
});
|
||||
|
||||
beforeEach(async (done): Promise<void> => {
|
||||
api = await ApiRx.create(new WsProvider(WS)).toPromise();
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
afterAll((): void => {
|
||||
jest.setTimeout(10000);
|
||||
});
|
||||
|
||||
// These derive.accounts tests only work on localhost, not the poc-3 URL
|
||||
// (and it is assuming it sent at least 1 tx)
|
||||
describe('derive.accounts', (): void => {
|
||||
describe('idAndIndex', (): void => {
|
||||
it('looks up AccountId & AccountIndex from AccountId', async (done): Promise<void> => {
|
||||
// @ts-ignore silence warning until we have static types here
|
||||
api.derive.accounts.idAndIndex(ID).subscribe(([accountId, accountIndex]): void => {
|
||||
expect(accountId!.toString()).toEqual(ID);
|
||||
// The first emitted value for ix is undefined when passing the ID
|
||||
if (accountIndex) {
|
||||
expect(accountIndex.toString()).toEqual(IX);
|
||||
} else {
|
||||
expect(accountIndex).toEqual(undefined);
|
||||
}
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('looks up AccountId & AccountIndex from AccountIndex', async (done): Promise<void> => {
|
||||
// @ts-ignore silence warning until we have static types here
|
||||
api.derive.accounts.idAndIndex(IX).subscribe(([accountId, accountIndex]): void => {
|
||||
// The first emitted value for id is undefined when passing the IX
|
||||
if (accountId) {
|
||||
expect(accountId.toString()).toEqual(ID);
|
||||
} else {
|
||||
expect(accountId).toEqual(undefined);
|
||||
}
|
||||
expect(accountIndex!.toString()).toEqual(IX);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('indexToId', (): void => {
|
||||
it('looks up AccountId from AccountIndex', async (done): Promise<void> => {
|
||||
// @ts-ignore silence warning until we have static types here
|
||||
api.derive.accounts.indexToId(IX).subscribe((accountId): void => {
|
||||
// The first emitted value for accountId is undefined when passing the IX
|
||||
if (accountId) {
|
||||
expect(accountId instanceof AccountId).toBe(true);
|
||||
expect(accountId.toString()).toEqual(ID);
|
||||
} else {
|
||||
expect(accountId).toEqual(undefined);
|
||||
}
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('idToIndex', (): void => {
|
||||
it('looks up AccountIndex from AccountId', async (done): Promise<void> => {
|
||||
// @ts-ignore silence warning until we have static types here
|
||||
api.derive.accounts.idToIndex(ID).subscribe((accountIndex): void => {
|
||||
// The first emitted value for AccountIndex is undefined when passing the ID
|
||||
if (accountIndex) {
|
||||
expect(accountIndex instanceof AccountIndex).toBe(true);
|
||||
expect(accountIndex.toString()).toEqual(IX);
|
||||
} else {
|
||||
expect(accountIndex).toEqual(undefined);
|
||||
}
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('indexes', (): void => {
|
||||
it('looks up all AccountIndexes', async (done): Promise<void> => {
|
||||
// @ts-ignore silence warning until we have static types here
|
||||
api.derive.accounts.indexes().subscribe((accountIndexes): void => {
|
||||
// A local dev chain should have the AccountIndex of Alice
|
||||
expect(accountIndexes).toHaveProperty(
|
||||
ID,
|
||||
new AccountIndex(IX)
|
||||
);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// these only work on localhost, not the poc-3 URL
|
||||
// (and it is assuming it sent at least 1 tx)
|
||||
describe('derive.balances', (): void => {
|
||||
describe('all', (): void => {
|
||||
it('It returns an object with all relevant balance information of an account', async (done): Promise<void> => {
|
||||
api.derive.balances.all(ID).subscribe((balances: DerivedBalances): void => {
|
||||
expect(balances).toEqual(expect.objectContaining({
|
||||
accountId: expect.any(AccountId),
|
||||
accountNonce: expect.any(Index),
|
||||
availableBalance: expect.any(BN),
|
||||
freeBalance: expect.any(BN),
|
||||
lockedBalance: expect.any(BN),
|
||||
reservedBalance: expect.any(BN),
|
||||
vestedBalance: expect.any(BN),
|
||||
votingBalance: expect.any(BN)
|
||||
}));
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('fees', (): void => {
|
||||
it('fees: It returns an object with all relevant fees of type BN', async (done): Promise<void> => {
|
||||
api.derive.balances.fees().subscribe((fees: DerivedFees): void => {
|
||||
expect(fees).toEqual(expect.objectContaining({
|
||||
creationFee: expect.any(BN),
|
||||
existentialDeposit: expect.any(BN),
|
||||
transactionBaseFee: expect.any(BN),
|
||||
transactionByteFee: expect.any(BN),
|
||||
transferFee: expect.any(BN)
|
||||
}));
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('derive.chain', (): void => {
|
||||
describe('bestNumber', (): void => {
|
||||
it('Get the latest block number', async (done): Promise<void> => {
|
||||
api.derive.chain.bestNumber().subscribe((blockNumber: BlockNumber): void => {
|
||||
expect(blockNumber instanceof BlockNumber).toBe(true);
|
||||
expect(blockNumber.gten(0)).toBe(true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('bestNumberFinalized', (): void => {
|
||||
it('Get the latest finalised block number', async (done): Promise<void> => {
|
||||
api.derive.chain.bestNumberFinalized().subscribe((blockNumber: BlockNumber): void => {
|
||||
expect(blockNumber instanceof BlockNumber).toBe(true);
|
||||
expect(blockNumber.gten(0)).toBe(true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('bestNumberLag', (): void => {
|
||||
it('lag between finalised head and best head', async (done): Promise<void> => {
|
||||
api.derive.chain.bestNumberLag().subscribe((numberLag: BlockNumber): void => {
|
||||
expect(numberLag instanceof BlockNumber).toBe(true);
|
||||
expect(numberLag.gten(0)).toBe(true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// FIXME https://github.com/polkadot-js/api/issues/868
|
||||
describe.skip('getHeader', (): void => {
|
||||
it('gets a specific block header and extended with it`s author', async (done): Promise<void> => {
|
||||
api.derive.chain.getHeader('TODO').subscribe((headerExtended: HeaderExtended | undefined): void => {
|
||||
// WIP
|
||||
expect(headerExtended).toEqual(expect.arrayContaining([]));
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('subscribeNewHead', (): void => {
|
||||
it('gets an observable of the current block header and it\'s author', async (done): Promise<void> => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
api.derive.chain.subscribeNewHead().subscribe((headerExtended: HeaderExtended): void => {
|
||||
// WIP https://github.com/polkadot-js/api/issues/868
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('derive.contracts', (): void => {
|
||||
describe('fees', (): void => {
|
||||
it('fees: It returns an object with all relevant constract fees of type Balance', async (done): Promise<void> => {
|
||||
api.derive.contracts.fees().subscribe((fees: DerivedContractFees): void => {
|
||||
expect(fees).toEqual(expect.objectContaining({
|
||||
callBaseFee: expect.any(BN),
|
||||
contractFee: expect.any(BN),
|
||||
createBaseFee: expect.any(BN),
|
||||
creationFee: expect.any(BN),
|
||||
rentByteFee: expect.any(BN),
|
||||
rentDepositOffset: expect.any(BN),
|
||||
tombstoneDeposit: expect.any(BN),
|
||||
transactionBaseFee: expect.any(BN),
|
||||
transactionByteFee: expect.any(BN),
|
||||
transferFee: expect.any(BN)
|
||||
}));
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('derive.session', (): void => {
|
||||
describe('sessionProgress', (): void => {
|
||||
it('derive.session.sessionProgress', async (done): Promise<void> => {
|
||||
api.derive.session.sessionProgress().subscribe((progress: BN): void => {
|
||||
expect(progress instanceof BN).toBe(true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('session.info', (): void => {
|
||||
it('retrieves all session info', async (done): Promise<void> => {
|
||||
api.derive.session.info().subscribe((info: DerivedSessionInfo): void => {
|
||||
expect(info).toEqual(expect.objectContaining({
|
||||
currentEra: expect.anything(),
|
||||
currentIndex: expect.anything(),
|
||||
eraLength: expect.anything(),
|
||||
eraProgress: expect.anything(),
|
||||
lastEraLengthChange: expect.anything(),
|
||||
lastLengthChange: expect.anything(),
|
||||
sessionLength: expect.anything(),
|
||||
sessionsPerEra: expect.anything(),
|
||||
sessionProgress: expect.anything()
|
||||
}));
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('session.eraLength', (): void => {
|
||||
it('derive.session.eraLength', async (done): Promise<void> => {
|
||||
api.derive.session.eraLength().subscribe((length: BN): void => {
|
||||
expect(length instanceof BN).toBe(true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('session.eraProgress', (): void => {
|
||||
it('derive.session.eraProgress', async (done): Promise<void> => {
|
||||
api.derive.session.eraProgress().subscribe((progress: BN): void => {
|
||||
expect(progress instanceof BN).toBe(true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('derive.staking', (): void => {
|
||||
describe('controllers', (): void => {
|
||||
// @TODO https://github.com/polkadot-js/api/issues/868
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user