From 80d5913e5c86822814e8e5100d97c3f23eaba065 Mon Sep 17 00:00:00 2001 From: ChrisD <18092467+ChristopherDedominici@users.noreply.github.com> Date: Thu, 21 Nov 2024 11:04:11 +0100 Subject: [PATCH] add plugin to example project --- pnpm-lock.yaml | 9 +++++++++ v-next/example-project/hardhat.config.ts | 2 ++ v-next/example-project/package.json | 7 +++++-- v-next/example-project/test/mocha/mocha-test.ts | 16 ++++++++++++++++ v-next/hardhat-chai-matchers/package.json | 5 +++-- v-next/hardhat-chai-matchers/src/index.ts | 2 ++ .../src/{types.d.ts => type-extensions.d.ts} | 0 7 files changed, 37 insertions(+), 4 deletions(-) rename v-next/hardhat-chai-matchers/src/{types.d.ts => type-extensions.d.ts} (100%) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4456ec8c89..843689cf3a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1428,6 +1428,9 @@ importers: '@ignored/hardhat-vnext': specifier: workspace:^3.0.0-next.16 version: link:../hardhat + '@ignored/hardhat-vnext-chai-matchers': + specifier: workspace:^3.0.0-next.12 + version: link:../hardhat-chai-matchers '@ignored/hardhat-vnext-ethers': specifier: workspace:^3.0.0-next.12 version: link:../hardhat-ethers @@ -1449,12 +1452,18 @@ importers: '@openzeppelin/contracts': specifier: 5.1.0 version: 5.1.0 + '@types/chai': + specifier: ^4.2.0 + version: 4.3.20 '@types/mocha': specifier: '>=9.1.0' version: 10.0.9 '@types/node': specifier: ^20.14.9 version: 20.17.1 + chai: + specifier: ^5.1.2 + version: 5.1.2 forge-std: specifier: foundry-rs/forge-std#v1.9.4 version: https://codeload.github.com/foundry-rs/forge-std/tar.gz/1eea5bae12ae557d589f9f0f0edae2faa47cb262 diff --git a/v-next/example-project/hardhat.config.ts b/v-next/example-project/hardhat.config.ts index b65dca7018..3c284b0186 100644 --- a/v-next/example-project/hardhat.config.ts +++ b/v-next/example-project/hardhat.config.ts @@ -15,6 +15,7 @@ import HardhatKeystore from "@ignored/hardhat-vnext-keystore"; import HardhatViem from "@ignored/hardhat-vnext-viem"; import hardhatNetworkHelpersPlugin from "@ignored/hardhat-vnext-network-helpers"; import hardhatEthersPlugin from "@ignored/hardhat-vnext-ethers"; +import hardhatChaiMatchersPlugin from "@ignored/hardhat-vnext-chai-matchers"; util.inspect.defaultOptions.depth = null; @@ -156,6 +157,7 @@ const config: HardhatUserConfig = { hardhatNetworkHelpersPlugin, HardhatNodeTestRunner, HardhatViem, + hardhatChaiMatchersPlugin, ], paths: { tests: { diff --git a/v-next/example-project/package.json b/v-next/example-project/package.json index d882252ffe..d91a1ff113 100644 --- a/v-next/example-project/package.json +++ b/v-next/example-project/package.json @@ -21,6 +21,7 @@ }, "devDependencies": { "@ignored/hardhat-vnext": "workspace:^3.0.0-next.16", + "@ignored/hardhat-vnext-chai-matchers": "workspace:^3.0.0-next.12", "@ignored/hardhat-vnext-ethers": "workspace:^3.0.0-next.12", "@ignored/hardhat-vnext-keystore": "workspace:^3.0.0-next.12", "@ignored/hardhat-vnext-mocha-test-runner": "workspace:^3.0.0-next.12", @@ -28,13 +29,15 @@ "@ignored/hardhat-vnext-node-test-runner": "workspace:^3.0.0-next.12", "@ignored/hardhat-vnext-viem": "workspace:^3.0.0-next.11", "@openzeppelin/contracts": "5.1.0", + "@types/chai": "^4.2.0", "@types/mocha": ">=9.1.0", "@types/node": "^20.14.9", + "chai": "^5.1.2", + "forge-std": "foundry-rs/forge-std#v1.9.4", "mocha": "^10.0.0", "prettier": "3.2.5", "rimraf": "^5.0.5", "typescript": "~5.5.0", - "viem": "^2.21.42", - "forge-std": "foundry-rs/forge-std#v1.9.4" + "viem": "^2.21.42" } } diff --git a/v-next/example-project/test/mocha/mocha-test.ts b/v-next/example-project/test/mocha/mocha-test.ts index e9e35fd3d0..2251b827b4 100644 --- a/v-next/example-project/test/mocha/mocha-test.ts +++ b/v-next/example-project/test/mocha/mocha-test.ts @@ -1,8 +1,24 @@ import assert from "node:assert/strict"; import { describe, it } from "mocha"; +import { expect } from "chai"; + +import { anyUint } from "@ignored/hardhat-vnext-chai-matchers/withArgs"; +import { PANIC_CODES } from "@ignored/hardhat-vnext-chai-matchers/panic"; + describe("Mocha test", () => { it("should work", () => { assert.equal(1 + 1, 2); }); }); + +describe("Mocha test with chai-matchers", () => { + it("should import variables from the chai-matchers package", () => { + expect(anyUint).to.be.a("function"); + expect(PANIC_CODES.ASSERTION_ERROR).to.be.a("number"); + }); + + it("should have the hardhat additional matchers", () => { + expect("0x0000010AB").to.not.hexEqual("0x0010abc"); + }); +}); diff --git a/v-next/hardhat-chai-matchers/package.json b/v-next/hardhat-chai-matchers/package.json index a781a4a9f1..bfbeda2afb 100644 --- a/v-next/hardhat-chai-matchers/package.json +++ b/v-next/hardhat-chai-matchers/package.json @@ -14,7 +14,8 @@ "types": "dist/src/index.d.ts", "exports": { ".": "./dist/src/index.js", - "./types": "./dist/src/types.js" + "./panic": "./dist/src/panic.js", + "./withArgs": "./dist/src/withArgs.js" }, "keywords": [ "ethereum", @@ -32,7 +33,7 @@ "test:coverage": "c8 --reporter html --reporter text --all --exclude test --exclude src/internal/types.ts --exclude src/internal/ui/direct-user-interruption-manager.ts --src src node --import tsx/esm --test --test-reporter=@ignored/hardhat-vnext-node-test-reporter \"test/!(fixture-projects|helpers)/**/*.ts\"", "pretest": "pnpm build", "pretest:only": "pnpm build", - "build": "tsc --build .", + "build": "tsc --build . && cp src/type-extensions.d.ts dist/src/type-extensions.d.ts", "prepublishOnly": "pnpm build", "clean": "rimraf dist" }, diff --git a/v-next/hardhat-chai-matchers/src/index.ts b/v-next/hardhat-chai-matchers/src/index.ts index 3b87f57d46..d100005b49 100644 --- a/v-next/hardhat-chai-matchers/src/index.ts +++ b/v-next/hardhat-chai-matchers/src/index.ts @@ -1,5 +1,7 @@ import type { HardhatPlugin } from "@ignored/hardhat-vnext/types/plugins"; +import "./type-extensions.d.js"; + const hardhatChaiMatchersPlugin: HardhatPlugin = { id: "hardhat-chai-matchers", hookHandlers: { diff --git a/v-next/hardhat-chai-matchers/src/types.d.ts b/v-next/hardhat-chai-matchers/src/type-extensions.d.ts similarity index 100% rename from v-next/hardhat-chai-matchers/src/types.d.ts rename to v-next/hardhat-chai-matchers/src/type-extensions.d.ts