pass safe_math_tests

pull/5370/head
Omkara 6 years ago committed by 0mkar
parent 275a210da4
commit 696b8c649d
  1. 1
      remix-tests/tests/examples_1/simple_storage_test.sol
  2. 1
      remix-tests/tests/examples_2/simple_storage.sol
  3. 2
      remix-tests/tests/examples_4/SafeMath.sol
  4. 12
      remix-tests/tests/examples_4/SafeMathProxy.sol
  5. 37
      remix-tests/tests/examples_4/SafeMath_test.sol

@ -26,5 +26,4 @@ contract MyTest {
function shouldTriggerOnePass() public { function shouldTriggerOnePass() public {
Assert.equal(uint(1), uint(1), "the test 3 fails"); Assert.equal(uint(1), uint(1), "the test 3 fails");
} }
} }

@ -13,5 +13,4 @@ contract SimpleStorage {
function get() public view returns (uint retVal) { function get() public view returns (uint retVal) {
return storedData; return storedData;
} }
} }

@ -1,6 +1,6 @@
// Copyright (c) 2016 Smart Contract Solutions, Inc. // Copyright (c) 2016 Smart Contract Solutions, Inc.
pragma solidity ^0.4.24; pragma solidity >=0.4.22 <0.6.0;
/** /**

@ -1,4 +1,4 @@
pragma solidity ^0.4.24; pragma solidity >=0.4.22 <0.6.0;
import "./SafeMath.sol"; import "./SafeMath.sol";
/* /*
@ -9,23 +9,23 @@ https://truffleframework.com/tutorials/testing-for-throws-in-solidity-tests
contract SafeMathProxy { contract SafeMathProxy {
using SafeMath for uint; using SafeMath for uint;
function divProxy(uint256 a, uint256 b) returns (uint256) { function divProxy(uint256 a, uint256 b) public pure returns (uint256) {
return a.div(b); return a.div(b);
} }
function mulProxy(uint256 a, uint256 b) returns (uint256) { function mulProxy(uint256 a, uint256 b) public pure returns (uint256) {
return a.mul(b); return a.mul(b);
} }
function subProxy(uint256 a, uint256 b) returns (uint256) { function subProxy(uint256 a, uint256 b) public pure returns (uint256) {
return a.sub(b); return a.sub(b);
} }
function addProxy(uint256 a, uint256 b) returns (uint256) { function addProxy(uint256 a, uint256 b) public pure returns (uint256) {
return a.add(b); return a.add(b);
} }
function modProxy(uint256 a, uint256 b) returns (uint256) { function modProxy(uint256 a, uint256 b) public pure returns (uint256) {
return a.mod(b); return a.mod(b);
} }
} }

@ -1,16 +1,16 @@
pragma solidity ^0.4.24; pragma solidity >=0.4.22 <0.6.0;
import "./remix_tests.sol"; import "remix_tests.sol";
import "./SafeMath.sol"; import "./SafeMath.sol";
import "./SafeMathProxy.sol"; import "./SafeMathProxy.sol";
contract SafeMathTest { contract SafeMathTest {
SafeMathProxy safemathproxy; SafeMathProxy safemathproxy;
function beforeAll() { function beforeAll() public {
safemathproxy = new SafeMathProxy(); safemathproxy = new SafeMathProxy();
} }
function unsafeMultiplicationShouldOverflow() public view returns (bool) { function unsafeMultiplicationShouldOverflow() public returns (bool) {
uint256 a = 4; uint256 a = 4;
uint256 b = 2 ** 256 - 1; uint256 b = 2 ** 256 - 1;
return Assert.equal( return Assert.equal(
@ -20,27 +20,29 @@ contract SafeMathTest {
); );
} }
function safeMultiplicationShouldRevert() public view returns (bool) { function safeMultiplicationShouldRevert() public returns (bool) {
uint256 a = 4; uint256 a = 4;
uint256 b = 2 ** 256 - 1; uint256 b = 2 ** 256 - 1;
(bool success, bytes memory data) = address(safemathproxy).call.gas(40000).value(0)(abi.encode("mulProxy, [a, b]"));
return Assert.equal( return Assert.equal(
address(safemathproxy).call.gas(40000).value(0)("mulProxy",[a, b]), success,
false, false,
"safe multiplication did not revert" "safe multiplication did not revert"
); );
} }
function safeDivisionByZeroShouldRevert() public view returns (bool) { function safeDivisionByZeroShouldRevert() public returns (bool) {
uint256 a = 4; uint256 a = 4;
uint256 b = 0; uint256 b = 0;
(bool success, bytes memory data) = address(safemathproxy).call.gas(40000).value(0)(abi.encode("divProxy, [a, b]"));
return Assert.equal( return Assert.equal(
address(safemathproxy).call.gas(40000).value(0)("divProxy", [a, b]), success,
false, false,
"safe division did not revert" "safe division did not revert"
); );
} }
function unsafeSubtractShouldUnderflow() public view returns (bool) { function unsafeSubtractShouldUnderflow() public returns (bool) {
uint256 a = 0; uint256 a = 0;
uint256 b = a - 1; uint256 b = a - 1;
return Assert.equal( return Assert.equal(
@ -50,35 +52,38 @@ contract SafeMathTest {
); );
} }
function safeSubtractShouldRevert() public constant returns (bool) { function safeSubtractShouldRevert() public returns (bool) {
(bool success, bytes memory data) = address(safemathproxy).call.gas(40000).value(0)(abi.encode("subProxy, [0, 1]"));
return Assert.equal( return Assert.equal(
address(safemathproxy).call.gas(40000).value(0)("subProxy", [0, 1]), success,
false, false,
"safe subtract should revert" "safe subtract should revert"
); );
} }
function unsafeAdditionShouldOverflow() public constant returns (bool) { function unsafeAdditionShouldOverflow() public returns (bool) {
uint256 a = 1; uint256 a = 1;
uint256 b = 2 ** 256 - 1; uint256 b = 2 ** 256 - 1;
return Assert.equal(a + b, 0, "unsafe addition did not overflow"); return Assert.equal(a + b, 0, "unsafe addition did not overflow");
} }
function safeAdditionShouldRevert() public constant returns (bool) { function safeAdditionShouldRevert() public returns (bool) {
uint256 a = 1; uint256 a = 1;
uint256 b = 2 ** 256 - 1; uint256 b = 2 ** 256 - 1;
(bool success, bytes memory data) = address(safemathproxy).call.gas(40000).value(0)(abi.encode("addProxy, [a, b]"));
return Assert.equal( return Assert.equal(
address(safemathproxy).call.gas(40000).value(0)("addProxy", [a, b]), success,
false, false,
"safe addition should revert" "safe addition should revert"
); );
} }
function safeModulusShouldRevert() public constant returns (bool) { function safeModulusShouldRevert() public returns (bool) {
uint256 a = 1; uint256 a = 1;
uint256 b = 0; uint256 b = 0;
(bool success, bytes memory data) = address(safemathproxy).call.gas(40000).value(0)(abi.encode("modProxy, [a, b]"));
return Assert.equal( return Assert.equal(
address(safemathproxy).call.gas(40000).value(0)("modProxy", [a, b]), success,
false, false,
"safe modulus did not revert" "safe modulus did not revert"
); );

Loading…
Cancel
Save