From 56bc2944d06fd76d04366299592eb11c2ae3c3a0 Mon Sep 17 00:00:00 2001 From: Greg Hysen Date: Tue, 4 Jun 2019 17:58:34 -0700 Subject: [PATCH] Fixed false positives in expectTransactionFailedAsync --- contracts/test-utils/CHANGELOG.json | 9 +++++++++ contracts/test-utils/src/assertions.ts | 6 ++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/contracts/test-utils/CHANGELOG.json b/contracts/test-utils/CHANGELOG.json index 79d328a824..93db26dbc1 100644 --- a/contracts/test-utils/CHANGELOG.json +++ b/contracts/test-utils/CHANGELOG.json @@ -1,4 +1,13 @@ [ + { + "version": "3.1.8", + "changes": [ + { + "note": "Fixed false positives in `expectTransactionFailedAsync` and `expectContractCallFailedAsync`", + "pr": 1852 + } + ] + }, { "timestamp": 1558712885, "version": "3.1.7", diff --git a/contracts/test-utils/src/assertions.ts b/contracts/test-utils/src/assertions.ts index c24a3d1696..a60ebd78a1 100644 --- a/contracts/test-utils/src/assertions.ts +++ b/contracts/test-utils/src/assertions.ts @@ -104,7 +104,8 @@ export async function expectTransactionFailedAsync(p: sendTransactionResult, rea } switch (nodeType) { case NodeType.Ganache: - return expect(p).to.be.rejectedWith(reason); + const rejectionMessageRegex = new RegExp(`^VM Exception while processing transaction: revert ${reason}$`); + return expect(p).to.be.rejectedWith(rejectionMessageRegex); case NodeType.Geth: logUtils.warn( 'WARNING: Geth does not support revert reasons for sendTransaction. This test will pass if the transaction fails for any reason.', @@ -160,7 +161,8 @@ export async function expectTransactionFailedWithoutReasonAsync(p: sendTransacti * otherwise resolve with no value. */ export async function expectContractCallFailedAsync(p: Promise, reason: RevertReason): Promise { - return expect(p).to.be.rejectedWith(reason); + const rejectionMessageRegex = new RegExp(`^VM Exception while processing transaction: revert ${reason}$`); + return expect(p).to.be.rejectedWith(rejectionMessageRegex); } /**