diff --git a/contracts/asset-proxy/contracts/src/ERC1155Proxy.sol b/contracts/asset-proxy/contracts/src/ERC1155Proxy.sol index 2e43635325..9ae6e5bc88 100644 --- a/contracts/asset-proxy/contracts/src/ERC1155Proxy.sol +++ b/contracts/asset-proxy/contracts/src/ERC1155Proxy.sol @@ -19,7 +19,7 @@ pragma solidity ^0.5.9; import "@0x/contracts-utils/contracts/src/LibBytes.sol"; -import "@0x/contracts-utils/contracts/src/SafeMath.sol"; +import "@0x/contracts-utils/contracts/src/LibSafeMath.sol"; import "@0x/contracts-erc1155/contracts/src/interfaces/IERC1155.sol"; import "../archive/MixinAuthorizable.sol"; import "./interfaces/IAssetProxy.sol"; @@ -27,10 +27,10 @@ import "./interfaces/IAssetProxy.sol"; contract ERC1155Proxy is MixinAuthorizable, - SafeMath, IAssetProxy { using LibBytes for bytes; + using LibSafeMath for uint256; // Id of this proxy. bytes4 constant internal PROXY_ID = bytes4(keccak256("ERC1155Assets(address,uint256[],uint256[],bytes)")); @@ -71,7 +71,7 @@ contract ERC1155Proxy is // to avoid copying over `ids` or `data`. This is possible if they are // identical to `values` and the offsets for each are pointing to the // same location in the ABI encoded calldata. - scaledValues[i] = _safeMul(values[i], amount); + scaledValues[i] = values[i].safeMul(amount); } // Execute `safeBatchTransferFrom` call diff --git a/contracts/erc1155/contracts/src/ERC1155.sol b/contracts/erc1155/contracts/src/ERC1155.sol index afebfbc634..ab81c61aec 100644 --- a/contracts/erc1155/contracts/src/ERC1155.sol +++ b/contracts/erc1155/contracts/src/ERC1155.sol @@ -18,7 +18,7 @@ pragma solidity ^0.5.9; -import "@0x/contracts-utils/contracts/src/SafeMath.sol"; +import "@0x/contracts-utils/contracts/src/LibSafeMath.sol"; import "@0x/contracts-utils/contracts/src/LibAddress.sol"; import "./interfaces/IERC1155.sol"; import "./interfaces/IERC1155Receiver.sol"; @@ -26,11 +26,11 @@ import "./MixinNonFungibleToken.sol"; contract ERC1155 is - SafeMath, IERC1155, MixinNonFungibleToken { using LibAddress for address; + using LibSafeMath for uint256; // selectors for receiver callbacks bytes4 constant public ERC1155_RECEIVED = 0xf23a6e61; @@ -88,11 +88,11 @@ contract ERC1155 is nfOwners[id] = to; // You could keep balance of NF type in base type id like so: // uint256 baseType = getNonFungibleBaseType(_id); - // balances[baseType][_from] = balances[baseType][_from]._safeSub(_value); - // balances[baseType][_to] = balances[baseType][_to]._safeAdd(_value); + // balances[baseType][_from] = balances[baseType][_from].safeSub(_value); + // balances[baseType][_to] = balances[baseType][_to].safeAdd(_value); } else { - balances[id][from] = _safeSub(balances[id][from], value); - balances[id][to] = _safeAdd(balances[id][to], value); + balances[id][from] = balances[id][from].safeSub(value); + balances[id][to] = balances[id][to].safeAdd(value); } emit TransferSingle(msg.sender, from, to, id, value); @@ -170,8 +170,8 @@ contract ERC1155 is ); nfOwners[id] = to; } else { - balances[id][from] = _safeSub(balances[id][from], value); - balances[id][to] = _safeAdd(balances[id][to], value); + balances[id][from] = balances[id][from].safeSub(value); + balances[id][to] = balances[id][to].safeAdd(value); } } emit TransferBatch(msg.sender, from, to, ids, values); diff --git a/contracts/erc1155/contracts/src/ERC1155Mintable.sol b/contracts/erc1155/contracts/src/ERC1155Mintable.sol index 5057f956c7..5d99a535cf 100644 --- a/contracts/erc1155/contracts/src/ERC1155Mintable.sol +++ b/contracts/erc1155/contracts/src/ERC1155Mintable.sol @@ -1,6 +1,6 @@ pragma solidity ^0.5.9; -import "@0x/contracts-utils/contracts/src/SafeMath.sol"; +import "@0x/contracts-utils/contracts/src/LibSafeMath.sol"; import "./ERC1155.sol"; import "./interfaces/IERC1155Mintable.sol"; @@ -11,6 +11,7 @@ contract ERC1155Mintable is IERC1155Mintable, ERC1155 { + using LibSafeMath for uint256; /// token nonce uint256 internal nonce; @@ -37,7 +38,7 @@ contract ERC1155Mintable is ) external returns (uint256 type_) - { + { // Store the type in the upper 128 bits type_ = (++nonce << 128); @@ -114,7 +115,7 @@ contract ERC1155Mintable is uint256 quantity = quantities[i]; // Grant the items to the caller - balances[id][dst] = _safeAdd(quantity, balances[id][dst]); + balances[id][dst] = quantity.safeAdd(balances[id][dst]); // Emit the Transfer/Mint event. // the 0x0 source address implies a mint @@ -172,7 +173,7 @@ contract ERC1155Mintable is nfOwners[id] = dst; // You could use base-type id to store NF type balances if you wish. - // balances[_type][dst] = quantity._safeAdd(balances[_type][dst]); + // balances[_type][dst] = quantity.safeAdd(balances[_type][dst]); emit TransferSingle(msg.sender, address(0x0), dst, id, 1); @@ -194,6 +195,6 @@ contract ERC1155Mintable is // record the `maxIndex` of this nft type // this allows us to mint more nft's of this type in a subsequent call. - maxIndex[type_] = _safeAdd(to.length, maxIndex[type_]); + maxIndex[type_] = to.length.safeAdd(maxIndex[type_]); } } diff --git a/contracts/erc20/contracts/src/MintableERC20Token.sol b/contracts/erc20/contracts/src/MintableERC20Token.sol index 65e102135b..fab2aac164 100644 --- a/contracts/erc20/contracts/src/MintableERC20Token.sol +++ b/contracts/erc20/contracts/src/MintableERC20Token.sol @@ -18,22 +18,23 @@ pragma solidity ^0.5.9; -import "@0x/contracts-utils/contracts/src/SafeMath.sol"; +import "@0x/contracts-utils/contracts/src/LibSafeMath.sol"; import "./UnlimitedAllowanceERC20Token.sol"; -contract MintableERC20Token is - SafeMath, +contract MintableERC20Token is UnlimitedAllowanceERC20Token { + using LibSafeMath for uint256; + /// @dev Mints new tokens /// @param _to Address of the beneficiary that will own the minted token /// @param _value Amount of tokens to mint function _mint(address _to, uint256 _value) internal { - balances[_to] = _safeAdd(_value, balances[_to]); - _totalSupply = _safeAdd(_totalSupply, _value); + balances[_to] = _value.safeAdd(balances[_to]); + _totalSupply = _totalSupply.safeAdd(_value); emit Transfer( address(0), @@ -48,8 +49,8 @@ contract MintableERC20Token is function _burn(address _owner, uint256 _value) internal { - balances[_owner] = _safeSub(balances[_owner], _value); - _totalSupply = _safeSub(_totalSupply, _value); + balances[_owner] = balances[_owner].safeSub(_value); + _totalSupply = _totalSupply.safeSub(_value); emit Transfer( _owner, diff --git a/contracts/erc20/contracts/test/DummyERC20Token.sol b/contracts/erc20/contracts/test/DummyERC20Token.sol index 2a74d21237..be39ac3048 100644 --- a/contracts/erc20/contracts/test/DummyERC20Token.sol +++ b/contracts/erc20/contracts/test/DummyERC20Token.sol @@ -18,14 +18,17 @@ pragma solidity ^0.5.5; +import "@0x/contracts-utils/contracts/src/LibSafeMath.sol"; import "@0x/contracts-utils/contracts/src/Ownable.sol"; import "../src/MintableERC20Token.sol"; -contract DummyERC20Token is +contract DummyERC20Token is Ownable, MintableERC20Token { + using LibSafeMath for uint256; + string public name; string public symbol; uint256 public decimals; @@ -55,9 +58,9 @@ contract DummyERC20Token is { uint256 currBalance = balances[_target]; if (_value < currBalance) { - _totalSupply = _safeSub(_totalSupply, _safeSub(currBalance, _value)); + _totalSupply = _totalSupply.safeSub(currBalance.safeSub(_value)); } else { - _totalSupply = _safeAdd(_totalSupply, _safeSub(_value, currBalance)); + _totalSupply = _totalSupply.safeAdd(_value.safeSub(currBalance)); } balances[_target] = _value; } diff --git a/contracts/erc721/contracts/src/ERC721Token.sol b/contracts/erc721/contracts/src/ERC721Token.sol index aa2ba3cca0..810016d195 100644 --- a/contracts/erc721/contracts/src/ERC721Token.sol +++ b/contracts/erc721/contracts/src/ERC721Token.sol @@ -20,13 +20,14 @@ pragma solidity ^0.5.9; import "./interfaces/IERC721Token.sol"; import "./interfaces/IERC721Receiver.sol"; -import "@0x/contracts-utils/contracts/src/SafeMath.sol"; +import "@0x/contracts-utils/contracts/src/LibSafeMath.sol"; contract ERC721Token is - IERC721Token, - SafeMath + IERC721Token { + using LibSafeMath for uint256; + // Function selector for ERC721Receiver.onERC721Received // 0x150b7a02 bytes4 constant internal ERC721_RECEIVED = bytes4(keccak256("onERC721Received(address,address,uint256,bytes)")); @@ -163,7 +164,7 @@ contract ERC721Token is _approved ); } - + /// @notice Count all NFTs assigned to an owner /// @dev NFTs assigned to the zero address are considered invalid, and this /// function throws for queries about the zero address. @@ -223,9 +224,9 @@ contract ERC721Token is } owners[_tokenId] = _to; - balances[_from] = _safeSub(balances[_from], 1); - balances[_to] = _safeAdd(balances[_to], 1); - + balances[_from] = balances[_from].safeSub(1); + balances[_to] = balances[_to].safeAdd(1); + emit Transfer( _from, _to, diff --git a/contracts/erc721/contracts/src/MintableERC721Token.sol b/contracts/erc721/contracts/src/MintableERC721Token.sol index c3e0a6dca9..667b5994a9 100644 --- a/contracts/erc721/contracts/src/MintableERC721Token.sol +++ b/contracts/erc721/contracts/src/MintableERC721Token.sol @@ -18,16 +18,19 @@ pragma solidity ^0.5.9; +import "@0x/contracts-utils/contracts/src/LibSafeMath.sol"; import "./ERC721Token.sol"; contract MintableERC721Token is ERC721Token { + using LibSafeMath for uint256; + /// @dev Function to mint a new token /// Reverts if the given token ID already exists /// @param _to Address of the beneficiary that will own the minted token - /// @param _tokenId ID of the token to be minted by the msg.sender + /// @param _tokenId ID of the token to be minted by the msg.sender function _mint(address _to, uint256 _tokenId) internal { @@ -43,7 +46,7 @@ contract MintableERC721Token is ); owners[_tokenId] = _to; - balances[_to] = _safeAdd(balances[_to], 1); + balances[_to] = balances[_to].safeAdd(1); emit Transfer( address(0), @@ -71,7 +74,7 @@ contract MintableERC721Token is ); owners[_tokenId] = address(0); - balances[_owner] = _safeSub(balances[_owner], 1); + balances[_owner] = balances[_owner].safeSub(1); emit Transfer( _owner, diff --git a/contracts/exchange-libs/contracts/src/LibMath.sol b/contracts/exchange-libs/contracts/src/LibMath.sol index 29d61afdd7..e18c746bf1 100644 --- a/contracts/exchange-libs/contracts/src/LibMath.sol +++ b/contracts/exchange-libs/contracts/src/LibMath.sol @@ -85,9 +85,9 @@ library LibMath { )); } - // _safeDiv computes `floor(a / b)`. We use the identity (a, b integer): + // safeDiv computes `floor(a / b)`. We use the identity (a, b integer): // ceil(a / b) = floor((a + b - 1) / b) - // To implement `ceil(a / b)` using _safeDiv. + // To implement `ceil(a / b)` using safeDiv. partialAmount = numerator.safeMul(target) .safeAdd(denominator.safeSub(1)) .safeDiv(denominator); @@ -127,9 +127,9 @@ library LibMath { pure returns (uint256 partialAmount) { - // _safeDiv computes `floor(a / b)`. We use the identity (a, b integer): + // safeDiv computes `floor(a / b)`. We use the identity (a, b integer): // ceil(a / b) = floor((a + b - 1) / b) - // To implement `ceil(a / b)` using _safeDiv. + // To implement `ceil(a / b)` using safeDiv. partialAmount = numerator.safeMul(target) .safeAdd(denominator.safeSub(1)) .safeDiv(denominator); diff --git a/contracts/extensions/contracts/src/DutchAuction/DutchAuction.sol b/contracts/extensions/contracts/src/DutchAuction/DutchAuction.sol index 78f69fa4c3..e8ddfaca64 100644 --- a/contracts/extensions/contracts/src/DutchAuction/DutchAuction.sol +++ b/contracts/extensions/contracts/src/DutchAuction/DutchAuction.sol @@ -23,13 +23,13 @@ import "@0x/contracts-exchange/contracts/src/interfaces/IExchange.sol"; import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol"; import "@0x/contracts-erc20/contracts/src/interfaces/IERC20Token.sol"; import "@0x/contracts-utils/contracts/src/LibBytes.sol"; -import "@0x/contracts-utils/contracts/src/SafeMath.sol"; +import "@0x/contracts-utils/contracts/src/LibSafeMath.sol"; -contract DutchAuction is - SafeMath -{ +contract DutchAuction { + using LibBytes for bytes; + using LibSafeMath for uint256; // solhint-disable var-name-mixedcase IExchange internal EXCHANGE; @@ -120,8 +120,8 @@ contract DutchAuction is address token = assetData.readAddress(16); // Calculate the excess from the buy order. This can occur if the buyer sends in a higher // amount than the calculated current amount - uint256 buyerExcessAmount = _safeSub(buyOrder.makerAssetAmount, auctionDetails.currentAmount); - uint256 sellerExcessAmount = _safeSub(leftMakerAssetSpreadAmount, buyerExcessAmount); + uint256 buyerExcessAmount = buyOrder.makerAssetAmount.safeSub(auctionDetails.currentAmount); + uint256 sellerExcessAmount = leftMakerAssetSpreadAmount.safeSub(buyerExcessAmount); // Return the difference between auctionDetails.currentAmount and sellOrder.takerAssetAmount // to the seller if (sellerExcessAmount > 0) { @@ -190,12 +190,8 @@ contract DutchAuction is // Auction end time is guaranteed by 0x Exchange due to the order expiration auctionDetails.currentAmount = minAmount; } else { - auctionDetails.currentAmount = _safeAdd( - minAmount, - _safeDiv( - _safeMul(remainingDurationSeconds, amountDelta), - auctionDurationSeconds - ) + auctionDetails.currentAmount = minAmount.safeAdd( + remainingDurationSeconds.safeMul(amountDelta).safeDiv(auctionDurationSeconds) ); } return auctionDetails; diff --git a/contracts/utils/contracts/src/SafeMath.sol b/contracts/utils/contracts/src/SafeMath.sol deleted file mode 100644 index bf0e95145a..0000000000 --- a/contracts/utils/contracts/src/SafeMath.sol +++ /dev/null @@ -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; - } -} diff --git a/contracts/utils/contracts/test/TestSafeMath.sol b/contracts/utils/contracts/test/TestLibSafeMath.sol similarity index 83% rename from contracts/utils/contracts/test/TestSafeMath.sol rename to contracts/utils/contracts/test/TestLibSafeMath.sol index 36670e13af..a3ee8555c0 100644 --- a/contracts/utils/contracts/test/TestSafeMath.sol +++ b/contracts/utils/contracts/test/TestLibSafeMath.sol @@ -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); } } diff --git a/contracts/utils/package.json b/contracts/utils/package.json index 7f9631d7fc..76834fe6d9 100644 --- a/contracts/utils/package.json +++ b/contracts/utils/package.json @@ -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", diff --git a/contracts/utils/src/artifacts.ts b/contracts/utils/src/artifacts.ts index 47a2d61628..983f2951ed 100644 --- a/contracts/utils/src/artifacts.ts +++ b/contracts/utils/src/artifacts.ts @@ -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, }; diff --git a/contracts/utils/src/wrappers.ts b/contracts/utils/src/wrappers.ts index 78edd2ddec..da266a03dd 100644 --- a/contracts/utils/src/wrappers.ts +++ b/contracts/utils/src/wrappers.ts @@ -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'; diff --git a/contracts/utils/test/safe_math.ts b/contracts/utils/test/lib_safe_math.ts similarity index 95% rename from contracts/utils/test/safe_math.ts rename to contracts/utils/test/lib_safe_math.ts index 15590b29ff..39e1ae5d1a 100644 --- a/contracts/utils/test/safe_math.ts +++ b/contracts/utils/test/lib_safe_math.ts @@ -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)); diff --git a/contracts/utils/tsconfig.json b/contracts/utils/tsconfig.json index 13059711d1..58803aad69 100644 --- a/contracts/utils/tsconfig.json +++ b/contracts/utils/tsconfig.json @@ -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"] }