Skip to content

Commit

Permalink
test(medusa): ghosts refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
simon-something committed Nov 13, 2024
1 parent c0ffee7 commit c0ffeed
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 44 deletions.
24 changes: 12 additions & 12 deletions test/invariants/handlers/BaseHandler.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,28 @@ contract BaseHandler is Setup, Actors {
bytes32[] internal _ghost_requests;

// Track request details
mapping(bytes32 => IOracle.Request) internal _ghost_requestData;
mapping(bytes32 _requestId => IOracle.Request _data) internal _ghost_requestData;

// Track responses for requests
mapping(bytes32 => bytes32) internal _ghost_activeResponses; // requestId => responseId
mapping(bytes32 => IOracle.Response) internal _ghost_responseData;
mapping(bytes32 => bool) internal _ghost_finalizedResponses;
mapping(bytes32 _requestId => bytes32 _responseId) internal _ghost_activeResponses; // requestId => responseId
mapping(bytes32 _responseId => IOracle.Response _data) internal _ghost_responseData;
mapping(bytes32 _responseId => bool _isFinalized) internal _ghost_finalizedResponses;

// Track disputes
mapping(bytes32 => bytes32[]) internal _ghost_disputes; // requestId => disputeIds
mapping(bytes32 => IOracle.Dispute) internal _ghost_disputeData;
mapping(bytes32 => IOracle.DisputeStatus) internal _ghost_disputeStatuses;
mapping(bytes32 _requestId => bytes32[] _disputeIds) internal _ghost_disputes; // requestId => disputeIds
mapping(bytes32 _disputeId => IOracle.Dispute _data) internal _ghost_disputeData;
mapping(bytes32 _disputeId => IOracle.DisputeStatus _status) internal _ghost_disputeStatuses;

// Track which requests came from EBORequestCreator
mapping(bytes32 => bool) internal _ghost_validRequests;
mapping(bytes32 _requestId => bool _isFromRequestCreator) internal _ghost_validRequests;

// Track chain IDs used per epoch to prevent duplicates
mapping(uint256 => mapping(string => bool)) internal _ghost_epochChainIds;
mapping(uint256 _epoch => mapping(string _chainId => bool _isRequested)) internal _ghost_epochChainIds;

// Track bonds and pledges
mapping(address => mapping(bytes32 => uint256)) internal _ghost_bonds;
mapping(address => mapping(bytes32 => uint256)) internal _ghost_pledgesFor;
mapping(address => mapping(bytes32 => uint256)) internal _ghost_pledgesAgainst;
mapping(address _owner => mapping(bytes32 _requestId => uint256 _boundedAmount)) internal _ghost_bonds;
mapping(address _pledger => mapping(bytes32 _disputeId => uint256 _pledgedAmount)) internal _ghost_pledgesFor;
mapping(address _pledger => mapping(bytes32 _disputeId => uint256 _pledgedAmount)) internal _ghost_pledgesAgainst;

// Helper functions
function _boundEpoch(uint256 _epoch) internal view returns (uint256) {
Expand Down
32 changes: 0 additions & 32 deletions test/invariants/handlers/HandlerBondEscalationModule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,6 @@ pragma solidity 0.8.26;
import {BaseHandler, IOracle} from './BaseHandler.t.sol';

contract HandlerBondEscalationModule is BaseHandler {
function handleDisputeResponseBondEscalationModule(uint256 _requestSeed, uint256 _actorSeed) external {
bytes32 requestId = _getRandomRequest(_requestSeed);
if (requestId == bytes32(0) || !_ghost_validRequests[requestId]) return;

bytes32 responseId = _ghost_activeResponses[requestId];
if (responseId == bytes32(0)) return;

IOracle.Response memory response = _ghost_responseData[responseId];
if (_ghost_finalizedResponses[responseId]) return;

// Create dispute data
address disputer = _pickActor(_actorSeed);
uint256 bond = _boundAmount(1e18);

IOracle.Dispute memory dispute =
IOracle.Dispute({disputer: disputer, proposer: msg.sender, responseId: responseId, requestId: requestId});

// Submit dispute
bondEscalationModule.disputeResponse(_ghost_requestData[requestId], response, dispute);

// Track dispute
bytes32 disputeId = keccak256(abi.encode(dispute));
_ghost_disputes[requestId].push(disputeId);
_ghost_disputeData[disputeId] = dispute;
_ghost_bonds[disputer][requestId] = bond;
_ghost_disputeStatuses[disputeId] = IOracle.DisputeStatus.Escalated;
_ghost_pledgesFor[disputer][disputeId] = 0;
_ghost_pledgesAgainst[disputer][disputeId] = 0;

emit DisputeCreated(requestId, responseId, disputeId);
}

function handlePledgeForDispute(uint256 _requestSeed, uint256 _disputeIndex, uint256 _actorSeed) external {
bytes32 requestId = _getRandomRequest(_requestSeed);
if (requestId == bytes32(0)) return;
Expand Down

0 comments on commit c0ffeed

Please sign in to comment.