diff --git a/packages/ua-utils-evm-hardhat-test/test/task/oapp/__data__/configs/empty.config.js b/packages/ua-utils-evm-hardhat-test/test/task/oapp/__data__/configs/empty.config.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/ua-utils-evm-hardhat-test/test/task/oapp/__data__/configs/empty.config.json b/packages/ua-utils-evm-hardhat-test/test/task/oapp/__data__/configs/empty.config.json new file mode 100644 index 000000000..e69de29bb diff --git a/packages/ua-utils-evm-hardhat-test/test/task/oapp/__data__/configs/invalid.config.001.js b/packages/ua-utils-evm-hardhat-test/test/task/oapp/__data__/configs/invalid.config.001.js new file mode 100644 index 000000000..d6d1738de --- /dev/null +++ b/packages/ua-utils-evm-hardhat-test/test/task/oapp/__data__/configs/invalid.config.001.js @@ -0,0 +1 @@ +export default []; diff --git a/packages/ua-utils-evm-hardhat-test/test/task/oapp/wire.test.ts b/packages/ua-utils-evm-hardhat-test/test/task/oapp/wire.test.ts new file mode 100644 index 000000000..41af6e7ff --- /dev/null +++ b/packages/ua-utils-evm-hardhat-test/test/task/oapp/wire.test.ts @@ -0,0 +1,42 @@ +import { setupDefaultEndpoint } from '../../__utils__/endpoint' +import hre from 'hardhat' +import { isFile } from '@layerzerolabs/io-utils' +import { resolve } from 'path' +import { TASK_LZ_WIRE_OAPP } from '@layerzerolabs/ua-utils-evm-hardhat' + +describe('task/oapp/wire', () => { + const CONFIGS_BASE_DIR = resolve(__dirname, '__data__', 'configs') + + beforeEach(async () => { + await setupDefaultEndpoint() + }) + + it('should fail if the config file does not exist', async () => { + await expect(hre.run(TASK_LZ_WIRE_OAPP, { oappConfig: './does-not-exist.js' })).rejects.toThrow( + /Unable to read config file/ + ) + }) + + it('should fail if the config file is not a file', async () => { + await expect(hre.run(TASK_LZ_WIRE_OAPP, { oappConfig: __dirname })).rejects.toThrow( + /Unable to read config file/ + ) + }) + + it('should fail if the config file is not a valid JSON or JS file', async () => { + const readme = resolve(__dirname, '..', '..', '..', 'README.md') + + expect(isFile(readme)).toBeTruthy() + + await expect(hre.run(TASK_LZ_WIRE_OAPP, { oappConfig: readme })).rejects.toThrow(/Unable to read config file/) + }) + + // TODO This should fail once the task is complete + it('should succeed with an empty JS file', async () => { + const oappConfig = resolve(CONFIGS_BASE_DIR, 'empty.config.js') + + expect(isFile(oappConfig)).toBeTruthy() + + await hre.run(TASK_LZ_WIRE_OAPP, { oappConfig }) + }) +}) diff --git a/packages/ua-utils-evm-hardhat/src/tasks/index.ts b/packages/ua-utils-evm-hardhat/src/tasks/index.ts index edfb64bc4..be8df89d5 100644 --- a/packages/ua-utils-evm-hardhat/src/tasks/index.ts +++ b/packages/ua-utils-evm-hardhat/src/tasks/index.ts @@ -1 +1,2 @@ +import './oapp' import './getDefaultConfig' diff --git a/packages/ua-utils-evm-hardhat/src/tasks/oapp/index.ts b/packages/ua-utils-evm-hardhat/src/tasks/oapp/index.ts new file mode 100644 index 000000000..8010ab13b --- /dev/null +++ b/packages/ua-utils-evm-hardhat/src/tasks/oapp/index.ts @@ -0,0 +1 @@ +import './wire' diff --git a/packages/ua-utils-evm-hardhat/src/tasks/oapp/wire.ts b/packages/ua-utils-evm-hardhat/src/tasks/oapp/wire.ts new file mode 100644 index 000000000..6db752be9 --- /dev/null +++ b/packages/ua-utils-evm-hardhat/src/tasks/oapp/wire.ts @@ -0,0 +1,31 @@ +import { task, types } from 'hardhat/config' +import type { ActionType } from 'hardhat/types' +import { TASK_LZ_WIRE_OAPP } from '@/constants/tasks' +import { isFile, isReadable } from '@layerzerolabs/io-utils' + +interface TaskArgs { + oappConfig: string +} + +const action: ActionType = async ({ oappConfig: oappConfigPath }) => { + // First we check that the config file is indeed there and we can read it + const isConfigReadable = isFile(oappConfigPath) && isReadable(oappConfigPath) + if (!isConfigReadable) { + throw new Error( + `Unable to read config file '${oappConfigPath}'. Check that the file exists and is readable to your terminal user` + ) + } + + // Now let's see if we can load the config file + let config: unknown + try { + config = require(oappConfigPath) + } catch (error) { + throw new Error(`Unable to read config file '${oappConfigPath}': ${error}`) + } + + console.log({ config }) +} +task(TASK_LZ_WIRE_OAPP, 'Wire LayerZero OApp') + .addParam('oappConfig', 'Path to your LayerZero OApp config', './layerzero.config.js', types.string) + .setAction(action)