diff --git a/.changeset/fast-ties-smoke.md b/.changeset/fast-ties-smoke.md new file mode 100644 index 000000000..020b649c9 --- /dev/null +++ b/.changeset/fast-ties-smoke.md @@ -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 diff --git a/packages/ua-devtools-evm-hardhat/src/tasks/oapp/config.get.default.ts b/packages/ua-devtools-evm-hardhat/src/tasks/oapp/config.get.default.ts index 4a4ec7b38..983a01022 100644 --- a/packages/ua-devtools-evm-hardhat/src/tasks/oapp/config.get.default.ts +++ b/packages/ua-devtools-evm-hardhat/src/tasks/oapp/config.get.default.ts @@ -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 = async ({ logLevel = 'info', networks }) => { +export const getDefaultConfig: ActionType = 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> = {} + const networks = + networksArgument ?? + Object.entries(getEidsByNetworkName(hre)).flatMap(([networkName, eid]) => (eid == null ? [] : [networkName])) + const configs: Record> = {} for (const localNetworkName of networks) { configs[localNetworkName] = {} - for (const remoteNetworkName of networks) { if (remoteNetworkName === localNetworkName) continue @@ -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) diff --git a/packages/ua-devtools-evm-hardhat/src/tasks/oapp/config.get.ts b/packages/ua-devtools-evm-hardhat/src/tasks/oapp/config.get.ts index e711c9d33..5cc060e09 100644 --- a/packages/ua-devtools-evm-hardhat/src/tasks/oapp/config.get.ts +++ b/packages/ua-devtools-evm-hardhat/src/tasks/oapp/config.get.ts @@ -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 = async ({ logLevel = 'info', networks, addresses }) => { +export const getOAppConfig: ActionType = 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> = {} for (const [index, localNetworkName] of networks.entries()) { configs[localNetworkName] = {} - for (const remoteNetworkName of networks) { if (remoteNetworkName === localNetworkName) continue @@ -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) diff --git a/tests/ua-devtools-evm-hardhat-test/test/task/oapp/config.get.default.test.ts b/tests/ua-devtools-evm-hardhat-test/test/task/oapp/config.get.default.test.ts index d946b4ec3..b82341867 100644 --- a/tests/ua-devtools-evm-hardhat-test/test/task/oapp/config.get.default.test.ts +++ b/tests/ua-devtools-evm-hardhat-test/test/task/oapp/config.get.default.test.ts @@ -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)) + } + } + }) }) diff --git a/tests/ua-devtools-evm-hardhat-test/test/task/oapp/config.get.test.ts b/tests/ua-devtools-evm-hardhat-test/test/task/oapp/config.get.test.ts index 8c6a37059..e5f09ed0c 100644 --- a/tests/ua-devtools-evm-hardhat-test/test/task/oapp/config.get.test.ts +++ b/tests/ua-devtools-evm-hardhat-test/test/task/oapp/config.get.test.ts @@ -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)