Skip to content

Commit

Permalink
chore: started & service
Browse files Browse the repository at this point in the history
  • Loading branch information
iamsahu committed Nov 7, 2023
1 parent 43335e6 commit 63f0343
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 46 deletions.
60 changes: 14 additions & 46 deletions contracts/test/invariants/Base.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import "../../src/RedeemManager.1.sol";
import "../../src/TUPProxy.sol";

import {StakerService} from "./handlers/StakerService.sol";
import {OperatorService} from "./handlers/OperatorService.sol";
import {OracleDaemonService} from "./handlers/OracleDaemonService.sol";

// 1. add getTimestamp, getBlockNumber, setTimestamp, setBlockNumber to Base
// 2. create BaseService that is constructed with a Base instance
Expand Down Expand Up @@ -64,27 +66,17 @@ contract Base is Test, BytesGenerator {
OperatorsRegistryV1 public operatorsRegistry;
RedeemManagerV1 public redeemManager;

address internal admin;
address public admin;
address internal proxyAdmin;
address internal newAdmin;
address internal collector;
address internal newCollector;
address internal allower;
address internal oracleMember;
address internal newAllowlist;
address internal operatorOne;
address internal operatorOneFeeRecipient;
address internal operatorTwo;
address internal operatorTwoFeeRecipient;
address public oracleMember;
address internal bob;
address internal joe;

string internal operatorOneName = "NodeMasters";
string internal operatorTwoName = "StakePros";

uint256 internal operatorOneIndex;
uint256 internal operatorTwoIndex;

uint64 constant epochsPerFrame = 225;
uint64 constant slotsPerEpoch = 32;
uint64 constant secondsPerSlot = 12;
Expand All @@ -99,6 +91,8 @@ contract Base is Test, BytesGenerator {

// Services
StakerService public stakerService;
OperatorService public operatorService;
OracleDaemonService public oracleDaemonService;

function setUp() public virtual {
deployProtocol();
Expand Down Expand Up @@ -142,9 +136,8 @@ contract Base is Test, BytesGenerator {
newCollector = makeAddr("newCollector");
allower = makeAddr("allower");
oracleMember = makeAddr("oracleMember");

newAllowlist = makeAddr("newAllowlist");
operatorOne = makeAddr("operatorOne");
operatorTwo = makeAddr("operatorTwo");
bob = makeAddr("bob");
joe = makeAddr("joe");

Expand Down Expand Up @@ -174,11 +167,7 @@ contract Base is Test, BytesGenerator {
operatorsRegistryProxy = new TUPProxy(address(operatorsRegistryImplementation), proxyAdmin, "");
redeemManagerProxy = new TUPProxy(address(redeemManagerImplementation), proxyAdmin, "");
riverProxy = new TUPProxy(address(riverImplementation), proxyAdmin, "");
oracleProxy = new TUPProxy(
address(oracleImplementation),
proxyAdmin,
""
);
oracleProxy = new TUPProxy(address(oracleImplementation), proxyAdmin, "");

bytes32 withdrawalCredentials = WithdrawV1(address(withdrawProxy)).getCredentials();
// Proxy initialization
Expand Down Expand Up @@ -209,34 +198,8 @@ contract Base is Test, BytesGenerator {
operatorsRegistry = OperatorsRegistryV1(address(operatorsRegistryProxy));
redeemManager = RedeemManagerV1(address(redeemManagerProxy));

vm.startPrank(admin);

vm.prank(admin);
river.setCoverageFund(address(coverageFund));

// ===================

oracle.addMember(oracleMember, 1);

operatorOneIndex = operatorsRegistry.addOperator(operatorOneName, operatorOne);
operatorTwoIndex = operatorsRegistry.addOperator(operatorTwoName, operatorTwo);

bytes memory hundredKeysOp1 = genBytes((48 + 96) * 100);

operatorsRegistry.addValidators(operatorOneIndex, 100, hundredKeysOp1);

bytes memory hundredKeysOp2 = genBytes((48 + 96) * 100);

operatorsRegistry.addValidators(operatorTwoIndex, 100, hundredKeysOp2);

uint256[] memory operatorIndexes = new uint256[](2);
operatorIndexes[0] = operatorOneIndex;
operatorIndexes[1] = operatorTwoIndex;
uint32[] memory operatorLimits = new uint32[](2);
operatorLimits[0] = 100;
operatorLimits[1] = 100;

operatorsRegistry.setOperatorLimits(operatorIndexes, operatorLimits, block.number);
vm.stopPrank();
}

function deployServices() internal {
Expand All @@ -247,6 +210,9 @@ contract Base is Test, BytesGenerator {
stakerServiceMask[0] = 5;
vm.prank(allower);
allowlist.allow(stakerServiceArray, stakerServiceMask);

operatorService = new OperatorService(this);
oracleDaemonService = new OracleDaemonService(this);
}

function dealETH(address _to, uint256 _amount) public {
Expand All @@ -256,6 +222,8 @@ contract Base is Test, BytesGenerator {

function addTargetSelectors() internal virtual {
targetSelector(stakerService.getTargetSelectors());
// targetSelector(operatorService.getTargetSelectors());
targetSelector(oracleDaemonService.getTargetSelectors());
}

function excludeDeployedContracts() internal virtual {
Expand Down
12 changes: 12 additions & 0 deletions contracts/test/invariants/handlers/BaseService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ abstract contract BaseService is Test {
base.writeBlockState();
}

modifier prankAdmin() {
vm.startPrank(base.admin());
_;
vm.stopPrank();
}

modifier prankOracleMember() {
vm.startPrank(base.oracleMember());
_;
vm.stopPrank();
}

constructor(Base _base) {
base = _base;
}
Expand Down
56 changes: 56 additions & 0 deletions contracts/test/invariants/handlers/OperatorService.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.10;

import "../../utils/BytesGenerator.sol";

import {Base} from "../Base.sol";
import {BaseService} from "./BaseService.sol";

contract OperatorService is BaseService, BytesGenerator {
string internal operatorOneName = "NodeMasters";
string internal operatorTwoName = "StakePros";

uint256 internal operatorOneIndex;
uint256 internal operatorTwoIndex;

address internal operatorOne;
address internal operatorOneFeeRecipient;
address internal operatorTwo;
address internal operatorTwoFeeRecipient;

constructor(Base _base) BaseService(_base) {
operatorOne = makeAddr("operatorOne");
operatorTwo = makeAddr("operatorTwo");
staticOperatorsSetup();
}

function staticOperatorsSetup() internal prankAdmin {
base.oracle().addMember(base.oracleMember(), 1);

operatorOneIndex = base.operatorsRegistry().addOperator(operatorOneName, operatorOne);
operatorTwoIndex = base.operatorsRegistry().addOperator(operatorTwoName, operatorTwo);

bytes memory hundredKeysOp1 = genBytes((48 + 96) * 100);

base.operatorsRegistry().addValidators(operatorOneIndex, 100, hundredKeysOp1);

bytes memory hundredKeysOp2 = genBytes((48 + 96) * 100);

base.operatorsRegistry().addValidators(operatorTwoIndex, 100, hundredKeysOp2);

uint256[] memory operatorIndexes = new uint256[](2);
operatorIndexes[0] = operatorOneIndex;
operatorIndexes[1] = operatorTwoIndex;
uint32[] memory operatorLimits = new uint32[](2);
operatorLimits[0] = 100;
operatorLimits[1] = 100;

base.operatorsRegistry().setOperatorLimits(operatorIndexes, operatorLimits, block.number);
}

// function getTargetSelectors() external view override returns (StdInvariant.FuzzSelector memory selectors) {
// }

// TODO: Add the dynamic operator management
}
27 changes: 27 additions & 0 deletions contracts/test/invariants/handlers/OracleDaemonService.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.10;

import "forge-std/StdInvariant.sol";

import {Base} from "../Base.sol";
import {BaseService} from "./BaseService.sol";

import {IOracleManagerV1} from "../../../src/interfaces/components/IOracleManager.1.sol";
contract OracleDaemonService is BaseService {
constructor(Base _base) BaseService(_base) {}

function getTargetSelectors() external view override returns (StdInvariant.FuzzSelector memory selectors) {
bytes4[] memory selectorsArray = new bytes4[](1);
selectorsArray[0] = this.action_report.selector;

selectors.selectors = selectorsArray;
selectors.addr = address(this);
}

function action_report() external prankOracleMember {
IOracleManagerV1.ConsensusLayerReport memory dummyReport;
dummyReport.stoppedValidatorCountPerOperator = new uint32[](1);
base.oracle().reportConsensusLayerData(dummyReport);
}
}

0 comments on commit 63f0343

Please sign in to comment.