From 56f0d14feee6e763ffa9e843f8adbd59e58c15c0 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 23 Jul 2024 13:56:07 +0200 Subject: [PATCH] - removed support that the DAO could be an EOA. - refactored deployment to a helper function. --- contracts/BlockRewardHbbft.sol | 22 ++++++++++------------ test/BlockRewardHbbft.ts | 17 ++++------------- test/testhelpers/daoDeployment.ts | 18 ++++++++++++++++++ 3 files changed, 32 insertions(+), 25 deletions(-) create mode 100644 test/testhelpers/daoDeployment.ts diff --git a/contracts/BlockRewardHbbft.sol b/contracts/BlockRewardHbbft.sol index 14a5f90..7c57147 100644 --- a/contracts/BlockRewardHbbft.sol +++ b/contracts/BlockRewardHbbft.sol @@ -447,19 +447,17 @@ contract BlockRewardHbbft is // on closing a block, the governance pot is able to execute functions. // those calls are able to fail. // more details: https://github.com/DMDcoin/diamond-contracts-core/issues/231 - if (governancePotAddress.code.length > 0 ) { - IGovernancePot governancePot = IGovernancePot(governancePotAddress); - - // solhint-disable no-empty-blocks - try governancePot.switchPhase() { - // all good - } catch { - // we got an error on switch phase. - // phase switching currently not working in an automated way. - // This is a problem in the DAO, but closing blocks should still work as expected. - } - // solhint-enable no-empty-blocks + IGovernancePot governancePot = IGovernancePot(governancePotAddress); + + // solhint-disable no-empty-blocks + try governancePot.switchPhase() { + // all good, we just wanted to catch. + } catch { + // we got an error on switch phase. + // phase switching currently not working in an automated way. + // This is a problem in the DAO, but closing blocks should still work as expected. } + // solhint-enable no-empty-blocks } function _markRewardedValidators( diff --git a/test/BlockRewardHbbft.ts b/test/BlockRewardHbbft.ts index 830a41e..5388d33 100644 --- a/test/BlockRewardHbbft.ts +++ b/test/BlockRewardHbbft.ts @@ -12,6 +12,7 @@ import { } from "../src/types"; import { getNValidatorsPartNAcks } from "./testhelpers/data"; +import { GovernanceAddress, deployDao } from "./testhelpers/daoDeployment"; // one epoch in 1 day. const STAKING_FIXED_EPOCH_DURATION = 86400n; @@ -25,7 +26,7 @@ const DELEGATOR_MIN_STAKE = ethers.parseEther('100'); const MAX_STAKE = ethers.parseEther('100000'); const SystemAccountAddress = '0xffffFFFfFFffffffffffffffFfFFFfffFFFfFFfE'; -const GovernanceAddress = '0xDA0da0da0Da0Da0Da0DA00DA0da0da0DA0DA0dA0'; + const addToDeltaPotValue = ethers.parseEther('60'); const validatorInactivityThreshold = 365n * 86400n // 1 year @@ -86,18 +87,8 @@ describe('BlockRewardHbbft', () => { // every second deployment we add the DAOMock contract, // so we also cover the possibility that no contract was deployed. - if (contractDeployCounter % 2 == 0) { - // we fake the deployment of a governance contract here. - const DaoMockFactory = await ethers.getContractFactory("DaoMock"); - let deployedDaoMock = await (await DaoMockFactory.deploy()).waitForDeployment(); - let daoMockBytecode = await deployedDaoMock.getDeployedCode(); - - await network.provider.send("hardhat_setCode", [ - GovernanceAddress, - daoMockBytecode!, - ]); - } - + await deployDao(); + const ConnectivityTrackerFactory = await ethers.getContractFactory("ConnectivityTrackerHbbftMock"); const connectivityTrackerContract = await ConnectivityTrackerFactory.deploy(); await connectivityTrackerContract.waitForDeployment(); diff --git a/test/testhelpers/daoDeployment.ts b/test/testhelpers/daoDeployment.ts new file mode 100644 index 0000000..4b7d9b8 --- /dev/null +++ b/test/testhelpers/daoDeployment.ts @@ -0,0 +1,18 @@ +import { ethers, network, upgrades } from "hardhat"; + + +export const GovernanceAddress = '0xDA0da0da0Da0Da0Da0DA00DA0da0da0DA0DA0dA0'; + +/// deploys the DAO Mock on the predefined address `GovernanceAddress`. +export async function deployDao() { + + // we fake the deployment of a governance contract here. + const DaoMockFactory = await ethers.getContractFactory("DaoMock"); + let deployedDaoMock = await (await DaoMockFactory.deploy()).waitForDeployment(); + let daoMockBytecode = await deployedDaoMock.getDeployedCode(); + + await network.provider.send("hardhat_setCode", [ + GovernanceAddress, + daoMockBytecode!, + ]); +} \ No newline at end of file