Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(contracts): setup for AssetManager and ValidatorManager #359

Merged
merged 2 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions packages/contracts/contracts/L1/ValidatorManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,6 @@ contract ValidatorManager is ISemver, IValidatorManager {
constructor(ConstructorParams memory _constructorParams) {
if (_constructorParams._minRegisterAmount > _constructorParams._minActivateAmount)
revert InvalidConstructorParams();
if (_constructorParams._minRegisterAmount < _constructorParams._assetManager.BOND_AMOUNT())
revert InvalidConstructorParams();
Comment on lines -162 to -163
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed it since AssetManagerProxy might not be upgraded (don't have BOND_AMOUNT) when deploying ValidatorManager implementation contract.


L2_ORACLE = _constructorParams._l2Oracle;
ASSET_MANAGER = _constructorParams._assetManager;
Expand Down
15 changes: 6 additions & 9 deletions packages/contracts/contracts/test/AssetManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { Uint128Math } from "../libraries/Uint128Math.sol";
import { AssetManager } from "../L1/AssetManager.sol";
import { IAssetManager } from "../L1/interfaces/IAssetManager.sol";
import { IValidatorManager } from "../L1/interfaces/IValidatorManager.sol";
import { IKGHManager } from "../universal/IKGHManager.sol";
import { Proxy } from "../universal/Proxy.sol";
import { ValidatorSystemUpgrade_Initializer } from "./CommonTest.t.sol";
import { MockL2OutputOracle } from "./ValidatorManager.t.sol";
Expand All @@ -29,22 +28,20 @@ contract MockAssetManager is AssetManager {
constructor(
IERC20 _assetToken,
IERC721 _kgh,
IKGHManager _kghManager,
address _securityCouncil,
address _validatorRewardVault,
IValidatorManager _validatorManager,
uint128 _undelegationPeriod,
uint128 _slashingRate,
uint128 _minSlashingAmount
uint128 _minDelegationPeriod,
uint128 _bondAmount
)
AssetManager(
_assetToken,
_kgh,
_kghManager,
_securityCouncil,
_validatorRewardVault,
_validatorManager,
_undelegationPeriod,
_slashingRate,
_minSlashingAmount
_minDelegationPeriod,
_bondAmount
)
{}

Expand Down
42 changes: 20 additions & 22 deletions packages/contracts/contracts/test/CommonTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import { CodeDeployer } from "../libraries/CodeDeployer.sol";
import { Constants } from "../libraries/Constants.sol";
import { Predeploys } from "../libraries/Predeploys.sol";
import { Types } from "../libraries/Types.sol";
import { IKGHManager } from "../universal/IKGHManager.sol";
import { KromaMintableERC20 } from "../universal/KromaMintableERC20.sol";
import { KromaMintableERC20Factory } from "../universal/KromaMintableERC20Factory.sol";
import { Proxy } from "../universal/Proxy.sol";
Expand Down Expand Up @@ -195,18 +194,12 @@ contract MockKgh is ERC721 {
}
}

contract MockKghManager is IKGHManager {
function totalKroInKgh(uint256 /* tokenId */) external pure override returns (uint128) {
return 100e18;
}
}

contract L2OutputOracle_Initializer is UpgradeGovernor_Initializer {
// Test target
ValidatorPool pool;
ValidatorPool poolImpl;
AssetManager assetMgr;
AssetManager assetManImpl;
AssetManager assetMgrImpl;
ValidatorManager valMgr;
ValidatorManager valMgrImpl;
L2OutputOracle oracle;
Expand Down Expand Up @@ -236,14 +229,14 @@ contract L2OutputOracle_Initializer is UpgradeGovernor_Initializer {
// AssetManager constructor arguments
MockKro assetToken;
MockKgh kgh;
MockKghManager kghManager;
uint256 internal undelegationPeriod = 7 days;
uint128 internal slashingRate = 20;
uint128 internal minSlashingAmount = 1e18;
address internal validatorRewardVault = makeAddr("validatorRewardVault");
uint128 internal minDelegationPeriod = 7 days;
uint128 internal bondAmount = 10e18;

// ValidatorManager constructor arguments
uint128 internal commissionChangeDelaySeconds = 7 days;
uint128 internal jailPeriodSeconds = 7 days;
uint128 internal softJailPeriodSeconds = 3 days;
uint128 internal hardJailPeriodSeconds = 7 days;
uint128 internal jailThreshold = 2;
uint128 internal maxOutputFinalizations = 10;
uint128 internal baseReward = 20e18;
Expand Down Expand Up @@ -279,10 +272,11 @@ contract L2OutputOracle_Initializer is UpgradeGovernor_Initializer {
assetToken.mint(trusted, minActivateAmount * 10);
assetToken.mint(asserter, minActivateAmount * 10);
assetToken.mint(challenger, minActivateAmount * 10);
// Set up validatorRewardVault
assetToken.mint(validatorRewardVault, baseReward * 1000);

// Set up KGH and KGHManager
// Set up KGH
kgh = new MockKgh();
kghManager = new MockKghManager();

// Give actors some ETH
vm.deal(trusted, requiredBondAmount * 10);
Expand All @@ -299,6 +293,10 @@ contract L2OutputOracle_Initializer is UpgradeGovernor_Initializer {
oracle = L2OutputOracle(address(new Proxy(multisig)));
vm.label(address(oracle), "L2OutputOracle");

// Allow AssetManager contract can get asset token from validatorRewardVault
vm.prank(validatorRewardVault);
assetToken.approve(address(assetMgr), baseReward * 1000);

ResourceMetering.ResourceConfig memory config = Constants.DEFAULT_RESOURCE_CONFIG();
systemConfig = new SystemConfig({
_owner: address(1),
Expand Down Expand Up @@ -334,15 +332,14 @@ contract L2OutputOracle_Initializer is UpgradeGovernor_Initializer {
});

// Deploy the AssetManager
assetManImpl = new AssetManager({
assetMgrImpl = new AssetManager({
_assetToken: IERC20(assetToken),
_kgh: IERC721(kgh),
_kghManager: IKGHManager(kghManager),
_securityCouncil: guardian,
_validatorRewardVault: validatorRewardVault,
_validatorManager: valMgr,
_undelegationPeriod: uint128(undelegationPeriod),
_slashingRate: slashingRate,
_minSlashingAmount: minSlashingAmount
_minDelegationPeriod: minDelegationPeriod,
_bondAmount: bondAmount
});

// Deploy the ValidatorManager
Expand All @@ -352,7 +349,8 @@ contract L2OutputOracle_Initializer is UpgradeGovernor_Initializer {
_trustedValidator: trusted,
_commissionChangeDelaySeconds: commissionChangeDelaySeconds,
_roundDurationSeconds: uint128(roundDuration),
_jailPeriodSeconds: jailPeriodSeconds,
_softJailPeriodSeconds: softJailPeriodSeconds,
_hardJailPeriodSeconds: hardJailPeriodSeconds,
_jailThreshold: jailThreshold,
_maxOutputFinalizations: maxOutputFinalizations,
_baseReward: baseReward,
Expand Down Expand Up @@ -385,7 +383,7 @@ contract L2OutputOracle_Initializer is UpgradeGovernor_Initializer {
);

vm.prank(multisig);
Proxy(payable(address(assetMgr))).upgradeTo(address(assetManImpl));
Proxy(payable(address(assetMgr))).upgradeTo(address(assetMgrImpl));

vm.prank(multisig);
Proxy(payable(address(valMgr))).upgradeTo(address(valMgrImpl));
Expand Down
8 changes: 3 additions & 5 deletions packages/contracts/contracts/test/ValidatorManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { Constants } from "../libraries/Constants.sol";
import { Types } from "../libraries/Types.sol";
import { Proxy } from "../universal/Proxy.sol";
import { IValidatorManager } from "../L1/interfaces/IValidatorManager.sol";
import { IKGHManager } from "../universal/IKGHManager.sol";
import { L2OutputOracle } from "../L1/L2OutputOracle.sol";
import { ValidatorManager } from "../L1/ValidatorManager.sol";
import { ValidatorPool } from "../L1/ValidatorPool.sol";
Expand Down Expand Up @@ -154,12 +153,11 @@ contract ValidatorManagerTest is ValidatorSystemUpgrade_Initializer {
MockAssetManager mockAssetMgrImpl = new MockAssetManager(
IERC20(assetToken),
IERC721(kgh),
IKGHManager(kghManager),
guardian,
validatorRewardVault,
valMgr,
uint128(undelegationPeriod),
slashingRate,
minSlashingAmount
minDelegationPeriod,
bondAmount
);
vm.prank(multisig);
Proxy(payable(assetMgrAddress)).upgradeTo(address(mockAssetMgrImpl));
Expand Down
Loading