Skip to content

Commit

Permalink
chore: Add stub of OApp wiring
Browse files Browse the repository at this point in the history
  • Loading branch information
janjakubnanista committed Dec 8, 2023
1 parent 2ea1c28 commit 322c02a
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 0 deletions.
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default [];
42 changes: 42 additions & 0 deletions packages/ua-utils-evm-hardhat-test/test/task/oapp/wire.test.ts
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 })
})
})
1 change: 1 addition & 0 deletions packages/ua-utils-evm-hardhat/src/tasks/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
import './oapp'
import './getDefaultConfig'
1 change: 1 addition & 0 deletions packages/ua-utils-evm-hardhat/src/tasks/oapp/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './wire'
31 changes: 31 additions & 0 deletions packages/ua-utils-evm-hardhat/src/tasks/oapp/wire.ts
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)

0 comments on commit 322c02a

Please sign in to comment.