Skip to content

Commit

Permalink
test(contracts): setup for AssetManager and ValidatorManager
Browse files Browse the repository at this point in the history
  • Loading branch information
seolaoh committed Jul 23, 2024
1 parent 0b00b05 commit 5f96f92
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 33 deletions.
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
36 changes: 17 additions & 19 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,12 +194,6 @@ 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;
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 @@ -337,12 +335,11 @@ contract L2OutputOracle_Initializer is UpgradeGovernor_Initializer {
assetManImpl = 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
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

0 comments on commit 5f96f92

Please sign in to comment.