Skip to content

Commit

Permalink
🗞️ Compile project before running lz:deploy (#354)
Browse files Browse the repository at this point in the history
  • Loading branch information
janjakubnanista authored Feb 6, 2024
1 parent 2007d55 commit 3a438b1
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
7 changes: 7 additions & 0 deletions .changeset/khaki-garlics-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@layerzerolabs/devtools-evm-hardhat-test": patch
"@layerzerolabs/devtools-evm-hardhat": patch
"@layerzerolabs/toolbox-hardhat": patch
---

Compile project before depolying in lz:deploy
20 changes: 14 additions & 6 deletions packages/devtools-evm-hardhat/src/tasks/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { task } from 'hardhat/config'
import type { ActionType } from 'hardhat/types'
import { TASK_COMPILE } from 'hardhat/builtin-tasks/task-names'
import { TASK_LZ_DEPLOY } from '@/constants/tasks'
import {
PromptOption,
Expand Down Expand Up @@ -53,12 +54,10 @@ type NetworkDeployResult =
error: unknown
}

const action: ActionType<TaskArgs> = async ({
networks: networksArgument,
tags: tagsArgument = [],
logLevel = 'info',
ci = false,
}): Promise<DeployResults> => {
const action: ActionType<TaskArgs> = async (
{ networks: networksArgument, tags: tagsArgument = [], logLevel = 'info', ci = false },
hre
): Promise<DeployResults> => {
printLogo()

// Make sure to check that the networks are defined
Expand All @@ -74,6 +73,15 @@ const action: ActionType<TaskArgs> = async ({
const isInteractive = !ci
logger.debug(isInteractive ? 'Running in interactive mode' : 'Running in non-interactive (CI) mode')

// The first thing to do is to ensure that the project is compiled
try {
logger.info(`Compiling you hardhat project`)

await hre.run(TASK_COMPILE)
} catch (error) {
logger.warn(`Failed to compile the project: ${error}`)
}

// We grab a mapping between network names and endpoint IDs
const eidsByNetworks = Object.entries(getEidsByNetworkName())
const configuredNetworkNames = eidsByNetworks.flatMap(([name, eid]) => (eid == null ? [] : [name]))
Expand Down
27 changes: 27 additions & 0 deletions tests/devtools-evm-hardhat-test/test/task/deploy.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/// <reference types="jest-extended" />

import hre from 'hardhat'
import { TASK_COMPILE } from 'hardhat/builtin-tasks/task-names'
import {
TASK_LZ_DEPLOY,
createClearDeployments,
Expand All @@ -23,6 +24,7 @@ jest.mock('@layerzerolabs/io-devtools', () => {
const promptForTextMock = promptForText as jest.Mock
const promptToContinueMock = promptToContinue as jest.Mock
const promptToSelectMultipleMock = promptToSelectMultiple as jest.Mock
const runMock = jest.spyOn(hre, 'run')

describe(`task ${TASK_LZ_DEPLOY}`, () => {
const expectDeployment = expect.objectContaining({
Expand Down Expand Up @@ -57,6 +59,21 @@ describe(`task ${TASK_LZ_DEPLOY}`, () => {
})

describe('in interactive mode', () => {
it('should compile contracts', async () => {
// We want to say no to deployment, just test that the compilation has run
promptToContinueMock.mockResolvedValueOnce(false)
// We want to deploy all files
promptForTextMock.mockResolvedValueOnce('')
// And we want to select two networks
promptToSelectMultipleMock.mockResolvedValueOnce([])

await hre.run(TASK_LZ_DEPLOY, {})

// For some reason even though we did not specify any arguments to the compile task,
// jest still sees some aarguments being passed so we need to pass those to make this expect work
expect(runMock).toHaveBeenCalledWith(TASK_COMPILE, undefined, {}, undefined)
})

it('should ask for networks & tags', async () => {
// We want to say yes to deployment
promptToContinueMock.mockResolvedValueOnce(true)
Expand Down Expand Up @@ -181,6 +198,16 @@ describe(`task ${TASK_LZ_DEPLOY}`, () => {
})

describe('in CI mode', () => {
it('should compile contracts', async () => {
// We want to just check the compilation and not deploy anything
// se we set the networks to an empty array
await hre.run(TASK_LZ_DEPLOY, { ci: true, networks: [] })

// For some reason even though we did not specify any arguments to the compile task,
// jest still sees some aarguments being passed so we need to pass those to make this expect work
expect(runMock).toHaveBeenCalledWith(TASK_COMPILE, undefined, {}, undefined)
})

it('should use all available networks & tags if networks argument is undefined', async () => {
await expect(
hre.run(TASK_LZ_DEPLOY, {
Expand Down

0 comments on commit 3a438b1

Please sign in to comment.