Skip to content
This repository was archived by the owner on Jan 18, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@
"@0xproject/abi-gen": "1.0.4",
"@0xproject/base-contract": "^1.0.4",
"@0xproject/order-utils": "^1.0.1-rc.2",
"@0xproject/web3-wrapper": "^1.1.2",
"@0xproject/types": "^1.0.1-rc.3",
"@0xproject/typescript-typings": "^1.0.3",
"@0xproject/utils": "^0.1.0",
"@0xproject/web3-wrapper": "^1.1.2",
"@types/bignumber.js": "^4.0.3",
"@types/fs-extra": "^5.0.0",
"@types/json-stable-stringify": "^1.0.32",
Expand Down Expand Up @@ -81,6 +81,7 @@
"web3": "0.20.0"
},
"dependencies": {
"eth-gas-reporter": "^0.1.10",
"fs-extra": "^5.0.0",
"husky": "^0.14.3",
"lint-staged": "^7.2.0",
Expand Down
2 changes: 1 addition & 1 deletion test/core/extensions/coreExchangeDispatcher.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ contract('CoreExchangeDispatcher', accounts => {
),
];

await assertLogEquivalence(expectedLogs, formattedLogs);
await assertLogEquivalence(formattedLogs, expectedLogs);
});

describe('when the caller is not the owner of the contract', async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/core/extensions/coreFactory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ contract('CoreFactory', accounts => {
),
];

await assertLogEquivalence(expectedLogs, logs);
await assertLogEquivalence(logs, expectedLogs);
});

describe('when the factory is not valid', async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/core/extensions/coreIssuance.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ contract('CoreIssuance', accounts => {
);
});

await assertLogEquivalence(expectedLogs, formattedLogs);
await assertLogEquivalence(formattedLogs, expectedLogs);
});

it('updates the balances of the components in the vault to belong to the set token', async () => {
Expand Down
6 changes: 3 additions & 3 deletions test/core/extensions/coreIssuanceOrder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ contract('CoreIssuanceOrder', accounts => {
core.address
);

await assertLogEquivalence(expectedLogs, formattedLogs);
await assertLogEquivalence(formattedLogs, expectedLogs);
});

describe('when the fill size is less than the order quantity', async () => {
Expand Down Expand Up @@ -327,7 +327,7 @@ contract('CoreIssuanceOrder', accounts => {
core.address
);

await assertLogEquivalence(expectedLogs, formattedLogs);
await assertLogEquivalence(formattedLogs, expectedLogs);
});
});

Expand Down Expand Up @@ -609,7 +609,7 @@ contract('CoreIssuanceOrder', accounts => {
core.address
);

await assertLogEquivalence(expectedLogs, formattedLogs);
await assertLogEquivalence(formattedLogs, expectedLogs);
});

describe('when the quantity to cancel is greater than the open amount', async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/core/extensions/coreIssuanceOrderScenarios.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ contract('CoreIssuanceOrder::Scenarios', accounts => {
core.address
);

await assertLogEquivalence(expectedLogs, [formattedLogs[0]]);
await assertLogEquivalence(formattedLogs, expectedLogs);
});
});
});
Expand Down
6 changes: 3 additions & 3 deletions test/lib/authorizable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ contract('Authorizable', accounts => {
authorizableContract.address,
);

await assertLogEquivalence(expectedLogs, formattedLogs);
await assertLogEquivalence(formattedLogs, expectedLogs);
});

describe('when the caller is not the owner of the contract', async () => {
Expand Down Expand Up @@ -161,7 +161,7 @@ contract('Authorizable', accounts => {
authorizableContract.address,
);

await assertLogEquivalence(expectedLogs, formattedLogs);
await assertLogEquivalence(formattedLogs, expectedLogs);
});

describe('when the caller is not the owner of the contract', async () => {
Expand Down Expand Up @@ -240,7 +240,7 @@ contract('Authorizable', accounts => {
authorizableContract.address,
);

await assertLogEquivalence(expectedLogs, formattedLogs);
await assertLogEquivalence(formattedLogs, expectedLogs);
});

describe('when the caller is not the owner of the contract', async () => {
Expand Down
10 changes: 9 additions & 1 deletion truffle.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,13 @@ module.exports = {
gas: 0xfffffffffff,
gasPrice: 0x01,
},
}

},
mocha: {
reporter: 'eth-gas-reporter',
reporterOptions : {
currency: 'USD',
gasPrice: 5
}
},
};
72 changes: 25 additions & 47 deletions utils/logs.ts
Original file line number Diff line number Diff line change
@@ -1,63 +1,45 @@
import * as ABIDecoder from "abi-decoder";
import * as chai from "chai";
import * as _ from "lodash";
import * as _ from 'lodash';
import * as ABIDecoder from 'abi-decoder';
import * as bigNumber from 'bignumber.js';
import * as chai from 'chai';

import { BigNumber } from "bignumber.js";
import { Log } from "../types/common";

import ChaiSetup from "./chaiSetup";
import { Log } from '../types/common';
import ChaiSetup from './chaiSetup';
ChaiSetup.configure();
const { expect, assert } = chai;
const { expect } = chai;

export async function getFormattedLogsFromTxHash(txHash: string): Promise<Log[]> {
export async function getFormattedLogsFromTxHash(
txHash: string
): Promise<Log[]> {
const receipt = await web3.eth.getTransactionReceipt(txHash);
const logs: ABIDecoder.DecodedLog[] = _.compact(ABIDecoder.decodeLogs(receipt.logs));
return _.map(logs, (log) => formatLogEntry(log));
return _.map(logs, log => formatLogEntry(log));
}

export async function assertLogEquivalence(
actual: Log[],
expected: Log[]
) {
const formattedExpectedLogs = _.map(expected, log => JSON.stringify(log));
const formattedActualLogs = _.map(actual, log => JSON.stringify(log));
expect(formattedActualLogs).to.include.members(formattedExpectedLogs);
}

/**
* Converts a ABI Decoded Log into a Log
* Input Example
* {
* name: 'Transfer',
* events: [
* { name: 'from',
* type: 'address',
* value: '0xc604980c49f5c3be6e7e42526ec00f211e333385' },
* { name: 'to',
* type: 'address',
* value: '0xf8600afbf76236454a53e8dcc4d1feaa26fe1a77' },
* { name: 'value', type: 'uint256', value: '10000000000000000000' },
* ],
* address: '0xea76972f7587c27887aa403d84671717f6826f62'
* }
*
* Output Example
* {
* event: "Transfer",
* address: tokenAddress,
* args: {
* from,
* to,
* value,
* },
* };
*/
export function formatLogEntry(logs: ABIDecoder.DecodedLog): Log {
function formatLogEntry(logs: ABIDecoder.DecodedLog): Log {
const { name, events, address } = logs;
let args: any = {};
const args: any = {};

// Loop through each event and add to args
_.each(events, (event) => {
_.each(events, event => {
const { name, type, value } = event;

var argValue: any = value;
let argValue: any = value;
switch (true) {
case (/^(uint)\d*\[\]/.test(type)): {
break;
}
case (/^(uint)\d*/.test(type)): {
argValue = new BigNumber(value.toString());
argValue = new bigNumber.BigNumber(value.toString());
break;
}
}
Expand All @@ -71,7 +53,3 @@ export function formatLogEntry(logs: ABIDecoder.DecodedLog): Log {
args,
};
}

export async function assertLogEquivalence(expected: Log[], actual: Log[]) {
expect(JSON.stringify(actual)).to.eql(JSON.stringify(expected));
}
Loading