feat: add localhost network for e2e against Anvil
- Declare 'localhost' network in hardhat.config.ts pointing to http://127.0.0.1:8545 (chainId 31337) so deploy scripts work against an external Anvil/Hardhat node. - Make MNEMONIC and ALCHEMY_API_KEY optional: fall back to the Hardhat/Anvil deterministic mnemonic when MNEMONIC is missing, and only require ALCHEMY_API_KEY when targeting public networks. - Reset deploys/localhost.json to a starter state (signers populated, contract addresses empty) so the frontend e2e setup writes fresh addresses on every run.
This commit is contained in:
@@ -3,6 +3,6 @@
|
||||
"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
||||
"0x70997970C51812dc3A010C7d01b50e0d17dc79C8"
|
||||
],
|
||||
"p2pix": "0xC86042E9F2977C62Da8c9dDF7F9c40fde4796A29",
|
||||
"token": "0xD38D6367f452D097ccBfDe4490b7de570B6A72Db"
|
||||
"p2pix": "",
|
||||
"token": ""
|
||||
}
|
||||
|
||||
@@ -9,22 +9,19 @@ import "solidity-docgen";
|
||||
|
||||
dotenvConfig({ path: resolve(__dirname, "./.env") });
|
||||
|
||||
const mnemonic: string | undefined = process.env.MNEMONIC;
|
||||
if (!mnemonic) {
|
||||
throw new Error("Please set your MNEMONIC in a .env file");
|
||||
}
|
||||
// Default mnemonic used by Hardhat / Anvil for deterministic accounts.
|
||||
// Lets `--network localhost` (and the default in-process `hardhat` net)
|
||||
// run without a .env. Public networks still require a real MNEMONIC.
|
||||
const DEFAULT_MNEMONIC =
|
||||
"test test test test test test test test test test test junk";
|
||||
|
||||
const alchemyApiKey: string | undefined =
|
||||
process.env.ALCHEMY_API_KEY;
|
||||
if (!alchemyApiKey) {
|
||||
throw new Error(
|
||||
"Please set your ALCHEMY_API_KEY in a .env file",
|
||||
);
|
||||
}
|
||||
const mnemonic: string = process.env.MNEMONIC ?? DEFAULT_MNEMONIC;
|
||||
const alchemyApiKey: string | undefined = process.env.ALCHEMY_API_KEY;
|
||||
|
||||
const chainIds = {
|
||||
// "{INSERT_NAME}": {INSERT_ID},
|
||||
hardhat: 31337,
|
||||
localhost: 31337,
|
||||
mainnet: 1,
|
||||
"eth-sepolia": 11155111,
|
||||
"polygon-mumbai": 80001,
|
||||
@@ -35,6 +32,11 @@ const chainIds = {
|
||||
function getChainConfig(
|
||||
chain: keyof typeof chainIds,
|
||||
): NetworkUserConfig {
|
||||
if (!alchemyApiKey) {
|
||||
throw new Error(
|
||||
`Please set ALCHEMY_API_KEY in a .env file before targeting ${chain}`,
|
||||
);
|
||||
}
|
||||
let jsonRpcUrl = "https://" + chain + ".g.alchemy.com/v2/" + alchemyApiKey;
|
||||
return {
|
||||
// Comment out for default hardhat account settings
|
||||
@@ -82,6 +84,15 @@ const config: HardhatUserConfig = {
|
||||
},
|
||||
chainId: chainIds.hardhat,
|
||||
},
|
||||
// External Anvil / Hardhat node (e.g. `anvil --port 8545`). Used by
|
||||
// the frontend e2e suite to deploy a fresh chain per CI run.
|
||||
localhost: {
|
||||
url: "http://127.0.0.1:8545",
|
||||
chainId: chainIds.localhost,
|
||||
accounts: {
|
||||
mnemonic,
|
||||
},
|
||||
},
|
||||
// network: getChainConfig("{INSERT_NAME}"),
|
||||
mainnet: getChainConfig("mainnet"),
|
||||
sepolia: getChainConfig("eth-sepolia"),
|
||||
|
||||
Reference in New Issue
Block a user