-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0bacae4
commit 8410f54
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* These tests are only for mul and add overflows. | ||
sub, div, rounded div covered by other test cases | ||
*/ | ||
|
||
const BigNumber = require("bignumber.js"); | ||
const Locker = artifacts.require("./Locker.sol"); | ||
const testHelpers = require("./helpers/testHelpers.js"); | ||
const MonetarySupervisor = artifacts.require("./MonetarySupervisor.sol"); | ||
|
||
let locker; | ||
let monetarySupervisor; | ||
const MAX_UINT256 = new BigNumber(2).pow(256).sub(1); | ||
|
||
contract("SafeMath", () => { | ||
before(() => { | ||
locker = Locker.at(Locker.address); | ||
monetarySupervisor = MonetarySupervisor.at(MonetarySupervisor.address); | ||
}); | ||
|
||
it("should throw if mul overflows", async function() { | ||
await testHelpers.expectThrow( | ||
locker.calculateInterest( | ||
2, | ||
MAX_UINT256.add(1) | ||
.div(2) | ||
.round(0, BigNumber.ROUND_UP) | ||
) | ||
); | ||
}); | ||
|
||
it("should throw if add overflows", async function() { | ||
await monetarySupervisor.issueToReserve(1); | ||
await testHelpers.expectThrow(monetarySupervisor.issueToReserve(MAX_UINT256.toString())); | ||
}); | ||
}); |