diff options
author | fragosti <francesco.agosti93@gmail.com> | 2018-08-08 04:52:53 +0800 |
---|---|---|
committer | fragosti <francesco.agosti93@gmail.com> | 2018-08-08 04:52:53 +0800 |
commit | 0a616ad3b8b87c8142598b535154564cb9276cbe (patch) | |
tree | 2069631964815b60dafd7f093cdd47579ec4d129 /packages/contracts/test/utils/assertions.ts | |
parent | 57a44291233548da9785aec3cde92171342c9eb3 (diff) | |
parent | 8199e8794331f555679496d32cb87ad8513c31d1 (diff) | |
download | dexon-sol-tools-0a616ad3b8b87c8142598b535154564cb9276cbe.tar dexon-sol-tools-0a616ad3b8b87c8142598b535154564cb9276cbe.tar.gz dexon-sol-tools-0a616ad3b8b87c8142598b535154564cb9276cbe.tar.bz2 dexon-sol-tools-0a616ad3b8b87c8142598b535154564cb9276cbe.tar.lz dexon-sol-tools-0a616ad3b8b87c8142598b535154564cb9276cbe.tar.xz dexon-sol-tools-0a616ad3b8b87c8142598b535154564cb9276cbe.tar.zst dexon-sol-tools-0a616ad3b8b87c8142598b535154564cb9276cbe.zip |
Merge branch 'development' of https://github.com/0xProject/0x-monorepo into feature/sra/add-sra-package
Diffstat (limited to 'packages/contracts/test/utils/assertions.ts')
-rw-r--r-- | packages/contracts/test/utils/assertions.ts | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/packages/contracts/test/utils/assertions.ts b/packages/contracts/test/utils/assertions.ts index 112a470f6..61df800c8 100644 --- a/packages/contracts/test/utils/assertions.ts +++ b/packages/contracts/test/utils/assertions.ts @@ -15,6 +15,14 @@ let nodeType: NodeType | undefined; // resolve with either a transaction receipt or a transaction hash. export type sendTransactionResult = Promise<TransactionReceipt | TransactionReceiptWithDecodedLogs | string>; +/** + * Returns ganacheError if the backing Ethereum node is Ganache and gethError + * if it is Geth. + * @param ganacheError the error to be returned if the backing node is Ganache. + * @param gethError the error to be returned if the backing node is Geth. + * @returns either the given ganacheError or gethError depending on the backing + * node. + */ async function _getGanacheOrGethError(ganacheError: string, gethError: string): Promise<string> { if (_.isUndefined(nodeType)) { nodeType = await web3Wrapper.getNodeTypeAsync(); @@ -42,6 +50,25 @@ async function _getContractCallFailedErrorMessageAsync(): Promise<string> { } /** + * Returns the expected error message for an 'invalid opcode' resulting from a + * contract call. The exact error message depends on the backing Ethereum node. + */ +export async function getInvalidOpcodeErrorMessageForCallAsync(): Promise<string> { + return _getGanacheOrGethError('invalid opcode', 'Contract call failed'); +} + +/** + * Returns the expected error message for the given revert reason resulting from + * a sendTransaction call. The exact error message depends on the backing + * Ethereum node and whether it supports revert reasons. + * @param reason a specific revert reason. + * @returns the expected error message. + */ +export async function getRevertReasonOrErrorMessageForSendTransactionAsync(reason: RevertReason): Promise<string> { + return _getGanacheOrGethError(reason, 'always failing transaction'); +} + +/** * Rejects if the given Promise does not reject with an error indicating * insufficient funds. * @param p a promise resulting from a contract call or sendTransaction call. |