From 72fb8460e90237fb7879fc47e95d84b6aa54911b Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Mon, 21 May 2018 14:26:25 -0700 Subject: Update code after rebase --- packages/contracts/src/utils/assertions.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 packages/contracts/src/utils/assertions.ts (limited to 'packages/contracts/src/utils/assertions.ts') diff --git a/packages/contracts/src/utils/assertions.ts b/packages/contracts/src/utils/assertions.ts new file mode 100644 index 000000000..72c2734d8 --- /dev/null +++ b/packages/contracts/src/utils/assertions.ts @@ -0,0 +1,20 @@ +import * as chai from 'chai'; +import * as _ from 'lodash'; + +import { constants } from './constants'; + +const expect = chai.expect; + +// throws if the given promise does not reject with one of two expected error +// messages. +export const expectRevertOrAlwaysFailingTransaction = (p: Promise) => { + return expect(p) + .to.be.rejected() + .then(e => { + expect(e).to.satisfy( + (err: Error) => + _.includes(err.message, constants.REVERT) || + _.includes(err.message, constants.ALWAYS_FAILING_TRANSACTION), + ); + }); +}; -- cgit v1.2.3 From 1cc9d9c0713a56b59717498fcae6dc2720ca4fb0 Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Tue, 22 May 2018 12:47:37 -0700 Subject: Replace constant.REVERT test assertions with expectRevertOrAlwaysFailingTransaction --- packages/contracts/src/utils/assertions.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'packages/contracts/src/utils/assertions.ts') diff --git a/packages/contracts/src/utils/assertions.ts b/packages/contracts/src/utils/assertions.ts index 72c2734d8..e3f31bf89 100644 --- a/packages/contracts/src/utils/assertions.ts +++ b/packages/contracts/src/utils/assertions.ts @@ -7,7 +7,7 @@ const expect = chai.expect; // throws if the given promise does not reject with one of two expected error // messages. -export const expectRevertOrAlwaysFailingTransaction = (p: Promise) => { +export function expectRevertOrAlwaysFailingTransaction(p: Promise): PromiseLike { return expect(p) .to.be.rejected() .then(e => { @@ -17,4 +17,4 @@ export const expectRevertOrAlwaysFailingTransaction = (p: Promise) => { _.includes(err.message, constants.ALWAYS_FAILING_TRANSACTION), ); }); -}; +} -- cgit v1.2.3 From 2dfc4680941293ca9f4a55f3ca58b9ee68872754 Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Fri, 1 Jun 2018 15:59:34 -0700 Subject: Update more tests to pass on Geth --- packages/contracts/src/utils/assertions.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'packages/contracts/src/utils/assertions.ts') diff --git a/packages/contracts/src/utils/assertions.ts b/packages/contracts/src/utils/assertions.ts index e3f31bf89..1e8d58b9f 100644 --- a/packages/contracts/src/utils/assertions.ts +++ b/packages/contracts/src/utils/assertions.ts @@ -18,3 +18,15 @@ export function expectRevertOrAlwaysFailingTransaction(p: Promise): Promis ); }); } + +export function expectInsufficientFunds(p: Promise): PromiseLike { + 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"), + ); + }); +} -- cgit v1.2.3 From bca62c813d2e821c56968916615861366402435b Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Mon, 4 Jun 2018 18:10:42 -0700 Subject: Throw in web3-wrapper when rawCallResult is '0x' --- packages/contracts/src/utils/assertions.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'packages/contracts/src/utils/assertions.ts') diff --git a/packages/contracts/src/utils/assertions.ts b/packages/contracts/src/utils/assertions.ts index 1e8d58b9f..4fc410363 100644 --- a/packages/contracts/src/utils/assertions.ts +++ b/packages/contracts/src/utils/assertions.ts @@ -30,3 +30,15 @@ export function expectInsufficientFunds(p: Promise): PromiseLike { ); }); } + +export function expectRevertOrContractCallFailed(p: Promise): PromiseLike { + return expect(p) + .to.be.rejected() + .then(e => { + expect(e).to.satisfy( + (err: Error) => + _.includes(err.message, constants.REVERT) || + _.includes(err.message, constants.CONTRACT_CALL_FAILED), + ); + }); +} -- cgit v1.2.3 From 63caddea62453863de84a4b53e14fe3e61d3008f Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Tue, 5 Jun 2018 15:12:09 -0700 Subject: Small fixes and cleanup --- packages/contracts/src/utils/assertions.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'packages/contracts/src/utils/assertions.ts') diff --git a/packages/contracts/src/utils/assertions.ts b/packages/contracts/src/utils/assertions.ts index 4fc410363..1ea071d01 100644 --- a/packages/contracts/src/utils/assertions.ts +++ b/packages/contracts/src/utils/assertions.ts @@ -13,8 +13,7 @@ export function expectRevertOrAlwaysFailingTransaction(p: Promise): Promis .then(e => { expect(e).to.satisfy( (err: Error) => - _.includes(err.message, constants.REVERT) || - _.includes(err.message, constants.ALWAYS_FAILING_TRANSACTION), + _.includes(err.message, constants.REVERT) || _.includes(err.message, 'always failing transaction'), ); }); } @@ -37,8 +36,7 @@ export function expectRevertOrContractCallFailed(p: Promise): PromiseLike< .then(e => { expect(e).to.satisfy( (err: Error) => - _.includes(err.message, constants.REVERT) || - _.includes(err.message, constants.CONTRACT_CALL_FAILED), + _.includes(err.message, constants.REVERT) || _.includes(err.message, 'Contract call failed'), ); }); } -- cgit v1.2.3 From d6d7f4e875b161aa7284467a61f67989f76ec89e Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Tue, 5 Jun 2018 16:20:38 -0700 Subject: Update more things to work with both Geth and Ganache --- packages/contracts/src/utils/assertions.ts | 36 ++++++++++++------------------ 1 file changed, 14 insertions(+), 22 deletions(-) (limited to 'packages/contracts/src/utils/assertions.ts') 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(p: Promise): PromiseLike { +function _expectEitherError(p: Promise, error1: string, error2: string): PromiseLike { 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(p: Promise): PromiseLike { - 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(p: Promise, otherError: string): PromiseLike { + return _expectEitherError(p, constants.REVERT, otherError); +} + +export function expectRevertOrAlwaysFailingTransaction(p: Promise): PromiseLike { + return expectRevertOrOtherError(p, 'always failing transaction'); } export function expectRevertOrContractCallFailed(p: Promise): PromiseLike { - 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(p, 'Contract call failed'); } -- cgit v1.2.3 From ba6806df5d2d4b31c125a0c58cc6cd65bf555933 Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Tue, 5 Jun 2018 16:45:37 -0700 Subject: Fix linter errors --- packages/contracts/src/utils/assertions.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'packages/contracts/src/utils/assertions.ts') diff --git a/packages/contracts/src/utils/assertions.ts b/packages/contracts/src/utils/assertions.ts index c08bc7271..fc57f93fb 100644 --- a/packages/contracts/src/utils/assertions.ts +++ b/packages/contracts/src/utils/assertions.ts @@ -17,18 +17,47 @@ function _expectEitherError(p: Promise, error1: string, error2: string): P }); } +/** + * Rejects if the given Promise does not reject with an error indicating + * insufficient funds. + * @param p the Promise which is expected to reject + * @returns a new Promise which will reject if the conditions are not met and + * otherwise resolve with no value. + */ export function expectInsufficientFunds(p: Promise): PromiseLike { return _expectEitherError(p, 'insufficient funds', "sender doesn't have enough funds"); } +/** + * Rejects if the given Promise does not reject with a "revert" error or the + * given otherError. + * @param p the Promise which is expected to reject + * @param otherError the other error which is accepted as a valid reject error. + * @returns a new Promise which will reject if the conditions are not met and + * otherwise resolve with no value. + */ export function expectRevertOrOtherError(p: Promise, otherError: string): PromiseLike { return _expectEitherError(p, constants.REVERT, otherError); } +/** + * Rejects if the given Promise does not reject with a "revert" or "always + * failing transaction" error. + * @param p the Promise which is expected to reject + * @returns a new Promise which will reject if the conditions are not met and + * otherwise resolve with no value. + */ export function expectRevertOrAlwaysFailingTransaction(p: Promise): PromiseLike { return expectRevertOrOtherError(p, 'always failing transaction'); } +/** + * Rejects if the given Promise does not reject with a "revert" or "Contract + * call failed" error. + * @param p the Promise which is expected to reject + * @returns a new Promise which will reject if the conditions are not met and + * otherwise resolve with no value. + */ export function expectRevertOrContractCallFailed(p: Promise): PromiseLike { return expectRevertOrOtherError(p, 'Contract call failed'); } -- cgit v1.2.3 From 167a38e27d09af12af6c59f1b486c835420fbac1 Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Tue, 5 Jun 2018 16:56:16 -0700 Subject: Add Async suffix to relevant assertions --- packages/contracts/src/utils/assertions.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'packages/contracts/src/utils/assertions.ts') diff --git a/packages/contracts/src/utils/assertions.ts b/packages/contracts/src/utils/assertions.ts index fc57f93fb..615e648f3 100644 --- a/packages/contracts/src/utils/assertions.ts +++ b/packages/contracts/src/utils/assertions.ts @@ -5,7 +5,7 @@ import { constants } from './constants'; const expect = chai.expect; -function _expectEitherError(p: Promise, error1: string, error2: string): PromiseLike { +function _expectEitherErrorAsync(p: Promise, error1: string, error2: string): PromiseLike { return expect(p) .to.be.rejected() .then(e => { @@ -24,8 +24,8 @@ function _expectEitherError(p: Promise, error1: string, error2: string): P * @returns a new Promise which will reject if the conditions are not met and * otherwise resolve with no value. */ -export function expectInsufficientFunds(p: Promise): PromiseLike { - return _expectEitherError(p, 'insufficient funds', "sender doesn't have enough funds"); +export function expectInsufficientFundsAsync(p: Promise): PromiseLike { + return _expectEitherErrorAsync(p, 'insufficient funds', "sender doesn't have enough funds"); } /** @@ -36,8 +36,8 @@ export function expectInsufficientFunds(p: Promise): PromiseLike { * @returns a new Promise which will reject if the conditions are not met and * otherwise resolve with no value. */ -export function expectRevertOrOtherError(p: Promise, otherError: string): PromiseLike { - return _expectEitherError(p, constants.REVERT, otherError); +export function expectRevertOrOtherErrorAsync(p: Promise, otherError: string): PromiseLike { + return _expectEitherErrorAsync(p, constants.REVERT, otherError); } /** @@ -47,8 +47,8 @@ export function expectRevertOrOtherError(p: Promise, otherError: string): * @returns a new Promise which will reject if the conditions are not met and * otherwise resolve with no value. */ -export function expectRevertOrAlwaysFailingTransaction(p: Promise): PromiseLike { - return expectRevertOrOtherError(p, 'always failing transaction'); +export function expectRevertOrAlwaysFailingTransactionAsync(p: Promise): PromiseLike { + return expectRevertOrOtherErrorAsync(p, 'always failing transaction'); } /** @@ -58,6 +58,6 @@ export function expectRevertOrAlwaysFailingTransaction(p: Promise): Promis * @returns a new Promise which will reject if the conditions are not met and * otherwise resolve with no value. */ -export function expectRevertOrContractCallFailed(p: Promise): PromiseLike { - return expectRevertOrOtherError(p, 'Contract call failed'); +export function expectRevertOrContractCallFailedAsync(p: Promise): PromiseLike { + return expectRevertOrOtherErrorAsync(p, 'Contract call failed'); } -- cgit v1.2.3