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
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
5d5fd14
chore: properties md update
simon-something Oct 29, 2024
3b77715
test(medusa): handlers and working setup
simon-something Nov 10, 2024
1b53763
test(medusa): add lib to crytic compile
simon-something Nov 10, 2024
98de161
test(medusa): prop 0 sanity check ok
simon-something Nov 10, 2024
92a50e3
test(medusa): git ignore corpus
simon-something Nov 10, 2024
1e78bdb
test(medusa): git ignore corpus
simon-something Nov 10, 2024
efc8876
test(medusa): typo medusa json
simon-something Nov 10, 2024
e4cf1e5
test(medusa): rm corpus
simon-something Nov 10, 2024
c0ffee6
test(medusa): natspec
simon-something Nov 11, 2024
c0ffee7
test(medusa): rm non-sensical handlers onlyoracle etc
simon-something Nov 11, 2024
c0ffeed
test(medusa): ghosts refactor
simon-something Nov 13, 2024
c0ffee6
test(medusa): more handler fixes
simon-something Nov 13, 2024
c0ffeee
test(medusa): properties md update
simon-something Nov 20, 2024
9c8dce2
test(medusa): requester properties (#57)
0xJabberwock Nov 28, 2024
c0ffee9
test(medusa): dispute window in prop6
simon-something Nov 28, 2024
c0ffeef
test(medusa): fix approveModule
simon-something Nov 28, 2024
c0ffeeb
test(medusa): fix approveModule
simon-something Nov 28, 2024
97fff3c
test(medusa): rename PropertyDispute to PropertyDisputer
0xJabberwock Nov 29, 2024
80d145f
test(medusa): correct prop-6
0xJabberwock Nov 29, 2024
1d45342
test(medusa): assert prop-7
0xJabberwock Nov 29, 2024
c0ffee6
test(medusa): properties 13
simon-something Nov 30, 2024
c0ffee9
test(medusa): fix prop1 for empty finalized req
simon-something Dec 7, 2024
c0ffee7
test(medusa): fix fp
simon-something Dec 11, 2024
7218056
test(medusa): proposer properties
0xJabberwock Dec 13, 2024
2b8bc63
test(medusa): fix prop8b
simon-something Dec 11, 2024
c0ffee2
test(medusa): false pos fix
simon-something Dec 16, 2024
c0ffeea
test(medusa): false pos fix
simon-something Dec 16, 2024
a3b8f1c
Merge branch 'dev' into test/handler-cov
simon-something Dec 18, 2024
c0ffee8
Revert "Merge branch 'dev' into test/handler-cov"
simon-something Dec 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added 1
Empty file.
Empty file added log/log-1733753739.log
Empty file.
241 changes: 241 additions & 0 deletions log/log-1733753780.log

Large diffs are not rendered by default.

Empty file added log/log-1733753814.log
Empty file.
36 changes: 25 additions & 11 deletions test/invariants/FuzzTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,19 @@ contract FuzzTest is PropertyParent {
otherRequestResponseIdx < _ghost_activeResponses[otherRequestId].length;
otherRequestResponseIdx++
) {
// check that it is not pointing to the same request
assertTrue(
// 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.

)
) {
assertTrue(false, 'prop 13: same response id for different requests');
}
}
}
}
Expand All @@ -62,12 +69,19 @@ contract FuzzTest is PropertyParent {
otherRequestDisputeIdx < _ghost_disputes[otherRequestId].length;
otherRequestDisputeIdx++
) {
// check that it is not pointing to the same request
assertTrue(
_ghost_disputes[currentRequestId][currentRequestDisputeIdx]
!= _ghost_disputes[otherRequestId][otherRequestDisputeIdx],
'prop 13: different dispute id for same request'
);
// check that it is not pointing to the same request. If it does, check it wasn't
// finalized without answer

if (
_ghost_activeResponses[currentRequestId][currentRequestDisputeIdx]
== _ghost_activeResponses[otherRequestId][otherRequestDisputeIdx]
Comment on lines +75 to +77
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?

&& (
(oracle.finalizedAt(currentRequestId) == 0 && oracle.finalizedResponseId(currentRequestId) != 0)
|| (oracle.finalizedAt(otherRequestId) == 0 && oracle.finalizedResponseId(otherRequestId) != 0)
)
) {
assertTrue(false, 'prop 13: same response id for different requests');
}
}
}
}
Expand Down
112 changes: 94 additions & 18 deletions test/invariants/Reproducers.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,108 @@ import {FuzzTest} from './FuzzTest.t.sol';
import {IEBORequestModule, IOracle} from './Setup.t.sol';

