Skip to content

Commit

Permalink
add initializer tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Lam committed Sep 9, 2024
1 parent 612b626 commit 299d3a4
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 3 deletions.
4 changes: 1 addition & 3 deletions contracts/validatormanager/PoSValidatorManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,7 @@ abstract contract PoSValidatorManager is IPoSValidatorManager, ValidatorManager
minimumStakeAmount <= maximumStakeAmount,
"PoSValidatorManager: invalid stake amount range"
);
require(
maximumStakeMultiplier > 0, "PoSValidatorManager: zero max validator stake multiplier"
);
require(maximumStakeMultiplier > 0, "PoSValidatorManager: zero maximum stake multiplier");

$._minimumStakeAmount = minimumStakeAmount;
$._maximumStakeAmount = maximumStakeAmount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,69 @@ contract ERC20TokenStakingManagerTest is PoSValidatorManagerTest {
posValidatorManager = app;
}

function testZeroDelegationFee() public {
app = new ERC20TokenStakingManager(ICMInitializable.Allowed);
vm.expectRevert("PoSValidatorManager: zero delegation fee");
app.initialize(
PoSValidatorManagerSettings({
baseSettings: ValidatorManagerSettings({
pChainBlockchainID: P_CHAIN_BLOCKCHAIN_ID,
subnetID: DEFAULT_SUBNET_ID,
maximumHourlyChurn: DEFAULT_MAXIMUM_HOURLY_CHURN
}),
minimumStakeAmount: DEFAULT_MINIMUM_STAKE,
maximumStakeAmount: DEFAULT_MAXIMUM_STAKE,
minimumStakeDuration: DEFAULT_MINIMUM_STAKE_DURATION,
minimumDelegationFee: 0,
maximumStakeMultiplier: DEFAULT_MAXIMUM_STAKE_MULTIPLIER,
rewardCalculator: IRewardCalculator(address(0))
}),
token
);
}

function testInvalidStakeAmountRange() public {
app = new ERC20TokenStakingManager(ICMInitializable.Allowed);
vm.expectRevert("PoSValidatorManager: invalid stake amount range");
app.initialize(
PoSValidatorManagerSettings({
baseSettings: ValidatorManagerSettings({
pChainBlockchainID: P_CHAIN_BLOCKCHAIN_ID,
subnetID: DEFAULT_SUBNET_ID,
maximumHourlyChurn: DEFAULT_MAXIMUM_HOURLY_CHURN
}),
minimumStakeAmount: DEFAULT_MAXIMUM_STAKE,
maximumStakeAmount: DEFAULT_MINIMUM_STAKE,
minimumStakeDuration: DEFAULT_MINIMUM_STAKE_DURATION,
minimumDelegationFee: DEFAULT_MINIMUM_DELEGATION_FEE,
maximumStakeMultiplier: DEFAULT_MAXIMUM_STAKE_MULTIPLIER,
rewardCalculator: IRewardCalculator(address(0))
}),
token
);
}

function testZeroMaxStakeMultiplier() public {
app = new ERC20TokenStakingManager(ICMInitializable.Allowed);
vm.expectRevert("PoSValidatorManager: zero maximum stake multiplier");
app.initialize(
PoSValidatorManagerSettings({
baseSettings: ValidatorManagerSettings({
pChainBlockchainID: P_CHAIN_BLOCKCHAIN_ID,
subnetID: DEFAULT_SUBNET_ID,
maximumHourlyChurn: DEFAULT_MAXIMUM_HOURLY_CHURN
}),
minimumStakeAmount: DEFAULT_MINIMUM_STAKE,
maximumStakeAmount: DEFAULT_MAXIMUM_STAKE,
minimumStakeDuration: DEFAULT_MINIMUM_STAKE_DURATION,
minimumDelegationFee: DEFAULT_MINIMUM_DELEGATION_FEE,
maximumStakeMultiplier: 0,
rewardCalculator: IRewardCalculator(address(0))
}),
token
);
}

function _initializeValidatorRegistration(
ValidatorRegistrationInput memory input,
uint64 weight
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,66 @@ contract NativeTokenStakingManagerTest is PoSValidatorManagerTest {
posValidatorManager = app;
}

function testZeroDelegationFee() public {
app = new NativeTokenStakingManager(ICMInitializable.Allowed);
vm.expectRevert("PoSValidatorManager: zero delegation fee");
app.initialize(
PoSValidatorManagerSettings({
baseSettings: ValidatorManagerSettings({
pChainBlockchainID: P_CHAIN_BLOCKCHAIN_ID,
subnetID: DEFAULT_SUBNET_ID,
maximumHourlyChurn: DEFAULT_MAXIMUM_HOURLY_CHURN
}),
minimumStakeAmount: DEFAULT_MINIMUM_STAKE,
maximumStakeAmount: DEFAULT_MAXIMUM_STAKE,
minimumStakeDuration: DEFAULT_MINIMUM_STAKE_DURATION,
minimumDelegationFee: 0,
maximumStakeMultiplier: DEFAULT_MAXIMUM_STAKE_MULTIPLIER,
rewardCalculator: IRewardCalculator(address(0))
})
);
}

function testInvalidStakeAmountRange() public {
app = new NativeTokenStakingManager(ICMInitializable.Allowed);
vm.expectRevert("PoSValidatorManager: invalid stake amount range");
app.initialize(
PoSValidatorManagerSettings({
baseSettings: ValidatorManagerSettings({
pChainBlockchainID: P_CHAIN_BLOCKCHAIN_ID,
subnetID: DEFAULT_SUBNET_ID,
maximumHourlyChurn: DEFAULT_MAXIMUM_HOURLY_CHURN
}),
minimumStakeAmount: DEFAULT_MAXIMUM_STAKE,
maximumStakeAmount: DEFAULT_MINIMUM_STAKE,
minimumStakeDuration: DEFAULT_MINIMUM_STAKE_DURATION,
minimumDelegationFee: DEFAULT_MINIMUM_DELEGATION_FEE,
maximumStakeMultiplier: DEFAULT_MAXIMUM_STAKE_MULTIPLIER,
rewardCalculator: IRewardCalculator(address(0))
})
);
}

function testZeroMaxStakeMultiplier() public {
app = new NativeTokenStakingManager(ICMInitializable.Allowed);
vm.expectRevert("PoSValidatorManager: zero maximum stake multiplier");
app.initialize(
PoSValidatorManagerSettings({
baseSettings: ValidatorManagerSettings({
pChainBlockchainID: P_CHAIN_BLOCKCHAIN_ID,
subnetID: DEFAULT_SUBNET_ID,
maximumHourlyChurn: DEFAULT_MAXIMUM_HOURLY_CHURN
}),
minimumStakeAmount: DEFAULT_MINIMUM_STAKE,
maximumStakeAmount: DEFAULT_MAXIMUM_STAKE,
minimumStakeDuration: DEFAULT_MINIMUM_STAKE_DURATION,
minimumDelegationFee: DEFAULT_MINIMUM_DELEGATION_FEE,
maximumStakeMultiplier: 0,
rewardCalculator: IRewardCalculator(address(0))
})
);
}

// Helpers
function _initializeValidatorRegistration(
ValidatorRegistrationInput memory input,
Expand Down

0 comments on commit 299d3a4

Please sign in to comment.