Skip to content

Commit

Permalink
Merge branch 'main' into getOAppConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
sirarthurmoney committed Dec 9, 2023
2 parents 47cf99b + 6007bd7 commit 0c04461
Show file tree
Hide file tree
Showing 36 changed files with 407 additions and 213 deletions.
5 changes: 1 addition & 4 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
"browser": true,
"commonjs": true,
"es6": true,
"mocha": true,
"node": true,
"jest": true
},
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint", "mocha", "prettier"],
"plugins": ["@typescript-eslint", "prettier"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
Expand All @@ -20,8 +19,6 @@
},
"ignorePatterns": ["node_modules/", "dist/", ".turbo/"],
"rules": {
"mocha/no-skipped-tests": "error",
"mocha/no-exclusive-tests": "error",
"prettier/prettier": "error",

// Intermediate deescalation to warnings
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"eslint-config-prettier": "^9.0.0",
"eslint-config-standard": "^17.1.0",
"eslint-plugin-import": "^2.24.2",
"eslint-plugin-mocha": "10.2.0",
"eslint-plugin-n": "^16.3.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^5.0.1",
Expand Down
5 changes: 0 additions & 5 deletions packages/create-lz-oapp/.mocharc.json

This file was deleted.

17 changes: 17 additions & 0 deletions packages/create-lz-oapp/jest.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: "ts-jest",
testEnvironment: "node",
testTimeout: 15000,
moduleNameMapper: {
"^@/(.*)\\.js$": "<rootDir>/src/$1",
},
transform: {
// ts-jest does not yet work great with node16 module resolution
// so we need to help it a little
//
// See https://github.com/kulshekhar/ts-jest/issues/4207 for the issue
// And https://github.com/kulshekhar/ts-jest/issues/4198 for another one
"^.+\\.tsx?$": ["ts-jest", { tsconfig: "tsconfig.test.json" }],
},
};
8 changes: 4 additions & 4 deletions packages/create-lz-oapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,18 @@
"dev": "npx tsup --watch",
"lint": "npx eslint '**/*.{js,ts,json}'",
"start": "./cli.cjs",
"test": "mocha --parallel"
"test": "jest --config jest.config.cjs"
},
"dependencies": {
"yoga-wasm-web": "~0.3.3"
},
"devDependencies": {
"@layerzerolabs/io-utils": "~0.0.1",
"@tanstack/react-query": "^5.8.4",
"@types/mocha": "^10.0.6",
"@types/jest": "^29.5.10",
"@types/prompts": "^2.4.9",
"@types/react": "^18.2.38",
"@types/which": "~3.0.3",
"chai": "^4.3.10",
"commander": "^11.1.0",
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react-hooks": "^4.6.0",
Expand All @@ -48,11 +47,12 @@
"ink-select-input": "^5.0.0",
"ink-spinner": "^5.0.0",
"ink-text-input": "^5.0.1",
"mocha": "^10.0.0",
"jest": "^29.7.0",
"prompts": "^2.4.2",
"react": "^18.2.0",
"react-devtools-core": "^4.28.5",
"tiged": "^2.12.5",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"typescript": "^5.2.2",
"which": "~4.0.0"
Expand Down
24 changes: 11 additions & 13 deletions packages/create-lz-oapp/test/utilities/cloning.test.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
import { expect } from 'chai'
import { describe, it } from 'mocha'
import { createExampleGitURL } from '../../src/utilities/cloning.js'
import { createExampleGitURL } from '@/utilities/cloning.js'

describe('utilities/cloning', () => {
describe('createExampleGitURL', () => {
const REPO_URL = '[email protected]:LayerZero-Labs/lz-utils'

it('should return the repository field if directory and ref are not specified', () => {
expect(createExampleGitURL({ repository: REPO_URL, id: 'dummy', label: 'Dummy' })).to.eql(REPO_URL)
expect(createExampleGitURL({ repository: REPO_URL, id: 'dummy', label: 'Dummy' })).toEqual(REPO_URL)
})

it('should return the repository field with directory if directory is specified', () => {
expect(createExampleGitURL({ repository: REPO_URL, directory: 'dir', id: 'dummy', label: 'Dummy' })).to.eql(
`${REPO_URL}/dir`
)
expect(
createExampleGitURL({ repository: REPO_URL, directory: 'dir', id: 'dummy', label: 'Dummy' })
).toEqual(`${REPO_URL}/dir`)
expect(
createExampleGitURL({ repository: REPO_URL, directory: '/dir', id: 'dummy', label: 'Dummy' })
).to.eql(`${REPO_URL}/dir`)
).toEqual(`${REPO_URL}/dir`)
expect(
createExampleGitURL({ repository: REPO_URL, directory: 'dir', ref: '', id: 'dummy', label: 'Dummy' })
).to.eql(`${REPO_URL}/dir`)
).toEqual(`${REPO_URL}/dir`)
})

it('should return the repository field with directory and ref if directory and ref are specified', () => {
expect(
createExampleGitURL({ repository: REPO_URL, directory: 'dir', ref: 'ref', id: 'dummy', label: 'Dummy' })
).to.eql(`${REPO_URL}/dir#ref`)
).toEqual(`${REPO_URL}/dir#ref`)
expect(
createExampleGitURL({
repository: REPO_URL,
Expand All @@ -34,14 +32,14 @@ describe('utilities/cloning', () => {
id: 'dummy',
label: 'Dummy',
})
).to.eql(`${REPO_URL}/dir#ref`)
).toEqual(`${REPO_URL}/dir#ref`)
})

it('should return the repository field with ref if only ref specified', () => {
expect(createExampleGitURL({ repository: REPO_URL, ref: 'ref', id: 'dummy', label: 'Dummy' })).to.eql(
expect(createExampleGitURL({ repository: REPO_URL, ref: 'ref', id: 'dummy', label: 'Dummy' })).toEqual(
`${REPO_URL}#ref`
)
expect(createExampleGitURL({ repository: REPO_URL, ref: '#ref', id: 'dummy', label: 'Dummy' })).to.eql(
expect(createExampleGitURL({ repository: REPO_URL, ref: '#ref', id: 'dummy', label: 'Dummy' })).toEqual(
`${REPO_URL}#ref`
)
})
Expand Down
2 changes: 1 addition & 1 deletion packages/create-lz-oapp/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"lib": ["dom", "dom.Iterable", "es2022"],
"resolveJsonModule": false,
"target": "esnext",
"types": ["mocha", "node"],
"types": ["jest", "node"],
"paths": {
"@/*": ["./src/*"]
}
Expand Down
7 changes: 7 additions & 0 deletions packages/create-lz-oapp/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "Node10"
}
}
16 changes: 16 additions & 0 deletions packages/io-utils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,19 @@ Returns `true` if specified filesystem `path` points to a file, `false` otherwis
#### isReadable(path)

Returns `true` if specified filesystem `path` can be read by the current user, `false` otherwise. Does not throw if `path` does not exist on the filesystem, instead returns `false`

### Standard input/output utilities

#### promptToContinue([message, defaultValue])

Asks the user whether they want to continue and reads the input from the CLI standard input. By default the question displayed is `Do you want to continue?` and the default response is `yes`

```typescript
const goahead = await promptToContinue();

// To ask a different question
const goahead = await promptToContinue("Are you sure?");

// To default the response to false, good for important and unsafe decisions
const goahead = await promptToContinue("Are you sure?", false);
```
8 changes: 8 additions & 0 deletions packages/io-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
"types": "./dist/index.d.ts",
"require": "./dist/index.js",
"import": "./dist/index.mjs"
},
"./*": {
"types": "./dist/*.d.ts",
"require": "./dist/*.js",
"import": "./dist/*.mjs"
}
},
"main": "dist/index.js",
Expand All @@ -29,6 +34,9 @@
"lint": "npx eslint '**/*.{js,ts,json}'",
"test": "jest --passWithNoTests"
},
"dependencies": {
"prompts": "^2.4.2"
},
"devDependencies": {
"@types/jest": "^29.5.10",
"fast-check": "^3.14.0",
Expand Down
1 change: 1 addition & 0 deletions packages/io-utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './filesystem'
export * from './stdio'
1 change: 1 addition & 0 deletions packages/io-utils/src/stdio/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './prompts'
18 changes: 18 additions & 0 deletions packages/io-utils/src/stdio/prompts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import assert from 'assert'
import prompts from 'prompts'

export const promptToContinue = async (
message: string = 'Do you want to continue?',
defaultValue = true
): Promise<boolean> => {
const { value } = await prompts({
type: 'confirm',
name: 'value',
message,
initial: defaultValue,
})

assert(typeof value === 'boolean', `Invariant error: Expected a boolean response, got ${value}`)

return value
}
2 changes: 1 addition & 1 deletion packages/io-utils/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineConfig } from 'tsup'

