remix-project mirror
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
remix-project/remix-tests/tests/examples_4/SafeMath_test.sol

87 lines
2.2 KiB

pragma solidity ^0.4.24;
import "./remix_tests.sol";
import "./SafeMath.sol";
import "./SafeMathProxy.sol";
contract SafeMathTest {
SafeMathProxy safemathproxy;
function beforeAll() {
safemathproxy = new SafeMathProxy();
}
6 years ago
function unsafeMultiplicationShouldOverflow() public view returns (bool) {
uint256 a = 4;
uint256 b = 2 ** 256 - 1;
return Assert.equal(
a * b,
2 ** 256 - 4,
"unsafe multiplication did not overflow"
);
}
6 years ago
function safeMultiplicationShouldRevert() public view returns (bool) {
uint256 a = 4;
uint256 b = 2 ** 256 - 1;
return Assert.equal(
address(safemathproxy).call.gas(40000).value(0)("mulProxy",[a, b]),
false,
"safe multiplication did not revert"
);
}
6 years ago
function safeDivisionByZeroShouldRevert() public view returns (bool) {
uint256 a = 4;
uint256 b = 0;
return Assert.equal(
address(safemathproxy).call.gas(40000).value(0)("divProxy", [a, b]),
false,
"safe division did not revert"
);
}
6 years ago
function unsafeSubtractShouldUnderflow() public view returns (bool) {
uint256 a = 0;
uint256 b = a - 1;
return Assert.equal(
b,
2 ** 256 - 1,
"unsafe subtraction did not underflow"
);
}
function safeSubtractShouldRevert() public constant returns (bool) {
return Assert.equal(
address(safemathproxy).call.gas(40000).value(0)("subProxy", [0, 1]),
false,
"safe subtract should revert"
);
}
function unsafeAdditionShouldOverflow() public constant returns (bool) {
uint256 a = 1;
uint256 b = 2 ** 256 - 1;
return Assert.equal(a + b, 0, "unsafe addition did not overflow");
}
function safeAdditionShouldRevert() public constant returns (bool) {
uint256 a = 1;
uint256 b = 2 ** 256 - 1;
return Assert.equal(
address(safemathproxy).call.gas(40000).value(0)("addProxy", [a, b]),
false,
"safe addition should revert"
);
}
function safeModulusShouldRevert() public constant returns (bool) {
uint256 a = 1;
uint256 b = 0;
return Assert.equal(
address(safemathproxy).call.gas(40000).value(0)("modProxy", [a, b]),
false,
"safe modulus did not revert"
);
}
}