Skip to content
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

feat: create a mocha/ethers template project #5806

Merged
merged 1 commit into from
Oct 28, 2024

Conversation

kanej
Copy link
Member

@kanej kanej commented Oct 4, 2024

As part of the Alpha prep this adds a mocha/ethers template project (used during hardhat --init), that tries to recreate the functionality (we are currently able to support`f of the v2 Ethers typescript project in v3.

It pulls in the v-next versions of the mocha test runner, the 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 to import plugin types to get the full connection type
  • 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, sometime crudely.

Copy link

vercel bot commented Oct 4, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
hardhat ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 28, 2024 11:06pm

Copy link

changeset-bot bot commented Oct 4, 2024

⚠️ No Changeset found

Latest commit: 84f8aef

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions github-actions bot added the status:ready This issue is ready to be worked on label Oct 4, 2024
@kanej kanej force-pushed the chore/vnext-release branch from fc68dbd to 867b848 Compare October 7, 2024 11:33
Base automatically changed from chore/vnext-release to v-next October 7, 2024 11:49
@kanej kanej force-pushed the feat/update-sample-projects-with-hh-ethers branch from 8f9369c to fb535c6 Compare October 7, 2024 12:21
Copy link
Contributor

github-actions bot commented Oct 7, 2024

hardhat

Total size of the bundle: 225M
Total number of dependencies (including transitive): 58

List of dependencies (sorted by size)
220M	total
30M	@ignored/edr-optimism-linux-x64-musl
30M	@ignored/edr-optimism-linux-x64-gnu
27M	@ignored/edr-optimism-linux-arm64-musl
27M	@ignored/edr-optimism-linux-arm64-gnu
22M	@ignored/edr-optimism-win32-x64-msvc
21M	@ignored/edr-optimism-darwin-x64
20M	esbuild
20M	@ignored/edr-optimism-darwin-arm64
8.9M	solc
2.8M	@sentry/tracing
1.9M	@noble/curves
1.7M	undici
1.2M	@sentry/types
1.2M	@noble/hashes
932K	@sentry/node
920K	@sentry/utils
824K	zod
816K	@ignored/hardhat-vnext-utils
576K	tsx
548K	@sentry/core
504K	fast-equals
492K	@scure/bip39
460K	@ignored/edr
384K	@ignored/edr-optimism
368K	ethereum-cryptography
344K	@sentry/hub
320K	enquirer
284K	semver
268K	@ignored/hardhat-vnext-errors
188K	commander
168K	@scure/base
136K	adm-zip
128K	get-tsconfig
96K	@scure/bip32
92K	chalk
88K	tslib
88K	@sentry/minimal
84K	js-sha3
76K	agent-base
72K	@nomicfoundation/solidity-analyzer
68K	debug
64K	lru_map
64K	https-proxy-agent
60K	@ignored/hardhat-vnext-zod-utils
56K	rfdc
56K	follow-redirects
48K	memorystream
48K	command-exists
48K	ansi-colors
44K	tmp
40K	resolve-pkg-maps
36K	p-map
32K	cookie
24K	strip-ansi
24K	env-paths
24K	ansi-regex
20K	os-tmpdir
20K	ms

@kanej kanej force-pushed the feat/update-sample-projects-with-hh-ethers branch from fb535c6 to b979fdf Compare October 7, 2024 13:30
"@types/chai-as-promised": "^8.0.1",
"@types/mocha": ">=9.1.0",
"chai": "^4.4.1",
"chai-as-promised": "^8.0.0",
Copy link
Member Author

@kanej kanej Oct 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may be able to drop the direct dev dependency once hardhat-chai-matchers has been ported.

import * as chai from "chai";
import chaiAsPromised from "chai-as-promised";
chai.use(chaiAsPromised);
const { expect } = chai;
Copy link
Member Author

@kanej kanej Oct 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I applied the chaiAsPromised setup directly here.
I don't think we currently have support .mochars.json files to allow us to setup up supporting setup files.

const { expect } = chai;

describe("Lock", function () {
let connection: NetworkConnection<"l1">;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that the connection is not ambient to the global context we need a new pattern for tests.
I have no strong feelings here so opted for a shared connection that is explicitly typed for the expected network connection and that is setup for each test.

I suspect we may want to go with something other than connection as the variable name. Maybe networkConnection is less ambiguous?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to networkConnection. That's the name I used in the network-manager tests.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we need to reset it between tests, though.

@kanej kanej marked this pull request as ready for review October 7, 2024 14:19
@kanej kanej requested review from alcuadrado and schaable October 7, 2024 14:19
Copy link
Member

@schaable schaable left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just a minor comment regarding the networkConnection reset.

@alcuadrado alcuadrado added the v-next A Hardhat v3 development task label Oct 25, 2024
@kanej kanej force-pushed the feat/update-sample-projects-with-hh-ethers branch from 2b9a6b6 to 5e9955a Compare October 28, 2024 22:56
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.
@kanej kanej force-pushed the feat/update-sample-projects-with-hh-ethers branch from 5e9955a to 84f8aef Compare October 28, 2024 23:05
@kanej kanej added this pull request to the merge queue Oct 28, 2024
Merged via the queue into v-next with commit 2ebd3c9 Oct 28, 2024
137 checks passed
@kanej kanej deleted the feat/update-sample-projects-with-hh-ethers branch October 28, 2024 23:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:ready This issue is ready to be worked on v-next A Hardhat v3 development task
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants