Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Commit

Permalink
Merge pull request #2576 from 0xProject/feat/contracts-zero-ex/0x-api…
Browse files Browse the repository at this point in the history
…-erc20-transformers

ZeroEx: ERC20 Transformers
  • Loading branch information
dorothy-zbornak authored Jun 3, 2020
2 parents 98a99d9 + 112f4fc commit 0c6e05d
Show file tree
Hide file tree
Showing 34 changed files with 2,928 additions and 32 deletions.
9 changes: 9 additions & 0 deletions contracts/test-utils/CHANGELOG.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
[
{
"version": "5.3.3",
"changes": [
{
"note": "Add `msg` param to `assertIntegerRoughlyEquals`",
"pr": 2576
}
]
},
{
"timestamp": 1583220306,
"version": "5.3.2",
Expand Down
9 changes: 7 additions & 2 deletions contracts/test-utils/src/number_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,20 @@ export function assertRoughlyEquals(actual: Numberish, expected: Numberish, prec
/**
* Asserts that two numbers are equal with up to `maxError` difference between them.
*/
export function assertIntegerRoughlyEquals(actual: Numberish, expected: Numberish, maxError: number = 1): void {
export function assertIntegerRoughlyEquals(
actual: Numberish,
expected: Numberish,
maxError: number = 1,
msg?: string,
): void {
const diff = new BigNumber(actual)
.minus(expected)
.abs()
.toNumber();
if (diff <= maxError) {
return;
}
expect(actual).to.bignumber.eq(expected);
expect(actual, msg).to.bignumber.eq(expected);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,58 @@ library LibTransformERC20RichErrors {
);
}

// Common Transformer errors ///////////////////////////////////////////////

function OnlyCallableByDeployerError(
address caller,
address deployer
)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
bytes4(keccak256("OnlyCallableByDeployerError(address,address)")),
caller,
deployer
);
}

function InvalidExecutionContextError(
address actualContext,
address expectedContext
)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
bytes4(keccak256("InvalidExecutionContextError(address,address)")),
actualContext,
expectedContext
);
}

enum InvalidTransformDataErrorCode {
INVALID_TOKENS,
INVALID_ARRAY_LENGTH
}

function InvalidTransformDataError(
InvalidTransformDataErrorCode errorCode,
bytes memory transformData
)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
bytes4(keccak256("InvalidTransformDataError(uint8,bytes)")),
errorCode,
transformData
);
}

// FillQuoteTransformer errors /////////////////////////////////////////////

function IncompleteFillSellQuoteError(
Expand Down Expand Up @@ -177,33 +229,17 @@ library LibTransformERC20RichErrors {
);
}

// WethTransformer errors ////////////////////////////////////////////////////

function WrongNumberOfTokensReceivedError(
uint256 actual,
uint256 expected
)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
bytes4(keccak256("WrongNumberOfTokensReceivedError(uint256,uint256)")),
actual,
expected
);
}

function InvalidTokenReceivedError(
function InvalidTakerFeeTokenError(
address token
)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
bytes4(keccak256("InvalidTokenReceivedError(address)")),
bytes4(keccak256("InvalidTakerFeeTokenError(address)")),
token
);
}

}
Loading

0 comments on commit 0c6e05d

Please sign in to comment.