Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ contract DataAvailabilityChallengeTest is CommonTest {
// EntryPoint will revert if using amount > type(uint112).max.
vm.assume(sender != Preinstalls.EntryPoint_v060);
vm.assume(sender != address(dataAvailabilityChallenge));
vm.assume(sender != deploy.mustGetAddress("DataAvailabilityChallenge"));
vm.assume(sender.balance == 0);
vm.deal(sender, amount);

Expand Down
104 changes: 104 additions & 0 deletions packages/contracts-bedrock/test/dispute/DelayedWETH.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,110 @@ contract DelayedWETH_Unlock_Test is DelayedWETH_Init {
}

contract DelayedWETH_Withdraw_Test is DelayedWETH_Init {
/// @dev Tests that withdrawing while unlocked and delay has passed is successful.
function test_withdraw_whileUnlocked_succeeds() public {
// Deposit some WETH.
vm.prank(alice);
delayedWeth.deposit{ value: 1 ether }();
uint256 balance = address(alice).balance;

// Unlock the withdrawal.
vm.prank(alice);
delayedWeth.unlock(alice, 1 ether);

// Wait for the delay.
vm.warp(block.timestamp + delayedWeth.delay() + 1);

// Withdraw the WETH.
vm.expectEmit(true, true, false, false);
emit Withdrawal(address(alice), 1 ether);
vm.prank(alice);
delayedWeth.withdraw(1 ether);
assertEq(address(alice).balance, balance + 1 ether);
}

/// @dev Tests that withdrawing when unlock was not called fails.
function test_withdraw_whileLocked_fails() public {
// Deposit some WETH.
vm.prank(alice);
delayedWeth.deposit{ value: 1 ether }();
uint256 balance = address(alice).balance;

// Withdraw fails when unlock not called.
vm.expectRevert("DelayedWETH: withdrawal not unlocked");
vm.prank(alice);
delayedWeth.withdraw(0 ether);
assertEq(address(alice).balance, balance);
}

/// @dev Tests that withdrawing while locked and delay has not passed fails.
function test_withdraw_whileLockedNotLongEnough_fails() public {
// Deposit some WETH.
vm.prank(alice);
delayedWeth.deposit{ value: 1 ether }();
uint256 balance = address(alice).balance;

// Call unlock.
vm.prank(alice);
delayedWeth.unlock(alice, 1 ether);

// Wait for the delay, but not long enough.
vm.warp(block.timestamp + delayedWeth.delay() - 1);

// Withdraw fails when delay not met.
vm.expectRevert("DelayedWETH: withdrawal delay not met");
vm.prank(alice);
delayedWeth.withdraw(1 ether);
assertEq(address(alice).balance, balance);
}

/// @dev Tests that withdrawing more than unlocked amount fails.
function test_withdraw_tooMuch_fails() public {
// Deposit some WETH.
vm.prank(alice);
delayedWeth.deposit{ value: 1 ether }();
uint256 balance = address(alice).balance;

// Unlock the withdrawal.
vm.prank(alice);
delayedWeth.unlock(alice, 1 ether);

// Wait for the delay.
vm.warp(block.timestamp + delayedWeth.delay() + 1);

// Withdraw too much fails.
vm.expectRevert("DelayedWETH: insufficient unlocked withdrawal");
vm.prank(alice);
delayedWeth.withdraw(2 ether);
assertEq(address(alice).balance, balance);
}

/// @dev Tests that withdrawing while paused fails.
function test_withdraw_whenPaused_fails() public {
// Deposit some WETH.
vm.prank(alice);
delayedWeth.deposit{ value: 1 ether }();

// Unlock the withdrawal.
vm.prank(alice);
delayedWeth.unlock(alice, 1 ether);

// Wait for the delay.
vm.warp(block.timestamp + delayedWeth.delay() + 1);

// Pause the contract.
address guardian = optimismPortal.guardian();
vm.prank(guardian);
superchainConfig.pause("identifier");

// Withdraw fails.
vm.expectRevert("DelayedWETH: contract is paused");
vm.prank(alice);
delayedWeth.withdraw(1 ether);
}
}

contract DelayedWETH_WithdrawFrom_Test is DelayedWETH_Init {
/// @dev Tests that withdrawing while unlocked and delay has passed is successful.
function test_withdraw_whileUnlocked_succeeds() public {
// Deposit some WETH.
Expand Down