foundry-rs / hardhat Goto Github PK
View Code? Open in Web Editor NEWFoundry-Hardhat plugins: Use Foundry for Hardhat projects
License: Other
Foundry-Hardhat plugins: Use Foundry for Hardhat projects
License: Other
test
task that delegates to forge test
See https://github.com/foundry-rs/hardhat/runs/6646586678?check_suite_focus=true
@foundry-rs/hardhat
| thread 'main' panicked at 'error binding to 127.0.0.1:8545: error creating server listener: Address already in use (os error 98)', /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.14.18/src/server/server.rs:87:17
| note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
@foundry-rs/hardhat-anvil
| ✔ can send transaction (386ms)
| ✔ can send transaction with env provider
|
It looks like anvil
has already started and its trying to be started again?
Hardhat generates the source name in the format as a relative path to the file containing the source while this plugin adds the name of the source file with the name of the contract appended.
This plugin:
"sourceName": "L1CrossDomainMessenger.sol:L1CrossDomainMessenger"
Hardhat:
"sourceName": "contracts/L1/messaging/L1CrossDomainMessenger.sol"
The offending line is here:
I'm trying to run a hardhat project that uses an anvil node in docker. So I set the url for the anvil network in the hardhat config to "http://anvil-1:8545/"
where anvil-1
is the name of the service that contains the anvil node, instead of setting it to http://127.0.0.1:8545/
as this is required for the hardhat service to connect to the anvil-1
service.
Below is the error that the hardhat service fails with:
Error in plugin @foundry-rs/hardhat-anvil: Anvil network only works with localhost
2023-10-03 10:14:05 NomicLabsHardhatPluginError: Anvil network only works with localhost
2023-10-03 10:14:05 at Function.getCheckedArgs (/app/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/@foundry-rs/hardhat-anvil/src/anvil-service.ts:85:13)
2023-10-03 10:14:05 at async Function.create (/app/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/@foundry-rs/hardhat-anvil/src/anvil-service.ts:98:18)
2023-10-03 10:14:05 at async handlePluginTask (/app/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/@foundry-rs/hardhat-anvil/src/index.ts:207:24)
2023-10-03 10:14:05 at async Environment._runTaskDefinition (/app/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/hardhat/src/internal/core/runtime-environment.ts:333:14)
2023-10-03 10:14:05 at async Environment.run (/app/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/hardhat/src/internal/core/runtime-environment.ts:166:14)
2023-10-03 10:14:05 at async main (/app/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/hardhat/src/internal/cli/cli.ts:280:7)
Is there some way to still access the native hardhat calls using this plugin?
I really like how this cleanly integrates into hardhat and replaces the compilation pipeline with forge and hardhat node with anvil as it gives a huge performance boost. And because it generates hardhat artifacts, all the hardhat scripts work well with foundry under the hood.
However, it would still be useful to do the default hardhat compile
from time to time to be able to generate typechain artifacts that I can pass to the front-end. And similarly, I can't seem to figure out a way to run the native hardhat tests, as hardhat test
only looks for forge tests.
right now all test files seems to share the same anvil node so there is a problem of a "nonce has already been used".
"nonce has already been used","code":"NONCE_EXPIRED"
hardhat node doesn't have this kind of a problem.
I have Turborepo + pnpm project setup; a workspaces monorepo with a symlink dependency graph.
When running hardhat compile
with the foundry-rs/hardhat-*
plugins installed I get the following mapping errors.
[⠊] Compiling...
[⠒] Unable to resolve import: "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol" with remappings:
contracts/=/Users/kames/workspace/kames/code/turbo-eth/contracts/
[⠢] Unable to resolve import: "@openzeppelin/contracts/access/Ownable.sol" with remappings:
contracts/=/Users/kames/workspace/kames/code/turbo-eth/contracts/
[⠆] Unable to resolve import: "@openzeppelin/contracts/token/ERC20/IERC20.sol" with remappings:
contracts/=/Users/kames/workspace/kames/code/turbo-eth/contracts/
...
...
...
[⠊] Unable to resolve import: "../../node_modules/zeppelin-solidity/contracts//math/SafeMath.sol" with remappings:
contracts/=/Users/kames/workspace/kames/code/turbo-eth/contracts/
This is obviously a problem with my monorepo build system, but just wanted to flag this issue.
Maybe someone has an idea for a good work-around to get foundry-rs
to work nicely in an NPM workspaces build setup?
Just finished installing foundryup
and adding the hardhat plugins to an existing project.
When running hadhat compile
I have gotten 2 different CLI outputs; only run 3 times.
However, the main issue I am reporting is the checksum mismatch for v0.8.15
1st and 3rd time
[⠘] installing solc version "0.5.8"
[⠃] Successfully installed solc 0.5.8
[⠊] installing solc version "0.8.15"
[⠒] Failed to install solc 0.8.15: Checksum mismatch for version 0.8.15
Error:
0: Checksum mismatch for version 0.8.15
Location:
cli/src/compile.rs:100
2nd time
[⠢] installing solc version "0.7.6"
[⠔] Successfully installed solc 0.7.6
[⠒] installing solc version "0.4.26"
[⠆] Successfully installed solc 0.4.26
[⠆] installing solc version "0.7.3"
[⠰] Successfully installed solc 0.7.3
[⠰] installing solc version "0.5.17"
[⠆] Successfully installed solc 0.5.17
[⠢] installing solc version "0.6.12"
[⠢] Successfully installed solc 0.6.12
[⠆] installing solc version "0.8.15"
[⠔] Failed to install solc 0.8.15: Checksum mismatch for version 0.8.15
valid main entry
errorhardhat-anvil
can work around that error by changing node_modules/@foundry-rs/hardhat-anvil/package.json
and change main
from dist/index.js
to dist/src/index.js
install in sample hardhat project / existing project
npm i --save-dev @foundry-rs/hardhat
hardhat.config.js
require("@foundry-rs/hardhat");
// require("@foundry-rs/hardhat-anvil");
// require("@foundry-rs/hardhat-forge");
// require("@foundry-rs/easy-foundryup");
/**
* @type import('hardhat/config').HardhatUserConfig
*/
module.exports = {
defaultNetwork: "anvil",
anvil: {
url: "http://127.0.0.1:8545/",
launch: false,
},
solidity: "0.8.4",
};
try to run node with anvil
➜ integration git:(master) ✗ npx hardhat node
An unexpected error occurred:
Error: Cannot find module '/Users/m1/Desktop/integration/node_modules/@foundry-rs/hardhat/dist/index.js'. Please verify that the package.json has a valid "main" entry
try just hardhat
➜ integration git:(master) ✗ npx hardhat
An unexpected error occurred:
Error: Cannot find module '/Users/m1/Desktop/integration/node_modules/@foundry-rs/hardhat/dist/index.js'. Please verify that the package.json has a valid "main" entry
try using anvil
//hardhat.config.js
// require("@foundry-rs/hardhat");
require("@foundry-rs/hardhat-anvil");
// require("@foundry-rs/hardhat-forge");
// require("@foundry-rs/easy-foundryup");
/**
* @type import('hardhat/config').HardhatUserConfig
*/
module.exports = {
defaultNetwork: "anvil",
anvil: {
url: "http://127.0.0.1:8545/",
launch: false,
},
solidity: "0.8.4",
};
npm i --save-dev @foundry-rs/hardhat-anvil
➜ integration git:(master) ✗ npx hardhat node
An unexpected error occurred:
Error: Cannot find module '/Users/m1/Desktop/integration/node_modules/@foundry-rs/hardhat-anvil/dist/index.js'. Please verify that the package.json has a valid "main" entry
go to node_modules/@foundry-rs/hardhat-anvil/package.json and change main from dist/index.js
to dist/src/index.js
{
"name": "@foundry-rs/hardhat-anvil",
"version": "0.1.2",
"description": "Hardhat plugin for managing Anvil",
"homepage": "https://github.com/foundry-rs/hardhat",
"repository": "github:foundry-rs/hardhat",
"license": "MIT",
"main": "dist/src/index.js",
and get the value.url is missing error
➜ integration git:(master) ✗ npx hardhat node
Error in plugin @nomiclabs/hardhat-anvil: Anvil network config is invalid: value.url is missing
For more info run Hardhat with --show-stack-traces
I've set allowUnlimitedContractSize
to true
in my anvil
hardhat network config, however I still get the following error when trying to deploy contracts that exceed the default 24KB.
ProviderError: max initcode size exceeded
Looking through the code it doesn't seem like the allowUnlimitedContractSize
is being considered for the --code-size-limit anvil flag
If allowUnlimitedContractSize
is true set --code-size-limit
to usize::MAX i.e. 2**32
some tests can fail randomly in ci: https://github.com/foundry-rs/hardhat/runs/6718891445?check_suite_focus=true
I am importing hardhat-anvil, but the additional params (ex: launch
) aren't recognized by typescript. It also is not using the accounts I specify (I've tried accounts: { mnemonic: ... }
as well as the array of private keys).
Stripped-down version of my config:
import '@nomiclabs/hardhat-ethers';
import '@nomiclabs/hardhat-etherscan';
import '@nomiclabs/hardhat-solhint';
import '@nomiclabs/hardhat-waffle';
import '@openzeppelin/hardhat-upgrades';
import '@typechain/hardhat';
import '@foundry-rs/hardhat-anvil';
import 'hardhat-deploy';
import * as dotenv from 'dotenv';
import { HardhatUserConfig } from 'hardhat/config';
const config: HardhatUserConfig = {
networks: {
anvil: {
url: 'http://localhost:8545',
chainId: 1337,
accounts: [process.env.ADMIN_PRIVATE_KEY!],
launch: true,
},
},
};
export default config;
I can get it to connect if I start anvil in a separate terminal, but I still need to be able to deploy from the ADMIN_PRIVATE_KEY
account. Any ideas?
The error message for hardhat compile
when forge
is not installed does not tell users this fact. This could help users debug the build process more easily. The following error is produced:
An unexpected error occurred:
TypeError: Cannot read properties of null (reading 'code')
at analyzeModuleNotFoundError (/home/circleci/project/node_modules/hardhat/src/internal/core/config/config-loading.ts:161:13)
at Environment.run (/home/circleci/project/node_modules/hardhat/src/internal/core/runtime-environment.ts:136:33)
at async main (/home/circleci/project/node_modules/hardhat/src/internal/cli/cli.ts:218:5)
error Command failed with exit code 1.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.