-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create a mocha/ethers template project
As part of the Alpha prep this adds a mocha/ethers template project that tries to recreate the functionality (we are currently able to support) of the v2 Ethers typescript project in v3. It pulls in the `v-next` versions of the mocha test runner, the `hardhat-test-helpers` and `hardhat-ethers`. It adds a the `Lock.sol` and `Lock.ts` test file. The test file has been modified to allow for running the tests while we still have rough edges. Specifically the rough edges are: - we need new patterns for sharing `connection` among tests (I added a `beforeEach`) - we don't have chai matchers so I added `chai-as-promised` and adapted the tests ... crudely.
- Loading branch information
Showing
9 changed files
with
347 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Node modules | ||
/node_modules | ||
|
||
# Compilation output | ||
/dist | ||
|
||
# pnpm deploy output | ||
/bundle | ||
|
||
# Hardhat Build Artifacts | ||
/artifacts | ||
|
||
# Hardhat compilation (v2) support directory | ||
/cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# A TypeScript Hardhat project using Mocha and Ethers | ||
|
||
> WARNING: This demonstration project is still in development. It is part of the Hardhat v3 upgrade. It is not for production use. | ||
> 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 a test. | ||
|
||
For integration testing it uses the Mocha test runner and the Ethers.js library for interacting with Ethereum nodes. | ||
|
||
Try running the following commands to see Hardhat in action: | ||
|
||
```shell | ||
# Setup a running Hardhat v2 node in another terminal: `npx hardhat node` | ||
|
||
# The test command does not currently trigger the compilation step | ||
npx hardhat3 compile | ||
# Run the mocha integration test suite | ||
npx hardhat3 test | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.24; | ||
|
||
// Uncomment this line to use console.log | ||
// import "hardhat/console.sol"; | ||
|
||
contract Lock { | ||
uint public unlockTime; | ||
address payable public owner; | ||
|
||
event Withdrawal(uint amount, uint when); | ||
|
||
constructor(uint _unlockTime) payable { | ||
require( | ||
block.timestamp < _unlockTime, | ||
"Unlock time should be in the future" | ||
); | ||
|
||
unlockTime = _unlockTime; | ||
owner = payable(msg.sender); | ||
} | ||
|
||
function withdraw() public { | ||
// Uncomment this line, and the import of "hardhat/console.sol", to print a log in your terminal | ||
// console.log("Unlock time is %o and block timestamp is %o", unlockTime, block.timestamp); | ||
|
||
require(block.timestamp >= unlockTime, "You can't withdraw yet"); | ||
require(msg.sender == owner, "You aren't the owner"); | ||
|
||
emit Withdrawal(address(this).balance, block.timestamp); | ||
|
||
owner.transfer(address(this).balance); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import type { HardhatUserConfig } from "@ignored/hardhat-vnext/types/config"; | ||
|
||
import HardhatMochaTestRunner from "@ignored/hardhat-vnext-mocha-test-runner"; | ||
import HardhatEthers from "@ignored/hardhat-vnext-ethers"; | ||
import HardhatNetworkHelpers from "@ignored/hardhat-vnext-network-helpers"; | ||
|
||
const config: HardhatUserConfig = { | ||
plugins: [HardhatMochaTestRunner, HardhatEthers, HardhatNetworkHelpers], | ||
solidity: "0.8.24", | ||
}; | ||
|
||
export default config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "template-mocha-ethers", | ||
"private": true, | ||
"version": "0.0.1", | ||
"description": "A Typescript Hardhat project using Mocha and Ethers.js", | ||
"type": "module", | ||
"devDependencies": { | ||
"@ignored/hardhat-vnext": "workspace:^3.0.0-next.5", | ||
"@ignored/hardhat-vnext-ethers": "workspace:^3.0.0-next.1", | ||
"@ignored/hardhat-vnext-mocha-test-runner": "workspace:^3.0.0-next.1", | ||
"@ignored/hardhat-vnext-network-helpers": "workspace:^3.0.0-next.1", | ||
"@types/chai": "^4.2.0", | ||
"@types/chai-as-promised": "^8.0.1", | ||
"@types/mocha": ">=9.1.0", | ||
"chai": "^4.4.1", | ||
"chai-as-promised": "^8.0.0", | ||
"mocha": "^10.0.0", | ||
"typescript": "~5.5.0" | ||
} | ||
} |
Oops, something went wrong.