When you have a contract that emits an event in an underlying library instead of the contract itself, since the contract doesn't contain the ABI of the event you probably face this error:
AssertionError: Expected event "MyEvent" to be emitted, but it doesn't exist in the contract. Please make sure you've compiled its latest version before running the test.
to fix it you can create a contract instance with the library ABI (The one that contains the event) and the contract address.
it's possible in two ways:
contractInstance is the instance with the contract ABI
MyEvent is the event emits in the library
EventLibrary is the library that emits the event
EventLibraryInstance is the library instance that has been used in deploying the contract
contractInstanceWithLibraryABI is the instance with the library ABI and the contract address
first:
let contractInstanceWithLibraryABI = await ethers.getContractAt("EventLibrary", contractInstance.address, signer)
await expect(
await contractInstance.myFunction()
).to.emit(contractInstanceWithLibraryABI, "MyEvent")
second:
contractInstanceWithLibraryABI = await EventLibraryInstance.attach(
contractInstance.address
)
await expect(
await contractInstance.myFunction()
).to.emit(contractInstanceWithLibraryABI, "MyEvent")