@@ -38,7 +38,7 @@ contract BottomTournamentTest is Util, Test {
3838
3939 function setUp () public {}
4040
41- function testBottom1 () public {
41+ function testComputeStep () public {
4242 topTournament = Util.initializePlayer0Tournament (factory);
4343
4444 // pair commitment, expect a match
@@ -148,7 +148,7 @@ contract BottomTournamentTest is Util, Test {
148148 Util.winLeafMatch (bottomTournament, _matchId, _playerToSeal);
149149 }
150150
151- function testBottom2 () public {
151+ function testComputeReset () public {
152152 topTournament = Util.initializePlayer0Tournament (factory);
153153
154154 // pair commitment, expect a match
@@ -278,4 +278,359 @@ contract BottomTournamentTest is Util, Test {
278278 // win match, expect revert
279279 Util.winLeafMatch (bottomTournament, _matchId, _playerToSeal);
280280 }
281+
282+ function testRollupsCmio () public {
283+ topTournament = Util.initializePlayer0RollupsTournament (factory);
284+
285+ // pair commitment, expect a match
286+ // player 1 joins tournament
287+ uint256 _opponent = 1 ;
288+ uint64 _height = 0 ;
289+ Util.joinTournament (topTournament, _opponent);
290+
291+ Match.Id memory _matchId = Util.matchId (_opponent, _height);
292+ Match.State memory _match =
293+ topTournament.getMatch (_matchId.hashFromId ());
294+ assertTrue (_match.exists (), "match should exist " );
295+
296+ // advance match to end, this match will always advance to left tree
297+ uint256 _playerToSeal =
298+ Util.advanceMatch (topTournament, _matchId, _opponent);
299+
300+ // expect new inner created
301+ vm.recordLogs ();
302+
303+ // seal match
304+ Util.sealInnerMatchAndCreateInnerTournament (
305+ topTournament, _matchId, _playerToSeal
306+ );
307+ _height += 1 ;
308+
309+ assertEq (
310+ topTournament.getMatchCycle (_matchId.hashFromId ()),
311+ 0 ,
312+ "agree cycle should be zero "
313+ );
314+
315+ Vm.Log[] memory _entries = vm.getRecordedLogs ();
316+ assertEq (_entries[0 ].topics.length , 2 );
317+ assertEq (
318+ _entries[0 ].topics[0 ],
319+ keccak256 ("newInnerTournament(bytes32,address) " )
320+ );
321+ assertEq (
322+ _entries[0 ].topics[1 ], Match.IdHash.unwrap (_matchId.hashFromId ())
323+ );
324+
325+ middleTournament = MiddleTournament (
326+ address (bytes20 (bytes32 (_entries[0 ].data) << (12 * 8 )))
327+ );
328+
329+ Util.joinTournament (middleTournament, 0 );
330+ Util.joinTournament (middleTournament, _opponent);
331+
332+ _matchId = Util.matchId (_opponent, _height);
333+ _match = middleTournament.getMatch (_matchId.hashFromId ());
334+ assertTrue (_match.exists (), "match should exist " );
335+
336+ // advance match to end, this match will always advance to left tree
337+ _playerToSeal = Util.advanceMatch (middleTournament, _matchId, _opponent);
338+
339+ // expect new inner created (middle 2)
340+ vm.recordLogs ();
341+
342+ // seal match
343+ Util.sealInnerMatchAndCreateInnerTournament (
344+ middleTournament, _matchId, _playerToSeal
345+ );
346+ _height += 1 ;
347+
348+ assertEq (
349+ middleTournament.getMatchCycle (_matchId.hashFromId ()),
350+ 0 ,
351+ "agree cycle should be zero "
352+ );
353+
354+ _entries = vm.getRecordedLogs ();
355+ assertEq (_entries[0 ].topics.length , 2 );
356+ assertEq (
357+ _entries[0 ].topics[0 ],
358+ keccak256 ("newInnerTournament(bytes32,address) " )
359+ );
360+ assertEq (
361+ _entries[0 ].topics[1 ], Match.IdHash.unwrap (_matchId.hashFromId ())
362+ );
363+
364+ bottomTournament = BottomTournament (
365+ address (bytes20 (bytes32 (_entries[0 ].data) << (12 * 8 )))
366+ );
367+
368+ Util.joinTournament (bottomTournament, 0 );
369+ Util.joinTournament (bottomTournament, _opponent);
370+
371+ _matchId = Util.matchId (_opponent, _height);
372+ _match = bottomTournament.getMatch (_matchId.hashFromId ());
373+ assertTrue (_match.exists (), "match should exist " );
374+
375+ // advance match to end, this match will always advance to left tree
376+ _playerToSeal = Util.advanceMatch (bottomTournament, _matchId, _opponent);
377+
378+ // seal match
379+ Util.sealLeafMatch (bottomTournament, _matchId, _playerToSeal);
380+
381+ assertEq (
382+ bottomTournament.getMatchCycle (_matchId.hashFromId ()),
383+ 0 ,
384+ "agree cycle should be zero "
385+ );
386+
387+ vm.expectRevert ();
388+ // win match, expect revert
389+ Util.winLeafMatchRollupsWithInput (
390+ bottomTournament, _matchId, _playerToSeal
391+ );
392+ }
393+
394+ function testRollupsStep () public {
395+ topTournament = Util.initializePlayer0RollupsTournament (factory);
396+
397+ // pair commitment, expect a match
398+ // player 1 joins tournament
399+ uint256 _opponent = 1 ;
400+ uint64 _height = 0 ;
401+ Util.joinTournament (topTournament, _opponent);
402+
403+ Match.Id memory _matchId = Util.matchId (_opponent, _height);
404+ Match.State memory _match =
405+ topTournament.getMatch (_matchId.hashFromId ());
406+ assertTrue (_match.exists (), "match should exist " );
407+
408+ // advance match to end, this match will always advance to left tree
409+ uint256 _playerToSeal =
410+ Util.advanceMatch (topTournament, _matchId, _opponent);
411+
412+ // expect new inner created
413+ vm.recordLogs ();
414+
415+ // seal match
416+ Util.sealInnerMatchAndCreateInnerTournament (
417+ topTournament, _matchId, _playerToSeal
418+ );
419+ _height += 1 ;
420+
421+ assertEq (
422+ topTournament.getMatchCycle (_matchId.hashFromId ()),
423+ 0 ,
424+ "agree cycle should be zero "
425+ );
426+
427+ Vm.Log[] memory _entries = vm.getRecordedLogs ();
428+ assertEq (_entries[0 ].topics.length , 2 );
429+ assertEq (
430+ _entries[0 ].topics[0 ],
431+ keccak256 ("newInnerTournament(bytes32,address) " )
432+ );
433+ assertEq (
434+ _entries[0 ].topics[1 ], Match.IdHash.unwrap (_matchId.hashFromId ())
435+ );
436+
437+ middleTournament = MiddleTournament (
438+ address (bytes20 (bytes32 (_entries[0 ].data) << (12 * 8 )))
439+ );
440+
441+ Util.joinTournament (middleTournament, 0 );
442+ Util.joinTournament (middleTournament, _opponent);
443+
444+ _matchId = Util.matchId (_opponent, _height);
445+ _match = middleTournament.getMatch (_matchId.hashFromId ());
446+ assertTrue (_match.exists (), "match should exist " );
447+
448+ // advance match to end, this match will always advance to left tree
449+ _playerToSeal = Util.advanceMatch (middleTournament, _matchId, _opponent);
450+
451+ // expect new inner created (middle 2)
452+ vm.recordLogs ();
453+
454+ // seal match
455+ Util.sealInnerMatchAndCreateInnerTournament (
456+ middleTournament, _matchId, _playerToSeal
457+ );
458+ _height += 1 ;
459+
460+ assertEq (
461+ middleTournament.getMatchCycle (_matchId.hashFromId ()),
462+ 0 ,
463+ "agree cycle should be zero "
464+ );
465+
466+ _entries = vm.getRecordedLogs ();
467+ assertEq (_entries[0 ].topics.length , 2 );
468+ assertEq (
469+ _entries[0 ].topics[0 ],
470+ keccak256 ("newInnerTournament(bytes32,address) " )
471+ );
472+ assertEq (
473+ _entries[0 ].topics[1 ], Match.IdHash.unwrap (_matchId.hashFromId ())
474+ );
475+
476+ bottomTournament = BottomTournament (
477+ address (bytes20 (bytes32 (_entries[0 ].data) << (12 * 8 )))
478+ );
479+
480+ Util.joinTournament (bottomTournament, 0 );
481+ Util.joinTournament (bottomTournament, _opponent);
482+
483+ _matchId = Util.matchId (_opponent, _height);
484+ _match = bottomTournament.getMatch (_matchId.hashFromId ());
485+ assertTrue (_match.exists (), "match should exist " );
486+
487+ // advance match to end, this match will always advance to left tree
488+ _playerToSeal = Util.advanceMatch (bottomTournament, _matchId, _opponent);
489+
490+ // seal match
491+ Util.sealLeafMatch (bottomTournament, _matchId, _playerToSeal);
492+
493+ assertEq (
494+ bottomTournament.getMatchCycle (_matchId.hashFromId ()),
495+ 0 ,
496+ "agree cycle should be zero "
497+ );
498+
499+ vm.expectRevert ();
500+ // win match, expect revert
501+ Util.winLeafMatchRollupsWithoutInput (
502+ bottomTournament, _matchId, _playerToSeal
503+ );
504+ }
505+
506+ function testRollupsReset () public {
507+ topTournament = Util.initializePlayer0RollupsTournament (factory);
508+
509+ // pair commitment, expect a match
510+ // player 2 joins tournament
511+ uint256 _opponent = 2 ;
512+ uint64 _height = 0 ;
513+ Util.joinTournament (topTournament, _opponent);
514+
515+ Match.Id memory _matchId = Util.matchId (_opponent, _height);
516+ Match.State memory _match =
517+ topTournament.getMatch (_matchId.hashFromId ());
518+ assertTrue (_match.exists (), "match should exist " );
519+
520+ // advance match to end, this match will always advance to right tree
521+ uint256 _playerToSeal =
522+ Util.advanceMatch (topTournament, _matchId, _opponent);
523+
524+ // expect new inner created
525+ vm.recordLogs ();
526+
527+ // seal match
528+ Util.sealInnerMatchAndCreateInnerTournament (
529+ topTournament, _matchId, _playerToSeal
530+ );
531+ _height += 1 ;
532+
533+ uint256 cycle = (
534+ 1
535+ << (
536+ ArbitrationConstants.height (0 )
537+ + ArbitrationConstants.log2step (0 )
538+ )
539+ ) - (1 << ArbitrationConstants.log2step (0 ));
540+ assertEq (
541+ topTournament.getMatchCycle (_matchId.hashFromId ()),
542+ cycle,
543+ "agree cycle should be 4951760157141503507410452480 "
544+ );
545+
546+ Vm.Log[] memory _entries = vm.getRecordedLogs ();
547+ assertEq (_entries[0 ].topics.length , 2 );
548+ assertEq (
549+ _entries[0 ].topics[0 ],
550+ keccak256 ("newInnerTournament(bytes32,address) " )
551+ );
552+ assertEq (
553+ _entries[0 ].topics[1 ], Match.IdHash.unwrap (_matchId.hashFromId ())
554+ );
555+
556+ middleTournament = MiddleTournament (
557+ address (bytes20 (bytes32 (_entries[0 ].data) << (12 * 8 )))
558+ );
559+
560+ Util.joinTournament (middleTournament, 0 );
561+ Util.joinTournament (middleTournament, _opponent);
562+
563+ _matchId = Util.matchId (_opponent, _height);
564+ _match = middleTournament.getMatch (_matchId.hashFromId ());
565+ assertTrue (_match.exists (), "match should exist " );
566+
567+ // advance match to end, this match will always advance to right tree
568+ _playerToSeal = Util.advanceMatch (middleTournament, _matchId, _opponent);
569+
570+ // expect new inner created (middle 2)
571+ vm.recordLogs ();
572+
573+ // seal match
574+ Util.sealInnerMatchAndCreateInnerTournament (
575+ middleTournament, _matchId, _playerToSeal
576+ );
577+ _height += 1 ;
578+
579+ cycle = (
580+ 1
581+ << (
582+ ArbitrationConstants.height (0 )
583+ + ArbitrationConstants.log2step (0 )
584+ )
585+ ) - (1 << ArbitrationConstants.log2step (1 ));
586+ assertEq (
587+ middleTournament.getMatchCycle (_matchId.hashFromId ()),
588+ cycle,
589+ "agree cycle should be 4951760157141521099462279168 "
590+ );
591+
592+ _entries = vm.getRecordedLogs ();
593+ assertEq (_entries[0 ].topics.length , 2 );
594+ assertEq (
595+ _entries[0 ].topics[0 ],
596+ keccak256 ("newInnerTournament(bytes32,address) " )
597+ );
598+ assertEq (
599+ _entries[0 ].topics[1 ], Match.IdHash.unwrap (_matchId.hashFromId ())
600+ );
601+
602+ bottomTournament = BottomTournament (
603+ address (bytes20 (bytes32 (_entries[0 ].data) << (12 * 8 )))
604+ );
605+
606+ Util.joinTournament (bottomTournament, 0 );
607+ Util.joinTournament (bottomTournament, _opponent);
608+
609+ _matchId = Util.matchId (_opponent, _height);
610+ _match = bottomTournament.getMatch (_matchId.hashFromId ());
611+ assertTrue (_match.exists (), "match should exist " );
612+
613+ // advance match to end, this match will always advance to right tree
614+ _playerToSeal = Util.advanceMatch (bottomTournament, _matchId, _opponent);
615+
616+ // seal match
617+ Util.sealLeafMatch (bottomTournament, _matchId, _playerToSeal);
618+
619+ cycle = (
620+ 1
621+ << (
622+ ArbitrationConstants.height (0 )
623+ + ArbitrationConstants.log2step (0 )
624+ )
625+ ) - (1 << ArbitrationConstants.log2step (2 ));
626+ assertEq (
627+ bottomTournament.getMatchCycle (_matchId.hashFromId ()),
628+ cycle,
629+ "agree cycle should be 4951760157141521099596496895 "
630+ );
631+
632+ vm.expectRevert ();
633+ // win match, expect revert
634+ Util.winLeafMatch (bottomTournament, _matchId, _playerToSeal);
635+ }
281636}
0 commit comments