Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: medusa tests #51

Draft
wants to merge 29 commits into
base: dev
Choose a base branch
from
Draft

feat: medusa tests #51

wants to merge 29 commits into from

Conversation

simon-something
Copy link
Member

@simon-something simon-something commented Nov 10, 2024

Add fuzzing tests (using Medusa) to the current codebase (see properties.MD and summary.MD for details)

medusa.json Show resolved Hide resolved
test/invariants/Setup.t.sol Outdated Show resolved Hide resolved
test/invariants/handlers/BaseHandler.t.sol Outdated Show resolved Hide resolved
test/invariants/handlers/BaseHandler.t.sol Outdated Show resolved Hide resolved
test/invariants/handlers/BaseHandler.t.sol Outdated Show resolved Hide resolved
test/invariants/handlers/BaseHandler.t.sol Outdated Show resolved Hide resolved
Comment on lines 28 to 29
// Calculate request ID using same logic as Oracle
bytes32 requestId = keccak256(abi.encode(requestData));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A getId() util would come in handy.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prophet-core/solidity/libraries/ValidatorLib.sol is at hand.

test/invariants/handlers/HandlerOracle.t.sol Outdated Show resolved Hide resolved
Comment on lines 48 to 49
if (_ghost_activeResponses[requestId].length == 0) return (bytes32(0));
bytes32 responseId = _ghost_activeResponses[requestId][0];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't _getRandomActiveResponse() be used in these situations (seen in handleDisputeResponseOracle() and handleFinalize()) so to fuzz _ghost_activeResponses?

simon-something and others added 2 commits November 20, 2024 21:56
# 🤖 Linear

Closes GRT-XXX

---------

Co-authored-by: drgorillamd <[email protected]>
Co-authored-by: Simon Something /DrGoNoGo <[email protected]>
@simon-something simon-something changed the title test(medusa): handlers and setup feat: medusa tests Nov 28, 2024
Comment on lines 17 to 18
// address proposer = _pickActor(_actorSeed);

// Build response data
IOracle.Response memory responseData = IOracle.Response(msg.sender, requestId, _response); // abi.encode(_blockNumber)?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering that the caller must coincide with the proposer, should an actor be picked as the proposer, or is using msg.sender enough? _stakeGRT() and _provisionGRT() helpers do not accept actor picking currently, so I set the proposer to msg.sender.

More generally, when should an actor be picked and/or pranked instead of relying on the fuzzed unpranked msg.sender?

Comment on lines +70 to +72
// active because finalized without answer
if ((oracle.finalizedAt(currRequestId) != 0 && oracle.finalizedResponseId(currRequestId) == 0)) {
++activeRequests;
Copy link
Member

@0xJabberwock 0xJabberwock Dec 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that a request is active after it has been created but before it has been finalized. A finalized request, be it with or without response, shouldn't be counted as an active request.

In fact, if so happens, EBORequestCreator wouldn't permit to create same chainId/epoch requests after a previous one has finalized without response – which I think is the opposite of what is wanted. Consider the assertion of this catch block: assertTrue(isFinalizedWithResponse || activeRequests > 0).

Comment on lines 33 to 41
// check that it is not pointing to the same request. If it does, check it wasn't
// finalized without answer

if (
_ghost_activeResponses[currentRequestId][currentRequestResponseIdx]
!= _ghost_activeResponses[otherRequestId][otherRequestResponseIdx],
'prop 13: different response id for same request'
);
== _ghost_activeResponses[otherRequestId][otherRequestResponseIdx]
&& (
(oracle.finalizedAt(currentRequestId) == 0 && oracle.finalizedResponseId(currentRequestId) != 0)
|| (oracle.finalizedAt(otherRequestId) == 0 && oracle.finalizedResponseId(otherRequestId) != 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does the finalization status have to do with this property? I'd expect that requests IDs, responses IDs and disputes IDs shouldn't collide regardless of the request finalization, be it with or without response.

Besides, the condition checks for a request unfinalized (oracle.finalizedAt(requestId) == 0) and finalized with response (oracle.finalizedResponseId(requestId) != 0), which doesn't seem possible at the same time.

Comment on lines +75 to +77
if (
_ghost_activeResponses[currentRequestId][currentRequestDisputeIdx]
== _ghost_activeResponses[otherRequestId][otherRequestDisputeIdx]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't _ghost_activeResponses be replaced with _ghost_disputes here?

Comment on lines 141 to 143
try bondEscalationModule.pledgeAgainstDispute(_requestData, _disputeData) {
assertTrue(_ghost_escalatedDisputes[_disputeId], 'property 8a: pledging for a dispute not escalated');
try bondEscalationModule.pledgeForDispute(_requestData, _disputeData) {
assertTrue(
_totalPledgesFor(_disputeId) >= _totalPledgesAgainst(_disputeId), 'property 8b: pledging for the wrong side'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the purpose of property 8b to call pledgeAgainstDispute() instead of pledgeForDispute()?

Comment on lines 152 to 157
IBondEscalationModule.BondEscalation memory _escalation = bondEscalationModule.getEscalation(_disputeId);

assertTrue(
!_ghost_escalatedDisputes[_disputeId]
|| block.timestamp > oracle.disputeCreatedAt(_disputeId) + DISPUTE_DEADLINE
|| _escalation.status != IBondEscalationModule.BondEscalationStatus.Active
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the escalation status comparison redundant with _ghost_escalatedDisputes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants