Skip to content

Commit

Permalink
test(medusa): wrap ghost logic within try blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
0xJabberwock committed Nov 25, 2024
1 parent 3e7ae3e commit 8072e09
Showing 1 changed file with 66 additions and 38 deletions.
104 changes: 66 additions & 38 deletions test/invariants/handlers/HandlerEBORequestCreator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,35 +32,39 @@ contract HandlerEBORequestCreator is BaseHandler {
if (bytes(chainId).length == 0) return;

// Create request via EBORequestCreator
eboRequestCreator.createRequest(_epoch, chainId);

// Get current request data
IOracle.Request memory requestData = eboRequestCreator.getRequestData();

// Build request module parameters
IEBORequestModule.RequestParameters memory requestParams =
abi.decode(requestData.requestModuleData, (IEBORequestModule.RequestParameters));
requestParams.epoch = _epoch;
requestParams.chainId = chainId;
requestData.requestModuleData = abi.encode(requestParams);

// Calculate request ID using same logic as Oracle
bytes32 requestId = keccak256(abi.encode(requestData));

// Track the request
_ghost_requests.push(requestId);
_ghost_requestsPerEpochChainId[_epoch][chainId].push(requestId);
_ghost_requestData[requestId] = requestData;
_ghost_validRequests[requestId] = true;

emit RequestCreated(requestId, _epoch, chainId);
try eboRequestCreator.createRequest(_epoch, chainId) {
// Get current request data
IOracle.Request memory requestData = eboRequestCreator.getRequestData();

// Build request module parameters
IEBORequestModule.RequestParameters memory requestParams =
abi.decode(requestData.requestModuleData, (IEBORequestModule.RequestParameters));
requestParams.epoch = _epoch;
requestParams.chainId = chainId;
requestData.requestModuleData = abi.encode(requestParams);

// Calculate request ID using same logic as Oracle
bytes32 requestId = keccak256(abi.encode(requestData));

// Track the request
_ghost_requests.push(requestId);
_ghost_requestsPerEpochChainId[_epoch][chainId].push(requestId);
_ghost_requestData[requestId] = requestData;
_ghost_validRequests[requestId] = true;

emit RequestCreated(requestId, _epoch, chainId);
} catch {
return;
}
}

function handleAddChain(string memory _chainId) external {
eboRequestCreator.addChain(_chainId);

// Track the chain
_ghost_chainIdToChain[keccak256(abi.encodePacked(_chainId))] = _chainId;
try eboRequestCreator.addChain(_chainId) {
// Track the chain
_ghost_chainIdToChain[keccak256(abi.encodePacked(_chainId))] = _chainId;
} catch {
return;
}
}

function handleRemoveChain(uint256 _chainIdSeed) external {
Expand All @@ -70,7 +74,7 @@ contract HandlerEBORequestCreator is BaseHandler {

function handleSetRequestModuleData() external {
// Deploy new request module
eboRequestModule = new EBORequestModule(oracle, eboRequestCreator, arbitrable);
EBORequestModule requestModule = new EBORequestModule(oracle, eboRequestCreator, arbitrable);

// Set up request module parameters
IEBORequestModule.RequestParameters memory requestParams = IEBORequestModule.RequestParameters({
Expand All @@ -80,12 +84,16 @@ contract HandlerEBORequestCreator is BaseHandler {
paymentAmount: PAYMENT_AMOUNT
});

eboRequestCreator.setRequestModuleData(address(eboRequestModule), requestParams);
try eboRequestCreator.setRequestModuleData(address(requestModule), requestParams) {
eboRequestModule = requestModule;
} catch {
return;
}
}

function handleSetResponseModuleData() external {
// Deploy new response module
bondedResponseModule = new BondedResponseModule(oracle);
BondedResponseModule responseModule = new BondedResponseModule(oracle);

// Set up response module parameters
IBondedResponseModule.RequestParameters memory responseParams = IBondedResponseModule.RequestParameters({
Expand All @@ -96,12 +104,16 @@ contract HandlerEBORequestCreator is BaseHandler {
disputeWindow: RESPONSE_DISPUTE_WINDOW
});

eboRequestCreator.setResponseModuleData(address(bondedResponseModule), responseParams);
try eboRequestCreator.setResponseModuleData(address(responseModule), responseParams) {
bondedResponseModule = responseModule;
} catch {
return;
}
}

function handleSetDisputeModuleData() external {
// Deploy new dispute module
bondEscalationModule = new BondEscalationModule(oracle);
BondEscalationModule disputeModule = new BondEscalationModule(oracle);

// Set up dispute module parameters
IBondEscalationModule.RequestParameters memory disputeParams = IBondEscalationModule.RequestParameters({
Expand All @@ -114,31 +126,47 @@ contract HandlerEBORequestCreator is BaseHandler {
disputeWindow: DISPUTE_DISPUTE_WINDOW
});

eboRequestCreator.setDisputeModuleData(address(bondEscalationModule), disputeParams);
try eboRequestCreator.setDisputeModuleData(address(disputeModule), disputeParams) {
bondEscalationModule = disputeModule;
} catch {
return;
}
}

function handleSetResolutionModuleData() external {
// Deploy new resolution module
arbitratorModule = new ArbitratorModule(oracle);
ArbitratorModule resolutionModule = new ArbitratorModule(oracle);

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

eboRequestCreator.setResolutionModuleData(address(arbitratorModule), resolutionParams);
try eboRequestCreator.setResolutionModuleData(address(resolutionModule), resolutionParams) {
arbitratorModule = resolutionModule;
} catch {
return;
}
}

function handleSetFinalityModuleData() external {
// Deploy new finality module
eboFinalityModule = new EBOFinalityModule(oracle, eboRequestCreator, arbitrable);
EBOFinalityModule finalityModule = new EBOFinalityModule(oracle, eboRequestCreator, arbitrable);

eboRequestCreator.setFinalityModuleData(address(eboFinalityModule));
try eboRequestCreator.setFinalityModuleData(address(finalityModule)) {
eboFinalityModule = finalityModule;
} catch {
return;
}
}

function handleSetEpochManager() external {
// Deploy new epoch manager
epochManager = IEpochManager(address(new MockEpochManager()));
IEpochManager manager = IEpochManager(address(new MockEpochManager()));

eboRequestCreator.setEpochManager(epochManager);
try eboRequestCreator.setEpochManager(epochManager) {
epochManager = manager;
} catch {
return;
}
}
}

0 comments on commit 8072e09

Please sign in to comment.