Skip to content

Commit

Permalink
test coverage for setValidatorInactivityThreshold()
Browse files Browse the repository at this point in the history
  • Loading branch information
SurfingNerd committed Dec 3, 2023
1 parent f79f9c1 commit 95b045b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion contracts/ValidatorSetHbbft.sol
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ contract ValidatorSetHbbft is Initializable, OwnableUpgradeable, IValidatorSetHb
// if you want smaller values for tests,
// the contract can be deployed with a smaller value
// (no restriction there)
require(_seconds > 604800);
require(_seconds > 604800, "_seconds value must be less then a week.");
validatorInactivityThreshold = _seconds;
}

Expand Down
24 changes: 24 additions & 0 deletions test/ValidatorSetHbbft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1222,6 +1222,30 @@ describe('ValidatorSetHbbft', () => {
}
});
});

describe('setValidatorInactivityThreshold()', async() => {
it('fail on small value', async () => {
const { validatorSetHbbft } = await helpers.loadFixture(deployContractsFixture);

await expect(validatorSetHbbft.setValidatorInactivityThreshold(100)).to.be.revertedWith("_seconds value must be less then a week.");

});

it('correct value is set', async () => {
const { validatorSetHbbft } = await helpers.loadFixture(deployContractsFixture);

let value30Days = 2592000;
await validatorSetHbbft.setValidatorInactivityThreshold(value30Days);
expect(await validatorSetHbbft.validatorInactivityThreshold()).to.be.equal(value30Days);
});

it('only owner should be able to change value', async () => {
const { validatorSetHbbft } = await helpers.loadFixture(deployContractsFixture);
let nobody = (await ethers.getSigners())[42];
let value30Days = 2592000;
await expect(validatorSetHbbft.connect(nobody).setValidatorInactivityThreshold(value30Days)).to.be.revertedWith("Ownable: caller is not the owner");
});
});
});

function convertToBigEndian(number: number): number[] {
Expand Down

0 comments on commit 95b045b

Please sign in to comment.