diff --git a/contracts/DiamondDao.sol b/contracts/DiamondDao.sol index 4bc3615..b60c4d9 100644 --- a/contracts/DiamondDao.sol +++ b/contracts/DiamondDao.sol @@ -563,9 +563,7 @@ contract DiamondDao is IDiamondDao, Initializable, ReentrancyGuardUpgradeable, V } function _isValidator(address stakingAddress) private view returns (bool) { - address miningAddress = validatorSet.miningByStakingAddress(stakingAddress); - - return validatorSet.isValidatorOrPending(miningAddress) && !validatorSet.isValidatorBanned(miningAddress); + return stakingHbbft.isPoolValid(stakingAddress); } /** diff --git a/contracts/interfaces/IStakingHbbft.sol b/contracts/interfaces/IStakingHbbft.sol index 2b56746..822b6a1 100644 --- a/contracts/interfaces/IStakingHbbft.sol +++ b/contracts/interfaces/IStakingHbbft.sol @@ -4,4 +4,5 @@ pragma solidity =0.8.25; interface IStakingHbbft { function stakeAmountTotal(address) external view returns (uint256); function totalStakedAmount() external view returns (uint256); + function isPoolValid(address) external view returns (bool); } diff --git a/contracts/interfaces/IValidatorSetHbbft.sol b/contracts/interfaces/IValidatorSetHbbft.sol index 92c9b81..b64aa24 100644 --- a/contracts/interfaces/IValidatorSetHbbft.sol +++ b/contracts/interfaces/IValidatorSetHbbft.sol @@ -4,8 +4,6 @@ pragma solidity =0.8.25; interface IValidatorSetHbbft { function isValidator(address) external view returns (bool); - function isValidatorBanned(address) external view returns (bool); - function isValidatorOrPending(address) external view returns (bool); function miningByStakingAddress(address) external view returns (address); diff --git a/contracts/mocks/MockStakingHbbft.sol b/contracts/mocks/MockStakingHbbft.sol index 51c7e5d..68ea74e 100644 --- a/contracts/mocks/MockStakingHbbft.sol +++ b/contracts/mocks/MockStakingHbbft.sol @@ -2,8 +2,10 @@ pragma solidity =0.8.25; import { IStakingHbbft } from "../interfaces/IStakingHbbft.sol"; +import { IValidatorSetHbbft } from "../interfaces/IValidatorSetHbbft.sol"; contract MockStakingHbbft is IStakingHbbft { + IValidatorSetHbbft public validatorSet; uint256 public totalStakedAmount; uint256 public delegatorMinStake = 100 ether; mapping(address => uint256) private _stakeAmountTotal; @@ -44,7 +46,9 @@ contract MockStakingHbbft is IStakingHbbft { _; } - constructor() {} + constructor(address _vs) { + validatorSet = IValidatorSetHbbft(_vs); + } function setStake(address staking, uint256 stakeAmount) external { _stakeAmountTotal[staking] = stakeAmount; @@ -129,4 +133,9 @@ contract MockStakingHbbft is IStakingHbbft { function getAllowedParamsRangeWithSelector(bytes4 _selector) external view returns (ParameterRange memory) { return allowedParameterRange[_selector]; } + + function isPoolValid(address _stakingAddress) public view returns (bool) { + address miningAddress = validatorSet.miningByStakingAddress(_stakingAddress); + return validatorSet.isValidator(miningAddress); + } } diff --git a/contracts/mocks/MockValidatorSetHbbft.sol b/contracts/mocks/MockValidatorSetHbbft.sol index cbe6252..ea10998 100644 --- a/contracts/mocks/MockValidatorSetHbbft.sol +++ b/contracts/mocks/MockValidatorSetHbbft.sol @@ -7,7 +7,6 @@ contract MockValidatorSetHbbft is IValidatorSetHbbft { mapping(address => address) private _stakingToMining; mapping(address => bool) private _isValidator; mapping(address => bool) private _availability; - mapping(address => uint256) public bannedUntil; receive() external payable { revert(); @@ -21,10 +20,6 @@ contract MockValidatorSetHbbft is IValidatorSetHbbft { _availability[mining] = available; } - function addBanned(address _miningAddress, uint256 _bannedUntil) external { - bannedUntil[_miningAddress] = _bannedUntil; - } - function remove(address staking) external { address mining = _stakingToMining[staking]; @@ -51,10 +46,6 @@ contract MockValidatorSetHbbft is IValidatorSetHbbft { return _availability[mining] ? block.number : 0; } - function isValidatorBanned(address _miningAddress) public view returns (bool) { - return block.timestamp <= bannedUntil[_miningAddress]; - } - function isValidatorOrPending(address _miningAddress) public view returns (bool) { return _isValidator[_miningAddress]; } diff --git a/test/DiamondDao.spec.ts b/test/DiamondDao.spec.ts index 1124716..61b0bfc 100644 --- a/test/DiamondDao.spec.ts +++ b/test/DiamondDao.spec.ts @@ -54,7 +54,7 @@ describe("DiamondDao contract", function () { const mockValidatorSet = await mockFactory.deploy(); await mockValidatorSet.waitForDeployment(); - const mockStaking = await stakingFactory.deploy(); + const mockStaking = await stakingFactory.deploy(await mockValidatorSet.getAddress()); await mockStaking.waitForDeployment(); const startTime = await time.latest(); @@ -762,16 +762,14 @@ describe("DiamondDao contract", function () { .withArgs(voter.address); }); - it("should revert vote by banned validator", async function () { - const { dao, mockValidatorSet } = await loadFixture(deployFixture); + it("should revert vote by inactive validator", async function () { + const { dao } = await loadFixture(deployFixture); const proposer = users[10]; const voter = users[9]; const { proposalId } = await createProposal(dao, proposer, "a"); - await mockValidatorSet.add(voter.address, voter.address, false); - await mockValidatorSet.addBanned(voter.address, Math.floor(new Date().getTime() / 1000) + 1000000); await swithPhase(dao); await expect( diff --git a/test/ProposalExecution.spec.ts b/test/ProposalExecution.spec.ts index 23f27be..cb2afa7 100644 --- a/test/ProposalExecution.spec.ts +++ b/test/ProposalExecution.spec.ts @@ -42,7 +42,7 @@ describe("DAO proposal execution", function () { const mockValidatorSet = await mockFactory.deploy(); await mockValidatorSet.waitForDeployment(); - const mockStaking = await stakingFactory.deploy(); + const mockStaking = await stakingFactory.deploy(await mockValidatorSet.getAddress()); await mockStaking.waitForDeployment(); const startTime = await time.latest(); diff --git a/test/ProposalFinalization.spec.ts b/test/ProposalFinalization.spec.ts index 7409a8d..a4ac30d 100644 --- a/test/ProposalFinalization.spec.ts +++ b/test/ProposalFinalization.spec.ts @@ -56,7 +56,7 @@ describe("Proposal Acceptance Threshold", function () { const mockValidatorSet = await mockFactory.deploy(); await mockValidatorSet.waitForDeployment(); - const mockStaking = await stakingFactory.deploy(); + const mockStaking = await stakingFactory.deploy(await mockValidatorSet.getAddress()); await mockStaking.waitForDeployment(); const startTime = await time.latest(); diff --git a/test/ProposalValueGuards.spec.ts b/test/ProposalValueGuards.spec.ts index a8e6c2a..3e38014 100644 --- a/test/ProposalValueGuards.spec.ts +++ b/test/ProposalValueGuards.spec.ts @@ -47,7 +47,7 @@ describe("DAO Ecosystem Paramater Change Value Guards Test", function () { const mockValidatorSet = await mockFactory.deploy(); await mockValidatorSet.waitForDeployment(); - const mockStaking = await stakingFactory.deploy(); + const mockStaking = await stakingFactory.deploy(await mockValidatorSet.getAddress()); await mockStaking.waitForDeployment(); const startTime = await time.latest();