Files
protocol/contracts/test-utils/src/log_utils.ts
mzhu25 b46eeadc64 Feat/multiplex/v2 (#263)
* Refactor Multiplex into multiple files

* Pull UniswapV3 into separate file

* Add support for multihop nested within batch sell

* Add useSelfBalance and recipient to _fillRfqOrder

* Expose onlySelf variant in UniswapV3Feature for Multiplex

* Add useSelfBalance and recipient to _transformERC20

* Add support for proportional fill amounts in batchSell

* Comments and renaming

* Unit tests

* Use caps for immutables

* Rename taker -> recipient in TransformContext and SettleOrderInfo

* lint

* Address nits

* Swallow reverts for LiquidityProvider and UniswapV2 batch sells

* Address spot-check findings (#279)

* Check didSucceed in _callWithOptionalBooleanResult

* Add takerToken=ETH support to OtcOrdersFeature (#287)

* Add takerToken=ETH support to OtcOrdersFeature

* Add batchFillTakerSignedOtcOrders

* Add support for OTC to Multiplex

* Address PR feedback

* Update TransformERC20Feature (#303)

* remove multiplex_utils

* Update changelog

* unbreak tests
2021-08-12 17:09:46 -07:00

46 lines
1.5 KiB
TypeScript

import { LogEntry, LogWithDecodedArgs, TransactionReceiptWithDecodedLogs } from 'ethereum-types';
import { expect } from './chai_setup';
// tslint:disable no-unnecessary-type-assertion
/**
* Filter logs by event name/type.
*/
export function filterLogs<TEventArgs>(logs: LogEntry[], event: string): Array<LogWithDecodedArgs<TEventArgs>> {
return (logs as Array<LogWithDecodedArgs<any>>).filter(log => log.event === event);
}
/**
* Filter logs by event name/type and convert to arguments.
*/
export function filterLogsToArguments<TEventArgs>(logs: LogEntry[], event: string): TEventArgs[] {
return filterLogs<TEventArgs>(logs, event).map(log => log.args);
}
/**
* Verifies that a transaction emitted the expected events of a particular type.
*/
export function verifyEvents<TEventArgs>(
txReceipt: TransactionReceiptWithDecodedLogs,
expectedEvents: TEventArgs[],
eventName: string,
): void {
return verifyEventsFromLogs(txReceipt.logs, expectedEvents, eventName);
}
/**
* Given a collection of logs, verifies that matching events are identical.
*/
export function verifyEventsFromLogs<TEventArgs>(
logs: LogEntry[],
expectedEvents: TEventArgs[],
eventName: string,
): void {
const _logs = filterLogsToArguments<TEventArgs>(logs, eventName);
expect(_logs.length, `Number of ${eventName} events emitted`).to.eq(expectedEvents.length);
_logs.forEach((log, index) => {
expect(log, `${eventName} event ${index}`).to.deep.equal({ ...log, ...expectedEvents[index] });
});
}