-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sending and receiving of ether to/from fakes #148
Comments
Furthermore, more transaction context like the |
To complete the use cases mentioned, it would be very useful to be able to check the amount of ether sent with a call to a fake. Just like you can check the arguments with "calledWith". |
Yes that would also be helpful, like expect(contract.func).to.have.receivedEther(amount) Even though hardhat chai matchers already allow for testing this on the fake's address with expect(tx).to.changeEtherBalance(fake.address, amount) this would still be nice, if possible. |
I tried to achieve sending ether from a fake with the following trick contract.func.returns(async () => {
await contract.wallet.sendTransaction({
to: receiver,
value: amount,
})
}) but this didn't work either, as |
Description
When a function receives ether, the
whenCalledWith
filter cannot be set to an expect amount of ether being received by the function. Likewise, a function as argument toreturns(input => { // do smth with input })
doesn't receive the amount of ether received with the function call.On the other hand, I also cannot set a function to send some amount of ether when called.
If any of this is possible, it is not documented.
Solution
whenCalledWith
should accept an optional last argument{value: BigNumberish}
with which I can set an expected amount of ether to receive.returns
should accept functions that have an optional last argument{value: BigNumberish}
to which the amount of ether is passed that this call received. The function should also be able to return a dynamic amount of ether to send, e.g. as an object{value: BigNumberish, to: string}
returns
should have an optional last argument{value: BigNumberish, to: string}
which, if present, lets the function send an amount ofvalue
ether to addressto
when called.I guess the handling of ether could also be applied to other functions not mentioned in this issue.
The text was updated successfully, but these errors were encountered: