From bdcd7195265477f2920e557c88f148cabae8881b Mon Sep 17 00:00:00 2001 From: Jan Nanista Date: Fri, 8 Dec 2023 13:08:10 -0800 Subject: [PATCH] chore: Use jest in utils-evm-test --- packages/utils-evm-test/jest.config.js | 9 +++ packages/utils-evm-test/package.json | 8 ++- .../utils-evm-test/test/errors/parser.test.ts | 67 +++++++++---------- packages/utils-evm-test/tsconfig.json | 2 +- 4 files changed, 48 insertions(+), 38 deletions(-) create mode 100644 packages/utils-evm-test/jest.config.js diff --git a/packages/utils-evm-test/jest.config.js b/packages/utils-evm-test/jest.config.js new file mode 100644 index 000000000..17ae5d1ac --- /dev/null +++ b/packages/utils-evm-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/utils-evm-test/package.json b/packages/utils-evm-test/package.json index 0ef9e6a77..bdbc5b3dd 100644 --- a/packages/utils-evm-test/package.json +++ b/packages/utils-evm-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 --pasWithNoTests" }, "devDependencies": { "@ethersproject/abi": "^5.7.0", @@ -25,11 +26,12 @@ "@layerzerolabs/utils-evm": "~0.0.1", "@nomicfoundation/hardhat-ethers": "^3.0.2", "@nomiclabs/hardhat-ethers": "^2.2.3", - "@types/mocha": "^10.0.6", - "chai": "^4.3.10", + "@types/jest": "^29.5.10", "ethers": "^5.7.0", "fast-check": "^3.14.0", "hardhat": "^2.19.2", + "jest": "^29.7.0", + "ts-jest": "^29.1.1", "ts-node": "^10.9.1", "typescript": "^5.2.2" } diff --git a/packages/utils-evm-test/test/errors/parser.test.ts b/packages/utils-evm-test/test/errors/parser.test.ts index 14c4f0a3e..ab7f3d6ab 100644 --- a/packages/utils-evm-test/test/errors/parser.test.ts +++ b/packages/utils-evm-test/test/errors/parser.test.ts @@ -1,6 +1,5 @@ import fc from 'fast-check' import hre from 'hardhat' -import { expect } from 'chai' import { Contract } from '@ethersproject/contracts' import { createErrorParser, @@ -33,7 +32,7 @@ describe('errors/parser', () => { const assertFailed = async (promise: Promise): Promise => promise.then( (result) => { - expect.fail(`Expected a promise to always reject but it resolved with ${JSON.stringify(result)}`) + fail(`Expected a promise to always reject but it resolved with ${JSON.stringify(result)}`) }, (error) => error ) @@ -53,9 +52,9 @@ describe('errors/parser', () => { const omniError: OmniError = { error: new RevertError('A reason is worth a million bytes'), point } const parsedError = await errorParser(omniError) - expect(parsedError.point).to.eql(point) - expect(parsedError.error).to.be.instanceOf(RevertError) - expect(parsedError.error.reason).to.equal('A reason is worth a million bytes') + expect(parsedError.point).toEqual(point) + expect(parsedError.error).toBeInstanceOf(RevertError) + expect(parsedError.error.reason).toBe('A reason is worth a million bytes') }) ) }) @@ -69,9 +68,9 @@ describe('errors/parser', () => { const omniError: OmniError = { error, point } const parsedError = await errorParser(omniError) - expect(parsedError.point).to.eql(point) - expect(parsedError.error).to.be.instanceOf(PanicError) - expect(parsedError.error.reason).to.eql(BigInt(1)) + expect(parsedError.point).toEqual(point) + expect(parsedError.error).toBeInstanceOf(PanicError) + expect(parsedError.error.reason).toEqual(BigInt(1)) }) ) }) @@ -85,9 +84,9 @@ describe('errors/parser', () => { const omniError: OmniError = { error, point } const parsedError = await errorParser(omniError) - expect(parsedError.point).to.eql(point) - expect(parsedError.error).to.be.instanceOf(RevertError) - expect(parsedError.error.reason).to.eql('my bad') + expect(parsedError.point).toEqual(point) + expect(parsedError.error).toBeInstanceOf(RevertError) + expect(parsedError.error.reason).toEqual('my bad') }) ) }) @@ -101,9 +100,9 @@ describe('errors/parser', () => { const omniError: OmniError = { error, point } const parsedError = await errorParser(omniError) - expect(parsedError.point).to.eql(point) - expect(parsedError.error).to.be.instanceOf(RevertError) - expect(parsedError.error.reason).to.eql('my bad') + expect(parsedError.point).toEqual(point) + expect(parsedError.error).toBeInstanceOf(RevertError) + expect(parsedError.error.reason).toEqual('my bad') }) ) }) @@ -117,10 +116,10 @@ describe('errors/parser', () => { const omniError: OmniError = { error, point } const parsedError = await errorParser(omniError) - expect(parsedError.point).to.eql(point) - expect(parsedError.error).to.be.instanceOf(CustomError) - expect(parsedError.error.reason).to.eql('CustomErrorWithNoArguments') - expect((parsedError.error as CustomError).args).to.eql([]) + expect(parsedError.point).toEqual(point) + expect(parsedError.error).toBeInstanceOf(CustomError) + expect(parsedError.error.reason).toEqual('CustomErrorWithNoArguments') + expect((parsedError.error as CustomError).args).toEqual([]) }) ) }) @@ -134,10 +133,10 @@ describe('errors/parser', () => { const omniError: OmniError = { error, point } const parsedError = await errorParser(omniError) - expect(parsedError.point).to.eql(point) - expect(parsedError.error).to.be.instanceOf(CustomError) - expect(parsedError.error.reason).to.eql('CustomErrorWithAnArgument') - expect((parsedError.error as CustomError).args).to.eql(['my bad']) + expect(parsedError.point).toEqual(point) + expect(parsedError.error).toBeInstanceOf(CustomError) + expect(parsedError.error.reason).toEqual('CustomErrorWithAnArgument') + expect((parsedError.error as CustomError).args).toEqual(['my bad']) }) ) }) @@ -150,10 +149,10 @@ describe('errors/parser', () => { const omniError: OmniError = { error: 'some weird error', point } const parsedError = await errorParser(omniError) - expect(parsedError.point).to.eql(point) - expect(parsedError.error).to.be.instanceOf(UnknownError) - expect(parsedError.error.reason).to.be.undefined - expect(parsedError.error.message).to.eql('Unknown error: some weird error') + expect(parsedError.point).toEqual(point) + expect(parsedError.error).toBeInstanceOf(UnknownError) + expect(parsedError.error.reason).toBeUndefined() + expect(parsedError.error.message).toEqual('Unknown error: some weird error') }) ) }) @@ -166,10 +165,10 @@ describe('errors/parser', () => { const omniError: OmniError = { error: new Error('some weird error'), point } const parsedError = await errorParser(omniError) - expect(parsedError.point).to.eql(point) - expect(parsedError.error).to.be.instanceOf(UnknownError) - expect(parsedError.error.reason).to.be.undefined - expect(parsedError.error.message).to.eql('Unknown error: Error: some weird error') + expect(parsedError.point).toEqual(point) + expect(parsedError.error).toBeInstanceOf(UnknownError) + expect(parsedError.error.reason).toBeUndefined() + expect(parsedError.error.message).toEqual('Unknown error: Error: some weird error') }) ) }) @@ -182,10 +181,10 @@ describe('errors/parser', () => { const omniError: OmniError = { error, point } const parsedError = await errorParser(omniError) - expect(parsedError.point).to.eql(point) - expect(parsedError.error).to.be.instanceOf(UnknownError) - expect(parsedError.error.reason).to.be.undefined - expect(parsedError.error.message).to.match(/Unknown error: /) + expect(parsedError.point).toEqual(point) + expect(parsedError.error).toBeInstanceOf(UnknownError) + expect(parsedError.error.reason).toBeUndefined() + expect(parsedError.error.message).toMatch(/Unknown error: /) }), // Test case for when toString method of the error is not defined { diff --git a/packages/utils-evm-test/tsconfig.json b/packages/utils-evm-test/tsconfig.json index 1e471dfdd..5613cee25 100644 --- a/packages/utils-evm-test/tsconfig.json +++ b/packages/utils-evm-test/tsconfig.json @@ -4,6 +4,6 @@ "include": ["src", "test", "*.config.ts"], "compilerOptions": { "module": "commonjs", - "types": ["node", "mocha"] + "types": ["node", "jest"] } }