aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/test/utils/assertions.ts
diff options
context:
space:
mode:
authorAlex Browne <stephenalexbrowne@gmail.com>2018-07-27 13:09:55 +0800
committerGitHub <noreply@github.com>2018-07-27 13:09:55 +0800
commit554d5f97df55779beed35ef73214e80b386d7927 (patch)
treeeaf73ce6cbd61d96d541c08d7e2d640f02f32083 /packages/contracts/test/utils/assertions.ts
parent95c627f581ec8d724a0c737cbbf5b53b96765f6e (diff)
downloaddexon-sol-tools-554d5f97df55779beed35ef73214e80b386d7927.tar
dexon-sol-tools-554d5f97df55779beed35ef73214e80b386d7927.tar.gz
dexon-sol-tools-554d5f97df55779beed35ef73214e80b386d7927.tar.bz2
dexon-sol-tools-554d5f97df55779beed35ef73214e80b386d7927.tar.lz
dexon-sol-tools-554d5f97df55779beed35ef73214e80b386d7927.tar.xz
dexon-sol-tools-554d5f97df55779beed35ef73214e80b386d7927.tar.zst
dexon-sol-tools-554d5f97df55779beed35ef73214e80b386d7927.zip
Add combinatorial tests for internal Exchange functions (#807)
* WIP add combinatorial tests for internal Exchange functions * Change combinitorial testing strategy based on feedback * Check value of filled[orderHash] in updateFilledState tests * Add combinatorial tests for addFillResults * Add combinatorial tests for getPartialAmount * Implement generic `testWithReferenceFuncAsync` * Implement generic `testCombinatoriallyWithReferenceFuncAsync` * Add combinatorial tests for isRoundingError * Add combinatorial tests for calculateFillResults * Add support for Geth in internal contract tests * Fix contract artifacts * Change DECIMAL_PLACES to 78 and add a note. * Document new functions in utils * Optimize tests by only reseting state when needed * Rename/move some files * Print parameter names on failure in testWithReferenceFuncAsync * Add to changelog for utils package * Appease various linters * Rename some more things related to FillOrderCombinatorialUtils * Remove .only from test/exchange/internal.ts * Remove old test for isRoundingError and getPartialAmount * Appease linters again * Remove old todos * Fix typos, add comments, rename some things * Re-add some LibMath tests * Update contract internal tests to use new SafeMath revert reasons * Apply PR feedback from Amir * Apply PR feedback from Remco * Re-add networks to ZRXToken artifact * Remove duplicate Whitelist in compiler.json
Diffstat (limited to 'packages/contracts/test/utils/assertions.ts')
-rw-r--r--packages/contracts/test/utils/assertions.ts27
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.