-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3f289c8
commit 0954c14
Showing
5 changed files
with
113 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,9 @@ import {IERC20Mintable} from "../interfaces/IERC20Mintable.sol"; | |
import {SafeERC20} from "@openzeppelin/[email protected]/token/ERC20/utils/SafeERC20.sol"; | ||
import {Initializable} from "@openzeppelin/[email protected]/proxy/utils/Initializable.sol"; | ||
import {ValidatorManagerTest} from "./ValidatorManagerTests.t.sol"; | ||
import {ACP99Manager, PChainOwner} from "../ACP99Manager.sol"; | ||
import {ACP99Manager, PChainOwner, ConversionData} from "../ACP99Manager.sol"; | ||
import {ValidatorManager} from "../ValidatorManager.sol"; | ||
import {ValidatorMessages} from "../ValidatorMessages.sol"; | ||
|
||
contract ERC20TokenStakingManagerTest is PoSValidatorManagerTest { | ||
using SafeERC20 for IERC20Mintable; | ||
|
@@ -29,14 +31,25 @@ contract ERC20TokenStakingManagerTest is PoSValidatorManagerTest { | |
|
||
_setUp(); | ||
_mockGetBlockchainID(); | ||
_mockInitializeValidatorSet(); | ||
app.initializeValidatorSet(_defaultConversionData(), 0); | ||
|
||
ConversionData memory conversion = _defaultConversionData(); | ||
bytes32 conversionID = sha256(ValidatorMessages.packConversionData(conversion)); | ||
_mockInitializeValidatorSet(conversionID); | ||
validatorManager.initializeValidatorSet(conversion, 0); | ||
} | ||
|
||
// | ||
// Initialization unit tests | ||
// The pattern in these tests requires that only non-admin validator manager functions are called, | ||
// as each test re-deploys the ERC20TokenStakingManager contract. | ||
// | ||
function testDisableInitialization() public { | ||
app = new ERC20TokenStakingManager(ICMInitializable.Disallowed); | ||
vm.expectRevert(abi.encodeWithSelector(Initializable.InvalidInitialization.selector)); | ||
app.initialize(_defaultPoSSettings(), token); | ||
|
||
PoSValidatorManagerSettings memory defaultPoSSettings = _defaultPoSSettings(); | ||
defaultPoSSettings.manager = validatorManager; | ||
app.initialize(defaultPoSSettings, token); | ||
} | ||
|
||
function testZeroTokenAddress() public { | ||
|
@@ -46,7 +59,10 @@ contract ERC20TokenStakingManagerTest is PoSValidatorManagerTest { | |
ERC20TokenStakingManager.InvalidTokenAddress.selector, address(0) | ||
) | ||
); | ||
app.initialize(_defaultPoSSettings(), IERC20Mintable(address(0))); | ||
|
||
PoSValidatorManagerSettings memory defaultPoSSettings = _defaultPoSSettings(); | ||
defaultPoSSettings.manager = validatorManager; | ||
app.initialize(defaultPoSSettings, IERC20Mintable(address(0))); | ||
} | ||
|
||
function testZeroMinimumDelegationFee() public { | ||
|
@@ -56,6 +72,7 @@ contract ERC20TokenStakingManagerTest is PoSValidatorManagerTest { | |
); | ||
|
||
PoSValidatorManagerSettings memory defaultPoSSettings = _defaultPoSSettings(); | ||
defaultPoSSettings.manager = validatorManager; | ||
defaultPoSSettings.minimumDelegationFeeBips = 0; | ||
app.initialize(defaultPoSSettings, token); | ||
} | ||
|
@@ -70,6 +87,7 @@ contract ERC20TokenStakingManagerTest is PoSValidatorManagerTest { | |
); | ||
|
||
PoSValidatorManagerSettings memory defaultPoSSettings = _defaultPoSSettings(); | ||
defaultPoSSettings.manager = validatorManager; | ||
defaultPoSSettings.minimumDelegationFeeBips = minimumDelegationFeeBips; | ||
app.initialize(defaultPoSSettings, token); | ||
} | ||
|
@@ -83,6 +101,7 @@ contract ERC20TokenStakingManagerTest is PoSValidatorManagerTest { | |
); | ||
|
||
PoSValidatorManagerSettings memory defaultPoSSettings = _defaultPoSSettings(); | ||
defaultPoSSettings.manager = validatorManager; | ||
defaultPoSSettings.minimumStakeAmount = DEFAULT_MAXIMUM_STAKE_AMOUNT; | ||
defaultPoSSettings.maximumStakeAmount = DEFAULT_MINIMUM_STAKE_AMOUNT; | ||
app.initialize(defaultPoSSettings, token); | ||
|
@@ -95,6 +114,7 @@ contract ERC20TokenStakingManagerTest is PoSValidatorManagerTest { | |
); | ||
|
||
PoSValidatorManagerSettings memory defaultPoSSettings = _defaultPoSSettings(); | ||
defaultPoSSettings.manager = validatorManager; | ||
defaultPoSSettings.maximumStakeMultiplier = 0; | ||
app.initialize(defaultPoSSettings, token); | ||
} | ||
|
@@ -109,6 +129,7 @@ contract ERC20TokenStakingManagerTest is PoSValidatorManagerTest { | |
); | ||
|
||
PoSValidatorManagerSettings memory defaultPoSSettings = _defaultPoSSettings(); | ||
defaultPoSSettings.manager = validatorManager; | ||
defaultPoSSettings.minimumStakeDuration = minimumStakeDuration; | ||
app.initialize(defaultPoSSettings, token); | ||
} | ||
|
@@ -123,6 +144,7 @@ contract ERC20TokenStakingManagerTest is PoSValidatorManagerTest { | |
); | ||
|
||
PoSValidatorManagerSettings memory defaultPoSSettings = _defaultPoSSettings(); | ||
defaultPoSSettings.manager = validatorManager; | ||
defaultPoSSettings.maximumStakeMultiplier = maximumStakeMultiplier; | ||
app.initialize(defaultPoSSettings, token); | ||
} | ||
|
@@ -134,6 +156,7 @@ contract ERC20TokenStakingManagerTest is PoSValidatorManagerTest { | |
); | ||
|
||
PoSValidatorManagerSettings memory defaultPoSSettings = _defaultPoSSettings(); | ||
defaultPoSSettings.manager = validatorManager; | ||
defaultPoSSettings.weightToValueFactor = 0; | ||
app.initialize(defaultPoSSettings, token); | ||
} | ||
|
@@ -242,15 +265,18 @@ contract ERC20TokenStakingManagerTest is PoSValidatorManagerTest { | |
app = new ERC20TokenStakingManager(ICMInitializable.Allowed); | ||
token = new ExampleERC20(); | ||
rewardCalculator = new ExampleRewardCalculator(DEFAULT_REWARD_RATE); | ||
validatorManager = new ValidatorManager(ICMInitializable.Allowed); | ||
|
||
PoSValidatorManagerSettings memory defaultPoSSettings = _defaultPoSSettings(); | ||
defaultPoSSettings.rewardCalculator = rewardCalculator; | ||
defaultPoSSettings.manager = validatorManager; | ||
|
||
validatorManager.initialize(_defaultSettings(address(app))); | ||
app.initialize(defaultPoSSettings, token); | ||
|
||
validatorManager = app; | ||
posValidatorManager = app; | ||
|
||
return app; | ||
return validatorManager; | ||
} | ||
|
||
function _getStakeAssetBalance(address account) internal view override returns (uint256) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,9 @@ import {INativeMinter} from | |
"@avalabs/[email protected]/contracts/interfaces/INativeMinter.sol"; | ||
import {ValidatorManagerTest} from "./ValidatorManagerTests.t.sol"; | ||
import {Initializable} from "@openzeppelin/[email protected]/proxy/utils/Initializable.sol"; | ||
import {ACP99Manager, PChainOwner} from "../ACP99Manager.sol"; | ||
import {ACP99Manager, PChainOwner, ConversionData} from "../ACP99Manager.sol"; | ||
import {ValidatorManager} from "../ValidatorManager.sol"; | ||
import {ValidatorMessages} from "../ValidatorMessages.sol"; | ||
|
||
contract NativeTokenStakingManagerTest is PoSValidatorManagerTest { | ||
NativeTokenStakingManager public app; | ||
|
@@ -25,15 +27,25 @@ contract NativeTokenStakingManagerTest is PoSValidatorManagerTest { | |
|
||
_setUp(); | ||
_mockGetBlockchainID(); | ||
_mockInitializeValidatorSet(); | ||
app.initializeValidatorSet(_defaultConversionData(), 0); | ||
|
||
ConversionData memory conversion = _defaultConversionData(); | ||
bytes32 conversionID = sha256(ValidatorMessages.packConversionData(conversion)); | ||
_mockInitializeValidatorSet(conversionID); | ||
validatorManager.initializeValidatorSet(conversion, 0); | ||
} | ||
|
||
// | ||
// Initialization unit tests | ||
// The pattern in these tests requires that only non-admin validator manager functions are called, | ||
// as each test re-deploys the NativeTokenStakingManager contract. | ||
// | ||
function testDisableInitialization() public { | ||
app = new NativeTokenStakingManager(ICMInitializable.Disallowed); | ||
vm.expectRevert(abi.encodeWithSelector(Initializable.InvalidInitialization.selector)); | ||
|
||
app.initialize(_defaultPoSSettings()); | ||
PoSValidatorManagerSettings memory defaultPoSSettings = _defaultPoSSettings(); | ||
defaultPoSSettings.manager = validatorManager; | ||
app.initialize(defaultPoSSettings); | ||
} | ||
|
||
function testZeroMinimumDelegationFee() public { | ||
|
@@ -43,6 +55,7 @@ contract NativeTokenStakingManagerTest is PoSValidatorManagerTest { | |
); | ||
|
||
PoSValidatorManagerSettings memory defaultPoSSettings = _defaultPoSSettings(); | ||
defaultPoSSettings.manager = validatorManager; | ||
defaultPoSSettings.minimumDelegationFeeBips = 0; | ||
app.initialize(defaultPoSSettings); | ||
} | ||
|
@@ -57,6 +70,7 @@ contract NativeTokenStakingManagerTest is PoSValidatorManagerTest { | |
); | ||
|
||
PoSValidatorManagerSettings memory defaultPoSSettings = _defaultPoSSettings(); | ||
defaultPoSSettings.manager = validatorManager; | ||
defaultPoSSettings.minimumDelegationFeeBips = minimumDelegationFeeBips; | ||
app.initialize(defaultPoSSettings); | ||
} | ||
|
@@ -70,6 +84,7 @@ contract NativeTokenStakingManagerTest is PoSValidatorManagerTest { | |
); | ||
|
||
PoSValidatorManagerSettings memory defaultPoSSettings = _defaultPoSSettings(); | ||
defaultPoSSettings.manager = validatorManager; | ||
defaultPoSSettings.minimumStakeAmount = DEFAULT_MAXIMUM_STAKE_AMOUNT; | ||
defaultPoSSettings.maximumStakeAmount = DEFAULT_MINIMUM_STAKE_AMOUNT; | ||
app.initialize(defaultPoSSettings); | ||
|
@@ -82,6 +97,7 @@ contract NativeTokenStakingManagerTest is PoSValidatorManagerTest { | |
); | ||
|
||
PoSValidatorManagerSettings memory defaultPoSSettings = _defaultPoSSettings(); | ||
defaultPoSSettings.manager = validatorManager; | ||
defaultPoSSettings.maximumStakeMultiplier = 0; | ||
app.initialize(defaultPoSSettings); | ||
} | ||
|
@@ -96,6 +112,7 @@ contract NativeTokenStakingManagerTest is PoSValidatorManagerTest { | |
); | ||
|
||
PoSValidatorManagerSettings memory defaultPoSSettings = _defaultPoSSettings(); | ||
defaultPoSSettings.manager = validatorManager; | ||
defaultPoSSettings.maximumStakeMultiplier = maximumStakeMultiplier; | ||
app.initialize(defaultPoSSettings); | ||
} | ||
|
@@ -107,6 +124,7 @@ contract NativeTokenStakingManagerTest is PoSValidatorManagerTest { | |
); | ||
|
||
PoSValidatorManagerSettings memory defaultPoSSettings = _defaultPoSSettings(); | ||
defaultPoSSettings.manager = validatorManager; | ||
defaultPoSSettings.weightToValueFactor = 0; | ||
app.initialize(defaultPoSSettings); | ||
} | ||
|
@@ -121,6 +139,7 @@ contract NativeTokenStakingManagerTest is PoSValidatorManagerTest { | |
); | ||
|
||
PoSValidatorManagerSettings memory defaultPoSSettings = _defaultPoSSettings(); | ||
defaultPoSSettings.manager = validatorManager; | ||
defaultPoSSettings.minimumStakeDuration = minStakeDuration; | ||
app.initialize(defaultPoSSettings); | ||
} | ||
|
@@ -199,14 +218,18 @@ contract NativeTokenStakingManagerTest is PoSValidatorManagerTest { | |
// Construct the object under test | ||
app = new TestableNativeTokenStakingManager(ICMInitializable.Allowed); | ||
rewardCalculator = new ExampleRewardCalculator(DEFAULT_REWARD_RATE); | ||
validatorManager = new ValidatorManager(ICMInitializable.Allowed); | ||
|
||
PoSValidatorManagerSettings memory defaultPoSSettings = _defaultPoSSettings(); | ||
defaultPoSSettings.rewardCalculator = rewardCalculator; | ||
defaultPoSSettings.manager = validatorManager; | ||
|
||
validatorManager.initialize(_defaultSettings(address(app))); | ||
app.initialize(defaultPoSSettings); | ||
|
||
validatorManager = app; | ||
posValidatorManager = app; | ||
return app; | ||
|
||
return validatorManager; | ||
} | ||
|
||
function _getStakeAssetBalance(address account) internal view override returns (uint256) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,13 +6,15 @@ | |
pragma solidity 0.8.25; | ||
|
||
import {PoAValidatorManager} from "../PoAValidatorManager.sol"; | ||
import {ValidatorManager, ValidatorManagerSettings} from "../ValidatorManager.sol"; | ||
import {ValidatorManager} from "../ValidatorManager.sol"; | ||
import {ValidatorManagerTest} from "./ValidatorManagerTests.t.sol"; | ||
import {ICMInitializable} from "@utilities/ICMInitializable.sol"; | ||
import {OwnableUpgradeable} from | ||
"@openzeppelin/[email protected]/access/OwnableUpgradeable.sol"; | ||
import {Initializable} from "@openzeppelin/[email protected]/proxy/utils/Initializable.sol"; | ||
import {ACP99Manager, PChainOwner} from "../ACP99Manager.sol"; | ||
import {ACP99Manager, PChainOwner, ConversionData} from "../ACP99Manager.sol"; | ||
import {ValidatorManager} from "../ValidatorManager.sol"; | ||
import {ValidatorMessages} from "../ValidatorMessages.sol"; | ||
|
||
contract PoAValidatorManagerTest is ValidatorManagerTest { | ||
PoAValidatorManager public app; | ||
|
@@ -24,21 +26,17 @@ contract PoAValidatorManagerTest is ValidatorManagerTest { | |
|
||
_setUp(); | ||
_mockGetBlockchainID(); | ||
_mockInitializeValidatorSet(); | ||
app.initializeValidatorSet(_defaultConversionData(), 0); | ||
|
||
ConversionData memory conversion = _defaultConversionData(); | ||
bytes32 conversionID = sha256(ValidatorMessages.packConversionData(conversion)); | ||
_mockInitializeValidatorSet(conversionID); | ||
validatorManager.initializeValidatorSet(conversion, 0); | ||
} | ||
|
||
function testDisableInitialization() public { | ||
app = new PoAValidatorManager(ICMInitializable.Disallowed); | ||
vm.expectRevert(abi.encodeWithSelector(Initializable.InvalidInitialization.selector)); | ||
app.initialize( | ||
ValidatorManagerSettings({ | ||
subnetID: DEFAULT_SUBNET_ID, | ||
churnPeriodSeconds: DEFAULT_CHURN_PERIOD, | ||
maximumChurnPercentage: DEFAULT_MAXIMUM_CHURN_PERCENTAGE | ||
}), | ||
address(this) | ||
); | ||
app.initialize(validatorManager, address(this)); | ||
} | ||
|
||
function testInvalidOwnerRegistration() public { | ||
|
@@ -114,17 +112,12 @@ contract PoAValidatorManagerTest is ValidatorManagerTest { | |
|
||
function _setUp() internal override returns (ACP99Manager) { | ||
app = new PoAValidatorManager(ICMInitializable.Allowed); | ||
app.initialize( | ||
ValidatorManagerSettings({ | ||
subnetID: DEFAULT_SUBNET_ID, | ||
churnPeriodSeconds: DEFAULT_CHURN_PERIOD, | ||
maximumChurnPercentage: DEFAULT_MAXIMUM_CHURN_PERCENTAGE | ||
}), | ||
address(this) | ||
); | ||
validatorManager = app; | ||
validatorManager = new ValidatorManager(ICMInitializable.Allowed); | ||
|
||
validatorManager.initialize(_defaultSettings(address(app))); | ||
app.initialize(validatorManager, address(this)); | ||
|
||
return app; | ||
return validatorManager; | ||
} | ||
|
||
// solhint-disable-next-line no-empty-blocks | ||
|
Oops, something went wrong.