From b8c55a3aba29bc42e08cdecab79b9eb1ed99df9c Mon Sep 17 00:00:00 2001 From: Phil Bain Date: Thu, 8 Jul 2021 13:41:57 -0600 Subject: [PATCH] add test for user's staked balance --- .../dai-plugin-governance/src/VoteDelegateService.js | 7 ++++++- .../test/VoteDelegateService.test.js | 10 ++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/dai-plugin-governance/src/VoteDelegateService.js b/packages/dai-plugin-governance/src/VoteDelegateService.js index 93395355f..76b95033d 100644 --- a/packages/dai-plugin-governance/src/VoteDelegateService.js +++ b/packages/dai-plugin-governance/src/VoteDelegateService.js @@ -1,5 +1,6 @@ import { LocalService } from '@makerdao/services-core'; import VoteDelegate from './VoteDelegate'; +import BigNumber from 'bignumber.js'; import { MKR, VOTE_DELEGATE_FACTORY, ZERO_ADDRESS } from './utils/constants'; import { fromBuffer, getCurrency } from './utils/helpers'; import voteDelegateAbi from '../contracts/abis/VoteDelegate.json'; @@ -68,7 +69,11 @@ export default class VoteDelegateService extends LocalService { } async getStakedBalanceForAddress(delegateAddress, address) { - return await this._getStakedBalanceForAddress(delegateAddress, address); + const bal = await this._getStakedBalanceForAddress( + delegateAddress, + address + ); + return new BigNumber(bal).shiftedBy(-18); } async getAllDelegates() { diff --git a/packages/dai-plugin-governance/test/VoteDelegateService.test.js b/packages/dai-plugin-governance/test/VoteDelegateService.test.js index c4a08897f..627cffde4 100644 --- a/packages/dai-plugin-governance/test/VoteDelegateService.test.js +++ b/packages/dai-plugin-governance/test/VoteDelegateService.test.js @@ -78,6 +78,16 @@ test('user can lock MKR with a delegate', async () => { expect(postLockDeposits.toNumber()).toBe(amountToLock); }); +test("can check a user's delegated stake", async () => { + const stakedAmt = 3; + const deposits = await vds.getStakedBalanceForAddress( + delegateContractAddress, + maker.currentAccount().address + ); + + expect(deposits.toNumber()).toBe(stakedAmt); +}); + test('delegate can cast an executive vote and retrieve voted on addresses from slate', async () => { maker.useAccountWithAddress(delegateAddress);