Transferring ethers to a mocked contract
Hello all,
I'm trying to understand if there is an issue with Waffle or it's my lack of knowledge...
When transferring ethers from a contract to a mocked contract, I get the error contract call run out of gas and made the transaction revert even though the caller contract balance has enough.
This is the simple Test contract:
pragma solidity ^0.8.0;
import "hardhat/console.sol";
contract Test {
address payable public receiver;
constructor(address payable _receiver) {
receiver = _receiver;
}
function transferTest(uint256 amount) external {
console.log("Contract balance", address(this).balance);
console.log("Amount to be transfered", amount);
receiver.transfer(amount);
}
receive() external payable {}
}
The reproduction steps are:
- Deploy the
receivermocked contract - Deploy the
Testcontract withreceiver's contract address as argument - Send ethers to the
Testcontract - Call the
deployedTest.transferTestfunction
Thank you in advance.
I suspect there is no way to do what you want.
The mock contract's (payable) fallback function is how it delegates to the different initialized mock functions. Your transfer ultimately ends up invoking this function and since there's nothing for the mock contract to delegate, it will revert. In theory, it will call the receive first, but this is a special function and I don't know how to mock it.
Is there no way to transfer some ether into or increase the ether balance of a mocked contract?