From 3963eba29d718c9eec391af594d550e6a724256f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8r=E2=88=82=C2=A1?= Date: Wed, 10 Apr 2024 15:45:30 +0200 Subject: [PATCH] Clean in-memory fork tests --- .../contracts/deploy/01_repo/10_create_repo.ts | 15 +++++++++++---- packages/contracts/deploy/02_setup/10_setup.ts | 10 +++++++--- .../10_install_mgmt_dao_plugins.ts | 3 +++ .../11_drop_deployer_permission.ts | 3 +++ .../deploy/99_verification/10_verify-contracts.ts | 7 ++----- .../deploy/99_verification/20_mgmt_dao_plugin.ts | 3 +++ .../deploy/99_verification/21_mgmt_dao_root.ts | 3 +++ packages/contracts/utils/hardhat.ts | 3 +++ 8 files changed, 35 insertions(+), 12 deletions(-) create mode 100644 packages/contracts/utils/hardhat.ts diff --git a/packages/contracts/deploy/01_repo/10_create_repo.ts b/packages/contracts/deploy/01_repo/10_create_repo.ts index dc2731f..ea43646 100644 --- a/packages/contracts/deploy/01_repo/10_create_repo.ts +++ b/packages/contracts/deploy/01_repo/10_create_repo.ts @@ -3,6 +3,7 @@ import { PersonalSpaceAdminPluginSetupParams, SpacePluginSetupParams, } from '../../plugin-setup-params'; +import {isLocalChain} from '../../utils/hardhat'; import { findEventTopicLog, getPluginRepoFactoryAddress, @@ -33,19 +34,25 @@ async function deployRepo( const {network} = hre; let pluginRepoFactoryAddr: string; - if (!process.env.PLUGIN_REPO_FACTORY_ADDRESS) { + if ( + process.env.PLUGIN_REPO_FACTORY_ADDRESS && + !isLocalChain(hre.network.name) + ) { + // Use the given value when deploying to a live network + pluginRepoFactoryAddr = process.env.PLUGIN_REPO_FACTORY_ADDRESS; + } else { + // Use the well-known OSx addresses when in test/fork mode pluginRepoFactoryAddr = getPluginRepoFactoryAddress(network.name); - if (!pluginRepoFactoryAddr) + if (!pluginRepoFactoryAddr) { throw new Error( 'PLUGIN_REPO_FACTORY_ADDRESS is empty and no default value is available for ' + network.name ); + } console.log( 'Using the default Plugin Repo Factory address (PLUGIN_REPO_FACTORY_ADDRESS is empty)' ); - } else { - pluginRepoFactoryAddr = process.env.PLUGIN_REPO_FACTORY_ADDRESS; } console.log(`\nDeploying the "${ensSubdomain}" plugin repo`); diff --git a/packages/contracts/deploy/02_setup/10_setup.ts b/packages/contracts/deploy/02_setup/10_setup.ts index d45e48f..b3d84c9 100644 --- a/packages/contracts/deploy/02_setup/10_setup.ts +++ b/packages/contracts/deploy/02_setup/10_setup.ts @@ -3,6 +3,7 @@ import { PersonalSpaceAdminPluginSetupParams, SpacePluginSetupParams, } from '../../plugin-setup-params'; +import {isLocalChain} from '../../utils/hardhat'; import {getPluginSetupProcessorAddress} from '../../utils/helpers'; import {DeployFunction} from 'hardhat-deploy/types'; import {HardhatRuntimeEnvironment} from 'hardhat/types'; @@ -13,7 +14,12 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { const {deployer} = await getNamedAccounts(); let pspAddress: string; - if (!process.env.PLUGIN_SETUP_PROCESSOR_ADDRESS) { + if ( + process.env.PLUGIN_SETUP_PROCESSOR_ADDRESS && + !isLocalChain(hre.network.name) + ) { + pspAddress = process.env.PLUGIN_SETUP_PROCESSOR_ADDRESS; + } else { pspAddress = getPluginSetupProcessorAddress(network.name); if (!pspAddress) throw new Error( @@ -24,8 +30,6 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { console.log( 'Using the default Plugin Setup Processor address (PLUGIN_SETUP_PROCESSOR_ADDRESS is empty)' ); - } else { - pspAddress = process.env.PLUGIN_SETUP_PROCESSOR_ADDRESS; } // Space Setup diff --git a/packages/contracts/deploy/03_managing_dao/10_install_mgmt_dao_plugins.ts b/packages/contracts/deploy/03_managing_dao/10_install_mgmt_dao_plugins.ts index 471a664..58acbe0 100644 --- a/packages/contracts/deploy/03_managing_dao/10_install_mgmt_dao_plugins.ts +++ b/packages/contracts/deploy/03_managing_dao/10_install_mgmt_dao_plugins.ts @@ -8,6 +8,7 @@ import { InstallationPreparedEvent, PluginSetupRefStruct, } from '../../typechain/@aragon/osx/framework/plugin/setup/PluginSetupProcessor'; +import {isLocalChain} from '../../utils/hardhat'; import {findEvent, hashHelpers} from '../../utils/helpers'; import {getPluginRepoInfo} from '../../utils/plugin-repo-info'; import {IDAO, IDAO__factory, PluginSetupProcessor} from '@aragon/osx-ethers'; @@ -140,3 +141,5 @@ func.tags = [ GovernancePluginsSetupParams.PLUGIN_SETUP_CONTRACT_NAME, 'ManagingDAO', ]; +func.skip = (hre: HardhatRuntimeEnvironment) => + Promise.resolve(isLocalChain(hre.network.name)); diff --git a/packages/contracts/deploy/03_managing_dao/11_drop_deployer_permission.ts b/packages/contracts/deploy/03_managing_dao/11_drop_deployer_permission.ts index f2ca834..416d91c 100644 --- a/packages/contracts/deploy/03_managing_dao/11_drop_deployer_permission.ts +++ b/packages/contracts/deploy/03_managing_dao/11_drop_deployer_permission.ts @@ -1,3 +1,4 @@ +import {isLocalChain} from '../../utils/hardhat'; import {DAO__factory, IDAO} from '@aragon/osx-ethers'; import {DeployFunction} from 'hardhat-deploy/types'; import {HardhatRuntimeEnvironment} from 'hardhat/types'; @@ -36,3 +37,5 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { export default func; func.tags = ['ManagingDAO']; +func.skip = (hre: HardhatRuntimeEnvironment) => + Promise.resolve(isLocalChain(hre.network.name)); diff --git a/packages/contracts/deploy/99_verification/10_verify-contracts.ts b/packages/contracts/deploy/99_verification/10_verify-contracts.ts index cd90c05..2aded7c 100644 --- a/packages/contracts/deploy/99_verification/10_verify-contracts.ts +++ b/packages/contracts/deploy/99_verification/10_verify-contracts.ts @@ -1,4 +1,5 @@ import {verifyContract} from '../../utils/etherscan'; +import {isLocalChain} from '../../utils/hardhat'; import {DeployFunction} from 'hardhat-deploy/types'; import {HardhatRuntimeEnvironment} from 'hardhat/types'; @@ -31,8 +32,4 @@ export default func; func.tags = ['Verification']; func.runAtTheEnd = true; func.skip = (hre: HardhatRuntimeEnvironment) => - Promise.resolve( - hre.network.name === 'localhost' || - hre.network.name === 'hardhat' || - hre.network.name === 'coverage' - ); + Promise.resolve(isLocalChain(hre.network.name)); diff --git a/packages/contracts/deploy/99_verification/20_mgmt_dao_plugin.ts b/packages/contracts/deploy/99_verification/20_mgmt_dao_plugin.ts index 9382acb..b207b59 100644 --- a/packages/contracts/deploy/99_verification/20_mgmt_dao_plugin.ts +++ b/packages/contracts/deploy/99_verification/20_mgmt_dao_plugin.ts @@ -1,3 +1,4 @@ +import {isLocalChain} from '../../utils/hardhat'; import {DAO__factory} from '@aragon/osx-ethers'; import {DeployFunction} from 'hardhat-deploy/types'; import {HardhatRuntimeEnvironment} from 'hardhat/types'; @@ -31,3 +32,5 @@ export default func; func.tags = ['Verification']; func.runAtTheEnd = true; +func.skip = (hre: HardhatRuntimeEnvironment) => + Promise.resolve(isLocalChain(hre.network.name)); diff --git a/packages/contracts/deploy/99_verification/21_mgmt_dao_root.ts b/packages/contracts/deploy/99_verification/21_mgmt_dao_root.ts index bdec9f0..02249e6 100644 --- a/packages/contracts/deploy/99_verification/21_mgmt_dao_root.ts +++ b/packages/contracts/deploy/99_verification/21_mgmt_dao_root.ts @@ -1,3 +1,4 @@ +import {isLocalChain} from '../../utils/hardhat'; import {DAO__factory} from '@aragon/osx-ethers'; import {DeployFunction} from 'hardhat-deploy/types'; import {HardhatRuntimeEnvironment} from 'hardhat/types'; @@ -29,3 +30,5 @@ export default func; func.tags = ['Verification']; func.runAtTheEnd = true; +func.skip = (hre: HardhatRuntimeEnvironment) => + Promise.resolve(isLocalChain(hre.network.name)); diff --git a/packages/contracts/utils/hardhat.ts b/packages/contracts/utils/hardhat.ts new file mode 100644 index 0000000..b3c1e91 --- /dev/null +++ b/packages/contracts/utils/hardhat.ts @@ -0,0 +1,3 @@ +export function isLocalChain(networkName: string) { + return ['localhost', 'hardhat', 'coverage'].includes(networkName); +}