Skip to content

Commit

Permalink
feat(contracts): update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mempirate committed Oct 30, 2024
1 parent eab4944 commit 89c08a6
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 46 deletions.
50 changes: 22 additions & 28 deletions bolt-contracts/test/BoltManager.EigenLayer.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ pragma solidity 0.8.25;

import {Test, console} from "forge-std/Test.sol";

import {BoltValidatorsV1} from "../src/contracts/BoltValidatorsV1.sol";
import {BoltManagerV1} from "../src/contracts/BoltManagerV1.sol";
import {BoltValidatorsV2} from "../src/contracts/BoltValidatorsV2.sol";
import {BoltManagerV2} from "../src/contracts/BoltManagerV2.sol";
import {BoltParametersV1} from "../src/contracts/BoltParametersV1.sol";
import {BoltEigenLayerMiddlewareV2} from "../src/contracts/BoltEigenLayerMiddlewareV2.sol";
import {BoltConfig} from "../src/lib/Config.sol";
import {IBoltValidatorsV1} from "../src/interfaces/IBoltValidatorsV1.sol";
import {IBoltManagerV1} from "../src/interfaces/IBoltManagerV1.sol";
import {ValidatorsLib} from "../src/lib/ValidatorsLib.sol";
import {IBoltValidatorsV2} from "../src/interfaces/IBoltValidatorsV2.sol";
import {IBoltManagerV2} from "../src/interfaces/IBoltManagerV2.sol";
import {IBoltMiddlewareV1} from "../src/interfaces/IBoltMiddlewareV1.sol";
import {Utils} from "./Utils.sol";

