default before/after in FunctionAssertion

This commit is contained in:
Michael Zhu
2019-10-31 15:49:12 -07:00
parent af0de72bc3
commit 09d13b2bfa
2 changed files with 14 additions and 17 deletions

View File

@@ -1,9 +1,9 @@
import { PromiseWithTransactionHash } from '@0x/base-contract';
import { BlockchainTestsEnvironment } from '@0x/contracts-test-utils';
import { decodeThrownErrorAsRevertError } from '@0x/utils';
import { BlockParam, CallData, TransactionReceiptWithDecodedLogs, TxData } from 'ethereum-types';
import { TransactionReceiptWithDecodedLogs } from 'ethereum-types';
import * as _ from 'lodash';
// tslint:disable:max-classes-per-file
export interface ContractGetterFunction {
callAsync: (...args: any[]) => Promise<any>;
}
@@ -60,8 +60,12 @@ export class FunctionAssertion<TBefore> implements Assertion {
// The wrapper function that will be wrapped in assertions.
public wrapperFunction: ContractWrapperFunction;
constructor(wrapperFunction: ContractWrapperFunction, condition: Condition<TBefore>) {
this.condition = condition;
constructor(wrapperFunction: ContractWrapperFunction, condition: Partial<Condition<TBefore>> = {}) {
this.condition = {
before: _.noop.bind(this),
after: _.noop.bind(this),
...condition,
};
this.wrapperFunction = wrapperFunction;
}
@@ -123,10 +127,11 @@ class MetaAssertion implements Assertion {
) {}
public async executeAsync(): Promise<void> {
let idx: number;
while ((idx = this.indexGenerator()) > 0) {
let idx = this.indexGenerator();
while (idx > 0) {
const args = await this.assertionGenerators[idx].generator();
this.assertionGenerators[idx].assertion.executeAsync(...args);
await this.assertionGenerators[idx].assertion.executeAsync(...args);
idx = this.indexGenerator();
}
}
}