Skip to content
This repository was archived by the owner on Jan 18, 2023. It is now read-only.

Commit 452df3c

Browse files
committed
Set up testing of logs
1 parent 0df7653 commit 452df3c

File tree

4 files changed

+110
-16
lines changed

4 files changed

+110
-16
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
"@types/lodash": "^4.14.86",
4444
"@types/mocha": "^2.2.47",
4545
"@types/node": "^8.5.1",
46-
"abi-decoder": "^1.1.0",
4746
"bignumber.js": "^4.1.0",
4847
"chai": "^4.1.2",
4948
"chai-as-promised": "^7.1.1",

test/logs/SetToken.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { BigNumber } from "bignumber.js";
2+
import * as _ from "lodash";
3+
import * as LogUtils from "./log_utils";
4+
5+
import { Address, Bytes32, UInt } from "../../types/common";
6+
7+
interface LogInterface {
8+
address: Address;
9+
args: any;
10+
event: string;
11+
}
12+
13+
export function LogIssuance(
14+
senderAddress: Address,
15+
quantity: BigNumber,
16+
setTokenAddress: Address,
17+
): LogInterface {
18+
return {
19+
event: "LogIssuance",
20+
address: setTokenAddress,
21+
args: {
22+
_sender: senderAddress,
23+
_quantity: quantity,
24+
},
25+
};
26+
}
27+
28+
export function LogTransfer(
29+
from: Address,
30+
to: Address,
31+
value: BigNumber,
32+
tokenAddress: Address,
33+
): LogInterface {
34+
return {
35+
event: "Transfer",
36+
address: tokenAddress,
37+
args: {
38+
from,
39+
to,
40+
value,
41+
},
42+
};
43+
}
44+
45+
export function getExpectedIssueLogs(
46+
componentAddresses: Address[],
47+
quantityTransferred: BigNumber[],
48+
setTokenAddress: Address,
49+
quantityIssued: BigNumber,
50+
sender: Address,
51+
): LogInterface[] {
52+
const result: LogInterface[] = [];
53+
// Create transfer logs from components and units
54+
_.each(componentAddresses, (componentAddress, index) => {
55+
result.push(LogTransfer(
56+
sender,
57+
setTokenAddress,
58+
quantityTransferred[index],
59+
componentAddresses[index],
60+
));
61+
});
62+
63+
// Create Issuance Log
64+
result.push(LogIssuance(
65+
sender,
66+
quantityIssued,
67+
setTokenAddress,
68+
));
69+
70+
return result;
71+
}

test/logs/log_utils.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
export function extractLogEventAndArgs(logs: any) {
3+
const { event, args, address } = logs;
4+
return {
5+
event,
6+
address,
7+
args,
8+
};
9+
}

test/setToken-base.spec.ts

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as chai from "chai";
22
import * as _ from "lodash";
3-
// import * as ABIDecoder from "abi-decoder";
43

54
import { BigNumber } from "bignumber.js";
65
import { ether, gWei } from "./utils/units";
@@ -23,6 +22,10 @@ BigNumberSetup.configure();
2322
ChaiSetup.configure();
2423
const { expect, assert } = chai;
2524

25+
import { extractLogEventAndArgs } from "./logs/log_utils";
26+
27+
import { getExpectedIssueLogs } from "./logs/SetToken";
28+
2629
import {
2730
assertTokenBalance,
2831
expectInvalidOpcodeError,
@@ -197,21 +200,23 @@ contract("{Set}", (accounts) => {
197200

198201
// Expected Quantities of tokens moved are divided by a gWei
199202
// to reflect the new units in set instantiation
200-
const quantityA: BigNumber = units1.mul(standardQuantityIssued).div(gWei(1));
201-
const quantityB: BigNumber = units2.mul(standardQuantityIssued).div(gWei(1));
203+
quantitiesToTransfer = _.map(units, (unit) => unit.mul(standardQuantityIssued).div(gWei(1)));
202204

203205
const issuanceReceipt = await setToken.issue(standardQuantityIssued, TX_DEFAULTS);
204206

205-
const issuanceLog = issuanceReceipt.logs[issuanceReceipt.logs.length - 1].args;
206-
207-
// The logs should have the right sender
208-
assert.strictEqual(issuanceLog._sender, testAccount);
209-
210-
// The logs should have the right quantity
211-
expect(issuanceLog._quantity).to.be.bignumber.equal(standardQuantityIssued);
207+
const { logs } = issuanceReceipt;
208+
const formattedLogs = _.map(logs, (log) => extractLogEventAndArgs(log));
209+
const expectedLogs = getExpectedIssueLogs(
210+
componentAddresses,
211+
quantitiesToTransfer,
212+
setToken.address,
213+
standardQuantityIssued,
214+
testAccount,
215+
);
216+
expect(JSON.stringify(formattedLogs)).to.equal(JSON.stringify(expectedLogs));
212217

213-
assertTokenBalance(component1, initialTokens.sub(quantityA), testAccount);
214-
assertTokenBalance(component2, initialTokens.sub(quantityB), testAccount);
218+
assertTokenBalance(component1, initialTokens.sub(quantitiesToTransfer[0]), testAccount);
219+
assertTokenBalance(component2, initialTokens.sub(quantitiesToTransfer[1]), testAccount);
215220
assertTokenBalance(setToken, standardQuantityIssued, testAccount);
216221
});
217222

@@ -240,10 +245,20 @@ contract("{Set}", (accounts) => {
240245
// 60 is about the limit for the number of components in a Set
241246
// This is about ~2M Gas.
242247
describe("of 60 Component Set", () => {
243-
it(`work`, async () => {
244-
await deployStandardSetAndApprove(60);
248+
it(`should work`, async () => {
249+
await deployStandardSetAndApprove(5);
245250

246-
await setToken.issue(standardQuantityIssued, TX_DEFAULTS);
251+
const issuanceReceipt = await setToken.issue(standardQuantityIssued, TX_DEFAULTS);
252+
// const { logs } = issuanceReceipt;
253+
// const formattedLogs = _.map(logs, (log) => extractLogEventAndArgs(log));
254+
// const expectedLogs = getExpectedIssueLogs(
255+
// componentAddresses,
256+
// quantitiesToTransfer,
257+
// setToken.address,
258+
// standardQuantityIssued,
259+
// testAccount,
260+
// );
261+
// expect(JSON.stringify(formattedLogs)).to.equal(JSON.stringify(expectedLogs));
247262
assertTokenBalance(setToken, standardQuantityIssued, testAccount);
248263
});
249264
});

0 commit comments

Comments
 (0)