Waffle: Chai AssertionError for emit withArgs(nestedStruct)

Hi,

Env:

  • ethers@4.0.47
  • ethereum-waffle@2.4.1

Solidity:

struct Task {
    address foo;
    uint256 next; 
    address[] bar;  
}

struct TaskReceipt {
    uint256 id;
    address userProxy;
    Task task;
}

I get this errror when trying to listen to the emission of TaskReceipt via

....
to.emit(contract, "LogTaskSubmitted").withArgs(taskReceiptStruct);

Error: AssertionError: expected { Object (id, userProxy, ...) } to equal [ Array(3) ]

I assume this error is because of the way ethers v4 4.0.47 represents nested structs.

Because in this example I pass taskReceiptStruct to .withArgs as a JS obj. Something like:

const taskReceiptStruct = { 
     id: 1, 
     userProxy: "0xad..", 
     task: { 
         foo: "0xdff...", 
         next: 2, 
         bar: ["0xfa."] 
     } 
}

It would be great to get some help on this issue.

Thank you!

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 17 (5 by maintainers)

Commits related to this issue

Most upvoted comments

Hi all…

Same problem for me too even in 2021…

@gitpusha @marekkirejczyk any interesting workaround you followed ? I’d appreciate if you could share it …

@gitpusha Yeah, it is probably the case that the matcher could do a better job comparing the arrays.

Still having the issue, we used the following workaround @ juicebox (ie pushing every value in a new array, effectively getting rid of the Result object from ethers): https://github.com/jbx-protocol/juice-contracts-v2/blob/405d67c16ed150313912d9a64dbf92f19cb7bbb1/test/jb_splits_store/set.test.js#L68

Unfortunately, it’s not always possible (for instance when having the same events n-times within the same tx) 😕 I guess manually parsing logs is the alternative then? Or an “any” / wildcard would maybe help in this case ?

Hi @gitpusha,

That looks like something we should do. Currently however we are snowed under projects and it is hard to find just couple hours to fix it. We are looking for new people to join, so they can help, will let you know as soon as we have more time.

Marek

Hard to tell. Currently we have our eyes set straight on Waffle 3.0.0 with Ethers 5.0.0 support. If bugs for waffle v2 keep piling up we’ll probably release another v2 version.