diff --git a/contracts/utils/compiler.json b/contracts/utils/compiler.json index a31630ca81..c1de9dcb0e 100644 --- a/contracts/utils/compiler.json +++ b/contracts/utils/compiler.json @@ -37,6 +37,7 @@ "test/TestLibAddressArray.sol", "test/TestLibBytes.sol", "test/TestLibEIP712.sol", + "test/TestLibRichErrors.sol", "test/TestOwnable.sol", "test/TestReentrancyGuard.sol", "test/TestSafeMath.sol" diff --git a/contracts/utils/contracts/test/TestLibRichErrors.sol b/contracts/utils/contracts/test/TestLibRichErrors.sol new file mode 100644 index 0000000000..fe0909c18a --- /dev/null +++ b/contracts/utils/contracts/test/TestLibRichErrors.sol @@ -0,0 +1,32 @@ +/* + + Copyright 2019 ZeroEx Intl. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +*/ + +pragma solidity ^0.5.9; + +import "../src/LibRichErrors.sol"; + + +contract TestLibRichErrors { + + function externalRRevert(bytes calldata errorData) + external + pure + { + LibRichErrors._rrevert(errorData); + } +} diff --git a/contracts/utils/package.json b/contracts/utils/package.json index f05094d2fa..55aa8618ab 100644 --- a/contracts/utils/package.json +++ b/contracts/utils/package.json @@ -34,7 +34,7 @@ "lint-contracts": "solhint -c ../.solhint.json contracts/**/**/**/**/*.sol" }, "config": { - "abis": "./generated-artifacts/@(IOwnable|LibAddress|LibBytes|LibEIP1271|LibEIP712|Ownable|ReentrancyGuard|SafeMath|TestConstants|TestLibAddress|TestLibAddressArray|TestLibBytes|TestLibEIP712|TestOwnable|TestReentrancyGuard|TestSafeMath).json", + "abis": "./generated-artifacts/@(IOwnable|LibAddress|LibBytes|LibEIP1271|LibEIP712|Ownable|ReentrancyGuard|SafeMath|TestConstants|TestLibAddress|TestLibAddressArray|TestLibBytes|TestLibEIP712|TestLibRichErrors|TestOwnable|TestReentrancyGuard|TestSafeMath).json", "abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually." }, "repository": { diff --git a/contracts/utils/src/artifacts.ts b/contracts/utils/src/artifacts.ts index b72eac333e..52d1002075 100644 --- a/contracts/utils/src/artifacts.ts +++ b/contracts/utils/src/artifacts.ts @@ -18,6 +18,7 @@ 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 TestOwnable from '../generated-artifacts/TestOwnable.json'; import * as TestReentrancyGuard from '../generated-artifacts/TestReentrancyGuard.json'; import * as TestSafeMath from '../generated-artifacts/TestSafeMath.json'; @@ -35,6 +36,7 @@ export const artifacts = { TestLibAddressArray: TestLibAddressArray as ContractArtifact, TestLibBytes: TestLibBytes as ContractArtifact, TestLibEIP712: TestLibEIP712 as ContractArtifact, + TestLibRichErrors: TestLibRichErrors as ContractArtifact, TestOwnable: TestOwnable as ContractArtifact, TestReentrancyGuard: TestReentrancyGuard as ContractArtifact, TestSafeMath: TestSafeMath as ContractArtifact, diff --git a/contracts/utils/src/wrappers.ts b/contracts/utils/src/wrappers.ts index 5337a00e36..3caa25b828 100644 --- a/contracts/utils/src/wrappers.ts +++ b/contracts/utils/src/wrappers.ts @@ -16,6 +16,7 @@ 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_ownable'; export * from '../generated-wrappers/test_reentrancy_guard'; export * from '../generated-wrappers/test_safe_math'; diff --git a/contracts/utils/test/lib_rich_errors.ts b/contracts/utils/test/lib_rich_errors.ts new file mode 100644 index 0000000000..7178275162 --- /dev/null +++ b/contracts/utils/test/lib_rich_errors.ts @@ -0,0 +1,34 @@ +import { chaiSetup, constants, provider, txDefaults, web3Wrapper } from '@0x/contracts-test-utils'; +import { BlockchainLifecycle } from '@0x/dev-utils'; +import * as chai from 'chai'; +import * as _ from 'lodash'; + +import { artifacts, TestLibRichErrorsContract } from '../src'; + +chaiSetup.configure(); +const expect = chai.expect; +const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); + +describe('LibEIP712', () => { + let lib: TestLibRichErrorsContract; + + before(async () => { + await blockchainLifecycle.startAsync(); + // Deploy SafeMath + lib = await TestLibRichErrorsContract.deployFrom0xArtifactAsync( + artifacts.TestLibRichErrors, + provider, + txDefaults, + ); + }); + + after(async () => { + await blockchainLifecycle.revertAsync(); + }); + + describe('_rrevert', () => { + it('should correctly revert the extra bytes', async () => { + return expect(lib.externalRRevert.callAsync(constants.NULL_BYTES)).to.revertWith(constants.NULL_BYTES); + }); + }); +}); diff --git a/contracts/utils/tsconfig.json b/contracts/utils/tsconfig.json index d63200ed62..3e74470d85 100644 --- a/contracts/utils/tsconfig.json +++ b/contracts/utils/tsconfig.json @@ -16,6 +16,7 @@ "generated-artifacts/TestLibAddressArray.json", "generated-artifacts/TestLibBytes.json", "generated-artifacts/TestLibEIP712.json", + "generated-artifacts/TestLibRichErrors.json", "generated-artifacts/TestOwnable.json", "generated-artifacts/TestReentrancyGuard.json", "generated-artifacts/TestSafeMath.json"