-
Notifications
You must be signed in to change notification settings - Fork 53
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
Add support of network forking with Hardhat #718
Comments
Thanks @maksimKrukovich for the ticket and context. For context most EVM tools that provide forking support actually run their own EVM client as part of the node, sometimes with custom logic to support that tools features. For Hedera because we have additional functionality such as system contracts that expose native services in smart contracts the tool encounters issues as it doesn't have the logic for these services. Nonetheless we're actively looking into this and exploring how we can support this in a seamless way for developers like yourself. That being said if you're not forking contracts with system contract functions you should be fine and forking should work. If your flow relies on system contract functionality then the above issue applies and we're currently blocked in supporting this flow. We'll continue to explore this challenge though to best enable devs |
Revisiting. |
@maksimKrukovich Can you give me a snippet of how you try to fork the network ? |
Hey @georgi-l95, Often I do this like that:
And it fails on this line: I've heard Hedera doesn't support fixtures, so I use Of course I run a test which involves HTS. |
Hi @maksimKrukovich, thanks for sending this. We are aware of this situation. See #863 (comment) for a related issue on forking with HTS. Would you be able to provide a minimal example on how to reproduce the error you mentioned above? This will help us to provide a more comprehensible solution for forking. |
Hi @acuarica, The example contract: contract Example {
IERC20 public stakingToken;
constructor(address _stakingToken) payable {
stakingToken = IERC20(_stakingToken);
SafeHTS.safeAssociateToken(address(_stakingToken), address(this));
}
function stake(uint256 amount) external {
SafeHTS.safeTransferToken(address(stakingToken), msg.sender, address(this), int64(uint64(amount)));
} The example test: describe("Example", function () {
async function deployFixture() {
const [
owner,
] = await ethers.getSigners();
let client = Client.forTestnet();
const operatorPrKey = PrivateKey.fromStringECDSA(process.env.PRIVATE_KEY || '');
const operatorAccountId = AccountId.fromString(process.env.ACCOUNT_ID || '');
client.setOperator(
operatorAccountId,
operatorPrKey
);
const stakingToken = await ethers.getContractAt(
"ExampleToken",
stakingTokenAddress
);
const Example = await ethers.getContractFactory("Example");
const example = await Example.deploy(
stakingTokenAddress,
{ from: owner.address, gasLimit: 3000000, value: ethers.parseUnits("12", 18) }
);
await example.waitForDeployment();
return {
example,
stakingToken,
client,
owner,
};
}
describe("stake", function () {
it("Should stake the staking token", async function () {
const { example, stakingToken } = await deployFixture();
const amountToStake = ethers.parseUnits("10", 8);
await stakingToken.approve(example.target, amountToStake);
const tx = await example.stake(amountToStake);
});
});
}); |
Problem
It would be really helpful to have the option to fork all Hedera networks with hardhat for testing contracts and scripts.
Explanation why forking is the really important thing:
https://hardhat.org/hardhat-network/docs/guides/forking-other-networks
Now if you try to fork for example testnet network it's the next error:
ProviderError: Invalid parent hash: 0x5c4eb51347f68986db69a79aea1f64f0a5baa22aae494b64b1204745a7fd3f6f. Expected: 0xb2adf94780dc4a445a2bd41a75e1aff8f91ce016ec283c0012338d75897a1726.
Solution
Add support of network forking with Hardhat
Alternatives
No response
The text was updated successfully, but these errors were encountered: