Skip to content

Commit

Permalink
- removed support that the DAO could be an EOA.
Browse files Browse the repository at this point in the history
- refactored deployment to a helper function.
  • Loading branch information
SurfingNerd committed Jul 23, 2024
1 parent 4f0f579 commit 56f0d14
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 25 deletions.
22 changes: 10 additions & 12 deletions contracts/BlockRewardHbbft.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
17 changes: 4 additions & 13 deletions test/BlockRewardHbbft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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();
Expand Down
18 changes: 18 additions & 0 deletions test/testhelpers/daoDeployment.ts
Original file line number Diff line number Diff line change
@@ -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!,
]);
}

0 comments on commit 56f0d14

Please sign in to comment.