Skip to content

Commit

Permalink
fix(pg): support upgrades using the hardhat test command
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-goldman committed Nov 23, 2022
1 parent a1ae30f commit 9e48bbf
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 30 deletions.
5 changes: 5 additions & 0 deletions .changeset/orange-pumas-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@chugsplash/plugins': patch
---

Support upgrades with the hardhat test command
1 change: 0 additions & 1 deletion packages/plugins/src/hardhat/deployments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ export const deployChugSplashConfig = async (
{
configPath,
silent: true,
remoteExecution,
amount: executionAmountPlusBuffer,
skipMonitorStatus: true,
},
Expand Down
14 changes: 10 additions & 4 deletions packages/plugins/src/hardhat/execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import {
import { HardhatRuntimeEnvironment } from 'hardhat/types'
import { ethers } from 'ethers'
import { ChugSplashManagerABI } from '@chugsplash/contracts'
import { sleep } from '@eth-optimism/core-utils'
import { getChainId, sleep } from '@eth-optimism/core-utils'

import { getFinalDeploymentTxnHash } from './deployments'
import { writeHardhatSnapshotId } from './utils'

export const monitorRemoteExecution = async (
hre: HardhatRuntimeEnvironment,
Expand Down Expand Up @@ -106,10 +107,10 @@ npx hardhat chugsplash-fund --network ${hre.network.name} --amount ${estCost} <c
* @param parsedConfig Parsed ChugSplashConfig.
*/
export const postExecutionActions = async (
provider: ethers.providers.JsonRpcProvider,
hre: HardhatRuntimeEnvironment,
parsedConfig: ChugSplashConfig
) => {
const signer = provider.getSigner()
const signer = hre.ethers.provider.getSigner()
const ChugSplashManager = getChugSplashManager(
signer,
parsedConfig.options.projectName
Expand All @@ -123,7 +124,7 @@ export const postExecutionActions = async (

// Withdraw any of the current project owner's funds in the ChugSplashManager.
const ownerFunds = await getOwnerBalanceInChugSplashManager(
provider,
hre.ethers.provider,
parsedConfig.options.projectName
)
if (ownerFunds.gt(0)) {
Expand All @@ -144,4 +145,9 @@ export const postExecutionActions = async (
).wait()
}
}

// Save the snapshot ID if we're on the hardhat network.
if ((await getChainId(hre.ethers.provider)) === 31337) {
await writeHardhatSnapshotId(hre)
}
}
44 changes: 22 additions & 22 deletions packages/plugins/src/hardhat/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,14 +390,12 @@ export const chugsplashApproveTask = async (
args: {
configPath: string
silent: boolean
remoteExecution: boolean
amount: ethers.BigNumber
skipMonitorStatus: boolean
},
hre: HardhatRuntimeEnvironment
) => {
const { configPath, silent, remoteExecution, amount, skipMonitorStatus } =
args
const { configPath, silent, amount, skipMonitorStatus } = args

const provider = hre.ethers.provider
const signer = provider.getSigner()
Expand Down Expand Up @@ -469,14 +467,14 @@ Please wait a couple minutes then try again.`
await (await ChugSplashManager.approveChugSplashBundle(bundleId)).wait()
spinner.succeed(`Project approved on ${hre.network.name}.`)

if (remoteExecution && !skipMonitorStatus) {
if (!skipMonitorStatus) {
spinner.start('The deployment is being executed. This may take a moment.')
const finalDeploymentTxnHash = await monitorRemoteExecution(
hre,
parsedConfig,
bundleId
)
await postExecutionActions(provider, parsedConfig)
await postExecutionActions(hre, parsedConfig)
await createDeploymentArtifacts(hre, parsedConfig, finalDeploymentTxnHash)
displayDeploymentTable(parsedConfig, silent)
spinner.succeed(
Expand Down Expand Up @@ -883,25 +881,27 @@ project with a name other than ${parsedConfig.options.projectName}`
spinner.start(
'The deployment is currently being executed. This may take a moment.'
)
}

const finalDeploymentTxnHash = await monitorRemoteExecution(
hre,
parsedConfig,
bundleId
)
await postExecutionActions(provider, parsedConfig)
await createDeploymentArtifacts(hre, parsedConfig, finalDeploymentTxnHash)
// If we make it to this point, the bundle status is either completed or approved.

bundleState.status === ChugSplashBundleStatus.APPROVED
? spinner.succeed(
`${parsedConfig.options.projectName} successfully deployed on ${hre.network.name}.`
)
: spinner.succeed(
`${parsedConfig.options.projectName} was already deployed on ${hre.network.name}.`
)
const finalDeploymentTxnHash = await monitorRemoteExecution(
hre,
parsedConfig,
bundleId
)
await postExecutionActions(hre, parsedConfig)
await createDeploymentArtifacts(hre, parsedConfig, finalDeploymentTxnHash)

displayDeploymentTable(parsedConfig, silent)
}
bundleState.status === ChugSplashBundleStatus.APPROVED
? spinner.succeed(
`${parsedConfig.options.projectName} successfully deployed on ${hre.network.name}.`
)
: spinner.succeed(
`${parsedConfig.options.projectName} was already deployed on ${hre.network.name}.`
)

displayDeploymentTable(parsedConfig, silent)
}

task(TASK_CHUGSPLASH_MONITOR)
Expand Down Expand Up @@ -1012,7 +1012,7 @@ task(TASK_NODE)
}
await deployAllChugSplashConfigs(hre, hide, '', true, spinner)
}
await writeHardhatSnapshotId(hre)
await writeHardhatSnapshotId(hre, 'localhost')
}
await runSuper(args)
}
Expand Down
10 changes: 7 additions & 3 deletions packages/plugins/src/hardhat/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ import {
import { TASK_COMPILE, TASK_CLEAN } from 'hardhat/builtin-tasks/task-names'
import { Signer } from 'ethers'

export const writeHardhatSnapshotId = async (hre: any) => {
const networkName = hre.network.name === 'localhost' ? 'localhost' : 'hardhat'
export const writeHardhatSnapshotId = async (
hre: any,
networkName?: string
) => {
const inferredNetworkName =
hre.network.name === 'localhost' ? 'localhost' : 'hardhat'
await writeSnapshotId(
networkName,
networkName === undefined ? inferredNetworkName : networkName,
hre.config.paths.deployed,
await hre.network.provider.send('evm_snapshot', [])
)
Expand Down

0 comments on commit 9e48bbf

Please sign in to comment.