aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/src/utils/assertions.ts
diff options
context:
space:
mode:
authorAlex Browne <stephenalexbrowne@gmail.com>2018-06-06 07:20:38 +0800
committerAlex Browne <stephenalexbrowne@gmail.com>2018-06-07 03:40:31 +0800
commitd6d7f4e875b161aa7284467a61f67989f76ec89e (patch)
treed0287504809489cec96a9673ffac41429cf14cd7 /packages/contracts/src/utils/assertions.ts
parent63caddea62453863de84a4b53e14fe3e61d3008f (diff)
downloaddexon-sol-tools-d6d7f4e875b161aa7284467a61f67989f76ec89e.tar.gz
dexon-sol-tools-d6d7f4e875b161aa7284467a61f67989f76ec89e.tar.zst
dexon-sol-tools-d6d7f4e875b161aa7284467a61f67989f76ec89e.zip
Update more things to work with both Geth and Ganache
Diffstat (limited to 'packages/contracts/src/utils/assertions.ts')
-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');
}