Skip to content

Commit

Permalink
chore: example the mocha tutorial with a script running against optimism
Browse files Browse the repository at this point in the history
A `base` network has been added to the `hardhat.config.ts` and a simple
deployment script added that runs against the Base network.
  • Loading branch information
kanej committed Oct 29, 2024
1 parent c710c21 commit 896dfea
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
21 changes: 20 additions & 1 deletion v-next/hardhat/templates/mocha-ethers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@
> NOTE: There are several plugins from the Hardhat toolbox that have not been ported to Hardhat v3 yet. In testing terms, the biggest ommision is `hardhat-chai-matchers`.
This project demonstrates basic Hardhat usecases within a TypeScript project. It comes with a minimal Hardhat configuration file and both JS/TS integration tests and Solidity Tests.
This project demonstrates basic Hardhat usecases within a TypeScript project. It comes with:

* a minimal Hardhat configuration file
* JS/TS integration tests
* Solidity Tests
* A script demonstrating how to deploy a contract to an in-memory Hardhat node simulating Base (an Optimism l2 chain)

## Usage

### Testing

For integration testing it uses the Mocha test runner and the Ethers.js library for interacting with Ethereum nodes.

Expand All @@ -15,3 +24,13 @@ Try running the following commands to see Hardhat in action:
# and the Solidity Test suite
npx hardhat3 test
```

Hardhat v3 comes with support for simulating chains other than Ethereum l1. To deploy against an

### Multi-chain support

To deploy a contract to an in-memory Hardhat node simulating Base (an Optimism l2 chain), run:

```shell
npx hardhat3 run scripts/deploy-counter-contract.ts
```
11 changes: 11 additions & 0 deletions v-next/hardhat/templates/mocha-ethers/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ import HardhatNetworkHelpers from "@ignored/hardhat-vnext-network-helpers";
const config: HardhatUserConfig = {
plugins: [HardhatMochaTestRunner, HardhatEthers, HardhatNetworkHelpers],
solidity: "0.8.24",
defaultNetwork: "hardhat",
networks: {
"local-base": {
chainId: 8453,
type: "edr",
chainType: "optimism",
gas: "auto",
gasPrice: "auto",
gasMultiplier: 1,
},
},
};

export default config;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import hre from "@ignored/hardhat-vnext";

async function deployCounterContract() {
const optimism = await hre.network.connect("local-base", "optimism");

const contract = await optimism.ethers.deployContract("Counter");

console.log("Counter contract address:", await contract.getAddress());
}

deployCounterContract();

0 comments on commit 896dfea

Please sign in to comment.