* Error handling in ERC20 and ERC721 * Added message string for require. * Fixed solhint errors. * Updated PR as per issue #1709 * changes as per #1709 and openzeppelin forum. * Changes in require statement * Changes in require statement * build pipeline fix * Changes as per @nventuro's comment. * Update revert reason strings. * Fianal update of revert reason strings. * WIP: Updating reason strings in test cases * WIP: Added changes to ERC20 and ERC721 * Fixes linting errors in *.tes.js files * Achieved 100% code coverage * Updated the test cases with shouldFail.reverting.withMessage() * Fix package-lock. * address review comments * fix linter issues * fix remaining revert reasons
61 lines
1.8 KiB
Solidity
61 lines
1.8 KiB
Solidity
pragma solidity ^0.5.7;
|
|
|
|
/**
|
|
* @title SignedSafeMath
|
|
* @dev Signed math operations with safety checks that revert on error.
|
|
*/
|
|
library SignedSafeMath {
|
|
int256 constant private INT256_MIN = -2**255;
|
|
|
|
/**
|
|
* @dev Multiplies two signed integers, reverts on overflow.
|
|
*/
|
|
function mul(int256 a, int256 b) internal pure returns (int256) {
|
|
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
|
|
// benefit is lost if 'b' is also tested.
|
|
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
|
|
if (a == 0) {
|
|
return 0;
|
|
}
|
|
|
|
require(!(a == -1 && b == INT256_MIN), "SignedSafeMath: multiplication overflow");
|
|
|
|
int256 c = a * b;
|
|
require(c / a == b, "SignedSafeMath: multiplication overflow");
|
|
|
|
return c;
|
|
}
|
|
|
|
/**
|
|
* @dev Integer division of two signed integers truncating the quotient, reverts on division by zero.
|
|
*/
|
|
function div(int256 a, int256 b) internal pure returns (int256) {
|
|
require(b != 0, "SignedSafeMath: division by zero");
|
|
require(!(b == -1 && a == INT256_MIN), "SignedSafeMath: division overflow");
|
|
|
|
int256 c = a / b;
|
|
|
|
return c;
|
|
}
|
|
|
|
/**
|
|
* @dev Subtracts two signed integers, reverts on overflow.
|
|
*/
|
|
function sub(int256 a, int256 b) internal pure returns (int256) {
|
|
int256 c = a - b;
|
|
require((b >= 0 && c <= a) || (b < 0 && c > a), "SignedSafeMath: subtraction overflow");
|
|
|
|
return c;
|
|
}
|
|
|
|
/**
|
|
* @dev Adds two signed integers, reverts on overflow.
|
|
*/
|
|
function add(int256 a, int256 b) internal pure returns (int256) {
|
|
int256 c = a + b;
|
|
require((b >= 0 && c >= a) || (b < 0 && c < a), "SignedSafeMath: addition overflow");
|
|
|
|
return c;
|
|
}
|
|
}
|