Skip to content

Commit

Permalink
Refactor tests to support large integers: minDeposit and pMinDeposit
Browse files Browse the repository at this point in the history
* Must pass `toString()` of large number to `BN()`
* Multiply `minDeposit` by 10 instead of adding due to JS integer rounding
  • Loading branch information
kareem-ib authored and kangarang committed Aug 4, 2018
1 parent d8decda commit e2a0f66
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions test/parameterizer/challengeReparameterization.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,17 @@ contract('Parameterizer', (accounts) => {
'should have been successfully challenged');

const proposerFinalBalance = await token.balanceOf.call(proposer);
const proposerExpected = proposerStartingBalance.sub(new BN(paramConfig.pMinDeposit, 10));
const proposerExpected = proposerStartingBalance
.sub(new BN(paramConfig.pMinDeposit.toString(), 10));
assert.strictEqual(
proposerFinalBalance.toString(10), proposerExpected.toString(10),
'The challenge loser\'s token balance is not as expected',
);

// Edge case, challenger gets both deposits back because there were no voters
const challengerFinalBalance = await token.balanceOf.call(challenger);
const challengerExpected = challengerStartingBalance.add(new BN(paramConfig.pMinDeposit, 10));
const challengerExpected = challengerStartingBalance
.add(new BN(paramConfig.pMinDeposit.toString(), 10));
assert.strictEqual(
challengerFinalBalance.toString(10), challengerExpected.toString(10),
'The challenge winner\'s token balance is not as expected',
Expand Down Expand Up @@ -93,7 +95,8 @@ contract('Parameterizer', (accounts) => {
);

const challengerFinalBalance = await token.balanceOf.call(challenger);
const challengerExpected = challengerStartingBalance.sub(new BN(paramConfig.pMinDeposit, 10));
const challengerExpected = challengerStartingBalance
.sub(new BN(paramConfig.pMinDeposit.toString(), 10));
assert.strictEqual(
challengerFinalBalance.toString(10), challengerExpected.toString(10),
'The challenge loser\'s token balance is not as expected',
Expand All @@ -106,7 +109,7 @@ contract('Parameterizer', (accounts) => {
// make proposal to change pMinDeposit
// this is to induce an error where:
// a challenge could have a different stake than the proposal being challenged
const proposalReceiptOne = await utils.as(proposer, parameterizer.proposeReparameterization, 'pMinDeposit', paramConfig.pMinDeposit + 1);
const proposalReceiptOne = await utils.as(proposer, parameterizer.proposeReparameterization, 'pMinDeposit', paramConfig.pMinDeposit * 10);
const propIDOne = proposalReceiptOne.logs[0].args.propID;

// increase time
Expand Down

0 comments on commit e2a0f66

Please sign in to comment.