Skip to content

Viem matchers first iteration #6574

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

Merged
merged 74 commits into from
May 23, 2025

Conversation

ChristopherDedominici
Copy link
Contributor

@ChristopherDedominici ChristopherDedominici commented Apr 14, 2025

Parent issue

POC for the viem matchers.

Decision to be taken for POC - requires input

  • Do we want to support contracts or ABIs as parameters passed to the matchers in this iteration?

Note

  • IMPORTANT: The tests are not exhaustive like those in the chai-matchers plugin. This is intentional, we first need to finalize the implementation approach we want to take with these matchers.
    I've included test scenarios that cover basic cases, mainly to provide a rough idea of how the matchers are intended to be used.
  • The functions’ documentation is also missing for now, it will be added once we finalize the matchers

How the matchers object is implemented (pseudocode):

connection.viem.assertions = {
    balancesHaveChanged
    emit
    emitWithArgs
    revert
    revertWith
    revertWithCustomError
    revertWithCustomErrorWithArgs
}

Follow up work

  • general updates to add, modify, or remove matchers and reorganize the code
  • add type definitions for custom error names so they are recognized, similar to how events are handled in this PR. When contracts are not compiled, any string value is accepted. However, when contracts are compiled, only names listed in the ABI are allowed, otherwise an error will be shown
  • improve the tests: add all the test scenarios similar to chai-matchers, add tests to check that types are correctly handled when contracts are compiled/not compiled, group similar tests in same file
  • improve assertHardhatInvariant usage in the code by leveraging Viem types
  • add a readme when the matchers are finalized

@ChristopherDedominici ChristopherDedominici added the v-next A Hardhat v3 development task label Apr 14, 2025
@ChristopherDedominici ChristopherDedominici self-assigned this Apr 14, 2025
@github-project-automation github-project-automation bot moved this to Backlog in Hardhat Apr 14, 2025
Copy link

changeset-bot bot commented Apr 14, 2025

⚠️ No Changeset found

Latest commit: 8c7bfce

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

Copy link

vercel bot commented Apr 14, 2025

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 Apr 16, 2025 2:41pm

Copy link
Contributor

github-actions bot commented Apr 14, 2025

hardhat

Total size of the bundle: 226M
Total number of dependencies (including transitive): 113

List of dependencies (sorted by size)
220M	total
24M	@ignored/edr-optimism-linux-x64-musl
24M	@ignored/edr-optimism-linux-x64-gnu
22M	@ignored/edr-optimism-win32-x64-msvc
21M	@ignored/edr-optimism-linux-arm64-musl
21M	@ignored/edr-optimism-linux-arm64-gnu
20M	esbuild
18M	@ignored/edr-optimism-darwin-x64
17M	@ignored/edr-optimism-darwin-arm64
7.7M	@opentelemetry/semantic-conventions
6.2M	@sentry/core
4.3M	@sentry/node
3.1M	@opentelemetry/api
2.5M	zod
2.5M	micro-eth-signer
2.3M	@opentelemetry/core
1.9M	@opentelemetry/resources
1.9M	@noble/curves
1.7M	undici
1.6M	@opentelemetry/sdk-trace-base
1.2M	@noble/hashes
956K	@opentelemetry/instrumentation
876K	@sentry/opentelemetry
864K	@streamparser/json
860K	@nomicfoundation/hardhat-utils
760K	@opentelemetry/api-logs
684K	import-in-the-middle
624K	resolve
624K	micro-packed
588K	minimatch
584K	tsx
572K	acorn
544K	fast-equals
492K	@scure/bip39
472K	@nomicfoundation/hardhat-errors
408K	json-stream-stringify
368K	ethereum-cryptography
348K	@ignored/edr
332K	@streamparser/json-node
320K	pg-protocol
320K	enquirer
304K	@ignored/edr-optimism
300K	@opentelemetry/instrumentation-http
288K	semver
224K	@opentelemetry/instrumentation-pg
212K	@opentelemetry/instrumentation-graphql
200K	undici-types
196K	ws
188K	@opentelemetry/instrumentation-mongodb
180K	@opentelemetry/instrumentation-undici
176K	@opentelemetry/instrumentation-express
172K	@opentelemetry/instrumentation-amqplib
168K	@scure/base
164K	cjs-module-lexer
156K	@opentelemetry/instrumentation-hapi
148K	@opentelemetry/instrumentation-redis-4
148K	@opentelemetry/instrumentation-mysql
144K	@opentelemetry/instrumentation-fs
136K	get-tsconfig
136K	adm-zip
136K	@opentelemetry/instrumentation-koa
132K	@opentelemetry/instrumentation-knex
124K	@opentelemetry/instrumentation-mongoose
124K	@opentelemetry/instrumentation-ioredis
120K	@opentelemetry/instrumentation-mysql2
120K	@opentelemetry/instrumentation-connect
116K	@opentelemetry/instrumentation-kafkajs
112K	@opentelemetry/instrumentation-tedious
112K	@opentelemetry/context-async-hooks
96K	@scure/bip32
96K	@opentelemetry/instrumentation-dataloader
92K	chalk
80K	@opentelemetry/instrumentation-generic-pool
76K	pg-types
76K	@prisma/instrumentation
72K	@nomicfoundation/solidity-analyzer
68K	debug
68K	@opentelemetry/sql-common
68K	@opentelemetry/instrumentation-lru-memoizer
64K	@nomicfoundation/hardhat-zod-utils
60K	acorn-import-attributes
60K	@opentelemetry/redis-common
56K	rfdc
56K	is-core-module
56K	function-bind
52K	@types/tedious
48K	shimmer
48K	ansi-colors
44K	resolve.exports
40K	resolve-pkg-maps
40K	require-in-the-middle
40K	forwarded-parse
40K	@types/mysql
36K	supports-preserve-symlinks-flag
36K	p-map
36K	@types/pg
32K	hasown
28K	xtend
28K	brace-expansion
24K	strip-ansi
24K	postgres-interval
24K	postgres-array
24K	env-paths
24K	ansi-regex
20K	postgres-date
20K	postgres-bytea
20K	pg-int8
20K	path-parse
20K	ms
20K	module-details-from-path
20K	balanced-match
20K	@types/shimmer
20K	@types/pg-pool
20K	@types/connect

@ChristopherDedominici ChristopherDedominici added the no changeset needed This PR doesn't require a changeset label Apr 16, 2025
@kanej kanej removed the request for review from alcuadrado May 22, 2025 11:11
Copy link
Member

@kanej kanej left a comment

Choose a reason for hiding this comment

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

Great work. Lets get this merged!

@ChristopherDedominici ChristopherDedominici added this pull request to the merge queue May 23, 2025
Merged via the queue into v-next with commit 614f1ec May 23, 2025
137 checks passed
@ChristopherDedominici ChristopherDedominici deleted the viem-matchers-first-iteration branch May 23, 2025 14:42
@github-project-automation github-project-automation bot moved this from In Review to Done in Hardhat May 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no changeset needed This PR doesn't require a changeset v-next A Hardhat v3 development task
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Product refinement on viem assertion library Minimal port of assertions to viem
3 participants