Add rewardDestination to derive.staking.info (#977)

* rewardDestination in staking.info

* squash a couple lines together to please CodeClimate
This commit is contained in:
Thibaut Sardan
2019-06-07 12:14:14 +02:00
committed by Jaco Greeff
parent 91ae98c9e6
commit 5f43da0623
3 changed files with 45 additions and 26 deletions
+11 -11
View File
@@ -3,7 +3,7 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import { ApiInterface$Rx } from '@polkadot/api/types';
import { AccountId, BlockNumber, Exposure, Option, StakingLedger,StructAny, ValidatorPrefs, UnlockChunk } from '@polkadot/types';
import { AccountId, BlockNumber, Exposure, Option, RewardDestination, StakingLedger, StructAny, ValidatorPrefs, UnlockChunk } from '@polkadot/types';
import { DerivedStaking, DerivedUnlocking } from '../types';
import BN from 'bn.js';
@@ -80,22 +80,22 @@ function withStashController (api: ApiInterface$Rx, accountId: AccountId, contro
[api.query.session.nextKeyFor, controllerId],
[api.query.staking.ledger, controllerId],
[api.query.staking.nominators, stashId],
[api.query.staking.payee, stashId],
[api.query.staking.stakers, stashId],
[api.query.staking.validators, stashId]
])
]) as any as Observable<[BN, BlockNumber, [Option<AccountId>, Option<StakingLedger>, [Array<AccountId>], Exposure, [ValidatorPrefs]]]>
]) as any as Observable<[BN, BlockNumber, [Option<AccountId>, Option<StakingLedger>, [Array<AccountId>], RewardDestination, Exposure, [ValidatorPrefs]]]>
).pipe(
map(([eraLength, bestNumber,[nextKeyFor, _stakingLedger, [nominators], stakers, [validatorPrefs]]]) => {
map(([eraLength, bestNumber,[nextKeyFor, _stakingLedger, [nominators], rewardDestination, stakers, [validatorPrefs]]]) => {
const stakingLedger = _stakingLedger.isSome ? _stakingLedger.unwrap() : undefined;
return new StructAny({
accountId,
controllerId,
nextSessionId: nextKeyFor.isSome
? nextKeyFor.unwrap()
: undefined,
nextSessionId: nextKeyFor.unwrapOr(null) || undefined,
nominators,
redeemable: redeemableSum(stakingLedger, eraLength, bestNumber),
rewardDestination,
stakers,
stakingLedger,
stashId,
@@ -115,18 +115,18 @@ function withControllerLedger (api: ApiInterface$Rx, accountId: AccountId, staki
api.queryMulti([
[api.query.session.nextKeyFor, controllerId],
[api.query.staking.nominators, stashId],
[api.query.staking.payee, stashId],
[api.query.staking.stakers, stashId],
[api.query.staking.validators, stashId]
]) as any as Observable<[Option<AccountId>, [Array<AccountId>], Exposure, [ValidatorPrefs]]>
]) as any as Observable<[Option<AccountId>, [Array<AccountId>], RewardDestination, Exposure, [ValidatorPrefs]]>
).pipe(
map(([nextKeyFor, [nominators], stakers, [validatorPrefs]]) =>
map(([nextKeyFor, [nominators], rewardDestination, stakers, [validatorPrefs]]) =>
new StructAny({
accountId,
controllerId,
nextSessionId: nextKeyFor.isSome
? nextKeyFor.unwrap()
: undefined,
nextSessionId: nextKeyFor.unwrapOr(null) || undefined,
nominators,
rewardDestination,
stakers,
stakingLedger,
stashId,
+2 -1
View File
@@ -3,7 +3,7 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import BN from 'bn.js';
import { AccountId, Balance, BlockNumber, Exposure, Index, StakingLedger, StructAny, ValidatorPrefs, Vote } from '@polkadot/types';
import { AccountId, Balance, BlockNumber, Exposure, Index, RewardDestination, StakingLedger, StructAny, ValidatorPrefs, Vote } from '@polkadot/types';
export interface DerivedBalances extends StructAny {
accountId: AccountId;
@@ -64,6 +64,7 @@ export interface DerivedStaking extends StructAny {
nextSessionId?: AccountId;
nominators?: Array<AccountId>;
redeemable?: BN;
rewardDestination?: RewardDestination;
stakers?: Exposure;
stakingLedger?: StakingLedger;
stashId?: AccountId;
+32 -14
View File
@@ -120,24 +120,12 @@ describe.skip('derive e2e', () => {
});
describe('verifies derive.staking.unlocking',() => {
const BOND_VALUE = 10;
const UNBOND_VALUE = 1;
const ALICE_STASH = '5GNJqTPyNqANBkUVMN1LPPrxXnFouWXoe2wNSmmEoLctxiZY';
const ALICE = '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY';
const keyring = testKeyring();
const aliceStashPair = keyring.getPair(ALICE_STASH);
const alicePair = keyring.getPair(ALICE);
it('bondsExtra funds for Alice Stash', (done) => {
return api.tx.staking.bondExtra(BOND_VALUE)
.signAndSend(aliceStashPair, (result: SubmittableResult) => {
if (result.status.isFinalized) {
done();
}
});
});
it('unbonds dots for Alice (from Alice Stash)', (done) => {
return api.tx.staking.unbond(UNBOND_VALUE)
.signAndSend(alicePair, (result: SubmittableResult) => {
@@ -149,8 +137,38 @@ describe.skip('derive e2e', () => {
});
it('verifies that derive.staking.unlocking isn\'t empty/undefined', () => {
return api.derive.session.info(ALICE_STASH, (info: DerivedStaking) => {
expect(info.unlocking).toBeGreaterThan(0);
return api.derive.staking.info(ALICE_STASH, (info: DerivedStaking) => {
expect(info.unlocking).toBeDefined();
});
});
});
describe('verifies derive.staking.rewardDestination',() => {
const PAYEE = 2;
const ALICE_STASH = '5GNJqTPyNqANBkUVMN1LPPrxXnFouWXoe2wNSmmEoLctxiZY';
const ALICE = '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY';
const keyring = testKeyring();
const alicePair = keyring.getPair(ALICE);
it('Set payee for ALICE to 2', (done) => {
return api.tx.staking.setPayee(PAYEE)
.signAndSend(alicePair, (result: SubmittableResult) => {
if (result.status.isFinalized) {
done();
}
});
});
it('verifies payee for ALICE_STASH', (done) => {
return api.derive.staking.info(ALICE_STASH, (info: DerivedStaking) => {
if (!info.rewardDestination) {
return done.fail(new Error('rewardDestination is undefined.'));
} else {
expect(info.rewardDestination.toString()).toBe('Controller');
}
done();
});
});
});