export default defineConfig({
entry: ['src/index.ts'],
entry: ['src/index.ts', 'src/filesystem/index.ts', 'src/stdio/index.ts'],
outDir: './dist',
clean: true,
dts: true,
Expand Down
2 changes: 2 additions & 0 deletions packages/protocol-utils-evm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"devDependencies": {
"@ethersproject/abstract-provider": "^5.7.0",
"@ethersproject/abstract-signer": "^5.7.0",
"@ethersproject/bignumber": "^5.7.0",
"@ethersproject/contracts": "^5.7.0",
"@ethersproject/providers": "^5.7.0",
"@layerzerolabs/lz-definitions": "~1.5.69",
Expand All @@ -59,6 +60,7 @@
"peerDependencies": {
"@ethersproject/abstract-provider": "^5.7.0",
"@ethersproject/abstract-signer": "^5.7.0",
"@ethersproject/bignumber": "^5.7.0",
"@ethersproject/contracts": "^5.7.0",
"@ethersproject/providers": "^5.7.0",
"@layerzerolabs/lz-definitions": "~1.5.69",
Expand Down
1 change: 1 addition & 0 deletions packages/protocol-utils-evm/src/uln302/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './sdk'
export * from './types'
8 changes: 5 additions & 3 deletions packages/protocol-utils-evm/src/uln302/schema.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { z } from 'zod'
import { AddressSchema } from '@layerzerolabs/utils'
import { BigNumberishNumberSchema } from '@layerzerolabs/utils-evm'
import { BigNumberishBigintSchema } from '@layerzerolabs/utils-evm'
import { z } from 'zod'
import type { Uln302ExecutorConfig, Uln302UlnConfig } from '@layerzerolabs/protocol-utils'
import type { Uln302ExecutorConfigInput, Uln302UlnConfigInput } from './types'

/**
* Schema for parsing an ethers-specific UlnConfig into a common format
Expand All @@ -11,15 +13,15 @@ export const Uln302UlnConfigSchema = z.object({
requiredDVNs: z.array(AddressSchema),
optionalDVNs: z.array(AddressSchema),
optionalDVNThreshold: z.coerce.number().int().nonnegative(),
})
}) satisfies z.ZodSchema<Uln302UlnConfig, z.ZodTypeDef, Uln302UlnConfigInput>

/**
* Schema for parsing an ethers-specific ExecutorConfig into a common format
*/
export const Uln302ExecutorConfigSchema = z.object({
maxMessageSize: BigNumberishNumberSchema,
executor: AddressSchema,
})
}) satisfies z.ZodSchema<Uln302ExecutorConfig, z.ZodTypeDef, Uln302ExecutorConfigInput>

/**
* Schema for parsing a common UlnConfig into a ethers-specific format
Expand Down
10 changes: 10 additions & 0 deletions packages/protocol-utils-evm/src/uln302/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { BigNumberish } from '@ethersproject/bignumber'
import { Uln302ExecutorConfig, Uln302UlnConfig } from '@layerzerolabs/protocol-utils'

export interface Uln302UlnConfigInput extends Omit<Uln302UlnConfig, 'confirmations'> {
confirmations: BigNumberish
}

export interface Uln302ExecutorConfigInput extends Omit<Uln302ExecutorConfig, 'maxMessageSize'> {
maxMessageSize: BigNumberish
}
2 changes: 0 additions & 2 deletions packages/ua-utils-evm-hardhat-test/test/__utils__/endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,9 @@ export const setupDefaultEndpoint = async (): Promise<void> => {
contracts: [
{
contract: ethEndpoint,
config: undefined,
},
{
contract: avaxEndpoint,
config: undefined,
},
],
connections: [
Expand Down
4 changes: 0 additions & 4 deletions packages/ua-utils-evm-hardhat-test/test/oapp/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,19 @@ describe('oapp/config', () => {
contracts: [
{
contract: ethContract,
config: undefined,
},
{
contract: avaxContract,
config: undefined,
},
],
connections: [
{
from: ethContract,
to: avaxContract,
config: undefined,
},
{
from: avaxContract,
to: ethContract,
config: undefined,
},
],
}
Expand Down
1 change: 1 addition & 0 deletions packages/ua-utils-evm-hardhat/src/oapp/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './schema'
export * from './types'
18 changes: 18 additions & 0 deletions packages/ua-utils-evm-hardhat/src/oapp/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {
createOmniEdgeHardhatSchema,
createOmniGraphHardhatSchema,
createOmniNodeHardhatSchema,
} from '@layerzerolabs/utils-evm-hardhat'
import { z } from 'zod'
import type { OAppOmniGraphHardhat } from './types'

/**
* Validation schema for OApp configs in hardhat environment.
*
* Produces an `OAppOmniGraphHardhat` after successful parsing
* the user input.
*/
export const OAppOmniGraphHardhatSchema = createOmniGraphHardhatSchema(
createOmniNodeHardhatSchema(z.unknown()),
createOmniEdgeHardhatSchema(z.unknown())
) satisfies z.ZodSchema<OAppOmniGraphHardhat>
16 changes: 6 additions & 10 deletions packages/utils-evm-hardhat/src/omnigraph/coordinates.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
import type { EndpointId } from '@layerzerolabs/lz-definitions'
import type { OmniPoint } from '@layerzerolabs/utils'
import type { Deployment } from 'hardhat-deploy/dist/types'
import type { HardhatRuntimeEnvironment } from 'hardhat/types'
import pMemoize from 'p-memoize'
import { OmniContract } from '@layerzerolabs/utils-evm'
import { Contract } from '@ethersproject/contracts'
import assert from 'assert'
import { OmniContractFactoryHardhat } from './types'
import { OmniContractFactoryHardhat, OmniDeployment } from './types'
import { createNetworkEnvironmentFactory, getDefaultRuntimeEnvironment } from '@/runtime'
import { assertHardhatDeploy } from '@/internal/assertions'

export interface OmniDeployment {
eid: EndpointId
deployment: Deployment
}

export const omniDeploymentToPoint = ({ eid, deployment }): OmniPoint => ({ eid, address: deployment.address })
export const omniDeploymentToPoint = ({ eid, deployment }: OmniDeployment): OmniPoint => ({
eid,
address: deployment.address,
})

export const omniDeploymentToContract = ({ eid, deployment }): OmniContract => ({
export const omniDeploymentToContract = ({ eid, deployment }: OmniDeployment): OmniContract => ({
eid,
contract: new Contract(deployment.address, deployment.abi),
})
Expand Down
Loading

0 comments on commit 0c04461

Please sign in to comment.