contract Reproducers is FuzzTest {
function test_debug() public {
vm.roll(55_341);
vm.warp(292_791);
vm.prank(0x0000000000000000000000000000000000080000);
// forge test --match-test test_prop_singleRequestIdForSingleDisputeOrResponseId_0 -vv

function test_prop_singleRequestIdForSingleDisputeOrResponseId_0() public {
vm.roll(3);
vm.warp(107_622);
vm.prank(0x0000000000000000000000000000000000030000);
this.property_requesterCanAlwaysCreateRequest(
0, 91_936_153_333_790_985_814_765_645_281_331_945_670_085_017_288_440_355_350_976_283_151_607_122_591_831
10, 37_029_423_570_101_568_114_192_451_652_059_639_489_459_691_769_081_285_614_258_977_732_585_787
);

vm.roll(29_920);
vm.warp(191_126);
vm.prank(0x0000000000000000000000000000000000020000);
this.property_proposerProposeBeforeDeadlineAndNoAnswer(
3_533_694_129_556_768_659_166_594_920_800_430_618_073_929_656_453_786_986_859_439_806_182_558_244, ''
);

vm.roll(114_433);
vm.warp(791_132);
vm.prank(0x0000000000000000000000000000000000080000);
vm.roll(41_973);
vm.warp(293_378);
vm.prank(0x0000000000000000000000000000000000070000);
this.property_disputerCanAlwaysCreateDispute(
44_601_490_397_061_246_283_071_436_695_194_755_937_831_813,
24_519_928_653_539_120_916_142_750_395_984_862_678_837_009_021_121_402_119
);

vm.roll(72_668);
vm.warp(701_817);
vm.prank(0x0000000000000000000000000000000000090000);
this.property_finalizeAfterDeadline(
13_479_973_333_575_319_897_333_507_543_509_815_336_818_572_211_270_290_147_286_325_345_251,
107_839_786_668_602_559_178_668_057_886_353_385_264_177_471_300_505_974_851_760_065_510_272
441_711_766_194_596_082_395_824_375_183_268_584_384_174_444_443_096_125_085_881_927_426_324_089,
55_213_970_774_324_510_299_478_046_897_908_487_977_573_366_651_192_816_587_142_984_978_084_060
);

vm.roll(130_241);
vm.warp(1_239_575);
vm.prank(0x0000000000000000000000000000000000060000);
this.property_disputerEscalateFirstDisputedResponse(
441_711_766_194_596_082_395_824_375_183_267_903_819_727_185_636_638_495_186_960_857_860_556_558,
601_007_113_947_101_039_560_436_606_908_369_912_464
);

vm.roll(133_321);
vm.warp(1_272_520);
vm.prank(0x0000000000000000000000000000000000030000);
this.handleArbitrateDispute(
98_079_714_617_799_838_069_981_031_751_129_814_657_974_628_780_861_328_198,
10_543_876_310_748_807_825_434_603_100_744_632_307_071_557,
7_369_614_386_207_023_510_276_552_037
);

vm.roll(133_321);
vm.warp(1_272_520);
vm.prank(0x0000000000000000000000000000000000030000);
this.property_requesterCanAlwaysCreateRequest(
10, 1_184_941_554_243_250_179_654_158_452_865_908_463_662_710_136_610_601_139_976_392_267_926_618_806
);

vm.roll(164_579);
vm.warp(1_050_332);
vm.prank(0x00000000000000000000000000000000000a0000);
this.property_requesterCanAlwaysCreateRequest(0, 300_000_000_001_847_143);
vm.roll(133_469);
vm.warp(1_272_796);
vm.prank(0x0000000000000000000000000000000000060000);
this.prop_singleRequestIdForSingleDisputeOrResponseId();
}

// forge test --match-test test_property_pledgerCanPledgeFor_1 -vv

vm.roll(225_050);
vm.warp(1_491_370);
vm.prank(0x00000000000000000000000000000000000a0000);
function test_property_pledgerCanPledgeFor_1() public {
vm.roll(56_765);
vm.warp(310_068);
vm.prank(0x0000000000000000000000000000000000030000);
this.property_requesterCanAlwaysCreateRequest(
0, 115_792_089_237_316_195_423_570_985_008_687_907_853_269_984_665_640_564_039_456_584_007_913_130_122_499
23_945_252_909_255_375_823_092_408_840_274_513_180_624_399_837_945_186, 2_086_162_298_782_925_019_460
);

vm.roll(86_763);
vm.warp(575_158);
vm.prank(0x0000000000000000000000000000000000030000);
this.property_proposerProposeBeforeDeadlineAndNoAnswer(
631_432_499_075_532_304_456_395_701_379_901_335_158_300_516, ''
);

vm.roll(108_137);
vm.warp(650_339);
vm.prank(0x0000000000000000000000000000000000030000);
this.property_disputerCanAlwaysCreateDispute(
862_718_293_348_820_473_429_987_288_449_076_456_476_499_045_871_166_767_810_196_422_572_057,
1_239_938_753_245_600_703_949_804_873_417_738_265_153_932
);

vm.roll(143_071);
vm.warp(748_820);
vm.prank(0x0000000000000000000000000000000000070000);
this.property_disputerEscalateFirstDisputedResponse(
1_645_504_557_321_206_042_785_170_517_226_798_052_215_695_477_109_921_052_145_574_832,
3_213_876_088_517_980_570_777_725_284_107_382_648_403_960_509_936_676_257_779_973
);

vm.roll(150_070);
vm.warp(774_026);
vm.prank(0x0000000000000000000000000000000000070000);
this.property_pledgerCanPledgeFor(
6_901_746_346_790_563_787_434_755_862_238_646_067_770_489_658_248_914_019_106_131_779_923_731,
6_129_982_162_203_152_163_068_464_937_047_330_911_145_056_599_837_097_252
);
}
}
27 changes: 27 additions & 0 deletions test/invariants/handlers/BaseHandler.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,33 @@ contract BaseHandler is Setup, Actors {
mapping(address _pledger => mapping(bytes32 _disputeId => uint256 _pledgedAmount)) internal _ghost_pledgesFor;
mapping(address _pledger => mapping(bytes32 _disputeId => uint256 _pledgedAmount)) internal _ghost_pledgesAgainst;

// Aggregators

function _totalPledgesFor(bytes32 _disputeId) internal view returns (uint256) {
return _aggregateSum(_ghost_pledgesFor, _disputeId);
}

function _totalPledgesAgainst(bytes32 _disputeId) internal view returns (uint256) {
return _aggregateSum(_ghost_pledgesAgainst, _disputeId);
}

function _aggregateSum(
mapping(address => mapping(bytes32 => uint256)) storage _data,
bytes32 _id
) internal view returns (uint256) {
uint256 sum;
for (uint256 i; i < _ghost_actors.length; i++) {
sum += _data[_ghost_actors[i]][_id];
}
return sum;
}

function _forEach(bytes32[] storage _arr, function (bytes32) _fn) internal {
for (uint256 i; i < _arr.length; i++) {
_fn(_arr[i]);
}
}

// Helper functions
function _getRandomChain(uint256 _seed) internal view returns (string memory) {
bytes32[] memory chainIds = eboRequestCreator.getAllowedChainIds();
Expand Down
16 changes: 11 additions & 5 deletions test/invariants/properties/PropertyDisputer.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,18 @@ contract PropertyDisputer is HandlerParent {

vm.prank(msg.sender);
try bondEscalationModule.pledgeForDispute(_requestData, _disputeData) {
assertTrue(_ghost_escalatedDisputes[_disputeId], 'property 8a: pledging for a dispute not escalated');
assertTrue(
_totalPledgesFor(_disputeId) <= _totalPledgesAgainst(_disputeId), 'property 8a: pledging for the wrong side'
);
} catch {
// !_ghost_escalatedDisputes or
// past deadline/tying buffer or
// already pledged this turn or
//
// add tying buffer to deadline

assertTrue(
!_ghost_escalatedDisputes[_disputeId]
|| block.timestamp > oracle.disputeCreatedAt(_disputeId) + DISPUTE_DEADLINE
|| _totalPledgesFor(_disputeId) > _totalPledgesAgainst(_disputeId),
'property 8a: fails on pledging for the correct side'
);
}
}

Expand Down
Loading