Skip to content

Commit

Permalink
fix(test): adapt to new timing constants
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenctw committed Feb 19, 2024
1 parent 03d1ef0 commit 7638924
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 9 deletions.
43 changes: 38 additions & 5 deletions permissionless-arbitration/contracts/test/MultiTournament.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ contract MultiTournamentTest is Util, Test {
_playerToSeal =
Util.advanceMatch01AtLevel(middleTournament, _matchId, 1);

// expect new inner created (bottom)
// expect new inner created (middle 2)
vm.recordLogs();

// seal match
Expand All @@ -159,20 +159,53 @@ contract MultiTournamentTest is Util, Test {
_entries[0].topics[1], Match.IdHash.unwrap(_matchId.hashFromId())
);

bottomTournament = BottomTournament(
MiddleTournament middleTournament2 = MiddleTournament(
address(bytes20(bytes32(_entries[0].data) << (12 * 8)))
);

Util.joinTournament(bottomTournament, 0, 2);
Util.joinTournament(bottomTournament, 1, 2);
Util.joinTournament(middleTournament2, 0, 2);
Util.joinTournament(middleTournament2, 1, 2);

_matchId = Util.matchId(1, 2);
_match = middleTournament2.getMatch(_matchId.hashFromId());
assertTrue(_match.exists(), "match should exist");

// advance match to end, this match will always advance to left tree
_playerToSeal =
Util.advanceMatch01AtLevel(middleTournament2, _matchId, 2);

// expect new inner created (bottom)
vm.recordLogs();

// seal match
Util.sealInnerMatchAndCreateInnerTournament(
middleTournament2, _matchId, _playerToSeal
);

_entries = vm.getRecordedLogs();
assertEq(_entries[0].topics.length, 2);
assertEq(
_entries[0].topics[0],
keccak256("newInnerTournament(bytes32,address)")
);
assertEq(
_entries[0].topics[1], Match.IdHash.unwrap(_matchId.hashFromId())
);

bottomTournament = BottomTournament(
address(bytes20(bytes32(_entries[0].data) << (12 * 8)))
);

Util.joinTournament(bottomTournament, 0, 3);
Util.joinTournament(bottomTournament, 1, 3);

_matchId = Util.matchId(1, 3);
_match = bottomTournament.getMatch(_matchId.hashFromId());
assertTrue(_match.exists(), "match should exist");

// advance match to end, this match will always advance to left tree
_playerToSeal =
Util.advanceMatch01AtLevel(bottomTournament, _matchId, 2);
Util.advanceMatch01AtLevel(bottomTournament, _matchId, 3);

// seal match
Util.sealLeafMatch(bottomTournament, _matchId, _playerToSeal);
Expand Down
9 changes: 5 additions & 4 deletions permissionless-arbitration/contracts/test/Util.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,17 @@ contract Util {
Tree.Node constant TWO_NODE = Tree.Node.wrap(bytes32(uint256(2)));
Machine.Hash constant ONE_STATE = Machine.Hash.wrap(bytes32(uint256(1)));
Machine.Hash constant TWO_STATE = Machine.Hash.wrap(bytes32(uint256(2)));
uint64 constant LOG2_MAX_HEIGHT = 63;

// players' commitment node at different height
// player 0, player 1, and player 2
Tree.Node[][3] playerNodes;
Machine.Hash[3] finalStates;

constructor() {
playerNodes[0] = new Tree.Node[](ArbitrationConstants.height(0) + 1);
playerNodes[1] = new Tree.Node[](ArbitrationConstants.height(0) + 1);
playerNodes[2] = new Tree.Node[](ArbitrationConstants.height(0) + 1);
playerNodes[0] = new Tree.Node[](LOG2_MAX_HEIGHT + 1);
playerNodes[1] = new Tree.Node[](LOG2_MAX_HEIGHT + 1);
playerNodes[2] = new Tree.Node[](LOG2_MAX_HEIGHT + 1);

playerNodes[0][0] = ONE_NODE;
playerNodes[1][0] = TWO_NODE;
Expand All @@ -51,7 +52,7 @@ contract Util {
finalStates[1] = TWO_STATE;
finalStates[2] = TWO_STATE;

for (uint256 _i = 1; _i <= ArbitrationConstants.height(0); _i++) {
for (uint256 _i = 1; _i <= LOG2_MAX_HEIGHT; _i++) {
// player 0 is all 1
playerNodes[0][_i] =
playerNodes[0][_i - 1].join(playerNodes[0][_i - 1]);
Expand Down

0 comments on commit 7638924

Please sign in to comment.