I'm a three months old programmer. So if what I'm saying is ambiguous, please let me know and help me being a better programmer.
Now I'm coding a test code as using hardhat and ether.js.
My solidity contract is about orderbook token exchange. When people make an order, the contract emit specific event named "Make".
event Make(
bytes32 indexed orderId,
address indexed maker,
address makerToken,
address takerToken,
uint256 amountSell,
uint256 amountBuy
);
orderId is made by hashing some data.
And I want to check if event is emitted correctly. While coding test codes, I've spent quite a long time to know how to get emitted events.
finally I can get events using code below. but what I really want is
get 1st arg of event and put it a var. (in case, bytes32 hash) looks like, const hash = await events.args[0];
compare 2nd arg of event and compare it with value. (in case, address maker) looks like, expect(await events.args[1]).to.equal(add1.address);
actually it's not a two question. just one.
here's my test code.
const { expect } = require("chai");
const { ethers } = require("hardhat");
describe("EX contract", function () {
let EX, ex, token, Token, add0, add1, add2, add3;
before(async function () {
EX = await ethers.getContractFactory("EX");
Token = await ethers.getContractFactory("Token");
ex = await EX.deploy(1000);
token = await Token.deploy();
[add0, add1, add2, add3] = await ethers.getSigners();
});
beforeEach(async function () {
await token.mint(add1.address, 200000);
});
describe("Make / Take order", function () {
await ex.connect(add1).makeOrder(token.address, 100, {value : 100});
await ex.connect(add1).makeOrder(token.address, 100, {value : 200});
let eventFilter = ex.filters.Make();
let events = await ex.queryFilter(eventFilter, "latest");
console.log(events); //"events" contains too many information.
});
});
Help me please, mates!