Addressed some review feedback
This commit is contained in:
@@ -5,11 +5,6 @@ import * as _ from 'lodash';
|
||||
// tslint:disable:max-classes-per-file
|
||||
export type GenericContractFunction<T> = (...args: any[]) => ContractFunctionObj<T>;
|
||||
|
||||
export interface FunctionArguments<TArgs extends any[]> {
|
||||
args: TArgs;
|
||||
txData: Partial<TxData>;
|
||||
}
|
||||
|
||||
export interface FunctionResult {
|
||||
data?: any;
|
||||
success: boolean;
|
||||
@@ -27,8 +22,8 @@ export interface FunctionResult {
|
||||
* function.
|
||||
*/
|
||||
export interface Condition<TArgs extends any[], TBefore> {
|
||||
before: (args: FunctionArguments<TArgs>) => Promise<TBefore>;
|
||||
after: (beforeInfo: TBefore, result: FunctionResult, args: FunctionArguments<TArgs>) => Promise<any>;
|
||||
before: (args: TArgs, txData: Partial<TxData>) => Promise<TBefore>;
|
||||
after: (beforeInfo: TBefore, result: FunctionResult, args: TArgs, txData: Partial<TxData>) => Promise<any>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -39,7 +34,7 @@ export interface Condition<TArgs extends any[], TBefore> {
|
||||
* @param runAsync The function to execute for the assertion.
|
||||
*/
|
||||
export interface Assertion<TArgs extends any[]> {
|
||||
executeAsync: (args: FunctionArguments<TArgs>) => Promise<any>;
|
||||
executeAsync: (args: TArgs, txData: TxData) => Promise<any>;
|
||||
}
|
||||
|
||||
export interface AssertionResult<TBefore = unknown> {
|
||||
@@ -67,10 +62,10 @@ export class FunctionAssertion<TArgs extends any[], TBefore, ReturnDataType> imp
|
||||
condition: Partial<Condition<TArgs, TBefore>> = {},
|
||||
) {
|
||||
this.condition = {
|
||||
before: async (args: FunctionArguments<TArgs>) => {
|
||||
before: async (args: TArgs, txData: Partial<TxData>) => {
|
||||
return ({} as any) as TBefore;
|
||||
},
|
||||
after: async (beforeInfo: TBefore, result: FunctionResult, args: FunctionArguments<TArgs>) => {
|
||||
after: async (beforeInfo: TBefore, result: FunctionResult, args: TArgs, txData: Partial<TxData>) => {
|
||||
return ({} as any) as TBefore;
|
||||
},
|
||||
...condition,
|
||||
@@ -82,9 +77,9 @@ export class FunctionAssertion<TArgs extends any[], TBefore, ReturnDataType> imp
|
||||
* Runs the wrapped function and fails if the before or after assertions fail.
|
||||
* @param ...args The args to the contract wrapper function.
|
||||
*/
|
||||
public async executeAsync(args: FunctionArguments<TArgs>): Promise<AssertionResult<TBefore>> {
|
||||
public async executeAsync(args: TArgs, txData: Partial<TxData>): Promise<AssertionResult<TBefore>> {
|
||||
// Call the before condition.
|
||||
const beforeInfo = await this.condition.before(args);
|
||||
const beforeInfo = await this.condition.before(args, txData);
|
||||
|
||||
// Initialize the callResult so that the default success value is true.
|
||||
const callResult: FunctionResult = { success: true };
|
||||
@@ -92,11 +87,11 @@ export class FunctionAssertion<TArgs extends any[], TBefore, ReturnDataType> imp
|
||||
// Try to make the call to the function. If it is successful, pass the
|
||||
// result and receipt to the after condition.
|
||||
try {
|
||||
const functionWithArgs = this.wrapperFunction(...args.args) as ContractTxFunctionObj<ReturnDataType>;
|
||||
callResult.data = await functionWithArgs.callAsync(args.txData);
|
||||
const functionWithArgs = this.wrapperFunction(...args) as ContractTxFunctionObj<ReturnDataType>;
|
||||
callResult.data = await functionWithArgs.callAsync(txData);
|
||||
callResult.receipt =
|
||||
functionWithArgs.awaitTransactionSuccessAsync !== undefined
|
||||
? await functionWithArgs.awaitTransactionSuccessAsync(args.txData) // tslint:disable-line:await-promise
|
||||
? await functionWithArgs.awaitTransactionSuccessAsync(txData) // tslint:disable-line:await-promise
|
||||
: undefined;
|
||||
// tslint:enable:await-promise
|
||||
} catch (error) {
|
||||
@@ -106,7 +101,7 @@ export class FunctionAssertion<TArgs extends any[], TBefore, ReturnDataType> imp
|
||||
}
|
||||
|
||||
// Call the after condition.
|
||||
const afterInfo = await this.condition.after(beforeInfo, callResult, args);
|
||||
const afterInfo = await this.condition.after(beforeInfo, callResult, args, txData);
|
||||
|
||||
return {
|
||||
beforeInfo,
|
||||
|
Reference in New Issue
Block a user