In my Test I want to mock an external function that I call inside my smart contract to test both conditions without writing and deploying an extra fake smart contract.
My Contract
//SPDX-License-Identifier: Unlicense
pragma solidity 0.8.4;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
contract Greeter {
uint256 private number = 0;
constructor() {}
function getNumber() public view returns (uint256) {
return number;
}
// if transferFrom returns true then set number to 1 , else set number to 2
function setNumber(IERC20 erc20Address) public {
erc20Address.transferFrom(msg.sender, address(this), 10**18) ? number = 1 : number = 2;
}
}
The external contract
//SPDX-License-Identifier: Unlicense
pragma solidity 0.8.4;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract MyERC20 is ERC20 {
constructor() ERC20("Name", "M-T") {}
}
The function to mock is transferFrom