Skip to content

Commit

Permalink
Removed block check from setrefunded (OffchainLabs#419)
Browse files Browse the repository at this point in the history
  • Loading branch information
yahgwai authored Aug 24, 2023
1 parent fb9d12b commit 577a12f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
5 changes: 1 addition & 4 deletions contracts/src/challengeV2/libraries/ChallengeEdgeLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,11 @@ library ChallengeEdgeLib {
}

/// @notice Set the refunded flag of an edge
/// @dev Checks internally that edge is confirmed, Block type, layer zero edge and hasnt been refunded already
/// @dev Checks internally that edge is confirmed, layer zero edge and hasnt been refunded already
function setRefunded(ChallengeEdge storage edge) internal {
if (edge.status != EdgeStatus.Confirmed) {
revert EdgeNotConfirmed(ChallengeEdgeLib.id(edge), edge.status);
}
if (edge.eType != EdgeType.Block) {
revert EdgeTypeNotBlock(edge.eType);
}
if (!isLayerZero(edge)) {
revert EdgeNotLayerZero(ChallengeEdgeLib.id(edge), edge.staker, edge.claimId);
}
Expand Down
18 changes: 14 additions & 4 deletions contracts/test/challengeV2/EdgeChallengeManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1395,16 +1395,26 @@ contract EdgeChallengeManagerTest is Test {
ei.challengeManager.refundStake(allWinners[16].lowerChildId);
}

function testRevertRefundStakeBigStep() external {
function testRefundStakeBigStep() external {
(EdgeInitData memory ei, BisectionChildren[] memory allWinners) = testCanConfirmByOneStep();
vm.expectRevert(abi.encodeWithSelector(EdgeTypeNotBlock.selector, EdgeType.BigStep));

IERC20 stakeToken = ei.challengeManager.stakeToken();
uint256 beforeBalance = stakeToken.balanceOf(address(this));
vm.prank(nobody); // call refund as nobody
ei.challengeManager.refundStake(allWinners[11].lowerChildId);
uint256 afterBalance = stakeToken.balanceOf(address(this));
assertEq(afterBalance - beforeBalance, ei.challengeManager.stakeAmount(), "Stake refunded");
}

function testRevertRefundStakeSmallStep() external {
function testRefundStakeSmallStep() external {
(EdgeInitData memory ei, BisectionChildren[] memory allWinners) = testCanConfirmByOneStep();
vm.expectRevert(abi.encodeWithSelector(EdgeTypeNotBlock.selector, EdgeType.SmallStep));

IERC20 stakeToken = ei.challengeManager.stakeToken();
uint256 beforeBalance = stakeToken.balanceOf(address(this));
vm.prank(nobody); // call refund as nobody
ei.challengeManager.refundStake(allWinners[5].lowerChildId);
uint256 afterBalance = stakeToken.balanceOf(address(this));
assertEq(afterBalance - beforeBalance, ei.challengeManager.stakeAmount(), "Stake refunded");
}

function testRevertRefundStakeNotConfirmed() external {
Expand Down

0 comments on commit 577a12f

Please sign in to comment.