Skip to content

Commit

Permalink
test(medusa): tweak ebo request creator handler
Browse files Browse the repository at this point in the history
  • Loading branch information
0xJabberwock committed Nov 21, 2024
1 parent c0ffeed commit 28d711a
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 33 deletions.
6 changes: 6 additions & 0 deletions test/invariants/handlers/BaseHandler.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ contract BaseHandler is Setup, Actors {
return chains[_seed % 3];
}

function _getRandomChainId(uint256 _seed) internal view returns (string memory) {
bytes32[] memory chainIds = eboRequestCreator.getAllowedChainIds();
if (chainIds.length == 0) return '';
return string(abi.encodePacked(chainIds[_seed % chainIds.length]));
}

function _getRandomRequestId(uint256 _seed) internal view returns (bytes32) {
if (_ghost_requests.length == 0) return bytes32(0);
return _ghost_requests[_seed % _ghost_requests.length];
Expand Down
106 changes: 74 additions & 32 deletions test/invariants/handlers/HandlerEBORequestCreator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,29 @@
pragma solidity 0.8.26;

import {
ArbitratorModule,
BaseHandler,
BondEscalationModule,
BondedResponseModule,
EBOFinalityModule,
EBORequestModule,
IAccountingExtension,
IArbitratorModule,
IBondEscalationAccounting,
IBondEscalationModule,
IBondedResponseModule,
IEBORequestModule,
IEpochManager,
IOracle
IOracle,
MockEpochManager
} from './BaseHandler.t.sol';

contract HandlerEBORequestCreator is BaseHandler {
function handleCreateRequest(uint256 _epoch, uint256 _chainIdSeed) external {
_epoch = _boundEpoch(_epoch);
string memory chainId = _generateChainId(_chainIdSeed);

string memory chainId = _getRandomChainId(_chainIdSeed);
if (bytes(chainId).length == 0) return;

// Create request via EBORequestCreator
eboRequestCreator.createRequest(_epoch, chainId);
Expand Down Expand Up @@ -51,45 +61,77 @@ contract HandlerEBORequestCreator is BaseHandler {
eboRequestCreator.removeChain(chainId);
}

function handleSetRequestModuleData(
uint256 _actorSeed,
IEBORequestModule.RequestParameters calldata _params
) external {
address module = _pickActor(_actorSeed);
eboRequestCreator.setRequestModuleData(module, _params);
function handleSetRequestModuleData() external {
// Deploy new request module
eboRequestModule = new EBORequestModule(oracle, eboRequestCreator, arbitrable);

// Set up request module parameters
IEBORequestModule.RequestParameters memory requestParams = IEBORequestModule.RequestParameters({
epoch: START_EPOCH,
chainId: 'mainnet',
accountingExtension: IAccountingExtension(address(horizonAccountingExtension)),
paymentAmount: PAYMENT_AMOUNT
});

eboRequestCreator.setRequestModuleData(address(eboRequestModule), requestParams);
}

function handleSetResponseModuleData(
uint256 _actorSeed,
IBondedResponseModule.RequestParameters calldata _params
) external {
address module = _pickActor(_actorSeed);
eboRequestCreator.setResponseModuleData(module, _params);
function handleSetResponseModuleData() external {
// Deploy new response module
bondedResponseModule = new BondedResponseModule(oracle);

// Set up response module parameters
IBondedResponseModule.RequestParameters memory responseParams = IBondedResponseModule.RequestParameters({
accountingExtension: IAccountingExtension(address(horizonAccountingExtension)),
bondToken: GRT,
bondSize: RESPONSE_BOND_SIZE,
deadline: RESPONSE_DEADLINE,
disputeWindow: RESPONSE_DISPUTE_WINDOW
});

eboRequestCreator.setResponseModuleData(address(bondedResponseModule), responseParams);
}

function handleSetDisputeModuleData(
uint256 _actorSeed,
IBondEscalationModule.RequestParameters calldata _params
) external {
address module = _pickActor(_actorSeed);
eboRequestCreator.setDisputeModuleData(module, _params);
function handleSetDisputeModuleData() external {
// Deploy new dispute module
bondEscalationModule = new BondEscalationModule(oracle);

// Set up dispute module parameters
IBondEscalationModule.RequestParameters memory disputeParams = IBondEscalationModule.RequestParameters({
accountingExtension: IBondEscalationAccounting(address(horizonAccountingExtension)),
bondToken: GRT,
bondSize: DISPUTE_BOND_SIZE,
maxNumberOfEscalations: MAX_NB_ESCALATION,
bondEscalationDeadline: DISPUTE_DEADLINE,
tyingBuffer: TYING_BUFFER,
disputeWindow: DISPUTE_DISPUTE_WINDOW
});

eboRequestCreator.setDisputeModuleData(address(bondEscalationModule), disputeParams);
}

function handleSetResolutionModuleData(
uint256 _actorSeed,
IArbitratorModule.RequestParameters calldata _params
) external {
address module = _pickActor(_actorSeed);
eboRequestCreator.setResolutionModuleData(module, _params);
function handleSetResolutionModuleData() external {
// Deploy new resolution module
arbitratorModule = new ArbitratorModule(oracle);

// Set up resolution module parameters
IArbitratorModule.RequestParameters memory resolutionParams =
IArbitratorModule.RequestParameters({arbitrator: address(councilArbitrator)});

eboRequestCreator.setResolutionModuleData(address(arbitratorModule), resolutionParams);
}

function handleSetFinalityModuleData(uint256 _actorSeed) external {
address module = _pickActor(_actorSeed);
eboRequestCreator.setFinalityModuleData(module);
function handleSetFinalityModuleData() external {
// Deploy new finality module
eboFinalityModule = new EBOFinalityModule(oracle, eboRequestCreator, arbitrable);

eboRequestCreator.setFinalityModuleData(address(eboFinalityModule));
}

function handleSetEpochManager(uint256 _actorSeed) external {
address manager = _pickActor(_actorSeed);
eboRequestCreator.setEpochManager(IEpochManager(manager));
function handleSetEpochManager() external {
// Deploy new epoch manager
epochManager = IEpochManager(address(new MockEpochManager(START_EPOCH)));

eboRequestCreator.setEpochManager(epochManager);
}
}
4 changes: 3 additions & 1 deletion test/invariants/properties/PropertyRequester.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ contract PropertyRequester is HandlerParent {
/// @custom:property Requester can always create a request as long as the same chainId/epoch isn't requested yet
function property_canAlwaysCreateRequest(uint256 _epoch, uint256 _chainIdSeed) external {
_epoch = _boundEpoch(_epoch);
string memory chainId = _generateChainId(_chainIdSeed);

string memory chainId = _getRandomChainId(_chainIdSeed);
if (bytes(chainId).length == 0) return;

// Prevent duplicate chainId for same epoch
if (_ghost_requestsPerEpochChainId[_epoch][chainId].length > 0) return;
Expand Down

0 comments on commit 28d711a

Please sign in to comment.