From 4378ed4bb8fb3d46cad1f640c6c6ebe6bfaa7bde Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Fri, 10 May 2019 12:06:02 +0200 Subject: [PATCH] Remove combineLatest where multi is used (#895) * Remove combineLatest where multi is used * Add e2e test for derive.controllers --- packages/api-derive/src/democracy/votes.ts | 20 +++++++++++-------- .../api-derive/src/staking/controllers.ts | 8 +------- packages/api/test/e2e/promise-alex.spec.js | 14 ++++++++++++- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/packages/api-derive/src/democracy/votes.ts b/packages/api-derive/src/democracy/votes.ts index 6bd0d72343..d8beff079b 100644 --- a/packages/api-derive/src/democracy/votes.ts +++ b/packages/api-derive/src/democracy/votes.ts @@ -3,7 +3,7 @@ // of the Apache-2.0 license. See the LICENSE file for details. import BN from 'bn.js'; -import { combineLatest, Observable, of } from 'rxjs'; +import { Observable, of } from 'rxjs'; import { ApiInterface$Rx } from '@polkadot/api/types'; import { AccountId, Vote } from '@polkadot/types'; @@ -11,12 +11,16 @@ import { drr } from '../util/drr'; export function votes (api: ApiInterface$Rx) { return (referendumId: BN, accountIds: Array = []): Observable> => { - return !accountIds || !accountIds.length - ? of([]).pipe(drr()) - : combineLatest( - api.query.democracy.voteOf.multi(accountIds.map(accountId => [referendumId, accountId])) as Observable - ).pipe( - drr() - ); + return ( + !accountIds || !accountIds.length + ? of([]) + : api.query.democracy.voteOf.multi( + accountIds.map(accountId => + [referendumId, accountId] + ) + ) as any as Observable> + ).pipe( + drr() + ); }; } diff --git a/packages/api-derive/src/staking/controllers.ts b/packages/api-derive/src/staking/controllers.ts index 53f14fba9f..1d25b44af2 100644 --- a/packages/api-derive/src/staking/controllers.ts +++ b/packages/api-derive/src/staking/controllers.ts @@ -9,12 +9,6 @@ import { AccountId, Option } from '@polkadot/types'; import { drr } from '../util/drr'; -function allBonds (api: ApiInterface$Rx, stashIds: Array) { - return combineLatest( - api.query.staking.bonded.multi(stashIds) as Observable> - ); -} - /** * @description From the list of stash accounts, retrieve the list of controllers */ @@ -25,7 +19,7 @@ export function controllers (api: ApiInterface$Rx) { switchMap(([stashIds]) => combineLatest([ of(stashIds), - allBonds(api, stashIds) + api.query.staking.bonded.multi(stashIds) as any as Observable>> ]) ), drr() diff --git a/packages/api/test/e2e/promise-alex.spec.js b/packages/api/test/e2e/promise-alex.spec.js index b2a2cbcb10..1a67f96a42 100644 --- a/packages/api/test/e2e/promise-alex.spec.js +++ b/packages/api/test/e2e/promise-alex.spec.js @@ -12,7 +12,7 @@ describe.skip('alex queries', () => { jest.setTimeout(3000000); }); - describe.skip('Remote RPC queries', () => { + describe('Remote RPC queries', () => { beforeAll(async () => { api = await Api.create({ provider: new WsProvider('wss://poc3-rpc.polkadot.io/') @@ -29,6 +29,18 @@ describe.skip('alex queries', () => { }); }); + it('retrieves the list of the controllers', (done) => { + api.derive.staking.constrollers((res) => { + console.log('api.query.staking.controllers():', res.toJSON()); + + expect(res.length).toHaveLength(2); + expect(res[0].length).not.toHaveLength(0); + expect(res[0].length).toEqual(res[1].length); + + done(); + }); + }); + it('retrieves a single value', (done) => { api.query.staking.validators('5EF7wdkP9XZq38fu2ioAvxoEhHUJUc1E2KbuSQSMGofRKhCL', (res) => { console.log('api.query.staking.validators(id):', res.toJSON());