safemath tests enabled and updated

pull/724/head
aniket-engg 4 years ago committed by Aniket
parent 3225071a4b
commit d3be68298f
  1. 26
      libs/remix-tests/tests/examples_4/SafeMath_test.sol
  2. 20
      libs/remix-tests/tests/testRunner.spec.ts

@ -23,7 +23,7 @@ contract SafeMathTest {
function safeMultiplicationShouldRevert() public returns (bool) {
uint256 a = 4;
uint256 b = 2 ** 256 - 1;
(bool success, bytes memory data) = address(safemathproxy).call.gas(40000).value(0)(abi.encode("mulProxy, [a, b]"));
(bool success, bytes memory data) = address(safemathproxy).call{gas:40000, value:0}(abi.encode("mulProxy, [a, b]"));
return Assert.equal(
success,
false,
@ -34,7 +34,7 @@ contract SafeMathTest {
function safeDivisionByZeroShouldRevert() public returns (bool) {
uint256 a = 4;
uint256 b = 0;
(bool success, bytes memory data) = address(safemathproxy).call.gas(40000).value(0)(abi.encode("divProxy, [a, b]"));
(bool success, bytes memory data) = address(safemathproxy).call{gas:40000, value:0}(abi.encode("divProxy, [a, b]"));
return Assert.equal(
success,
false,
@ -53,7 +53,7 @@ contract SafeMathTest {
}
function safeSubtractShouldRevert() public returns (bool) {
(bool success, bytes memory data) = address(safemathproxy).call.gas(40000).value(0)(abi.encode("subProxy, [0, 1]"));
(bool success, bytes memory data) = address(safemathproxy).call{gas:40000, value:0}(abi.encode("subProxy, [0, 1]"));
return Assert.equal(
success,
false,
@ -61,6 +61,22 @@ contract SafeMathTest {
);
}
function safeSubtractShouldRevertUsingTryCatch() public returns (bool) {
try safemathproxy.subProxy(0, 1) returns ( uint256 res) {
Assert.ok(false, "Should revert");
} catch (bytes memory /*lowLevelData*/) {
Assert.ok(true, "safe subtract should revert");
}
}
function safeSubtractShouldNotRevert() public returns (bool) {
try safemathproxy.subProxy(3, 2) returns ( uint256 res) {
Assert.equal(res, 1, "should be equal to 1");
} catch (bytes memory /*lowLevelData*/) {
Assert.ok(false, "safe subtract should not revert");
}
}
function unsafeAdditionShouldOverflow() public returns (bool) {
uint256 a = 1;
uint256 b = 2 ** 256 - 1;
@ -70,7 +86,7 @@ contract SafeMathTest {
function safeAdditionShouldRevert() public returns (bool) {
uint256 a = 1;
uint256 b = 2 ** 256 - 1;
(bool success, bytes memory data) = address(safemathproxy).call.gas(40000).value(0)(abi.encode("addProxy, [a, b]"));
(bool success, bytes memory data) = address(safemathproxy).call{gas:40000, value:0}(abi.encode("addProxy, [a, b]"));
return Assert.equal(
success,
false,
@ -81,7 +97,7 @@ contract SafeMathTest {
function safeModulusShouldRevert() public returns (bool) {
uint256 a = 1;
uint256 b = 0;
(bool success, bytes memory data) = address(safemathproxy).call.gas(40000).value(0)(abi.encode("modProxy, [a, b]"));
(bool success, bytes memory data) = address(safemathproxy).call{gas:40000, value:0}(abi.encode("modProxy, [a, b]"));
return Assert.equal(
success,
false,

@ -392,6 +392,26 @@ describe('testRunner', () => {
})
})
//Test signed/unsigned integer weight
describe('test SafeMath library', () => {
const filename: string = __dirname + '/examples_4/SafeMath_test.sol'
beforeAll(done => {
compileAndDeploy(filename, function (_err: Error | null | undefined, compilationData: object, contracts: any, asts: any, accounts: string[]) {
runTest('SafeMathTest', contracts.SafeMathTest, compilationData[filename]['SafeMathTest'], asts[filename], { accounts }, testCallback, resultsCallback(done))
})
})
afterAll(() => { tests = [] })
it('should have 10 passing tests', () => {
assert.equal(results.passingNum, 10)
})
it('should have 0 failing tests', () => {
assert.equal(results.failureNum, 0)
})
})
//Test signed/unsigned integer weight
describe('test number weight', () => {
const filename: string = __dirname + '/number/number_test.sol'

Loading…
Cancel
Save