-
I have been able to test all other parts of my smart contract but I am unable to test the receive and fallback function. I have searched through the internet but I can't find a straightforward answer. I tried to test the fallback function using this code but it doesn't work. await expect(
transportManager.sendTransaction({
value: sendValue,
})
).to.be.revertedWith("TransportManager__Fallback"); The test failed with this result TypeError: transportManager.sendTransaction is not a function How do I go about this? How can I test the receive and fallback function. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
For the fallback you can send a function to the contract that doesn't exist here's an awesome article that goes more indept https://stackoverflow.com/questions/72584559/how-to-test-the-solidity-fallback-function-via-hardhat and for receive: I'd imagine you just send ether directly to the contract |
Beta Was this translation helpful? Give feedback.
-
@samlak I managed to test both function. This is my repo: https://github.com/PacelliV/hardhat-fund-me. Let me if it works for you. |
Beta Was this translation helpful? Give feedback.
For the fallback you can send a function to the contract that doesn't exist
here's an awesome article that goes more indept
https://stackoverflow.com/questions/72584559/how-to-test-the-solidity-fallback-function-via-hardhat
and for receive:
I'd imagine you just send ether directly to the contract