Fix typescript errors in recently added tests (#1032)
* type header * Fix typescript errors in recently added tests * Fix HeaderExtended type
This commit is contained in:
@@ -2,13 +2,14 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { DerivedStaking } from '../../src/types';
|
||||
import { SubmittableResult } from '../../../api/src';
|
||||
|
||||
import ApiPromise from '@polkadot/api/promise/Api';
|
||||
import testKeyring from '@polkadot/keyring/testing';
|
||||
import { WsProvider } from '@polkadot/rpc-provider';
|
||||
|
||||
import { HeaderExtended } from '../../src/type';
|
||||
import { DerivedBalances, DerivedFees, DerivedSessionInfo, DerivedStaking } from '../../src/types';
|
||||
import { SubmittableResult } from '../../../api/src';
|
||||
|
||||
const WS = 'ws://127.0.0.1:9944/';
|
||||
// const WS = 'wss://poc3-rpc.polkadot.io/';
|
||||
|
||||
@@ -34,7 +35,7 @@ describe.skip('derive e2e', () => {
|
||||
});
|
||||
|
||||
it('subscribes to newHead, retrieving the actual validator', (done) => {
|
||||
return api.derive.chain.subscribeNewHead(({ author }) => {
|
||||
return api.derive.chain.subscribeNewHead(({ author }: HeaderExtended) => {
|
||||
console.log('author', author && author.toString());
|
||||
|
||||
if (author) {
|
||||
@@ -44,7 +45,7 @@ describe.skip('derive e2e', () => {
|
||||
});
|
||||
|
||||
it('retrieves the fees (api.queryMulti)', (done) => {
|
||||
return api.derive.balances.fees((fees) => {
|
||||
return api.derive.balances.fees((fees: DerivedFees) => {
|
||||
console.error('fees', JSON.stringify(fees));
|
||||
|
||||
done();
|
||||
@@ -52,7 +53,7 @@ describe.skip('derive e2e', () => {
|
||||
});
|
||||
|
||||
it('retrieves the balances', (done) => {
|
||||
return api.derive.balances.all('5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y', (balance) => {
|
||||
return api.derive.balances.all('5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y', (balance: DerivedBalances) => {
|
||||
console.error(JSON.stringify(balance));
|
||||
|
||||
if (balance.freeBalance.gtn(1)) {
|
||||
@@ -62,7 +63,7 @@ describe.skip('derive e2e', () => {
|
||||
});
|
||||
|
||||
it('retrieves balances for a problematic account', (done) => {
|
||||
return api.derive.balances.all('5F7BJL6Z4m8RLtK7nXEqqpEqhBbd535Z3CZeYF6ccvaQAY6N', (balance) => {
|
||||
return api.derive.balances.all('5F7BJL6Z4m8RLtK7nXEqqpEqhBbd535Z3CZeYF6ccvaQAY6N', (balance: DerivedBalances) => {
|
||||
console.error(JSON.stringify(balance));
|
||||
|
||||
if (balance.availableBalance.eqn(0)) {
|
||||
@@ -74,7 +75,7 @@ describe.skip('derive e2e', () => {
|
||||
it('retrieves all session info', (done) => {
|
||||
let count = 0;
|
||||
|
||||
return api.derive.session.info((info) => {
|
||||
return api.derive.session.info((info: DerivedSessionInfo) => {
|
||||
console.error(JSON.stringify(info));
|
||||
|
||||
// 5 blocks only, then go our merry way
|
||||
@@ -87,7 +88,7 @@ describe.skip('derive e2e', () => {
|
||||
it('retrieves all staking info (for controller)', (done) => {
|
||||
const accountId = '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY';
|
||||
|
||||
return api.derive.staking.info(accountId, (info) => {
|
||||
return api.derive.staking.info(accountId, (info: DerivedStaking) => {
|
||||
console.error(JSON.stringify(info));
|
||||
|
||||
expect(info.accountId.eq(accountId)).toBe(true);
|
||||
|
||||
@@ -8,6 +8,9 @@ import ApiRx from '@polkadot/api/rx/Api';
|
||||
import { AccountId, AccountIndex, Balance, BlockNumber, Index } from '@polkadot/types';
|
||||
import { WsProvider } from '@polkadot/rpc-provider';
|
||||
|
||||
import { HeaderExtended } from '../../src/type';
|
||||
import { DerivedBalances, DerivedFees } from '../../src/types';
|
||||
|
||||
const WS_LOCAL = 'ws://127.0.0.1:9944/';
|
||||
// const WS_POC3 = 'wss://poc3-rpc.polkadot.io/';
|
||||
|
||||
@@ -112,7 +115,7 @@ describe.skip('derive e2e', () => {
|
||||
describe('derive.balances', () => {
|
||||
describe('all', () => {
|
||||
it('It returns an object with all relevant balance information of an account', async (done) => {
|
||||
api.derive.balances.all(ID).subscribe((balances) => {
|
||||
api.derive.balances.all(ID).subscribe((balances: DerivedBalances) => {
|
||||
expect(balances).toEqual(expect.objectContaining({
|
||||
accountId: expect.any(AccountId),
|
||||
accountNonce: expect.any(Index),
|
||||
@@ -130,7 +133,7 @@ describe.skip('derive e2e', () => {
|
||||
|
||||
describe('fees', () => {
|
||||
it('fees: It returns an object with all relevant fees of type BN', async (done) => {
|
||||
api.derive.balances.fees().subscribe((fees) => {
|
||||
api.derive.balances.fees().subscribe((fees: DerivedFees) => {
|
||||
expect(fees).toEqual(expect.objectContaining({
|
||||
creationFee: expect.any(BN),
|
||||
existentialDeposit: expect.any(BN),
|
||||
@@ -147,7 +150,7 @@ describe.skip('derive e2e', () => {
|
||||
describe('derive.chain', () => {
|
||||
describe('bestNumber', () => {
|
||||
it('Get the latest block number', async (done) => {
|
||||
api.derive.chain.bestNumber().subscribe((blockNumber) => {
|
||||
api.derive.chain.bestNumber().subscribe((blockNumber: BlockNumber) => {
|
||||
expect(blockNumber instanceof BlockNumber).toBe(true);
|
||||
expect(blockNumber.gten(0)).toBe(true);
|
||||
done();
|
||||
@@ -157,7 +160,7 @@ describe.skip('derive e2e', () => {
|
||||
|
||||
describe('bestNumberFinalized', () => {
|
||||
it('Get the latest finalised block number', async (done) => {
|
||||
api.derive.chain.bestNumberFinalized().subscribe((blockNumber) => {
|
||||
api.derive.chain.bestNumberFinalized().subscribe((blockNumber: BlockNumber) => {
|
||||
expect(blockNumber instanceof BlockNumber).toBe(true);
|
||||
expect(blockNumber.gten(0)).toBe(true);
|
||||
done();
|
||||
@@ -167,7 +170,7 @@ describe.skip('derive e2e', () => {
|
||||
|
||||
describe('bestNumberLag', () => {
|
||||
it('lag between finalised head and best head', async (done) => {
|
||||
api.derive.chain.bestNumberLag().subscribe((numberLag) => {
|
||||
api.derive.chain.bestNumberLag().subscribe((numberLag: BlockNumber) => {
|
||||
expect(numberLag instanceof BlockNumber).toBe(true);
|
||||
expect(numberLag.gten(0)).toBe(true);
|
||||
done();
|
||||
@@ -178,7 +181,7 @@ describe.skip('derive e2e', () => {
|
||||
// FIXME https://github.com/polkadot-js/api/issues/868
|
||||
describe.skip('getHeader', () => {
|
||||
it('gets a specific block header and extended with it\`s author', async (done) => {
|
||||
api.derive.chain.getHeader('TODO').subscribe((headerExtended) => {
|
||||
api.derive.chain.getHeader('TODO').subscribe((headerExtended: HeaderExtended | undefined) => {
|
||||
// WIP
|
||||
expect(headerExtended).toEqual(expect.arrayContaining([]));
|
||||
done();
|
||||
@@ -188,7 +191,7 @@ describe.skip('derive e2e', () => {
|
||||
|
||||
describe('subscribeNewHead', () => {
|
||||
it('gets an observable of the current block header and it\'s author', async (done) => {
|
||||
api.derive.chain.subscribeNewHead().subscribe((headerExtended) => {
|
||||
api.derive.chain.subscribeNewHead().subscribe((headerExtended: HeaderExtended) => {
|
||||
// WIP https://github.com/polkadot-js/api/issues/868
|
||||
done();
|
||||
});
|
||||
@@ -199,7 +202,7 @@ describe.skip('derive e2e', () => {
|
||||
describe('derive.session', () => {
|
||||
describe('sessionProgress', () => {
|
||||
it('derive.session.sessionProgress', async (done) => {
|
||||
api.derive.session.sessionProgress().subscribe((progress) => {
|
||||
api.derive.session.sessionProgress().subscribe((progress: BN) => {
|
||||
expect(progress instanceof BN).toBe(true);
|
||||
done();
|
||||
});
|
||||
|
||||
@@ -31,7 +31,7 @@ export default async function test () {
|
||||
console.log('current blockNumber:', header.blockNumber);
|
||||
});
|
||||
|
||||
await api.derive.chain.subscribeNewHead((header) => {
|
||||
await api.derive.chain.subscribeNewHead((header: HeaderExtended) => {
|
||||
console.log('current author:', header.author);
|
||||
});
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import WsProvider from '@polkadot/rpc-provider/ws';
|
||||
import { EventRecord, Hash, Header, Vector } from '@polkadot/types';
|
||||
import { AccountId, EventRecord, Hash, Header, Option, Vector } from '@polkadot/types';
|
||||
|
||||
import Api from './../../src/promise';
|
||||
|
||||
@@ -68,7 +68,7 @@ describe.skip('alex queries', () => {
|
||||
|
||||
it('derives a list of the controllers', (done) => {
|
||||
return (
|
||||
api.derive.staking.controllers((res) => {
|
||||
api.derive.staking.controllers((res: [Array<AccountId>, Array<Option<AccountId>>]) => {
|
||||
console.log('api.derive.staking.controllers:', JSON.stringify(res));
|
||||
|
||||
done();
|
||||
|
||||
@@ -4,10 +4,12 @@
|
||||
|
||||
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 { LinkageResult } from '@polkadot/types/codec/Linkage';
|
||||
import { Balance, EventRecord, Header, Option, ValidatorPrefs, Vector } from '@polkadot/types';
|
||||
import { Balance, EventRecord, Header, Index, Option, ValidatorPrefs, Vector } from '@polkadot/types';
|
||||
|
||||
import Api from './../../src/promise';
|
||||
|
||||
@@ -84,7 +86,7 @@ describe.skip('Promise e2e queries', () => {
|
||||
|
||||
it('subscribes to derive', (done) => {
|
||||
return (
|
||||
api.derive.chain.subscribeNewHead((header) => {
|
||||
api.derive.chain.subscribeNewHead((header: HeaderExtended) => {
|
||||
expect(header.blockNumber.isZero()).toBe(false);
|
||||
|
||||
done();
|
||||
@@ -94,7 +96,7 @@ describe.skip('Promise e2e queries', () => {
|
||||
|
||||
it('subscribes to queries', (done) => {
|
||||
return (
|
||||
api.query.system.accountNonce(keyring.ferdie.address, (nonce) => {
|
||||
api.query.system.accountNonce(keyring.ferdie.address, (nonce: Index) => {
|
||||
expect(nonce instanceof BN).toBe(true);
|
||||
|
||||
done();
|
||||
@@ -154,7 +156,7 @@ describe.skip('Promise e2e queries', () => {
|
||||
return (
|
||||
api.derive.balances.all(
|
||||
keyring.alice.address,
|
||||
(all) => {
|
||||
(all: DerivedBalances) => {
|
||||
expect(all.accountId.toString()).toEqual(keyring.alice.address);
|
||||
|
||||
expect(all.freeBalance).toBeDefined();
|
||||
|
||||
Reference in New Issue
Block a user