Remove combineLatest where multi is used (#895)

* Remove combineLatest where multi is used

* Add e2e test for derive.controllers
This commit is contained in:
Jaco Greeff
2019-05-10 12:06:02 +02:00
committed by GitHub
parent 52bae20ef4
commit 4378ed4bb8
3 changed files with 26 additions and 16 deletions
+12 -8
View File
@@ -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<AccountId> = []): Observable<Array<Vote>> => {
return !accountIds || !accountIds.length
? of([]).pipe(drr())
: combineLatest(
api.query.democracy.voteOf.multi(accountIds.map(accountId => [referendumId, accountId])) as Observable<Vote>
).pipe(
drr()
);
return (
!accountIds || !accountIds.length
? of([])
: api.query.democracy.voteOf.multi(
accountIds.map(accountId =>
[referendumId, accountId]
)
) as any as Observable<Array<Vote>>
).pipe(
drr()
);
};
}
@@ -9,12 +9,6 @@ import { AccountId, Option } from '@polkadot/types';
import { drr } from '../util/drr';
function allBonds (api: ApiInterface$Rx, stashIds: Array<AccountId>) {
return combineLatest(
api.query.staking.bonded.multi(stashIds) as Observable<Option<AccountId>>
);
}
/**
* @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<Array<Option<AccountId>>>
])
),
drr()
+13 -1
View File
@@ -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());