Typescript-eslint 2 (#1353)

* Make a start

* More minor cleanups

* Some more cleanups

* Last round?

* Exclude build folders
This commit is contained in:
Jaco Greeff
2019-09-02 07:01:32 +02:00
committed by GitHub
parent bd5c167c14
commit 2dd7cc0e69
94 changed files with 391 additions and 324 deletions
@@ -73,7 +73,7 @@ describeE2E({
}
expect(info.accountId.eq(accountId)).toBe(true);
expect(info.controllerId!.eq('5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY')).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);
@@ -142,17 +142,19 @@ describeE2E({
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;
api.derive.staking
.info(stashId, (result): void => {
++count;
console.error('***', count, JSON.stringify(result));
console.error('***', count, JSON.stringify(result));
if (count >= 2 && result.rewardDestination!.toString() === 'Stash') {
done();
}
}).catch(console.error);
if (count >= 2 && result.rewardDestination!.toString() === 'Stash') {
done();
}
});
// Wait a bit, and change reward destination
// eslint-disable-next-line @typescript-eslint/no-misused-promises
setTimeout(async (): Promise<void> => {
await api.tx.staking
.setPayee('Stash')
+18 -23
View File
@@ -44,8 +44,7 @@ describeE2E({
// (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
it('looks up AccountId & AccountIndex from AccountId', (done): void => {
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
@@ -58,8 +57,7 @@ describeE2E({
});
});
it('looks up AccountId & AccountIndex from AccountIndex', async (done): Promise<void> => {
// @ts-ignore silence warning until we have static types here
it('looks up AccountId & AccountIndex from AccountIndex', (done): void => {
api.derive.accounts.idAndIndex(IX).subscribe(([accountId, accountIndex]): void => {
// The first emitted value for id is undefined when passing the IX
if (accountId) {
@@ -74,8 +72,7 @@ describeE2E({
});
describe('indexToId', (): void => {
it('looks up AccountId from AccountIndex', async (done): Promise<void> => {
// @ts-ignore silence warning until we have static types here
it('looks up AccountId from AccountIndex', (done): void => {
api.derive.accounts.indexToId(IX).subscribe((accountId): void => {
// The first emitted value for accountId is undefined when passing the IX
if (accountId) {
@@ -90,8 +87,7 @@ describeE2E({
});
describe('idToIndex', (): void => {
it('looks up AccountIndex from AccountId', async (done): Promise<void> => {
// @ts-ignore silence warning until we have static types here
it('looks up AccountIndex from AccountId', (done): void => {
api.derive.accounts.idToIndex(ID).subscribe((accountIndex): void => {
// The first emitted value for AccountIndex is undefined when passing the ID
if (accountIndex) {
@@ -106,8 +102,7 @@ describeE2E({
});
describe('indexes', (): void => {
it('looks up all AccountIndexes', async (done): Promise<void> => {
// @ts-ignore silence warning until we have static types here
it('looks up all AccountIndexes', (done): void => {
api.derive.accounts.indexes().subscribe((accountIndexes): void => {
// A local dev chain should have the AccountIndex of Alice
expect(accountIndexes).toHaveProperty(
@@ -124,7 +119,7 @@ describeE2E({
// (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> => {
it('It returns an object with all relevant balance information of an account', (done): void => {
api.derive.balances.all(ID).subscribe((balances: DerivedBalances): void => {
expect(balances).toEqual(expect.objectContaining({
accountId: expect.any(ClassOf('AccountId')),
@@ -142,7 +137,7 @@ describeE2E({
});
describe('fees', (): void => {
it('fees: It returns an object with all relevant fees of type BN', async (done): Promise<void> => {
it('fees: It returns an object with all relevant fees of type BN', (done): void => {
api.derive.balances.fees().subscribe((fees: DerivedFees): void => {
expect(fees).toEqual(expect.objectContaining({
creationFee: expect.any(BN),
@@ -159,7 +154,7 @@ describeE2E({
describe('derive.chain', (): void => {
describe('bestNumber', (): void => {
it('Get the latest block number', async (done): Promise<void> => {
it('Get the latest block number', (done): void => {
api.derive.chain.bestNumber().subscribe((blockNumber: BlockNumber): void => {
expect(blockNumber instanceof ClassOf('BlockNumber')).toBe(true);
expect(blockNumber.gten(0)).toBe(true);
@@ -169,7 +164,7 @@ describeE2E({
});
describe('bestNumberFinalized', (): void => {
it('Get the latest finalised block number', async (done): Promise<void> => {
it('Get the latest finalised block number', (done): void => {
api.derive.chain.bestNumberFinalized().subscribe((blockNumber: BlockNumber): void => {
expect(blockNumber instanceof ClassOf('BlockNumber')).toBe(true);
expect(blockNumber.gten(0)).toBe(true);
@@ -179,7 +174,7 @@ describeE2E({
});
describe('bestNumberLag', (): void => {
it('lag between finalised head and best head', async (done): Promise<void> => {
it('lag between finalised head and best head', (done): void => {
api.derive.chain.bestNumberLag().subscribe((numberLag: BlockNumber): void => {
expect(numberLag instanceof ClassOf('BlockNumber')).toBe(true);
expect(numberLag.gten(0)).toBe(true);
@@ -190,7 +185,7 @@ describeE2E({
// FIXME https://github.com/polkadot-js/api/issues/868
describe('getHeader', (): void => {
it('gets a specific block header and extended with it`s author', async (done): Promise<void> => {
it('gets a specific block header and extended with it`s author', (done): void => {
api.derive.chain.getHeader('TODO').subscribe((headerExtended: HeaderExtended | undefined): void => {
// WIP
expect(headerExtended).toEqual(expect.arrayContaining([]));
@@ -200,7 +195,7 @@ describeE2E({
});
describe('subscribeNewHeads', (): void => {
it('gets an observable of the current block header and it\'s author', async (done): Promise<void> => {
it('gets an observable of the current block header and it\'s author', (done): void => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
api.derive.chain.subscribeNewHeads().subscribe((headerExtended: HeaderExtended): void => {
// WIP https://github.com/polkadot-js/api/issues/868
@@ -212,7 +207,7 @@ describeE2E({
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> => {
it('fees: It returns an object with all relevant constract fees of type Balance', (done): void => {
api.derive.contracts.fees().subscribe((fees: DerivedContractFees): void => {
expect(fees).toEqual(expect.objectContaining({
callBaseFee: expect.any(BN),
@@ -234,7 +229,7 @@ describeE2E({
describe('derive.elections', (): void => {
describe('info', (): void => {
it('It returns an object with all relevant elections properties', async (done): Promise<void> => {
it('It returns an object with all relevant elections properties', (done): void => {
api.derive.elections.info().subscribe((info: DerivedElectionsInfo): void => {
expect(info).toEqual(expect.objectContaining({
members: expect.anything(),
@@ -252,7 +247,7 @@ describeE2E({
describe('derive.session', (): void => {
describe('sessionProgress', (): void => {
it('derive.session.sessionProgress', async (done): Promise<void> => {
it('derive.session.sessionProgress', (done): void => {
api.derive.session.sessionProgress().subscribe((progress: BN): void => {
expect(progress instanceof BN).toBe(true);
done();
@@ -261,7 +256,7 @@ describeE2E({
});
describe('session.info', (): void => {
it('retrieves all session info', async (done): Promise<void> => {
it('retrieves all session info', (done): void => {
api.derive.session.info().subscribe((info: DerivedSessionInfo): void => {
expect(info).toEqual(expect.objectContaining({
currentEra: expect.anything(),
@@ -280,7 +275,7 @@ describeE2E({
});
describe('session.eraLength', (): void => {
it('derive.session.eraLength', async (done): Promise<void> => {
it('derive.session.eraLength', (done): void => {
api.derive.session.eraLength().subscribe((length: BN): void => {
expect(length instanceof BN).toBe(true);
done();
@@ -289,7 +284,7 @@ describeE2E({
});
describe('session.eraProgress', (): void => {
it('derive.session.eraProgress', async (done): Promise<void> => {
it('derive.session.eraProgress', (done): void => {
api.derive.session.eraProgress().subscribe((progress: BN): void => {
expect(progress instanceof BN).toBe(true);
done();
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { AccountId, EventRecord, Header } from '@polkadot/types/interfaces';
import { AccountId, EventRecord } from '@polkadot/types/interfaces';
import WsProvider from '@polkadot/rpc-provider/ws';
import { ClassOf, Option, Vec } from '@polkadot/types';
@@ -73,7 +73,7 @@ describeE2E({
});
it('makes a query at a latest block (specified)', async (): Promise<void> => {
const header = await api.rpc.chain.getHeader() as Header;
const header = await api.rpc.chain.getHeader();
const events = await api.query.system.events.at(header.hash) as Vec<EventRecord>;
expect(events.length).not.toEqual(0);
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { Balance, Header, Index } from '@polkadot/types/interfaces';
import { Balance, Index } from '@polkadot/types/interfaces';
import BN from 'bn.js';
@@ -40,7 +40,7 @@ describeE2E({
});
it('allows retrieval of fallback when at query is made', async (): Promise<void> => {
const header = await api.rpc.chain.getHeader() as Header;
const header = await api.rpc.chain.getHeader();
const nonce = await api.query.system.accountNonce.at(header.hash, '5DSo5RVtfrtgHoz2c7jK7Tca7FgJgpCzFnxoRVDeYUQcKPng');
expect(nonce.toHex()).toEqual('0x0000000000000000');
@@ -131,7 +131,7 @@ describeE2E({
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 header = await api.rpc.chain.getHeader();
const balanceAt = await api.query.balances.freeBalance.at(header.hash, keyring.alice_stash.address) as Balance;
expect(balanceAt.isZero()).toBe(false);
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { Header, Keys } from '@polkadot/types/interfaces';
import { Keys } from '@polkadot/types/interfaces';
import testingPairs from '@polkadot/keyring/testingPairs';
import WsProvider from '@polkadot/rpc-provider/ws';
@@ -41,7 +41,7 @@ describeE2E({
});
it('queries correct value at a specified block', async (): Promise<void> => {
const header = await api.rpc.chain.getHeader() as Header;
const header = await api.rpc.chain.getHeader();
// 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);
@@ -98,7 +98,7 @@ describeE2E({
});
describe('session Keys', (): void => {
it('sets a session key, retrieves the value', async (done): Promise<void> => {
it('sets a session key, retrieves the value', (done): void => {
const babe = encodeAddress(randomAsU8a());
const grandpa = encodeAddress(randomAsU8a());
const imOnline = encodeAddress(randomAsU8a());
@@ -72,14 +72,14 @@ describeE2E()('Promise e2e queries', (wsUrl: string): void => {
});
it('can retrive header by hash', async (): Promise<void> => {
const latest = await api.rpc.chain.getHeader() as Header;
const specific = await api.rpc.chain.getHeader(latest.hash) as Header;
const latest = await api.rpc.chain.getHeader();
const specific = await api.rpc.chain.getHeader(latest.hash);
expect(latest.hash).toEqual(specific.hash);
});
it('makes a query at a latest block (specified)', async (): Promise<void> => {
const header = await api.rpc.chain.getHeader() as Header;
const header = await api.rpc.chain.getHeader();
const events = await api.query.system.events.at(header.hash) as Vec<EventRecord>;
expect(events.length).not.toEqual(0);
@@ -106,7 +106,7 @@ describeE2E()('Promise e2e queries', (wsUrl: string): void => {
});
it('queries correct value at a specified block', async (): Promise<void> => {
const header = await api.rpc.chain.getHeader() as Header;
const header = await api.rpc.chain.getHeader();
const sessionIndex = await api.query.session.currentIndex.at(header.hash) as SessionIndex;
expect(sessionIndex.toNumber()).toBeGreaterThanOrEqual(0);
@@ -4,7 +4,7 @@
import testingPairs from '@polkadot/keyring/testingPairs';
import WsProvider from '@polkadot/rpc-provider/ws';
import { EventRecord, Header, Index, SignedBlock } from '@polkadot/types/interfaces';
import { EventRecord, Header, Index } from '@polkadot/types/interfaces';
import { createType } from '@polkadot/types';
import { SubmittableResult } from '../../../src';
@@ -50,7 +50,7 @@ describeE2E({
describe('eras', (): void => {
it('makes a transfer (specified era)', async (done): Promise<void> => {
const signedBlock = await api.rpc.chain.getBlock() as SignedBlock;
const signedBlock = await api.rpc.chain.getBlock();
const currentHeight = signedBlock.block.header.number;
const exERA = createType('ExtrinsicEra', { current: currentHeight, period: 4 });
const ex = api.tx.balances.transfer(keyring.eve.address, 12345);
@@ -62,7 +62,7 @@ describeE2E({
});
it('makes a transfer (specified era, previous block)', async (done): Promise<void> => {
const signedBlock = await api.rpc.chain.getBlock() as SignedBlock;
const signedBlock = await api.rpc.chain.getBlock();
const currentHeight = signedBlock.block.header.number.toBn().subn(1);
const exERA = createType('ExtrinsicEra', { current: currentHeight, period: 10 });
const ex = api.tx.balances.transfer(keyring.eve.address, 12345);
@@ -75,7 +75,7 @@ describeE2E({
it('fails on a transfer with invalid time', async (done): Promise<void> => {
const nonce = await api.query.system.accountNonce(keyring.alice.address) as Index;
const signedBlock = await api.rpc.chain.getBlock() as SignedBlock;
const signedBlock = await api.rpc.chain.getBlock();
const currentHeight = signedBlock.block.header.number;
const exERA = createType('ExtrinsicEra', { current: currentHeight, period: 4 });
const eraDeath = exERA.asMortalEra.death(currentHeight.toNumber());
@@ -104,7 +104,7 @@ describeE2E({
api.setSigner(signer);
const nonce = await api.query.system.accountNonce(keyring.bob_stash.address) as Index;
const signedBlock = await api.rpc.chain.getBlock() as SignedBlock;
const signedBlock = await api.rpc.chain.getBlock();
const currentHeight = signedBlock.block.header.number;
const exERA = createType('ExtrinsicEra', { current: currentHeight, period: 4 });
const eraDeath = exERA.asMortalEra.death(currentHeight.toNumber());
@@ -47,6 +47,7 @@ describeE2E({
beforeAll(async (done): Promise<() => void> => {
abi = new Abi(incrementerAbi);
api = await ApiPromise.create({ provider: new WsProvider(wsUrl) });
return (
api.tx.contracts
.putCode(MAX_GAS, `0x${incrementerCode}`)
@@ -62,7 +63,7 @@ describeE2E({
);
});
beforeEach(async (done): Promise<void> => {
beforeEach((done): void => {
rpc = new Rpc(new WsProvider(wsUrl));
done();
});
@@ -15,7 +15,7 @@ export class SingleAccountSigner implements Signer {
private signDelay: number;
public constructor (keyringPair: KeyringPair, signDelay: number = 0) {
public constructor (keyringPair: KeyringPair, signDelay = 0) {
this.keyringPair = keyringPair;
this.signDelay = signDelay;
}