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.ts29
-rw-r--r--packages/contracts/src/utils/increase_time.ts9
2 files changed, 36 insertions, 2 deletions
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<T>(p: Promise<T>, 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<T>(p: Promise<T>): PromiseLike<void> {
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<T>(p: Promise<T>, otherError: string): PromiseLike<void> {
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<T>(p: Promise<T>): PromiseLike<void> {
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<T>(p: Promise<T>): PromiseLike<void> {
return expectRevertOrOtherError<T>(p, 'Contract call failed');
}
diff --git a/packages/contracts/src/utils/increase_time.ts b/packages/contracts/src/utils/increase_time.ts
index 726a759f3..5336a180d 100644
--- a/packages/contracts/src/utils/increase_time.ts
+++ b/packages/contracts/src/utils/increase_time.ts
@@ -5,8 +5,13 @@ import { web3Wrapper } from './web3_wrapper';
let firstAccount: string | undefined;
-// increases time by the given number of seconds and then mines a block so that
-// the current block timestamp has the offset applied.
+/**
+ * Increases time by the given number of seconds and then mines a block so that
+ * the current block timestamp has the offset applied.
+ * @param seconds the Promise which is expected to reject
+ * @returns a new Promise which will resolve with the new total time offset or
+ * reject if the time could not be increased.
+ */
export async function increaseTimeAndMineBlockAsync(seconds: number): Promise<number> {
if (_.isUndefined(firstAccount)) {
const accounts = await web3Wrapper.getAvailableAddressesAsync();