From 427ef8875fe940b06b71631ea9ae1db8d63c37a3 Mon Sep 17 00:00:00 2001 From: Shahul Hameed <10547529+shahthepro@users.noreply.github.com> Date: Wed, 22 May 2024 16:34:31 +0530 Subject: [PATCH] Deploy only once for fork tests --- .gitignore | 2 +- script/deploy/DeployManager.sol | 6 +++++- tests/governance/XOGNGovernanceForkTest.t.sol | 4 +++- tests/staking/MigratorForkTest.t.sol | 4 +++- tests/staking/OGNRewardsSourceForkTest.t.sol | 4 +++- tests/staking/XOGNStakingForkTest.t..sol | 4 +++- 6 files changed, 18 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 5da01a55..e9064c85 100644 --- a/.gitignore +++ b/.gitignore @@ -16,5 +16,5 @@ out/ .vscode brownie-deploy/ .idea -deployments-fork.json +deployments-fork*.json broadcast/* \ No newline at end of file diff --git a/script/deploy/DeployManager.sol b/script/deploy/DeployManager.sol index fdb90ee0..00c31adc 100644 --- a/script/deploy/DeployManager.sol +++ b/script/deploy/DeployManager.sol @@ -14,6 +14,8 @@ contract DeployManager is Script { mapping(string => address) public deployedContracts; mapping(string => bool) public scriptsExecuted; + string internal forkFileId = ""; + function isForked() public view returns (bool) { return vm.isContext(VmSafe.ForgeContext.ScriptDryRun) || vm.isContext(VmSafe.ForgeContext.Test) || vm.isContext(VmSafe.ForgeContext.TestGroup); @@ -28,10 +30,12 @@ contract DeployManager is Script { } function getForkDeploymentFilePath() public view returns (string memory) { - return string(abi.encodePacked(vm.projectRoot(), "/build/deployments-fork.json")); + return string(abi.encodePacked(vm.projectRoot(), "/build/deployments-fork-", forkFileId, ".json")); } function setUp() external { + forkFileId = Strings.toString(block.timestamp); + string memory chainIdStr = Strings.toString(block.chainid); string memory chainIdKey = string(abi.encodePacked(".", chainIdStr)); diff --git a/tests/governance/XOGNGovernanceForkTest.t.sol b/tests/governance/XOGNGovernanceForkTest.t.sol index 5d4b43cf..dca93607 100644 --- a/tests/governance/XOGNGovernanceForkTest.t.sol +++ b/tests/governance/XOGNGovernanceForkTest.t.sol @@ -32,12 +32,14 @@ contract XOGNGovernanceForkTest is Test { int256 constant NEW_STAKE = -1; - function setUp() external { + constructor() { deployManager = new DeployManager(); deployManager.setUp(); deployManager.run(); + } + function setUp() external { xogn = ExponentialStaking(deployManager.getDeployment("XOGN")); timelock = Timelock(payable(Addresses.TIMELOCK)); xognGov = Governance(payable(deployManager.getDeployment("XOGN_GOV"))); diff --git a/tests/staking/MigratorForkTest.t.sol b/tests/staking/MigratorForkTest.t.sol index 2a310896..b6c8fb6b 100644 --- a/tests/staking/MigratorForkTest.t.sol +++ b/tests/staking/MigratorForkTest.t.sol @@ -24,12 +24,14 @@ contract MigratorForkTest is Test { address public ogvWhale = Addresses.GOV_MULTISIG; - function setUp() external { + constructor() { deployManager = new DeployManager(); deployManager.setUp(); deployManager.run(); + } + function setUp() external { migrator = Migrator(deployManager.getDeployment("MIGRATOR")); veogv = OgvStaking(Addresses.VEOGV); diff --git a/tests/staking/OGNRewardsSourceForkTest.t.sol b/tests/staking/OGNRewardsSourceForkTest.t.sol index f066f340..0578fab0 100644 --- a/tests/staking/OGNRewardsSourceForkTest.t.sol +++ b/tests/staking/OGNRewardsSourceForkTest.t.sol @@ -31,12 +31,14 @@ contract OGNRewardsSourceForkTest is Test { int256 constant NEW_STAKE = -1; - function setUp() external { + constructor() { deployManager = new DeployManager(); deployManager.setUp(); deployManager.run(); + } + function setUp() external { xogn = ExponentialStaking(deployManager.getDeployment("XOGN")); timelock = Timelock(payable(Addresses.TIMELOCK)); xognGov = Governance(payable(deployManager.getDeployment("XOGN_GOV"))); diff --git a/tests/staking/XOGNStakingForkTest.t..sol b/tests/staking/XOGNStakingForkTest.t..sol index f9d84e7a..db1a188c 100644 --- a/tests/staking/XOGNStakingForkTest.t..sol +++ b/tests/staking/XOGNStakingForkTest.t..sol @@ -32,12 +32,14 @@ contract XOGNStakingForkTest is Test { int256 constant NEW_STAKE = -1; - function setUp() external { + constructor() { deployManager = new DeployManager(); deployManager.setUp(); deployManager.run(); + } + function setUp() external { xogn = ExponentialStaking(deployManager.getDeployment("XOGN")); timelock = Timelock(payable(Addresses.TIMELOCK)); xognGov = Governance(payable(deployManager.getDeployment("XOGN_GOV")));