Skip to content

Commit

Permalink
🪚 OmniGraph™ Using jest for integration tests; Support legacy resolve…
Browse files Browse the repository at this point in the history
…rs for ua-utils-evm-hardhat (#79)
  • Loading branch information
janjakubnanista authored Dec 8, 2023
1 parent c3ef1c8 commit ced0ec9
Show file tree
Hide file tree
Showing 15 changed files with 58 additions and 71 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
9 changes: 9 additions & 0 deletions packages/ua-utils-evm-hardhat-test/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testTimeout: 15000,
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
},
};
12 changes: 6 additions & 6 deletions packages/ua-utils-evm-hardhat-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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"
}
Expand Down
15 changes: 7 additions & 8 deletions packages/ua-utils-evm-hardhat-test/test/endpoint/config.test.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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)
Expand All @@ -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)
})
})

Expand All @@ -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)
})
})
})
14 changes: 6 additions & 8 deletions packages/ua-utils-evm-hardhat-test/test/oapp/config.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'hardhat'
import { configureOApp } from '@layerzerolabs/ua-utils'
import { OApp } from '@layerzerolabs/ua-utils-evm'
import {
Expand All @@ -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'
Expand Down Expand Up @@ -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)
Expand All @@ -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),
])
Expand Down Expand Up @@ -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)])
})
})
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand All @@ -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)
}
}
})
Expand Down
2 changes: 1 addition & 1 deletion packages/ua-utils-evm-hardhat-test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"include": ["src", "test", "deploy", "*.config.ts"],
"compilerOptions": {
"module": "commonjs",
"types": ["node", "mocha"]
"types": ["node", "jest"]
}
}
5 changes: 3 additions & 2 deletions packages/ua-utils-evm-hardhat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"files": [
"dist/",
"LICENSE"
"tasks",
"dist"
],
"scripts": {
"prebuild": "tsc -noEmit",
Expand All @@ -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",
Expand Down
1 change: 1 addition & 0 deletions packages/ua-utils-evm-hardhat/src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './tasks'
1 change: 1 addition & 0 deletions packages/ua-utils-evm-hardhat/src/constants/tasks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const TASK_LZ_WIRE_OAPP = 'lz:oapp:wire'
2 changes: 2 additions & 0 deletions packages/ua-utils-evm-hardhat/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './constants'
export * from './oapp'
1 change: 1 addition & 0 deletions packages/ua-utils-evm-hardhat/tasks/README.md
Original file line number Diff line number Diff line change
@@ -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`
5 changes: 5 additions & 0 deletions packages/ua-utils-evm-hardhat/tasks/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"main": "../dist/tasks/index.js",
"module": "../dist/tasks/index.mjs",
"types": "../dist/tasks/index.d.ts"
}
12 changes: 1 addition & 11 deletions packages/ua-utils-evm-hardhat/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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'],
},
])
21 changes: 1 addition & 20 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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==
Expand Down

0 comments on commit ced0ec9

Please sign in to comment.