I'm trying to use OZ Test helpers to pass a test when a specific event is emitted. Here is the logic:
- I call function1 with a JS Promise.
- function1 calls function2 which emits an event.
Parts of code have been omitted for readability:
test.js
const { expectEvent } = require('@openzeppelin/test-helpers');
const { ethers } = require("hardhat");
describe("test", function() => {
let mycontract;
before( async() => {
const Mycontract = await ethers.getContractFactory("MyContract");
mycontract = await Mycontract.deploy();
})
it("expected event is emitted.", async() => {
const{ hash } = await mycontract.function1();
await expectEvent.inTransaction(hash, mycontract, "THIS_EVENT",
{message:"This event has happened."} );
});
});
myContract.sol
pragma solidity ^0.6.0;
contract MyContract
{
string message;
constructor(){
_message = "This event has happened."
}
event THIS_EVENT(string message);
function1() {
function2();
}
function2() {
emit THIS_EVENT("_message")
}
}
Error message:
Error: Unknown contract object
How can I write a test to pass when a specific event is emitted as a result of a nested function call ?
Your time is much appreciated,
Edit
hardhat: 2.2.1
test-helpers: 0.1.4