Expand All @@ -28,12 +29,12 @@ contract BoltManagerEigenLayerTest is Test {

uint48 public constant EPOCH_DURATION = 1 days;

BoltValidatorsV1 public validators;
BoltManagerV1 public manager;
BoltValidatorsV2 public validators;
BoltManagerV2 public manager;
BoltEigenLayerMiddlewareV2 public middleware;
EigenLayerDeployer public eigenLayerDeployer;

uint128 public constant PRECONF_MAX_GAS_LIMIT = 5_000_000;
uint32 public constant PRECONF_MAX_GAS_LIMIT = 5_000_000;

address staker = makeAddr("staker");
address validator = makeAddr("validator");
Expand Down Expand Up @@ -70,9 +71,9 @@ contract BoltManagerEigenLayerTest is Test {
);

// Deploy Bolt contracts
validators = new BoltValidatorsV1();
validators = new BoltValidatorsV2();
validators.initialize(admin, address(parameters));
manager = new BoltManagerV1();
manager = new BoltManagerV2();
manager.initialize(admin, address(parameters), address(validators));
middleware = new BoltEigenLayerMiddlewareV2();

Expand Down Expand Up @@ -186,10 +187,11 @@ contract BoltManagerEigenLayerTest is Test {

// pubkeys aren't checked, any point will be fine
validatorPubkey = BLS12381.generatorG1();
bytes20 pubkey = validators.hashPubkey(validatorPubkey);

vm.prank(validator);
validators.registerValidatorUnsafe(validatorPubkey, PRECONF_MAX_GAS_LIMIT, operator);
assertEq(validators.getValidatorByPubkey(validatorPubkey).exists, true);
validators.registerValidatorUnsafe(pubkey, PRECONF_MAX_GAS_LIMIT, operator);
assert(validators.getValidatorByPubkey(validatorPubkey).pubkeyHash != bytes20(0));
assertEq(validators.getValidatorByPubkey(validatorPubkey).authorizedOperator, operator);

// 2. --- Operator and strategy registration into BoltManager (middleware) ---
Expand All @@ -204,7 +206,7 @@ contract BoltManagerEigenLayerTest is Test {
_eigenLayerOptInRoutine();
vm.prank(operator);
middleware.deregisterOperator();
vm.expectRevert(IBoltManagerV1.OperatorNotRegistered.selector);
vm.expectRevert(IBoltManagerV2.OperatorNotRegistered.selector);
manager.isOperatorEnabled(operator);
}

Expand All @@ -220,9 +222,9 @@ contract BoltManagerEigenLayerTest is Test {
function testProposerStatus() public {
_eigenLayerOptInRoutine();

bytes32 pubkeyHash = _pubkeyHash(validatorPubkey);
bytes20 pubkeyHash = validators.hashPubkey(validatorPubkey);

IBoltValidatorsV1.ProposerStatus memory status = manager.getProposerStatus(pubkeyHash);
IBoltManagerV2.ProposerStatus memory status = manager.getProposerStatus(pubkeyHash);
assertEq(status.pubkeyHash, pubkeyHash);
assertEq(status.operator, operator);
assertEq(status.active, true);
Expand All @@ -235,36 +237,28 @@ contract BoltManagerEigenLayerTest is Test {
function testProposersLookaheadStatus() public {
// This also opts in the operator which is needed
_eigenLayerOptInRoutine();
bytes32[] memory pubkeyHashes = new bytes32[](10);
bytes20[] memory pubkeyHashes = new bytes20[](10);

// register 10 proposers with random pubkeys
for (uint256 i = 0; i < 10; i++) {
BLS12381.G1Point memory pubkey = BLS12381.generatorG1();
pubkey.x[0] = pubkey.x[0] + i + 2;
pubkey.y[0] = pubkey.y[0] + i + 2;

pubkeyHashes[i] = _pubkeyHash(pubkey);
validators.registerValidatorUnsafe(pubkey, PRECONF_MAX_GAS_LIMIT, operator);
pubkeyHashes[i] = validators.hashPubkey(pubkey);
validators.registerValidatorUnsafe(pubkeyHashes[i], PRECONF_MAX_GAS_LIMIT, operator);
}

IBoltValidatorsV1.ProposerStatus[] memory statuses = manager.getProposerStatuses(pubkeyHashes);
IBoltManagerV2.ProposerStatus[] memory statuses = manager.getProposerStatuses(pubkeyHashes);
assertEq(statuses.length, 10);
}

function testNonExistentProposerStatus() public {
_eigenLayerOptInRoutine();

bytes32 pubkeyHash = bytes32(uint256(1));
bytes20 pubkeyHash = bytes20("0x1");

vm.expectRevert(IBoltValidatorsV1.ValidatorDoesNotExist.selector);
vm.expectRevert(abi.encodeWithSelector(ValidatorsLib.ValidatorDoesNotExist.selector, pubkeyHash));
manager.getProposerStatus(pubkeyHash);
}

/// @notice Compute the hash of a BLS public key
function _pubkeyHash(
BLS12381.G1Point memory _pubkey
) internal pure returns (bytes32) {
uint256[2] memory compressedPubKey = _pubkey.compress();
return keccak256(abi.encodePacked(compressedPubKey));
}
}
39 changes: 21 additions & 18 deletions bolt-contracts/test/BoltManager.Symbiotic.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@ import {IDelegatorFactory} from "@symbiotic/interfaces/IDelegatorFactory.sol";
import {IMigratablesFactory} from "@symbiotic/interfaces/common/IMigratablesFactory.sol";
import {Subnetwork} from "@symbiotic/contracts/libraries/Subnetwork.sol";

import {IBoltValidatorsV1} from "../src/interfaces/IBoltValidatorsV1.sol";
import {IBoltValidatorsV2} from "../src/interfaces/IBoltValidatorsV2.sol";
import {IBoltMiddlewareV1} from "../src/interfaces/IBoltMiddlewareV1.sol";
import {IBoltManagerV2} from "../src/interfaces/IBoltManagerV2.sol";

import {BoltParametersV1} from "../src/contracts/BoltParametersV1.sol";
import {BoltValidatorsV1} from "../src/contracts/BoltValidatorsV1.sol";
import {BoltManagerV1} from "../src/contracts/BoltManagerV1.sol";
import {BoltValidatorsV2} from "../src/contracts/BoltValidatorsV2.sol";
import {BoltManagerV2} from "../src/contracts/BoltManagerV2.sol";
import {BoltSymbioticMiddlewareV1} from "../src/contracts/BoltSymbioticMiddlewareV1.sol";
import {BLS12381} from "../src/lib/bls/BLS12381.sol";
import {BoltConfig} from "../src/lib/Config.sol";
import {ValidatorsLib} from "../src/lib/ValidatorsLib.sol";
import {Utils} from "./Utils.sol";

import {SymbioticSetupFixture} from "./fixtures/SymbioticSetup.f.sol";
Expand All @@ -41,10 +43,10 @@ contract BoltManagerSymbioticTest is Test {
uint48 public constant EPOCH_DURATION = 1 days;
uint48 public constant SLASHING_WINDOW = 7 days;

uint128 public constant PRECONF_MAX_GAS_LIMIT = 5_000_000;
uint32 public constant PRECONF_MAX_GAS_LIMIT = 5_000_000;

BoltValidatorsV1 public validators;
BoltManagerV1 public manager;
BoltValidatorsV2 public validators;
BoltManagerV2 public manager;
BoltSymbioticMiddlewareV1 public middleware;

IVaultFactory public vaultFactory;
Expand Down Expand Up @@ -174,9 +176,9 @@ contract BoltManagerSymbioticTest is Test {
config.minimumOperatorStake
);

validators = new BoltValidatorsV1();
validators = new BoltValidatorsV2();
validators.initialize(admin, address(parameters));
manager = new BoltManagerV1();
manager = new BoltManagerV2();
manager.initialize(admin, address(parameters), address(validators));

middleware = new BoltSymbioticMiddlewareV1();
Expand Down Expand Up @@ -213,10 +215,11 @@ contract BoltManagerSymbioticTest is Test {

// pubkeys aren't checked, any point will be fine
BLS12381.G1Point memory pubkey = BLS12381.generatorG1();
bytes20 pubkeyHash = validators.hashPubkey(pubkey);

vm.prank(validator);
validators.registerValidatorUnsafe(pubkey, PRECONF_MAX_GAS_LIMIT, operator);
assertEq(validators.getValidatorByPubkey(pubkey).exists, true);
validators.registerValidatorUnsafe(pubkeyHash, PRECONF_MAX_GAS_LIMIT, operator);
assert(validators.getValidatorByPubkey(pubkey).pubkeyHash != bytes20(0));
assertEq(validators.getValidatorByPubkey(pubkey).authorizedOperator, operator);

// --- Register Operator in Symbiotic, opt-in network and vault ---
Expand Down Expand Up @@ -327,12 +330,12 @@ contract BoltManagerSymbioticTest is Test {
assertEq(networkRestakeDelegator.operatorNetworkShares(subnetwork, operator), 100);

BLS12381.G1Point memory pubkey = BLS12381.generatorG1();
bytes32 pubkeyHash = _pubkeyHash(pubkey);
bytes20 pubkeyHash = validators.hashPubkey(pubkey);

vm.warp(block.timestamp + EPOCH_DURATION * 2 + 1);
assertEq(vault.currentEpoch(), 2);

IBoltValidatorsV1.ProposerStatus memory status = manager.getProposerStatus(pubkeyHash);
IBoltManagerV2.ProposerStatus memory status = manager.getProposerStatus(pubkeyHash);
assertEq(status.pubkeyHash, pubkeyHash);
assertEq(status.operator, operator);
assertEq(status.active, true);
Expand All @@ -345,31 +348,31 @@ contract BoltManagerSymbioticTest is Test {
function testProposersLookaheadStatus() public {
_symbioticOptInRoutine();

bytes32[] memory pubkeyHashes = new bytes32[](10);
bytes20[] memory pubkeyHashes = new bytes20[](10);

// register 10 proposers with random pubkeys
for (uint256 i = 0; i < 10; i++) {
BLS12381.G1Point memory pubkey = BLS12381.generatorG1();
pubkey.x[0] = pubkey.x[0] + i + 2;
pubkey.y[0] = pubkey.y[0] + i + 2;

pubkeyHashes[i] = _pubkeyHash(pubkey);
validators.registerValidatorUnsafe(pubkey, PRECONF_MAX_GAS_LIMIT, operator);
pubkeyHashes[i] = validators.hashPubkey(pubkey);
validators.registerValidatorUnsafe(pubkeyHashes[i], PRECONF_MAX_GAS_LIMIT, operator);
}

vm.warp(block.timestamp + EPOCH_DURATION * 2 + 1);
assertEq(vault.currentEpoch(), 2);

IBoltValidatorsV1.ProposerStatus[] memory statuses = manager.getProposerStatuses(pubkeyHashes);
IBoltManagerV2.ProposerStatus[] memory statuses = manager.getProposerStatuses(pubkeyHashes);
assertEq(statuses.length, 10);
}

function testGetNonExistentProposerStatus() public {
_symbioticOptInRoutine();

bytes32 pubkeyHash = bytes32(uint256(1));
bytes20 pubkeyHash = bytes20("0x1");

vm.expectRevert(IBoltValidatorsV1.ValidatorDoesNotExist.selector);
vm.expectRevert(abi.encodeWithSelector(ValidatorsLib.ValidatorDoesNotExist.selector, pubkeyHash));
manager.getProposerStatus(pubkeyHash);
}
}

0 comments on commit 89c08a6

Please sign in to comment.