aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/src
diff options
context:
space:
mode:
Diffstat (limited to 'packages/contracts/src')
-rw-r--r--packages/contracts/src/utils/assertions.ts36
1 files changed, 14 insertions, 22 deletions
diff --git a/packages/contracts/src/utils/assertions.ts b/packages/contracts/src/utils/assertions.ts
index 1ea071d01..c08bc7271 100644
--- a/packages/contracts/src/utils/assertions.ts
+++ b/packages/contracts/src/utils/assertions.ts
@@ -5,38 +5,30 @@ import { constants } from './constants';
const expect = chai.expect;
-// throws if the given promise does not reject with one of two expected error
-// messages.
-export function expectRevertOrAlwaysFailingTransaction<T>(p: Promise<T>): PromiseLike<void> {
+function _expectEitherError<T>(p: Promise<T>, error1: string, error2: string): PromiseLike<void> {
return expect(p)
.to.be.rejected()
.then(e => {
expect(e).to.satisfy(
- (err: Error) =>
- _.includes(err.message, constants.REVERT) || _.includes(err.message, 'always failing transaction'),
+ (err: Error) => _.includes(err.message, error1) || _.includes(err.message, error2),
+ `expected promise to reject with error message that includes "${error1}" or "${error2}", but got: ` +
+ `"${e.message}"\n`,
);
});
}
export function expectInsufficientFunds<T>(p: Promise<T>): PromiseLike<void> {
- return expect(p)
- .to.be.rejected()
- .then(e => {
- expect(e).to.satisfy(
- (err: Error) =>
- _.includes(err.message, 'insufficient funds') ||
- _.includes(err.message, "sender doesn't have enough funds"),
- );
- });
+ return _expectEitherError(p, 'insufficient funds', "sender doesn't have enough funds");
+}
+
+export function expectRevertOrOtherError<T>(p: Promise<T>, otherError: string): PromiseLike<void> {
+ return _expectEitherError(p, constants.REVERT, otherError);
+}
+
+export function expectRevertOrAlwaysFailingTransaction<T>(p: Promise<T>): PromiseLike<void> {
+ return expectRevertOrOtherError(p, 'always failing transaction');
}
export function expectRevertOrContractCallFailed<T>(p: Promise<T>): PromiseLike<void> {
- return expect(p)
- .to.be.rejected()
- .then(e => {
- expect(e).to.satisfy(
- (err: Error) =>
- _.includes(err.message, constants.REVERT) || _.includes(err.message, 'Contract call failed'),
- );
- });
+ return expectRevertOrOtherError<T>(p, 'Contract call failed');
}