Binop -> BinOp

This commit is contained in:
Michael Zhu
2019-08-26 16:06:31 -07:00
parent 6827ebfb78
commit 078b1af04e
19 changed files with 176 additions and 176 deletions

View File

@@ -16,8 +16,8 @@ library LibSafeMath {
}
uint256 c = a * b;
if (c / a != b) {
LibRichErrors.rrevert(LibSafeMathRichErrors.Uint256BinopError(
LibSafeMathRichErrors.BinopErrorCodes.MULTIPLICATION_OVERFLOW,
LibRichErrors.rrevert(LibSafeMathRichErrors.Uint256BinOpError(
LibSafeMathRichErrors.BinOpErrorCodes.MULTIPLICATION_OVERFLOW,
a,
b
));
@@ -31,8 +31,8 @@ library LibSafeMath {
returns (uint256)
{
if (b == 0) {
LibRichErrors.rrevert(LibSafeMathRichErrors.Uint256BinopError(
LibSafeMathRichErrors.BinopErrorCodes.DIVISION_BY_ZERO,
LibRichErrors.rrevert(LibSafeMathRichErrors.Uint256BinOpError(
LibSafeMathRichErrors.BinOpErrorCodes.DIVISION_BY_ZERO,
a,
b
));
@@ -47,8 +47,8 @@ library LibSafeMath {
returns (uint256)
{
if (b > a) {
LibRichErrors.rrevert(LibSafeMathRichErrors.Uint256BinopError(
LibSafeMathRichErrors.BinopErrorCodes.SUBTRACTION_UNDERFLOW,
LibRichErrors.rrevert(LibSafeMathRichErrors.Uint256BinOpError(
LibSafeMathRichErrors.BinOpErrorCodes.SUBTRACTION_UNDERFLOW,
a,
b
));
@@ -63,8 +63,8 @@ library LibSafeMath {
{
uint256 c = a + b;
if (c < a) {
LibRichErrors.rrevert(LibSafeMathRichErrors.Uint256BinopError(
LibSafeMathRichErrors.BinopErrorCodes.ADDITION_OVERFLOW,
LibRichErrors.rrevert(LibSafeMathRichErrors.Uint256BinOpError(
LibSafeMathRichErrors.BinOpErrorCodes.ADDITION_OVERFLOW,
a,
b
));

View File

@@ -3,23 +3,23 @@ pragma solidity ^0.5.9;
library LibSafeMathRichErrors {
// bytes4(keccak256("Uint256BinopError(uint8,uint256,uint256)"))
// bytes4(keccak256("Uint256BinOpError(uint8,uint256,uint256)"))
bytes4 internal constant UINT256_BINOP_ERROR_SELECTOR =
0x8d8e1919;
0xe946c1bb;
// bytes4(keccak256("Uint96BinopError(uint8,uint96,uint96)"))
// bytes4(keccak256("Uint96BinOpError(uint8,uint96,uint96)"))
bytes4 internal constant UINT96_BINOP_ERROR_SELECTOR =
0x224cf712;
0xe486a353;
// bytes4(keccak256("Uint64BinopError(uint8,uint64,uint64)"))
// bytes4(keccak256("Uint64BinOpError(uint8,uint64,uint64)"))
bytes4 internal constant UINT64_BINOP_ERROR_SELECTOR =
0x4e79032d;
0x67e71b32;
// bytes4(keccak256("Uint256DowncastError(uint8,uint256)"))
bytes4 internal constant UINT256_DOWNCAST_ERROR_SELECTOR =
0xc996af7b;
enum BinopErrorCodes {
enum BinOpErrorCodes {
ADDITION_OVERFLOW,
MULTIPLICATION_OVERFLOW,
SUBTRACTION_UNDERFLOW,
@@ -32,8 +32,8 @@ library LibSafeMathRichErrors {
}
// solhint-disable func-name-mixedcase
function Uint256BinopError(
BinopErrorCodes errorCode,
function Uint256BinOpError(
BinOpErrorCodes errorCode,
uint256 a,
uint256 b
)
@@ -49,8 +49,8 @@ library LibSafeMathRichErrors {
);
}
function Uint96BinopError(
BinopErrorCodes errorCode,
function Uint96BinOpError(
BinOpErrorCodes errorCode,
uint96 a,
uint96 b
)
@@ -66,8 +66,8 @@ library LibSafeMathRichErrors {
);
}
function Uint64BinopError(
BinopErrorCodes errorCode,
function Uint64BinOpError(
BinOpErrorCodes errorCode,
uint64 a,
uint64 b
)

View File

@@ -16,8 +16,8 @@ contract SafeMath {
}
uint256 c = a * b;
if (c / a != b) {
LibRichErrors.rrevert(LibSafeMathRichErrors.Uint256BinopError(
LibSafeMathRichErrors.BinopErrorCodes.MULTIPLICATION_OVERFLOW,
LibRichErrors.rrevert(LibSafeMathRichErrors.Uint256BinOpError(
LibSafeMathRichErrors.BinOpErrorCodes.MULTIPLICATION_OVERFLOW,
a,
b
));
@@ -31,8 +31,8 @@ contract SafeMath {
returns (uint256)
{
if (b == 0) {
LibRichErrors.rrevert(LibSafeMathRichErrors.Uint256BinopError(
LibSafeMathRichErrors.BinopErrorCodes.DIVISION_BY_ZERO,
LibRichErrors.rrevert(LibSafeMathRichErrors.Uint256BinOpError(
LibSafeMathRichErrors.BinOpErrorCodes.DIVISION_BY_ZERO,
a,
b
));
@@ -47,8 +47,8 @@ contract SafeMath {
returns (uint256)
{
if (b > a) {
LibRichErrors.rrevert(LibSafeMathRichErrors.Uint256BinopError(
LibSafeMathRichErrors.BinopErrorCodes.SUBTRACTION_UNDERFLOW,
LibRichErrors.rrevert(LibSafeMathRichErrors.Uint256BinOpError(
LibSafeMathRichErrors.BinOpErrorCodes.SUBTRACTION_UNDERFLOW,
a,
b
));
@@ -63,8 +63,8 @@ contract SafeMath {
{
uint256 c = a + b;
if (c < a) {
LibRichErrors.rrevert(LibSafeMathRichErrors.Uint256BinopError(
LibSafeMathRichErrors.BinopErrorCodes.ADDITION_OVERFLOW,
LibRichErrors.rrevert(LibSafeMathRichErrors.Uint256BinOpError(
LibSafeMathRichErrors.BinOpErrorCodes.ADDITION_OVERFLOW,
a,
b
));

View File

@@ -8,7 +8,7 @@ const MAX_UINT256 = new BigNumber(2).pow(256).minus(1);
export function safeAdd(a: BigNumber, b: BigNumber): BigNumber {
const r = a.plus(b);
if (r.isGreaterThan(MAX_UINT256)) {
throw new SafeMathRevertErrors.Uint256BinopError(SafeMathRevertErrors.BinopErrorCodes.AdditionOverflow, a, b);
throw new SafeMathRevertErrors.Uint256BinOpError(SafeMathRevertErrors.BinOpErrorCodes.AdditionOverflow, a, b);
}
return r;
}
@@ -19,8 +19,8 @@ export function safeAdd(a: BigNumber, b: BigNumber): BigNumber {
export function safeSub(a: BigNumber, b: BigNumber): BigNumber {
const r = a.minus(b);
if (r.isLessThan(0)) {
throw new SafeMathRevertErrors.Uint256BinopError(
SafeMathRevertErrors.BinopErrorCodes.SubtractionUnderflow,
throw new SafeMathRevertErrors.Uint256BinOpError(
SafeMathRevertErrors.BinOpErrorCodes.SubtractionUnderflow,
a,
b,
);
@@ -34,8 +34,8 @@ export function safeSub(a: BigNumber, b: BigNumber): BigNumber {
export function safeMul(a: BigNumber, b: BigNumber): BigNumber {
const r = a.times(b);
if (r.isGreaterThan(MAX_UINT256)) {
throw new SafeMathRevertErrors.Uint256BinopError(
SafeMathRevertErrors.BinopErrorCodes.MultiplicationOverflow,
throw new SafeMathRevertErrors.Uint256BinOpError(
SafeMathRevertErrors.BinOpErrorCodes.MultiplicationOverflow,
a,
b,
);
@@ -48,7 +48,7 @@ export function safeMul(a: BigNumber, b: BigNumber): BigNumber {
*/
export function safeDiv(a: BigNumber, b: BigNumber): BigNumber {
if (b.isEqualTo(0)) {
throw new SafeMathRevertErrors.Uint256BinopError(SafeMathRevertErrors.BinopErrorCodes.DivisionByZero, a, b);
throw new SafeMathRevertErrors.Uint256BinOpError(SafeMathRevertErrors.BinOpErrorCodes.DivisionByZero, a, b);
}
return a.dividedToIntegerBy(b);
}

View File

@@ -21,8 +21,8 @@ describe('Reference Functions', () => {
it('reverts on overflow', () => {
const a = MAX_UINT256.dividedToIntegerBy(2);
const b = MAX_UINT256.dividedToIntegerBy(2).plus(2);
const expectedError = new SafeMathRevertErrors.Uint256BinopError(
SafeMathRevertErrors.BinopErrorCodes.AdditionOverflow,
const expectedError = new SafeMathRevertErrors.Uint256BinOpError(
SafeMathRevertErrors.BinOpErrorCodes.AdditionOverflow,
a,
b,
);
@@ -41,8 +41,8 @@ describe('Reference Functions', () => {
it('reverts on underflow', () => {
const a = MAX_UINT256.dividedToIntegerBy(2);
const b = MAX_UINT256.dividedToIntegerBy(2).plus(2);
const expectedError = new SafeMathRevertErrors.Uint256BinopError(
SafeMathRevertErrors.BinopErrorCodes.SubtractionUnderflow,
const expectedError = new SafeMathRevertErrors.Uint256BinOpError(
SafeMathRevertErrors.BinOpErrorCodes.SubtractionUnderflow,
a,
b,
);
@@ -61,8 +61,8 @@ describe('Reference Functions', () => {
it('reverts on overflow', () => {
const a = MAX_UINT256.dividedToIntegerBy(2);
const b = MAX_UINT256.dividedToIntegerBy(2).plus(2);
const expectedError = new SafeMathRevertErrors.Uint256BinopError(
SafeMathRevertErrors.BinopErrorCodes.MultiplicationOverflow,
const expectedError = new SafeMathRevertErrors.Uint256BinOpError(
SafeMathRevertErrors.BinOpErrorCodes.MultiplicationOverflow,
a,
b,
);
@@ -81,8 +81,8 @@ describe('Reference Functions', () => {
it('reverts if denominator is zero', () => {
const a = MAX_UINT256.dividedToIntegerBy(2);
const b = ZERO_AMOUNT;
const expectedError = new SafeMathRevertErrors.Uint256BinopError(
SafeMathRevertErrors.BinopErrorCodes.DivisionByZero,
const expectedError = new SafeMathRevertErrors.Uint256BinOpError(
SafeMathRevertErrors.BinOpErrorCodes.DivisionByZero,
a,
b,
);

View File

@@ -45,8 +45,8 @@ blockchainTests('SafeMath', env => {
it('should revert if the multiplication overflows', async () => {
const a = toBigNumber('0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'); // The largest uint256 number
const b = toBigNumber(2);
const expectedError = new SafeMathRevertErrors.Uint256BinopError(
SafeMathRevertErrors.BinopErrorCodes.MultiplicationOverflow,
const expectedError = new SafeMathRevertErrors.Uint256BinOpError(
SafeMathRevertErrors.BinOpErrorCodes.MultiplicationOverflow,
a,
b,
);
@@ -91,8 +91,8 @@ blockchainTests('SafeMath', env => {
it('should revert if second argument is zero', async () => {
const a = toBigNumber(1);
const b = toBigNumber(0);
const expectedError = new SafeMathRevertErrors.Uint256BinopError(
SafeMathRevertErrors.BinopErrorCodes.DivisionByZero,
const expectedError = new SafeMathRevertErrors.Uint256BinOpError(
SafeMathRevertErrors.BinOpErrorCodes.DivisionByZero,
a,
b,
);
@@ -112,8 +112,8 @@ blockchainTests('SafeMath', env => {
it('should revert if the subtraction underflows', async () => {
const a = toBigNumber(0);
const b = toBigNumber(1);
const expectedError = new SafeMathRevertErrors.Uint256BinopError(
SafeMathRevertErrors.BinopErrorCodes.SubtractionUnderflow,
const expectedError = new SafeMathRevertErrors.Uint256BinOpError(
SafeMathRevertErrors.BinOpErrorCodes.SubtractionUnderflow,
a,
b,
);
@@ -143,8 +143,8 @@ blockchainTests('SafeMath', env => {
it('should revert if the addition overflows', async () => {
const a = toBigNumber('0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'); // The largest uint256 number
const b = toBigNumber(1);
const expectedError = new SafeMathRevertErrors.Uint256BinopError(
SafeMathRevertErrors.BinopErrorCodes.AdditionOverflow,
const expectedError = new SafeMathRevertErrors.Uint256BinOpError(
SafeMathRevertErrors.BinOpErrorCodes.AdditionOverflow,
a,
b,
);