Skip to content

Commit

Permalink
🪚 Normalize task names (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
janjakubnanista authored Jan 10, 2024
1 parent 9182c69 commit 9bf8f60
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 57 deletions.
15 changes: 14 additions & 1 deletion DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ pnpm hardhat lz:test:oapp:deploy
And execute `hardhat` tasks as usual:

```bash
pnpm hardhat lz:oapp:getDefaultConfig
pnpm hardhat lz:oapp:config:get:default
```

If you are developing tasks, it's useful to build the code when it changes. To do this, run the following from the project root:
Expand Down Expand Up @@ -211,3 +211,16 @@ If you encounter errors when running these tests, just set the environment varia
```bash
CI=1 pnpm test
```

#### Problems with snapshot updating

If snapshots are used in a test that relies on filesystem paths, the situation becomes a bit complex. In long term, we should steer away from this approach as it makes updating snapshots a bit cumbersome.

Should you need to update snapshots for this kind of tests, follow these steps:

- Go to `docker-compose.yaml` and find the `volumes` section of the `tests` service
- Uncomment the line that says `./tests:/app/tests` - this will link the contain & host directories where the snapshots are being written
- Run the tests and pass a `-u` flag to `jest`
- `DOCKER_COMPOSE_RUN_TESTS_TURBO_ARGS="-- -u" pnpm test:ci` if you want to run all the tests
- `DOCKER_COMPOSE_RUN_TESTS_TURBO_ARGS="--filter=ua-devtools-evm-hardhat-test -- -u" pnpm test:ci` if you want to only run a specific test suite
- Profit
4 changes: 4 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ services:
- DOCKER_COMPOSE_RUN_TESTS_TURBO_ARGS=$DOCKER_COMPOSE_RUN_TESTS_TURBO_ARGS
volumes:
- ./node_modules/.cache/turbo:/app/node_modules/.cache/turbo
# Uncomment these lines if you run into issues with outdated snapshots
#
# See DEVELOPMENT.md for more details on this issue
# - ./tests:/app/tests
# Hardhat has an issue with caching compilers inside a docker container,
# failing with EACCES -13 error, pointing to a permissions issue with the cache folder.
#
Expand Down
8 changes: 4 additions & 4 deletions packages/ua-devtools-evm-hardhat/src/constants/tasks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const TASK_LZ_WIRE_OAPP = 'lz:oapp:wire'
export const TASK_LZ_GET_DEFAULT_CONFIG = 'lz:oapp:getDefaultConfig'
export const TASK_LZ_GET_OAPP_CONFIG = 'lz:oapp:getOAppConfig'
export const TASK_LZ_CHECK_WIRE_OAPP = 'lz:oapp:checkWire'
export const TASK_LZ_OAPP_WIRE = 'lz:oapp:wire'
export const TASK_LZ_OAPP_CONFIG_GET_DEFAULT = 'lz:oapp:config:get:default'
export const TASK_LZ_OAPP_CONFIG_GET = 'lz:oapp:config:get'
export const TASK_LZ_OAPP_CONFIG_CHECK = 'lz:oapp:config:check'
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ActionType } from 'hardhat/types'
import { task, types } from 'hardhat/config'
import { createLogger, setDefaultLogLevel } from '@layerzerolabs/io-devtools'
import { printRecords } from '@layerzerolabs/io-devtools/swag'
import { TASK_LZ_CHECK_WIRE_OAPP } from '@/constants/tasks'
import { TASK_LZ_OAPP_CONFIG_CHECK } from '@/constants/tasks'
import { printLogo } from '@layerzerolabs/io-devtools/swag'
import { OAppOmniGraph } from '@layerzerolabs/ua-devtools'
import { createConnectedContractFactory } from '@layerzerolabs/devtools-evm-hardhat'
Expand Down Expand Up @@ -50,7 +50,7 @@ export const checkWire: ActionType<TaskArgs> = async ({ oappConfig: oappConfigPa
}

task(
TASK_LZ_CHECK_WIRE_OAPP,
TASK_LZ_OAPP_CONFIG_CHECK,
'outputs visual console table to show current state of oapp connections via configuration'
)
.addParam('oappConfig', 'Path to your LayerZero OApp config', './layerzero.config.js', types.string)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ActionType } from 'hardhat/types'
import { task } from 'hardhat/config'
import { printRecord } from '@layerzerolabs/io-devtools'
import { getReceiveConfig, getSendConfig } from '@/utils/taskHelpers'
import { TASK_LZ_GET_DEFAULT_CONFIG } from '@/constants'
import { TASK_LZ_OAPP_CONFIG_GET_DEFAULT } from '@/constants'

