Tests for approvalFlagToBool (#1251)
* Tests for approvalFlagToBool * Merge master
This commit is contained in:
@@ -28,10 +28,16 @@ export function approvalsOf (api: ApiInterfaceRx): (who: AccountId) => Observabl
|
||||
(api.query.elections.nextVoterSet<SetIndex>())
|
||||
.pipe(
|
||||
switchMap((nextVoterSet: SetIndex): Observable<Vec<ApprovalFlag>[]> =>
|
||||
api.query.elections.approvalsOf.multi([...Array(nextVoterSet.toNumber() + 1).keys()].map((i): [string, number] => [who.toString(), i])) as any as Observable<Vec<ApprovalFlag>[]>
|
||||
api.query.elections.approvalsOf.multi(
|
||||
[...Array(nextVoterSet.toNumber() + 1).keys()].map((i): [string, number] => [
|
||||
who.toString(), i]
|
||||
)
|
||||
) as any as Observable<Vec<ApprovalFlag>[]>
|
||||
),
|
||||
map((votes: Vec<ApprovalFlag>[]): boolean[][] =>
|
||||
votes.map((flags: Vec<ApprovalFlag>): boolean[] => approvalFlagsToBools(flags))
|
||||
votes.map((flags: Vec<ApprovalFlag>): boolean[] =>
|
||||
approvalFlagsToBools(flags)
|
||||
)
|
||||
),
|
||||
drr()
|
||||
);
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
// 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 { ApprovalFlag } from '@polkadot/types/interfaces';
|
||||
|
||||
import { createType } from '@polkadot/types';
|
||||
|
||||
import { approvalFlagsToBools } from './approvalFlagsToBools';
|
||||
|
||||
describe('approvalFlagsToBools', (): void => {
|
||||
it('translates and empty array to empty', (): void => {
|
||||
expect(
|
||||
approvalFlagsToBools([] as ApprovalFlag[])
|
||||
).toEqual([]);
|
||||
});
|
||||
|
||||
it('translates a single input', (): void => {
|
||||
expect(
|
||||
approvalFlagsToBools([
|
||||
createType('ApprovalFlag', 0b1010)
|
||||
])
|
||||
).toEqual([false, true, false, true]);
|
||||
});
|
||||
|
||||
it('translates multiple inputs', (): void => {
|
||||
expect(
|
||||
approvalFlagsToBools([
|
||||
createType('ApprovalFlag', 0b0000),
|
||||
createType('ApprovalFlag', 0b1100)
|
||||
])
|
||||
).toEqual([false, false, false, true, true]);
|
||||
});
|
||||
});
|
||||
@@ -6,7 +6,7 @@ import { ApprovalFlag } from '@polkadot/types/interfaces/elections';
|
||||
|
||||
import { Vec } from '@polkadot/types';
|
||||
|
||||
export function approvalFlagsToBools (flags: Vec<ApprovalFlag>): boolean[] {
|
||||
export function approvalFlagsToBools (flags: Vec<ApprovalFlag> | ApprovalFlag[]): boolean[] {
|
||||
const bools: boolean[] = [];
|
||||
|
||||
flags.forEach((flag: ApprovalFlag): void => {
|
||||
|
||||
Reference in New Issue
Block a user