default before/after in FunctionAssertion
This commit is contained in:
		@@ -26,7 +26,6 @@ blockchainTests.resets('FunctionAssertion Unit Tests', env => {
 | 
				
			|||||||
                before: async (_input: BigNumber) => {
 | 
					                before: async (_input: BigNumber) => {
 | 
				
			||||||
                    sideEffectTarget = randomInput;
 | 
					                    sideEffectTarget = randomInput;
 | 
				
			||||||
                },
 | 
					                },
 | 
				
			||||||
                after: async (_beforeInfo: any, _result: Result, _input: BigNumber) => null,
 | 
					 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
            const randomInput = getRandomInteger(ZERO_AMOUNT, MAX_UINT256);
 | 
					            const randomInput = getRandomInteger(ZERO_AMOUNT, MAX_UINT256);
 | 
				
			||||||
            await assertion.executeAsync(randomInput);
 | 
					            await assertion.executeAsync(randomInput);
 | 
				
			||||||
@@ -36,7 +35,6 @@ blockchainTests.resets('FunctionAssertion Unit Tests', env => {
 | 
				
			|||||||
        it('should call the after function with the provided arguments', async () => {
 | 
					        it('should call the after function with the provided arguments', async () => {
 | 
				
			||||||
            let sideEffectTarget = ZERO_AMOUNT;
 | 
					            let sideEffectTarget = ZERO_AMOUNT;
 | 
				
			||||||
            const assertion = new FunctionAssertion(exampleContract.returnInteger, {
 | 
					            const assertion = new FunctionAssertion(exampleContract.returnInteger, {
 | 
				
			||||||
                before: async (_input: BigNumber) => null,
 | 
					 | 
				
			||||||
                after: async (_beforeInfo: any, _result: Result, input: BigNumber) => {
 | 
					                after: async (_beforeInfo: any, _result: Result, input: BigNumber) => {
 | 
				
			||||||
                    sideEffectTarget = input;
 | 
					                    sideEffectTarget = input;
 | 
				
			||||||
                },
 | 
					                },
 | 
				
			||||||
@@ -47,10 +45,7 @@ blockchainTests.resets('FunctionAssertion Unit Tests', env => {
 | 
				
			|||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        it('should not fail immediately if the wrapped function fails', async () => {
 | 
					        it('should not fail immediately if the wrapped function fails', async () => {
 | 
				
			||||||
            const assertion = new FunctionAssertion(exampleContract.emptyRevert, {
 | 
					            const assertion = new FunctionAssertion<{}>(exampleContract.emptyRevert);
 | 
				
			||||||
                before: async () => null,
 | 
					 | 
				
			||||||
                after: async (_beforeInfo: any, _result: Result) => null,
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
            await assertion.executeAsync();
 | 
					            await assertion.executeAsync();
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -72,7 +67,6 @@ blockchainTests.resets('FunctionAssertion Unit Tests', env => {
 | 
				
			|||||||
        it('should pass the result from the function call to "after"', async () => {
 | 
					        it('should pass the result from the function call to "after"', async () => {
 | 
				
			||||||
            let sideEffectTarget = ZERO_AMOUNT;
 | 
					            let sideEffectTarget = ZERO_AMOUNT;
 | 
				
			||||||
            const assertion = new FunctionAssertion(exampleContract.returnInteger, {
 | 
					            const assertion = new FunctionAssertion(exampleContract.returnInteger, {
 | 
				
			||||||
                before: async (_input: BigNumber) => null,
 | 
					 | 
				
			||||||
                after: async (_beforeInfo: any, result: Result, _input: BigNumber) => {
 | 
					                after: async (_beforeInfo: any, result: Result, _input: BigNumber) => {
 | 
				
			||||||
                    sideEffectTarget = result.data;
 | 
					                    sideEffectTarget = result.data;
 | 
				
			||||||
                },
 | 
					                },
 | 
				
			||||||
@@ -85,7 +79,6 @@ blockchainTests.resets('FunctionAssertion Unit Tests', env => {
 | 
				
			|||||||
        it('should pass the receipt from the function call to "after"', async () => {
 | 
					        it('should pass the receipt from the function call to "after"', async () => {
 | 
				
			||||||
            let sideEffectTarget: TransactionReceiptWithDecodedLogs;
 | 
					            let sideEffectTarget: TransactionReceiptWithDecodedLogs;
 | 
				
			||||||
            const assertion = new FunctionAssertion(exampleContract.emitEvent, {
 | 
					            const assertion = new FunctionAssertion(exampleContract.emitEvent, {
 | 
				
			||||||
                before: async (_input: string) => null,
 | 
					 | 
				
			||||||
                after: async (_beforeInfo: any, result: Result, _input: string) => {
 | 
					                after: async (_beforeInfo: any, result: Result, _input: string) => {
 | 
				
			||||||
                    if (result.receipt) {
 | 
					                    if (result.receipt) {
 | 
				
			||||||
                        sideEffectTarget = result.receipt;
 | 
					                        sideEffectTarget = result.receipt;
 | 
				
			||||||
@@ -107,7 +100,6 @@ blockchainTests.resets('FunctionAssertion Unit Tests', env => {
 | 
				
			|||||||
        it('should pass the error to "after" if the function call fails', async () => {
 | 
					        it('should pass the error to "after" if the function call fails', async () => {
 | 
				
			||||||
            let sideEffectTarget: Error;
 | 
					            let sideEffectTarget: Error;
 | 
				
			||||||
            const assertion = new FunctionAssertion(exampleContract.stringRevert, {
 | 
					            const assertion = new FunctionAssertion(exampleContract.stringRevert, {
 | 
				
			||||||
                before: async _string => null,
 | 
					 | 
				
			||||||
                after: async (_beforeInfo: any, result: Result, _input: string) => {
 | 
					                after: async (_beforeInfo: any, result: Result, _input: string) => {
 | 
				
			||||||
                    sideEffectTarget = result.data;
 | 
					                    sideEffectTarget = result.data;
 | 
				
			||||||
                },
 | 
					                },
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,9 +1,9 @@
 | 
				
			|||||||
import { PromiseWithTransactionHash } from '@0x/base-contract';
 | 
					import { PromiseWithTransactionHash } from '@0x/base-contract';
 | 
				
			||||||
import { BlockchainTestsEnvironment } from '@0x/contracts-test-utils';
 | 
					import { TransactionReceiptWithDecodedLogs } from 'ethereum-types';
 | 
				
			||||||
import { decodeThrownErrorAsRevertError } from '@0x/utils';
 | 
					 | 
				
			||||||
import { BlockParam, CallData, TransactionReceiptWithDecodedLogs, TxData } from 'ethereum-types';
 | 
					 | 
				
			||||||
import * as _ from 'lodash';
 | 
					import * as _ from 'lodash';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// tslint:disable:max-classes-per-file
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export interface ContractGetterFunction {
 | 
					export interface ContractGetterFunction {
 | 
				
			||||||
    callAsync: (...args: any[]) => Promise<any>;
 | 
					    callAsync: (...args: any[]) => Promise<any>;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -60,8 +60,12 @@ export class FunctionAssertion<TBefore> implements Assertion {
 | 
				
			|||||||
    // The wrapper function that will be wrapped in assertions.
 | 
					    // The wrapper function that will be wrapped in assertions.
 | 
				
			||||||
    public wrapperFunction: ContractWrapperFunction;
 | 
					    public wrapperFunction: ContractWrapperFunction;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    constructor(wrapperFunction: ContractWrapperFunction, condition: Condition<TBefore>) {
 | 
					    constructor(wrapperFunction: ContractWrapperFunction, condition: Partial<Condition<TBefore>> = {}) {
 | 
				
			||||||
        this.condition = condition;
 | 
					        this.condition = {
 | 
				
			||||||
 | 
					            before: _.noop.bind(this),
 | 
				
			||||||
 | 
					            after: _.noop.bind(this),
 | 
				
			||||||
 | 
					            ...condition,
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
        this.wrapperFunction = wrapperFunction;
 | 
					        this.wrapperFunction = wrapperFunction;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -123,10 +127,11 @@ class MetaAssertion implements Assertion {
 | 
				
			|||||||
    ) {}
 | 
					    ) {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public async executeAsync(): Promise<void> {
 | 
					    public async executeAsync(): Promise<void> {
 | 
				
			||||||
        let idx: number;
 | 
					        let idx = this.indexGenerator();
 | 
				
			||||||
        while ((idx = this.indexGenerator()) > 0) {
 | 
					        while (idx > 0) {
 | 
				
			||||||
            const args = await this.assertionGenerators[idx].generator();
 | 
					            const args = await this.assertionGenerators[idx].generator();
 | 
				
			||||||
            this.assertionGenerators[idx].assertion.executeAsync(...args);
 | 
					            await this.assertionGenerators[idx].assertion.executeAsync(...args);
 | 
				
			||||||
 | 
					            idx = this.indexGenerator();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user