Skip to content

Commit

Permalink
branch coverage: do not always add the DaoMock.
Browse files Browse the repository at this point in the history
  • Loading branch information
SurfingNerd committed Jul 22, 2024
1 parent 69a889c commit 4f0f579
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions test/BlockRewardHbbft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ const GovernanceAddress = '0xDA0da0da0Da0Da0Da0DA00DA0da0da0DA0DA0dA0';
const addToDeltaPotValue = ethers.parseEther('60');
const validatorInactivityThreshold = 365n * 86400n // 1 year

let contractDeployCounter = 0;

describe('BlockRewardHbbft', () => {
let owner: HardhatEthersSigner;
let accounts: HardhatEthersSigner[];
Expand Down Expand Up @@ -80,15 +82,21 @@ describe('BlockRewardHbbft', () => {
async function deployContractsFixture() {
const { parts, acks } = getNValidatorsPartNAcks(initialValidators.length);

// 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!,
]);
contractDeployCounter = contractDeployCounter + 1;

// 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!,
]);
}

const ConnectivityTrackerFactory = await ethers.getContractFactory("ConnectivityTrackerHbbftMock");
const connectivityTrackerContract = await ConnectivityTrackerFactory.deploy();
Expand Down

0 comments on commit 4f0f579

Please sign in to comment.