Skip to content

Commit

Permalink
👷‍♂️🪚Adding optional params to getDefaultConfig and getOAppConfig tas…
Browse files Browse the repository at this point in the history
…ks (#276)
  • Loading branch information
sirarthurmoney authored Jan 29, 2024
1 parent 0877186 commit 9b75fe1
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 23 deletions.
6 changes: 6 additions & 0 deletions .changeset/fast-ties-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@layerzerolabs/ua-devtools-evm-hardhat-test": patch
"@layerzerolabs/ua-devtools-evm-hardhat": patch
---

Adding optional params to getDefaultConfig and getOAppConfig tasks
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,27 @@ import { printRecord } from '@layerzerolabs/io-devtools'
import { getReceiveConfig, getSendConfig } from '@/utils/taskHelpers'
import { TASK_LZ_OAPP_CONFIG_GET_DEFAULT } from '@/constants'
import { setDefaultLogLevel } from '@layerzerolabs/io-devtools'
import { types } from '@layerzerolabs/devtools-evm-hardhat'
import { getEidsByNetworkName, types } from '@layerzerolabs/devtools-evm-hardhat'

interface TaskArgs {
logLevel?: string
networks: string[]
networks?: string[]
}

export const getDefaultConfig: ActionType<TaskArgs> = async ({ logLevel = 'info', networks }) => {
export const getDefaultConfig: ActionType<TaskArgs> = async (
{ logLevel = 'info', networks: networksArgument },
hre
) => {
// We'll set the global logging level to get as much info as needed
setDefaultLogLevel(logLevel)

const configs: Record<string, Record<string, unknown>> = {}
const networks =
networksArgument ??
Object.entries(getEidsByNetworkName(hre)).flatMap(([networkName, eid]) => (eid == null ? [] : [networkName]))

const configs: Record<string, Record<string, unknown>> = {}
for (const localNetworkName of networks) {
configs[localNetworkName] = {}

for (const remoteNetworkName of networks) {
if (remoteNetworkName === localNetworkName) continue

Expand Down Expand Up @@ -57,6 +62,6 @@ task(
TASK_LZ_OAPP_CONFIG_GET_DEFAULT,
'Outputs the default Send and Receive Messaging Library versions and the default application config'
)
.addParam('networks', 'comma separated list of networks', undefined, types.networks)
.addParam('networks', 'Comma-separated list of networks', undefined, types.networks, true)
.addParam('logLevel', 'Logging level. One of: error, warn, info, verbose, debug, silly', 'info', types.logLevel)
.setAction(getDefaultConfig)
29 changes: 20 additions & 9 deletions packages/ua-devtools-evm-hardhat/src/tasks/oapp/config.get.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,40 @@
import { ActionType } from 'hardhat/types'
import { task } from 'hardhat/config'
import { printCrossTable } from '@layerzerolabs/io-devtools'
import { getReceiveConfig, getSendConfig } from '@/utils/taskHelpers'
import { createLogger, printCrossTable } from '@layerzerolabs/io-devtools'
import { getReceiveConfig, getSendConfig, validateAndTransformOappConfig } from '@/utils/taskHelpers'
import { TASK_LZ_OAPP_CONFIG_GET } from '@/constants/tasks'
import assert from 'assert'
import { setDefaultLogLevel } from '@layerzerolabs/io-devtools'
import { types } from '@layerzerolabs/devtools-evm-hardhat'
import { OAppOmniGraph } from '@layerzerolabs/ua-devtools'
import { getNetworkNameForEid, types } from '@layerzerolabs/devtools-evm-hardhat'

interface TaskArgs {
logLevel?: string
networks: string[]
addresses: string[]
oappConfig: string
}

export const getOAppConfig: ActionType<TaskArgs> = async ({ logLevel = 'info', networks, addresses }) => {
export const getOAppConfig: ActionType<TaskArgs> = async ({ logLevel = 'info', oappConfig }) => {
// We'll set the global logging level to get as much info as needed
setDefaultLogLevel(logLevel)

const networks: string[] = []
const addresses: string[] = []
const logger = createLogger()
const graph: OAppOmniGraph = await validateAndTransformOappConfig(oappConfig, logger)
graph.contracts.forEach((contract) => {
networks.push(getNetworkNameForEid(contract.point.eid))
addresses.push(contract.point.address)
})

assert(
networks.length != 0,
'Please provide a valid list of networks & addresses or a path to your LayerZero OApp config.'
)
assert(networks.length === addresses.length, 'Passed in networks must match length of passed in addresses.')
const configs: Record<string, Record<string, unknown>> = {}

for (const [index, localNetworkName] of networks.entries()) {
configs[localNetworkName] = {}

for (const remoteNetworkName of networks) {
if (remoteNetworkName === localNetworkName) continue

Expand Down Expand Up @@ -100,7 +112,6 @@ task(
TASK_LZ_OAPP_CONFIG_GET,
'Outputs the default Send and Receive Messaging Library versions and the default application config'
)
.addParam('networks', 'Comma-separated list of networks', undefined, types.networks)
.addParam('addresses', 'Comma-separated list of addresses', undefined, types.csv)
.addParam('logLevel', 'Logging level. One of: error, warn, info, verbose, debug, silly', 'info', types.logLevel)
.addParam('oappConfig', 'Path to your LayerZero OApp config', './layerzero.config.js', types.string)
.setAction(getOAppConfig)
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,30 @@ describe(`task ${TASK_LZ_OAPP_CONFIG_GET_DEFAULT}`, () => {
}
}
})

it('should return default configurations with no input', async () => {
const getDefaultConfigTask = await hre.run(TASK_LZ_OAPP_CONFIG_GET_DEFAULT, {})
const networks = Object.keys(hre.userConfig.networks ?? {})
const contractFactory = createContractFactory()
for (const localNetwork of networks) {
const localEid = getEidForNetworkName(localNetwork)
for (const remoteNetwork of networks) {
if (localNetwork === remoteNetwork) continue
const defaultConfig = getDefaultConfigTask[localNetwork][remoteNetwork]

const sendUln302 = await contractFactory({ contractName: 'SendUln302', eid: localEid })
const receiveUln302 = await contractFactory({ contractName: 'ReceiveUln302', eid: localEid })
const executor = await contractFactory({ contractName: 'Executor', eid: localEid })
const executorPoint = await omniContractToPoint(executor)
const dvn = await contractFactory({ contractName: 'DVN', eid: localEid })
const dvnPoint = await omniContractToPoint(dvn)

expect(defaultConfig.defaultSendLibrary).toEqual(sendUln302.contract.address)
expect(defaultConfig.defaultReceiveLibrary).toEqual(receiveUln302.contract.address)
expect(defaultConfig.sendExecutorConfig).toEqual(getDefaultExecutorConfig(executorPoint.address))
expect(defaultConfig.sendUlnConfig).toEqual(getDefaultUlnConfig(dvnPoint.address))
expect(defaultConfig.receiveUlnConfig).toEqual(getDefaultUlnConfig(dvnPoint.address))
}
}
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,33 @@ import {
} from '../../__utils__/endpoint'
import { createContractFactory, getEidForNetworkName } from '@layerzerolabs/devtools-evm-hardhat'
import hre from 'hardhat'
import { AddressZero } from '@ethersproject/constants'
import { TASK_LZ_OAPP_CONFIG_GET } from '@layerzerolabs/ua-devtools-evm-hardhat'
import { omniContractToPoint } from '@layerzerolabs/devtools-evm'
import { resolve } from 'path'
import { isFile } from '@layerzerolabs/io-devtools'
import { deployOApp } from '../../__utils__/oapp'

describe(`task ${TASK_LZ_OAPP_CONFIG_GET}`, () => {
const CONFIGS_BASE_DIR = resolve(__dirname, '__data__', 'configs')
const configPathFixture = (fileName: string): string => {
const path = resolve(CONFIGS_BASE_DIR, fileName)
expect(isFile(path)).toBeTruthy()
return path
}

beforeEach(async () => {
await deployEndpoint()
await setupDefaultEndpoint()
})

it('should return app default configurations when addresses are not oapps', async () => {
const networks = Object.keys(hre.userConfig.networks ?? {})
const addresses = new Array(networks.length).fill(AddressZero)
const getDefaultConfigTask = await hre.run(TASK_LZ_OAPP_CONFIG_GET, {
networks,
addresses,
})
beforeEach(async () => {
await deployOApp()
})

it('should return app specific configurations with a valid LayerZero OApp config', async () => {
const oappConfig = configPathFixture('valid.config.connected.js')
const networks = ['britney', 'vengaboys']
const getDefaultConfigTask = await hre.run(TASK_LZ_OAPP_CONFIG_GET, { oappConfig })
const contractFactory = createContractFactory()
for (const localNetwork of networks) {
const localEid = getEidForNetworkName(localNetwork)
Expand Down

0 comments on commit 9b75fe1

Please sign in to comment.