diff --git a/.eslintrc.json b/.eslintrc.json index 99a4e6589..d5323083d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -5,7 +5,8 @@ "commonjs": true, "es6": true, "mocha": true, - "node": true + "node": true, + "jest": true }, "parser": "@typescript-eslint/parser", "plugins": ["@typescript-eslint", "mocha", "prettier"], diff --git a/packages/ua-utils-evm-hardhat-test/jest.config.js b/packages/ua-utils-evm-hardhat-test/jest.config.js new file mode 100644 index 000000000..17ae5d1ac --- /dev/null +++ b/packages/ua-utils-evm-hardhat-test/jest.config.js @@ -0,0 +1,9 @@ +/** @type {import('ts-jest').JestConfigWithTsJest} */ +module.exports = { + preset: 'ts-jest', + testEnvironment: 'node', + testTimeout: 15000, + moduleNameMapper: { + '^@/(.*)$': '/src/$1', + }, +}; diff --git a/packages/ua-utils-evm-hardhat-test/package.json b/packages/ua-utils-evm-hardhat-test/package.json index 481affb4d..2327a21ee 100644 --- a/packages/ua-utils-evm-hardhat-test/package.json +++ b/packages/ua-utils-evm-hardhat-test/package.json @@ -11,7 +11,8 @@ "license": "MIT", "scripts": { "lint": "npx eslint '**/*.{js,ts,json}'", - "test": "npx hardhat test" + "pretest": "npx hardhat compile", + "test": "jest --runInBand" }, "devDependencies": { "@ethersproject/abstract-signer": "^5.7.0", @@ -22,6 +23,7 @@ "@gnosis.pm/safe-core-sdk-types": "^1.0.0", "@gnosis.pm/safe-ethers-lib": "^1.0.0", "@gnosis.pm/safe-service-client": "1.1.1", + "@layerzerolabs/io-utils": "~0.0.1", "@layerzerolabs/lz-definitions": "~1.5.69", "@layerzerolabs/lz-evm-sdk-v1": "~1.5.69", "@layerzerolabs/lz-evm-sdk-v2": "~1.5.69", @@ -34,14 +36,12 @@ "@layerzerolabs/utils-evm": "~0.0.1", "@layerzerolabs/utils-evm-hardhat": "~0.0.1", "@nomicfoundation/hardhat-ethers": "^3.0.2", - "@types/chai-as-promised": "^7.1.7", - "@types/mocha": "^10.0.6", - "chai": "^4.3.10", - "chai-as-promised": "^7.1.1", + "@types/jest": "^29.5.10", "ethers": "^5.7.0", "hardhat": "^2.19.2", "hardhat-deploy": "^0.11.22", - "sinon": "^17.0.1", + "jest": "^29.7.0", + "ts-jest": "^29.1.1", "ts-node": "^10.9.1", "typescript": "^5.2.2" } diff --git a/packages/ua-utils-evm-hardhat-test/test/endpoint/config.test.ts b/packages/ua-utils-evm-hardhat-test/test/endpoint/config.test.ts index b9e0246c3..73dc83694 100644 --- a/packages/ua-utils-evm-hardhat-test/test/endpoint/config.test.ts +++ b/packages/ua-utils-evm-hardhat-test/test/endpoint/config.test.ts @@ -1,8 +1,7 @@ +import 'hardhat' import { createConnectedContractFactory } from '@layerzerolabs/utils-evm-hardhat' import type { OmniPoint } from '@layerzerolabs/utils' import { omniContractToPoint } from '@layerzerolabs/utils-evm' -import { expect } from 'chai' -import { describe } from 'mocha' import { EndpointId } from '@layerzerolabs/lz-definitions' import { defaultUlnConfig, setupDefaultEndpoint } from '../__utils__/endpoint' import { Endpoint, Uln302 } from '@layerzerolabs/protocol-utils-evm' @@ -39,8 +38,8 @@ describe('endpoint/config', () => { const ethSendUlnPoint = omniContractToPoint(await connectedContractFactory(ethSendUln)) const avaxSendUlnPoint = omniContractToPoint(await connectedContractFactory(avaxSendUln)) - expect(ethDefaultSendLib).to.equal(ethSendUlnPoint.address) - expect(avaxDefaultSendLib).to.equal(avaxSendUlnPoint.address) + expect(ethDefaultSendLib).toBe(ethSendUlnPoint.address) + expect(avaxDefaultSendLib).toBe(avaxSendUlnPoint.address) // Then let's check the receive libraries const ethDefaultReceiveLib = await ethEndpointSdk.defaultReceiveLibrary(avaxEndpointPoint.eid) @@ -49,8 +48,8 @@ describe('endpoint/config', () => { const ethReceiveUlnPoint = omniContractToPoint(await connectedContractFactory(ethReceiveUln)) const avaxReceiveUlnPoint = omniContractToPoint(await connectedContractFactory(avaxReceiveUln)) - expect(ethDefaultReceiveLib).to.equal(ethReceiveUlnPoint.address) - expect(avaxDefaultReceiveLib).to.equal(avaxReceiveUlnPoint.address) + expect(ethDefaultReceiveLib).toBe(ethReceiveUlnPoint.address) + expect(avaxDefaultReceiveLib).toBe(avaxReceiveUlnPoint.address) }) }) @@ -69,8 +68,8 @@ describe('endpoint/config', () => { const ethConfig = await ethSendUlnSdk.getUlnConfig(avaxSendUlnPoint.eid, avaxSendUlnPoint.address) const avaxConfig = await avaxSendUlnSdk.getUlnConfig(ethSendUlnPoint.eid, ethSendUlnPoint.address) - expect(ethConfig).to.eql(defaultUlnConfig) - expect(avaxConfig).to.eql(defaultUlnConfig) + expect(ethConfig).toEqual(defaultUlnConfig) + expect(avaxConfig).toEqual(defaultUlnConfig) }) }) }) diff --git a/packages/ua-utils-evm-hardhat-test/test/oapp/config.test.ts b/packages/ua-utils-evm-hardhat-test/test/oapp/config.test.ts index 1f22868e7..d2773fe60 100644 --- a/packages/ua-utils-evm-hardhat-test/test/oapp/config.test.ts +++ b/packages/ua-utils-evm-hardhat-test/test/oapp/config.test.ts @@ -1,3 +1,4 @@ +import 'hardhat' import { configureOApp } from '@layerzerolabs/ua-utils' import { OApp } from '@layerzerolabs/ua-utils-evm' import { @@ -9,8 +10,6 @@ import { import type { OmniGraphHardhat } from '@layerzerolabs/utils-evm-hardhat' import type { OmniPoint } from '@layerzerolabs/utils' import { omniContractToPoint } from '@layerzerolabs/utils-evm' -import { expect } from 'chai' -import { describe } from 'mocha' import { EndpointId } from '@layerzerolabs/lz-definitions' import { setupDefaultEndpoint } from '../__utils__/endpoint' import { deployOApp } from '../__utils__/oapp' @@ -52,12 +51,11 @@ describe('oapp/config', () => { it('should return all setPeer transactions', async () => { // This is the required tooling we need to set up - const contractFactory = createContractFactory() - const connectedContractFactory = createConnectedContractFactory(contractFactory) + const contractFactory = createConnectedContractFactory() const builder = await OmniGraphBuilderHardhat.fromConfig(config) // This so far the only non-oneliner, a function that returns an SDK for a contract on a network - const sdkFactory = async (point: OmniPoint) => new OApp(await connectedContractFactory(point)) + const sdkFactory = async (point: OmniPoint) => new OApp(await contractFactory(point)) // This is where the configuration happens const transactions = await configureOApp(builder.graph, sdkFactory) @@ -69,7 +67,7 @@ describe('oapp/config', () => { const avaxPoint = omniContractToPoint(await contractFactory(avaxContract)) const avaxSdk = await sdkFactory(avaxPoint) - expect(transactions).to.eql([ + expect(transactions).toEqual([ await ethSdk.setPeer(avaxPoint.eid, avaxPoint.address), await avaxSdk.setPeer(ethPoint.eid, ethPoint.address), ]) @@ -98,13 +96,13 @@ describe('oapp/config', () => { const ethResponse = await ethSigner.signAndSend(ethTransaction) const ethReceipt = await ethResponse.wait() - expect(ethReceipt.from).to.equal(await ethSigner.signer.getAddress()) + expect(ethReceipt.from).toBe(await ethSigner.signer.getAddress()) } // Now we configure the OApp const transactions = await configureOApp(builder.graph, sdkFactory) // And expect the setPeer on the eth contact not to be there - expect(transactions).to.eql([await avaxSdk.setPeer(ethPoint.eid, ethPoint.address)]) + expect(transactions).toEqual([await avaxSdk.setPeer(ethPoint.eid, ethPoint.address)]) }) }) diff --git a/packages/ua-utils-evm-hardhat-test/test/task/getDefaultConfig.test.ts b/packages/ua-utils-evm-hardhat-test/test/task/getDefaultConfig.test.ts index 66c3765bd..0fd6631bc 100644 --- a/packages/ua-utils-evm-hardhat-test/test/task/getDefaultConfig.test.ts +++ b/packages/ua-utils-evm-hardhat-test/test/task/getDefaultConfig.test.ts @@ -1,8 +1,6 @@ -import { describe } from 'mocha' import { defaultExecutorConfig, defaultUlnConfig, setupDefaultEndpoint } from '../__utils__/endpoint' import { createContractFactory, getEidForNetworkName } from '@layerzerolabs/utils-evm-hardhat' import hre from 'hardhat' -import { expect } from 'chai' describe('task: getDefaultConfig', () => { beforeEach(async () => { @@ -25,28 +23,28 @@ describe('task: getDefaultConfig', () => { const receiveUln302 = await contractFactory({ contractName: 'ReceiveUln302', eid: localEid }) // verify defaultSendLibrary & defaultReceiveLibrary - expect(defaultConfig.defaultSendLibrary).to.eql(sendUln302.contract.address) - expect(defaultConfig.defaultReceiveLibrary).to.eql(receiveUln302.contract.address) + expect(defaultConfig.defaultSendLibrary).toEqual(sendUln302.contract.address) + expect(defaultConfig.defaultReceiveLibrary).toEqual(receiveUln302.contract.address) // verify sendUln - expect(defaultConfig.sendExecutorConfig.maxMessageSize).to.eql(defaultExecutorConfig.maxMessageSize) - expect(defaultConfig.sendExecutorConfig.executor).to.eql(defaultExecutorConfig.executor) - expect(defaultConfig.sendUlnConfig.confirmations.toString()).to.eql( + expect(defaultConfig.sendExecutorConfig.maxMessageSize).toEqual(defaultExecutorConfig.maxMessageSize) + expect(defaultConfig.sendExecutorConfig.executor).toEqual(defaultExecutorConfig.executor) + expect(defaultConfig.sendUlnConfig.confirmations.toString()).toEqual( defaultUlnConfig.confirmations.toString() ) - expect(defaultConfig.sendUlnConfig.optionalDVNThreshold).to.eql(defaultUlnConfig.optionalDVNThreshold) - expect(defaultConfig.sendUlnConfig.requiredDVNs).to.eql(defaultUlnConfig.requiredDVNs) - expect(defaultConfig.sendUlnConfig.optionalDVNs).to.eql(defaultUlnConfig.optionalDVNs) + expect(defaultConfig.sendUlnConfig.optionalDVNThreshold).toEqual(defaultUlnConfig.optionalDVNThreshold) + expect(defaultConfig.sendUlnConfig.requiredDVNs).toEqual(defaultUlnConfig.requiredDVNs) + expect(defaultConfig.sendUlnConfig.optionalDVNs).toEqual(defaultUlnConfig.optionalDVNs) // verify receiveUln - expect(defaultConfig.receiveUlnConfig.confirmations.toString()).to.eql( + expect(defaultConfig.receiveUlnConfig.confirmations.toString()).toEqual( defaultUlnConfig.confirmations.toString() ) - expect(defaultConfig.receiveUlnConfig.optionalDVNThreshold).to.eql( + expect(defaultConfig.receiveUlnConfig.optionalDVNThreshold).toEqual( defaultUlnConfig.optionalDVNThreshold ) - expect(defaultConfig.receiveUlnConfig.requiredDVNs).to.eql(defaultUlnConfig.requiredDVNs) - expect(defaultConfig.receiveUlnConfig.optionalDVNs).to.eql(defaultUlnConfig.optionalDVNs) + expect(defaultConfig.receiveUlnConfig.requiredDVNs).toEqual(defaultUlnConfig.requiredDVNs) + expect(defaultConfig.receiveUlnConfig.optionalDVNs).toEqual(defaultUlnConfig.optionalDVNs) } } }) diff --git a/packages/ua-utils-evm-hardhat-test/tsconfig.json b/packages/ua-utils-evm-hardhat-test/tsconfig.json index b1fedd432..815fcb54e 100644 --- a/packages/ua-utils-evm-hardhat-test/tsconfig.json +++ b/packages/ua-utils-evm-hardhat-test/tsconfig.json @@ -4,6 +4,6 @@ "include": ["src", "test", "deploy", "*.config.ts"], "compilerOptions": { "module": "commonjs", - "types": ["node", "mocha"] + "types": ["node", "jest"] } } diff --git a/packages/ua-utils-evm-hardhat/package.json b/packages/ua-utils-evm-hardhat/package.json index 6dae08069..af9ed67bf 100644 --- a/packages/ua-utils-evm-hardhat/package.json +++ b/packages/ua-utils-evm-hardhat/package.json @@ -25,8 +25,8 @@ "module": "dist/index.mjs", "types": "dist/index.d.ts", "files": [ - "dist/", - "LICENSE" + "tasks", + "dist" ], "scripts": { "prebuild": "tsc -noEmit", @@ -41,6 +41,7 @@ "@gnosis.pm/safe-core-sdk-types": "^1.0.0", "@gnosis.pm/safe-ethers-lib": "^1.0.0", "@gnosis.pm/safe-service-client": "1.1.1", + "@layerzerolabs/io-utils": "~0.0.1", "@layerzerolabs/lz-definitions": "~1.5.69", "@layerzerolabs/ua-utils": "~0.1.0", "@layerzerolabs/utils": "~0.0.1", diff --git a/packages/ua-utils-evm-hardhat/src/constants/index.ts b/packages/ua-utils-evm-hardhat/src/constants/index.ts new file mode 100644 index 000000000..3fe1316d5 --- /dev/null +++ b/packages/ua-utils-evm-hardhat/src/constants/index.ts @@ -0,0 +1 @@ +export * from './tasks' diff --git a/packages/ua-utils-evm-hardhat/src/constants/tasks.ts b/packages/ua-utils-evm-hardhat/src/constants/tasks.ts new file mode 100644 index 000000000..459873c6c --- /dev/null +++ b/packages/ua-utils-evm-hardhat/src/constants/tasks.ts @@ -0,0 +1 @@ +export const TASK_LZ_WIRE_OAPP = 'lz:oapp:wire' diff --git a/packages/ua-utils-evm-hardhat/src/index.ts b/packages/ua-utils-evm-hardhat/src/index.ts index e69de29bb..d33f4c774 100644 --- a/packages/ua-utils-evm-hardhat/src/index.ts +++ b/packages/ua-utils-evm-hardhat/src/index.ts @@ -0,0 +1,2 @@ +export * from './constants' +export * from './oapp' diff --git a/packages/ua-utils-evm-hardhat/tasks/README.md b/packages/ua-utils-evm-hardhat/tasks/README.md new file mode 100644 index 000000000..bd81978a8 --- /dev/null +++ b/packages/ua-utils-evm-hardhat/tasks/README.md @@ -0,0 +1 @@ +This `package.json` ensures that the `@layerzerolabs/ua-utils-evm-hardhat/tasks` import is available even for older node versions and legacy module systems that don't respect the `exports` field in the root `package.json` diff --git a/packages/ua-utils-evm-hardhat/tasks/package.json b/packages/ua-utils-evm-hardhat/tasks/package.json new file mode 100644 index 000000000..b087adf0e --- /dev/null +++ b/packages/ua-utils-evm-hardhat/tasks/package.json @@ -0,0 +1,5 @@ +{ + "main": "../dist/tasks/index.js", + "module": "../dist/tasks/index.mjs", + "types": "../dist/tasks/index.d.ts" +} \ No newline at end of file diff --git a/packages/ua-utils-evm-hardhat/tsup.config.ts b/packages/ua-utils-evm-hardhat/tsup.config.ts index c1395151f..7e6ef5103 100644 --- a/packages/ua-utils-evm-hardhat/tsup.config.ts +++ b/packages/ua-utils-evm-hardhat/tsup.config.ts @@ -2,7 +2,7 @@ import { defineConfig } from 'tsup' export default defineConfig([ { - entry: ['src/index.ts'], + entry: ['src/index.ts', 'src/tasks/index.ts'], outDir: './dist', clean: true, dts: true, @@ -11,14 +11,4 @@ export default defineConfig([ treeshake: true, format: ['esm', 'cjs'], }, - { - entry: ['src/tasks/index.ts'], - outDir: './dist/tasks', - clean: true, - dts: true, - sourcemap: true, - splitting: false, - treeshake: true, - format: ['esm', 'cjs'], - }, ]) diff --git a/yarn.lock b/yarn.lock index 9f953ce72..069b74224 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2637,18 +2637,6 @@ "@types/node" "*" "@types/responselike" "^1.0.0" -"@types/chai-as-promised@^7.1.7": - version "7.1.8" - resolved "https://registry.npmjs.org/@types/chai-as-promised/-/chai-as-promised-7.1.8.tgz" - integrity sha512-ThlRVIJhr69FLlh6IctTXFkmhtP3NpMZ2QGq69StYLyKZFp/HOp1VdKZj7RvfNWYYcJ1xlbLGLLWj1UvP5u/Gw== - dependencies: - "@types/chai" "*" - -"@types/chai@*": - version "4.3.10" - resolved "https://registry.npmjs.org/@types/chai/-/chai-4.3.10.tgz" - integrity sha512-of+ICnbqjmFCiixUnqRulbylyXQrPqIGf/B3Jax1wIF3DvSheysQxAWvqHhZiW3IQrycvokcLcFQlveGp+vyNg== - "@types/connect@^3.4.33": version "3.4.38" resolved "https://registry.yarnpkg.com/@types/connect/-/connect-3.4.38.tgz#5ba7f3bc4fbbdeaff8dded952e5ff2cc53f8d858" @@ -4079,13 +4067,6 @@ catering@^2.1.0, catering@^2.1.1: resolved "https://registry.npmjs.org/catering/-/catering-2.1.1.tgz" integrity sha512-K7Qy8O9p76sL3/3m7/zLKbRkyOlSZAgzEaLhyj2mXS8PsCud2Eo4hAb8aLtZqHh0QGqLcb9dlJSu6lHRVENm1w== -chai-as-promised@^7.1.1: - version "7.1.1" - resolved "https://registry.npmjs.org/chai-as-promised/-/chai-as-promised-7.1.1.tgz" - integrity sha512-azL6xMoi+uxu6z4rhWQ1jbdUhOMhis2PvscD/xjLqNMkv3BPPp2JyyuTHOrf9BOosGpNQ11v6BKv/g57RXbiaA== - dependencies: - check-error "^1.0.2" - chai@^4.3.10: version "4.3.10" resolved "https://registry.npmjs.org/chai/-/chai-4.3.10.tgz" @@ -4131,7 +4112,7 @@ chardet@^0.7.0: resolved "https://registry.npmjs.org/chardet/-/chardet-0.7.0.tgz" integrity sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA== -check-error@^1.0.2, check-error@^1.0.3: +check-error@^1.0.3: version "1.0.3" resolved "https://registry.npmjs.org/check-error/-/check-error-1.0.3.tgz" integrity sha512-iKEoDYaRmd1mxM90a2OEfWhjsjPpYPuQ+lMYsoxB126+t8fw7ySEO48nmDg5COTjxDI65/Y2OWpeEHk3ZOe8zg==