DePayFi / web3-mock

🤡 JavaScript library to mock web3 responses either by emulating web3 wallets or web3 RPC requests.
https://depay.com
MIT License
87 stars 20 forks source link

Mock contract transactions do not check the 'value' of the transaction #13

Closed megamattron closed 2 years ago

megamattron commented 2 years ago

It would be great to verify that the 'value' of a mock transaction is also being specified as expected, for example: https://github.com/larvalabs/cryptopunksmarket/blob/cypresstests/cypress/integration/bidder-actions.spec.js#L111

As it stands now I can have any number specified for 'value', or value can be missing entirely and web3-mock won't warn that a mock is missing (and thereby cause my test to fail, as I was hoping).

10xSebastian commented 2 years ago

web3-mock does only match mocks with the correct value (see test case here) and it rejects the transaction request with asking you to mock the transaction correctly (with the correct value).

Problem usually is that due to javascripts async nature, nothing "raises" as the reject might not be catched in your application or in web3js.

What you e.g. could try is to check cypress console for that test if you see any "Web3Mock: Please mock the transaction XYZ"

And there is even an internal call counter compliant with test helpers like .toHaveBeenCalled() see here

You could also check the call count of the mockedTransaction at the end of your test directly like:

expect(mockTransaction.calls.count() > 0).equal(true)

Which would proof that the transaction has not been matched/called (due to the wrong value).

megamattron commented 2 years ago

You are correct, it was a mistake on my end. Sorry about that!