@0x:contracts-utils Removed SafeMath and the use of the contract throughout contracts/
This commit is contained in:
@@ -1,90 +0,0 @@
|
||||
pragma solidity ^0.5.9;
|
||||
|
||||
import "./LibRichErrors.sol";
|
||||
import "./LibSafeMathRichErrors.sol";
|
||||
|
||||
|
||||
contract SafeMath {
|
||||
|
||||
function _safeMul(uint256 a, uint256 b)
|
||||
internal
|
||||
pure
|
||||
returns (uint256)
|
||||
{
|
||||
if (a == 0) {
|
||||
return 0;
|
||||
}
|
||||
uint256 c = a * b;
|
||||
if (c / a != b) {
|
||||
LibRichErrors.rrevert(LibSafeMathRichErrors.Uint256BinOpError(
|
||||
LibSafeMathRichErrors.BinOpErrorCodes.MULTIPLICATION_OVERFLOW,
|
||||
a,
|
||||
b
|
||||
));
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
function _safeDiv(uint256 a, uint256 b)
|
||||
internal
|
||||
pure
|
||||
returns (uint256)
|
||||
{
|
||||
if (b == 0) {
|
||||
LibRichErrors.rrevert(LibSafeMathRichErrors.Uint256BinOpError(
|
||||
LibSafeMathRichErrors.BinOpErrorCodes.DIVISION_BY_ZERO,
|
||||
a,
|
||||
b
|
||||
));
|
||||
}
|
||||
uint256 c = a / b;
|
||||
return c;
|
||||
}
|
||||
|
||||
function _safeSub(uint256 a, uint256 b)
|
||||
internal
|
||||
pure
|
||||
returns (uint256)
|
||||
{
|
||||
if (b > a) {
|
||||
LibRichErrors.rrevert(LibSafeMathRichErrors.Uint256BinOpError(
|
||||
LibSafeMathRichErrors.BinOpErrorCodes.SUBTRACTION_UNDERFLOW,
|
||||
a,
|
||||
b
|
||||
));
|
||||
}
|
||||
return a - b;
|
||||
}
|
||||
|
||||
function _safeAdd(uint256 a, uint256 b)
|
||||
internal
|
||||
pure
|
||||
returns (uint256)
|
||||
{
|
||||
uint256 c = a + b;
|
||||
if (c < a) {
|
||||
LibRichErrors.rrevert(LibSafeMathRichErrors.Uint256BinOpError(
|
||||
LibSafeMathRichErrors.BinOpErrorCodes.ADDITION_OVERFLOW,
|
||||
a,
|
||||
b
|
||||
));
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
function _max256(uint256 a, uint256 b)
|
||||
internal
|
||||
pure
|
||||
returns (uint256)
|
||||
{
|
||||
return a >= b ? a : b;
|
||||
}
|
||||
|
||||
function _min256(uint256 a, uint256 b)
|
||||
internal
|
||||
pure
|
||||
returns (uint256)
|
||||
{
|
||||
return a < b ? a : b;
|
||||
}
|
||||
}
|
||||
@@ -18,18 +18,19 @@
|
||||
|
||||
pragma solidity ^0.5.9;
|
||||
|
||||
import "../src/SafeMath.sol";
|
||||
import "../src/LibSafeMath.sol";
|
||||
|
||||
|
||||
contract TestSafeMath is
|
||||
SafeMath
|
||||
{
|
||||
contract TestLibSafeMath {
|
||||
|
||||
using LibSafeMath for uint256;
|
||||
|
||||
function externalSafeMul(uint256 a, uint256 b)
|
||||
external
|
||||
pure
|
||||
returns (uint256)
|
||||
{
|
||||
return _safeMul(a, b);
|
||||
return a.safeMul(b);
|
||||
}
|
||||
|
||||
function externalSafeDiv(uint256 a, uint256 b)
|
||||
@@ -37,7 +38,7 @@ contract TestSafeMath is
|
||||
pure
|
||||
returns (uint256)
|
||||
{
|
||||
return _safeDiv(a, b);
|
||||
return a.safeDiv(b);
|
||||
}
|
||||
|
||||
function externalSafeSub(uint256 a, uint256 b)
|
||||
@@ -45,7 +46,7 @@ contract TestSafeMath is
|
||||
pure
|
||||
returns (uint256)
|
||||
{
|
||||
return _safeSub(a, b);
|
||||
return a.safeSub(b);
|
||||
}
|
||||
|
||||
function externalSafeAdd(uint256 a, uint256 b)
|
||||
@@ -53,7 +54,7 @@ contract TestSafeMath is
|
||||
pure
|
||||
returns (uint256)
|
||||
{
|
||||
return _safeAdd(a, b);
|
||||
return a.safeAdd(b);
|
||||
}
|
||||
|
||||
function externalMaxUint256(uint256 a, uint256 b)
|
||||
@@ -61,7 +62,7 @@ contract TestSafeMath is
|
||||
pure
|
||||
returns (uint256)
|
||||
{
|
||||
return _max256(a, b);
|
||||
return a.max256(b);
|
||||
}
|
||||
|
||||
function externalMinUint256(uint256 a, uint256 b)
|
||||
@@ -69,6 +70,6 @@ contract TestSafeMath is
|
||||
pure
|
||||
returns (uint256)
|
||||
{
|
||||
return _min256(a, b);
|
||||
return a.min256(b);
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,7 @@
|
||||
},
|
||||
"config": {
|
||||
"abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually.",
|
||||
"abis": "./generated-artifacts/@(Authorizable|IAuthorizable|IOwnable|LibAddress|LibAddressArray|LibAddressArrayRichErrors|LibAuthorizableRichErrors|LibBytes|LibBytesRichErrors|LibEIP1271|LibEIP712|LibFractions|LibOwnableRichErrors|LibReentrancyGuardRichErrors|LibRichErrors|LibSafeMath|LibSafeMathRichErrors|Ownable|ReentrancyGuard|Refundable|SafeMath|TestLibAddress|TestLibAddressArray|TestLibBytes|TestLibEIP712|TestLibRichErrors|TestLogDecoding|TestLogDecodingDownstream|TestOwnable|TestReentrancyGuard|TestRefundable|TestRefundableReceiver|TestSafeMath).json"
|
||||
"abis": "./generated-artifacts/@(Authorizable|IAuthorizable|IOwnable|LibAddress|LibAddressArray|LibAddressArrayRichErrors|LibAuthorizableRichErrors|LibBytes|LibBytesRichErrors|LibEIP1271|LibEIP712|LibFractions|LibOwnableRichErrors|LibReentrancyGuardRichErrors|LibRichErrors|LibSafeMath|LibSafeMathRichErrors|Ownable|ReentrancyGuard|Refundable|TestLibAddress|TestLibAddressArray|TestLibBytes|TestLibEIP712|TestLibRichErrors|TestLibSafeMath|TestLogDecoding|TestLogDecodingDownstream|TestOwnable|TestReentrancyGuard|TestRefundable|TestRefundableReceiver).json"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@@ -25,19 +25,18 @@ import * as LibSafeMathRichErrors from '../generated-artifacts/LibSafeMathRichEr
|
||||
import * as Ownable from '../generated-artifacts/Ownable.json';
|
||||
import * as ReentrancyGuard from '../generated-artifacts/ReentrancyGuard.json';
|
||||
import * as Refundable from '../generated-artifacts/Refundable.json';
|
||||
import * as SafeMath from '../generated-artifacts/SafeMath.json';
|
||||
import * as TestLibAddress from '../generated-artifacts/TestLibAddress.json';
|
||||
import * as TestLibAddressArray from '../generated-artifacts/TestLibAddressArray.json';
|
||||
import * as TestLibBytes from '../generated-artifacts/TestLibBytes.json';
|
||||
import * as TestLibEIP712 from '../generated-artifacts/TestLibEIP712.json';
|
||||
import * as TestLibRichErrors from '../generated-artifacts/TestLibRichErrors.json';
|
||||
import * as TestLibSafeMath from '../generated-artifacts/TestLibSafeMath.json';
|
||||
import * as TestLogDecoding from '../generated-artifacts/TestLogDecoding.json';
|
||||
import * as TestLogDecodingDownstream from '../generated-artifacts/TestLogDecodingDownstream.json';
|
||||
import * as TestOwnable from '../generated-artifacts/TestOwnable.json';
|
||||
import * as TestReentrancyGuard from '../generated-artifacts/TestReentrancyGuard.json';
|
||||
import * as TestRefundable from '../generated-artifacts/TestRefundable.json';
|
||||
import * as TestRefundableReceiver from '../generated-artifacts/TestRefundableReceiver.json';
|
||||
import * as TestSafeMath from '../generated-artifacts/TestSafeMath.json';
|
||||
export const artifacts = {
|
||||
Authorizable: Authorizable as ContractArtifact,
|
||||
LibAddress: LibAddress as ContractArtifact,
|
||||
@@ -57,7 +56,6 @@ export const artifacts = {
|
||||
Ownable: Ownable as ContractArtifact,
|
||||
ReentrancyGuard: ReentrancyGuard as ContractArtifact,
|
||||
Refundable: Refundable as ContractArtifact,
|
||||
SafeMath: SafeMath as ContractArtifact,
|
||||
IAuthorizable: IAuthorizable as ContractArtifact,
|
||||
IOwnable: IOwnable as ContractArtifact,
|
||||
TestLibAddress: TestLibAddress as ContractArtifact,
|
||||
@@ -65,11 +63,11 @@ export const artifacts = {
|
||||
TestLibBytes: TestLibBytes as ContractArtifact,
|
||||
TestLibEIP712: TestLibEIP712 as ContractArtifact,
|
||||
TestLibRichErrors: TestLibRichErrors as ContractArtifact,
|
||||
TestLibSafeMath: TestLibSafeMath as ContractArtifact,
|
||||
TestLogDecoding: TestLogDecoding as ContractArtifact,
|
||||
TestLogDecodingDownstream: TestLogDecodingDownstream as ContractArtifact,
|
||||
TestOwnable: TestOwnable as ContractArtifact,
|
||||
TestReentrancyGuard: TestReentrancyGuard as ContractArtifact,
|
||||
TestRefundable: TestRefundable as ContractArtifact,
|
||||
TestRefundableReceiver: TestRefundableReceiver as ContractArtifact,
|
||||
TestSafeMath: TestSafeMath as ContractArtifact,
|
||||
};
|
||||
|
||||
@@ -23,16 +23,15 @@ export * from '../generated-wrappers/lib_safe_math_rich_errors';
|
||||
export * from '../generated-wrappers/ownable';
|
||||
export * from '../generated-wrappers/reentrancy_guard';
|
||||
export * from '../generated-wrappers/refundable';
|
||||
export * from '../generated-wrappers/safe_math';
|
||||
export * from '../generated-wrappers/test_lib_address';
|
||||
export * from '../generated-wrappers/test_lib_address_array';
|
||||
export * from '../generated-wrappers/test_lib_bytes';
|
||||
export * from '../generated-wrappers/test_lib_e_i_p712';
|
||||
export * from '../generated-wrappers/test_lib_rich_errors';
|
||||
export * from '../generated-wrappers/test_lib_safe_math';
|
||||
export * from '../generated-wrappers/test_log_decoding';
|
||||
export * from '../generated-wrappers/test_log_decoding_downstream';
|
||||
export * from '../generated-wrappers/test_ownable';
|
||||
export * from '../generated-wrappers/test_reentrancy_guard';
|
||||
export * from '../generated-wrappers/test_refundable';
|
||||
export * from '../generated-wrappers/test_refundable_receiver';
|
||||
export * from '../generated-wrappers/test_safe_math';
|
||||
|
||||
@@ -2,7 +2,7 @@ import { blockchainTests, constants, describe, expect } from '@0x/contracts-test
|
||||
import { BigNumber, SafeMathRevertErrors } from '@0x/utils';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import { artifacts, TestSafeMathContract } from '../src';
|
||||
import { artifacts, TestLibSafeMathContract } from '../src';
|
||||
import * as ReferenceFunctions from '../src/reference_functions';
|
||||
|
||||
function toBigNumber(a: number | string): BigNumber {
|
||||
@@ -11,19 +11,19 @@ function toBigNumber(a: number | string): BigNumber {
|
||||
|
||||
blockchainTests('SafeMath', env => {
|
||||
const { ONE_ETHER } = constants;
|
||||
let safeMath: TestSafeMathContract;
|
||||
let safeMath: TestLibSafeMathContract;
|
||||
|
||||
before(async () => {
|
||||
// Deploy SafeMath
|
||||
safeMath = await TestSafeMathContract.deployFrom0xArtifactAsync(
|
||||
artifacts.TestSafeMath,
|
||||
safeMath = await TestLibSafeMathContract.deployFrom0xArtifactAsync(
|
||||
artifacts.TestLibSafeMath,
|
||||
env.provider,
|
||||
env.txDefaults,
|
||||
{},
|
||||
);
|
||||
});
|
||||
|
||||
describe('_safeMul', () => {
|
||||
describe('safeMul', () => {
|
||||
it('should match the output of the reference function', async () => {
|
||||
const a = ONE_ETHER;
|
||||
const b = ONE_ETHER.times(2);
|
||||
@@ -59,7 +59,7 @@ blockchainTests('SafeMath', env => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('_safeDiv', () => {
|
||||
describe('safeDiv', () => {
|
||||
it('should match the output of the reference function', async () => {
|
||||
const a = ONE_ETHER;
|
||||
const b = ONE_ETHER.times(2);
|
||||
@@ -100,7 +100,7 @@ blockchainTests('SafeMath', env => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('_safeSub', () => {
|
||||
describe('safeSub', () => {
|
||||
it('should match the output of the reference function', async () => {
|
||||
const a = ONE_ETHER;
|
||||
const b = ONE_ETHER.dividedToIntegerBy(2);
|
||||
@@ -131,7 +131,7 @@ blockchainTests('SafeMath', env => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('_safeAdd', () => {
|
||||
describe('safeAdd', () => {
|
||||
it('should match the output of the reference function', async () => {
|
||||
const a = ONE_ETHER;
|
||||
const b = ONE_ETHER.dividedToIntegerBy(2);
|
||||
@@ -167,7 +167,7 @@ blockchainTests('SafeMath', env => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('_maxUint256', () => {
|
||||
describe('maxUint256', () => {
|
||||
it('should return first argument if it is greater than the second', async () => {
|
||||
const result = await safeMath.externalMaxUint256.callAsync(toBigNumber(13), constants.ZERO_AMOUNT);
|
||||
expect(result).bignumber.to.be.eq(toBigNumber(13));
|
||||
@@ -184,7 +184,7 @@ blockchainTests('SafeMath', env => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('_minUint256', () => {
|
||||
describe('minUint256', () => {
|
||||
it('should return first argument if it is less than the second', async () => {
|
||||
const result = await safeMath.externalMaxUint256.callAsync(constants.ZERO_AMOUNT, toBigNumber(13));
|
||||
expect(result).bignumber.to.be.eq(toBigNumber(13));
|
||||
@@ -23,19 +23,18 @@
|
||||
"generated-artifacts/Ownable.json",
|
||||
"generated-artifacts/ReentrancyGuard.json",
|
||||
"generated-artifacts/Refundable.json",
|
||||
"generated-artifacts/SafeMath.json",
|
||||
"generated-artifacts/TestLibAddress.json",
|
||||
"generated-artifacts/TestLibAddressArray.json",
|
||||
"generated-artifacts/TestLibBytes.json",
|
||||
"generated-artifacts/TestLibEIP712.json",
|
||||
"generated-artifacts/TestLibRichErrors.json",
|
||||
"generated-artifacts/TestLibSafeMath.json",
|
||||
"generated-artifacts/TestLogDecoding.json",
|
||||
"generated-artifacts/TestLogDecodingDownstream.json",
|
||||
"generated-artifacts/TestOwnable.json",
|
||||
"generated-artifacts/TestReentrancyGuard.json",
|
||||
"generated-artifacts/TestRefundable.json",
|
||||
"generated-artifacts/TestRefundableReceiver.json",
|
||||
"generated-artifacts/TestSafeMath.json"
|
||||
"generated-artifacts/TestRefundableReceiver.json"
|
||||
],
|
||||
"exclude": ["./deploy/solc/solc_bin"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user