-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2ea1c28
commit 322c02a
Showing
7 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
Empty file.
1 change: 1 addition & 0 deletions
1
packages/ua-utils-evm-hardhat-test/test/task/oapp/__data__/configs/invalid.config.001.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default []; |
42 changes: 42 additions & 0 deletions
42
packages/ua-utils-evm-hardhat-test/test/task/oapp/wire.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
import './oapp' | ||
import './getDefaultConfig' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import './wire' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<TaskArgs> = 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) |