Closed JamesEarle closed 2 years ago
Why would you like to call a function of a fake on your own? Fakes don't store any logic inside the functions, so it would just return the default value (false in case of a bool for example). Maybe you are trying to use mocks
?
Extract from the docs:
Mocks are extensions to smart contracts that have all of the functionality of a fake with some extra goodies. Behind every mock is a real smart contract (with actual Solidity code!) of your choosing. You can modify the behavior of functions like a fake, or you can leave the functions alone and calls will pass through to your actual contract code. And, with a little bit of smock magic, you can even modify the value of variables within your contract! 🥳
Anyhow, as you saw, you can access the wallet of a fake or a mock by doing myFakeOrMock.wallet
. If you need funds there, you could either transfer some ETH from a default hardhat signer by doing something like:
...
import { ethers } from 'hardhat';
import { utils } from 'ethers';
const [whale] = await ethers.getSigners();
await whale.sendTransaction({ value: utils.parseUnits('10'), to: myFakeOrMock.address });
or by using hardhat setBalance:
await network.provider.send('hardhat_setBalance', [
myFakeOrMock.address,
'0x1000',
]);
Does this help? If so, feel free to close the issue
A mistake on my part using the smock incorrectly. Thanks for your help
I'm writing a test for a contract with hardhat that is forking mainnet. I'm deploying that contract and then creating a fake of it with smock.
Then I'm using this mock to send a function.
But this doesn't work because the function is not signed, so we also have to a signer for that transaction like the smock wallet, turning the code into
But now this is creating an issue because that wallet has no funds.
Am I able to add funds to this account? And if so, how? I don't see examples on doing this in your docs.
I am using Windows 19043.1237 with smock version 2.0.6