interface TaskArgs {
networks: string
Expand Down Expand Up @@ -47,7 +47,7 @@ export const getDefaultConfig: ActionType<TaskArgs> = async (taskArgs) => {
}

task(
TASK_LZ_GET_DEFAULT_CONFIG,
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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ActionType } from 'hardhat/types'
import { task } from 'hardhat/config'
import { printRecord } from '@layerzerolabs/io-devtools'
import { getReceiveConfig, getSendConfig } from '@/utils/taskHelpers'
import { TASK_LZ_GET_OAPP_CONFIG } from '@/constants/tasks'
import { TASK_LZ_OAPP_CONFIG_GET } from '@/constants/tasks'
import assert from 'assert'

interface TaskArgs {
Expand Down Expand Up @@ -52,7 +52,7 @@ export const getOAppConfig: ActionType<TaskArgs> = async (taskArgs) => {
}

task(
TASK_LZ_GET_OAPP_CONFIG,
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')
Expand Down
6 changes: 3 additions & 3 deletions packages/ua-devtools-evm-hardhat/src/tasks/oapp/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import './wire'
import './checkWire'
import './getDefaultConfig'
import './getOAppConfig'
import './config.check'
import './config.get.default'
import './config.get'
4 changes: 2 additions & 2 deletions packages/ua-devtools-evm-hardhat/src/tasks/oapp/wire.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { task, types } from 'hardhat/config'
import type { ActionType } from 'hardhat/types'
import { TASK_LZ_WIRE_OAPP } from '@/constants/tasks'
import { TASK_LZ_OAPP_WIRE } from '@/constants/tasks'
import {
createLogger,
setDefaultLogLevel,
Expand Down Expand Up @@ -194,7 +194,7 @@ const action: ActionType<TaskArgs> = async ({

return [successfulTransactions, errors, transactionsToSign]
}
task(TASK_LZ_WIRE_OAPP, 'Wire LayerZero OApp')
task(TASK_LZ_OAPP_WIRE, 'Wire LayerZero OApp')
.addParam('oappConfig', 'Path to your LayerZero OApp config', './layerzero.config.js', types.string)
.addParam('logLevel', 'Logging level. One of: error, warn, info, verbose, debug, silly', 'info', types.string)
.addParam(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`task/oapp/wire with invalid configs should fail if the config file does not exist 1`] = `[Error: Unable to read config file '/app/tests/ua-devtools-evm-hardhat-test/does-not-exist.js'. Check that the file exists and is readable to your terminal user]`;
exports[`task lz:oapp:wire with invalid configs should fail if the config file does not exist 1`] = `[Error: Unable to read config file '/app/tests/ua-devtools-evm-hardhat-test/does-not-exist.js'. Check that the file exists and is readable to your terminal user]`;

exports[`task/oapp/wire with invalid configs should fail if the config file is not a file 1`] = `[Error: Unable to read config file '/app/tests/ua-devtools-evm-hardhat-test/test/task/oapp'. Check that the file exists and is readable to your terminal user]`;
exports[`task lz:oapp:wire with invalid configs should fail if the config file is not a file 1`] = `[Error: Unable to read config file '/app/tests/ua-devtools-evm-hardhat-test/test/task/oapp'. Check that the file exists and is readable to your terminal user]`;

exports[`task/oapp/wire with invalid configs should fail if the config file is not a valid JSON or JS file 1`] = `[Error: Unable to read config file '/app/tests/ua-devtools-evm-hardhat-test/README.md': SyntaxError: Unexpected token '<']`;
exports[`task lz:oapp:wire with invalid configs should fail if the config file is not a valid JSON or JS file 1`] = `[Error: Unable to read config file '/app/tests/ua-devtools-evm-hardhat-test/README.md': SyntaxError: Unexpected token '<']`;

exports[`task/oapp/wire with invalid configs should fail with a malformed JS file (001) 1`] = `
exports[`task lz:oapp:wire with invalid configs should fail with a malformed JS file (001) 1`] = `
[Error: Config from file '/app/tests/ua-devtools-evm-hardhat-test/test/task/oapp/__data__/configs/invalid.config.001.js' is malformed. Please fix the following errors:
Property 'contracts.0.contract': Invalid input
Property 'contracts.1.contract': Invalid input
Property 'connections': Required]
`;

exports[`task/oapp/wire with invalid configs should fail with a misconfigured file (001) 1`] = `[Error: Config from file '/app/tests/ua-devtools-evm-hardhat-test/test/task/oapp/__data__/configs/valid.config.misconfigured.001.js' is invalid: AssertionError [ERR_ASSERTION]: Could not find a deployment for contract 'NonExistent']`;
exports[`task lz:oapp:wire with invalid configs should fail with a misconfigured file (001) 1`] = `[Error: Config from file '/app/tests/ua-devtools-evm-hardhat-test/test/task/oapp/__data__/configs/valid.config.misconfigured.001.js' is invalid: AssertionError [ERR_ASSERTION]: Could not find a deployment for contract 'NonExistent']`;

exports[`task/oapp/wire with invalid configs should fail with an empty JS file 1`] = `
exports[`task lz:oapp:wire with invalid configs should fail with an empty JS file 1`] = `
[Error: Config from file '/app/tests/ua-devtools-evm-hardhat-test/test/task/oapp/__data__/configs/invalid.config.empty.js' is malformed. Please fix the following errors:
Property 'contracts': Required
Property 'connections': Required]
`;

exports[`task/oapp/wire with invalid configs should fail with an empty JSON file 1`] = `[Error: Unable to read config file '/app/tests/ua-devtools-evm-hardhat-test/test/task/oapp/__data__/configs/invalid.config.empty.json': SyntaxError: Unexpected end of JSON input]`;
exports[`task lz:oapp:wire with invalid configs should fail with an empty JSON file 1`] = `[Error: Unable to read config file '/app/tests/ua-devtools-evm-hardhat-test/test/task/oapp/__data__/configs/invalid.config.empty.json': SyntaxError: Unexpected end of JSON input]`;
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import hre from 'hardhat'
import { resolve } from 'path'
import { isFile } from '@layerzerolabs/io-devtools'
import { deployOAppFixture } from '../../__utils__/oapp'
import { TASK_LZ_CHECK_WIRE_OAPP, TASK_LZ_WIRE_OAPP } from '@layerzerolabs/ua-devtools-evm-hardhat'
import { TASK_LZ_OAPP_CONFIG_CHECK, TASK_LZ_OAPP_WIRE } from '@layerzerolabs/ua-devtools-evm-hardhat'

describe('task: checkWire', () => {
describe(`task ${TASK_LZ_OAPP_CONFIG_CHECK}`, () => {
const CONFIGS_BASE_DIR = resolve(__dirname, '__data__', 'configs')
const configPathFixture = (fileName: string): string => {
const path = resolve(CONFIGS_BASE_DIR, fileName)
Expand All @@ -18,7 +18,7 @@ describe('task: checkWire', () => {

it('should show no chains are connected', async () => {
const oappConfig = configPathFixture('valid.config.connected.js')
const result = await hre.run(TASK_LZ_CHECK_WIRE_OAPP, { oappConfig })
const result = await hre.run(TASK_LZ_OAPP_CONFIG_CHECK, { oappConfig })
const expectPoint = { eid: expect.any(Number), address: expect.any(String) }
const expectVector = { from: expectPoint, to: expectPoint }
expect(result).toEqual([
Expand All @@ -29,8 +29,8 @@ describe('task: checkWire', () => {

it('should show both chains are connected after running wire', async () => {
const oappConfig = configPathFixture('valid.config.connected.js')
await hre.run(TASK_LZ_WIRE_OAPP, { oappConfig, ci: true })
const result = await hre.run(TASK_LZ_CHECK_WIRE_OAPP, { oappConfig })
await hre.run(TASK_LZ_OAPP_WIRE, { oappConfig, ci: true })
const result = await hre.run(TASK_LZ_OAPP_CONFIG_CHECK, { oappConfig })
const expectPoint = { eid: expect.any(Number), address: expect.any(String) }
const expectVector = { from: expectPoint, to: expectPoint }
expect(result).toEqual([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ import {
getDefaultExecutorConfig,
getDefaultUlnConfig,
setupDefaultEndpoint,
} from '../__utils__/endpoint'
} from '../../__utils__/endpoint'
import { createContractFactory, getEidForNetworkName } from '@layerzerolabs/devtools-evm-hardhat'
import hre from 'hardhat'
import { TASK_LZ_GET_DEFAULT_CONFIG } from '@layerzerolabs/ua-devtools-evm-hardhat'
import { TASK_LZ_OAPP_CONFIG_GET_DEFAULT } from '@layerzerolabs/ua-devtools-evm-hardhat'
import { omniContractToPoint } from '@layerzerolabs/devtools-evm'

describe('task: getDefaultConfig', () => {
describe(`task ${TASK_LZ_OAPP_CONFIG_GET_DEFAULT}`, () => {
beforeEach(async () => {
await deployEndpointFixture()
await setupDefaultEndpoint()
})

it('should return default configurations', async () => {
const networks = Object.keys(hre.userConfig.networks ?? {})
const getDefaultConfigTask = await hre.run(TASK_LZ_GET_DEFAULT_CONFIG, { networks: networks.toString() })
const getDefaultConfigTask = await hre.run(TASK_LZ_OAPP_CONFIG_GET_DEFAULT, { networks: networks.toString() })
const contractFactory = createContractFactory()
for (const localNetwork of networks) {
const localEid = getEidForNetworkName(localNetwork)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import {
getDefaultExecutorConfig,
getDefaultUlnConfig,
setupDefaultEndpoint,
} from '../__utils__/endpoint'
} from '../../__utils__/endpoint'
import { createContractFactory, getEidForNetworkName } from '@layerzerolabs/devtools-evm-hardhat'
import hre from 'hardhat'
import { AddressZero } from '@ethersproject/constants'
import { TASK_LZ_GET_OAPP_CONFIG } from '@layerzerolabs/ua-devtools-evm-hardhat'
import { TASK_LZ_OAPP_CONFIG_GET } from '@layerzerolabs/ua-devtools-evm-hardhat'
import { omniContractToPoint } from '@layerzerolabs/devtools-evm'

describe('task: getOAppConfig', () => {
describe(`task ${TASK_LZ_OAPP_CONFIG_GET}`, () => {
beforeEach(async () => {
await deployEndpointFixture()
await setupDefaultEndpoint()
Expand All @@ -19,7 +19,7 @@ describe('task: getOAppConfig', () => {
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).toString()
const getDefaultConfigTask = await hre.run(TASK_LZ_GET_OAPP_CONFIG, {
const getDefaultConfigTask = await hre.run(TASK_LZ_OAPP_CONFIG_GET, {
networks: networks.toString(),
addresses: addresses.toString(),
})
Expand Down
Loading

0 comments on commit 9bf8f60

Please sign in to comment.