Skip to content

Commit

Permalink
check for invalid ValidatorManager in initialize
Browse files Browse the repository at this point in the history
  • Loading branch information
cam-schultz committed Jan 29, 2025
1 parent e7e7af0 commit 12329fe
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 1 deletion.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions contracts/validator-manager/PoAValidatorManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ contract PoAValidatorManager is IPoAValidatorManager, OwnableUpgradeable {
internal
onlyInitializing
{
// Ensure the manager is valid by calling it
manager.getChurnPeriodSeconds();

PoAValidatorManagerStorage storage $ = _getPoAValidatorManagerStorage();
$._manager = manager;
}

Check warning

Code scanning / Slither

Unused return Medium

Check warning

Code scanning / Slither

Conformance to Solidity naming conventions Warning

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,14 @@ contract ERC20TokenStakingManagerTest is PoSValidatorManagerTest {
app.initialize(defaultPoSSettings, token);
}

function testInvalidValidatorManager() public {
app = new ERC20TokenStakingManager(ICMInitializable.Allowed);
vm.expectRevert();

// PoSValidatorManagerSettings.manager is not set
app.initialize(_defaultPoSSettings(), token);
}

function testInvalidValidatorMinStakeDuration() public {
uint256 stakeAmount = _weightToValue(DEFAULT_WEIGHT);
vm.expectRevert(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ contract NativeTokenStakingManagerTest is PoSValidatorManagerTest {
app.initialize(defaultPoSSettings);
}

function testInvalidValidatorManager() public {
app = new NativeTokenStakingManager(ICMInitializable.Allowed);
vm.expectRevert();

// PoSValidatorManagerSettings.manager is not set
app.initialize(_defaultPoSSettings());
}

// Helpers
function _initiateValidatorRegistration(
bytes memory nodeID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ contract PoAValidatorManagerTest is ValidatorManagerTest {
app.initialize(validatorManager, address(this));
}

function testInvalidValidatorManager() public {
app = new PoAValidatorManager(ICMInitializable.Allowed);
vm.expectRevert();

app.initialize(ValidatorManager(address(0)), address(this));
}

function testInvalidOwnerRegistration() public {
vm.prank(vm.addr(1));
vm.expectRevert(
Expand Down

0 comments on commit 12329fe

Please sign in to comment.