Skip to content

Commit

Permalink
L2
Browse files Browse the repository at this point in the history
  • Loading branch information
sanbir committed Oct 22, 2024
1 parent 92e6378 commit ef5da54
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/MerkleAirdrop.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import "./@openzeppelin/utils/Address.sol";
error MerkleAirdrop__AlreadyClaimed();
error MerkleAirdrop__InvalidProof();
error MerkleAirdrop__SameRoot();
error MerkleAirdrop__ZeroAddress();

contract MerkleAirdrop is Ownable2Step {
bytes32 public merkleRoot;
Expand All @@ -25,9 +26,7 @@ contract MerkleAirdrop is Ownable2Step {
}

function setMerkleRoot(bytes32 _merkleRoot) external onlyOwner {
if (_merkleRoot == merkleRoot) {
revert MerkleAirdrop__SameRoot();
}
require (_merkleRoot != merkleRoot, MerkleAirdrop__SameRoot());

merkleRoot = _merkleRoot;
emit MerkleAirdrop__MerkleRootSet(_merkleRoot);
Expand All @@ -52,6 +51,8 @@ contract MerkleAirdrop is Ownable2Step {
}

function recoverEther(address payable _recipient) external onlyOwner {
require (_recipient != address(0), MerkleAirdrop__ZeroAddress());

emit MerkleAirdrop__EtherRecovered(_recipient, address(this).balance);
Address.sendValue(_recipient, address(this).balance);
}
Expand Down
26 changes: 26 additions & 0 deletions test/TestMerkleAirdrop.sol
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,32 @@ contract TestMerkleAirdrop is Test {
merkleAirdrop.setMerkleRoot(bytes32(uint256(42)));
vm.stopPrank();
}

function test_RecoverEther() external {
vm.startPrank(deployer);
merkleAirdrop.transferOwnership(owner);
vm.stopPrank();

vm.startPrank(owner);
merkleAirdrop.acceptOwnership();

uint256 balanceBefore = address(merkleAirdrop).balance;
Address.sendValue(payable(address(merkleAirdrop)), TOTAL_ETHER);
uint256 balanceAfter = address(merkleAirdrop).balance;
assertEq(balanceAfter - balanceBefore, TOTAL_ETHER);

vm.expectRevert(MerkleAirdrop__ZeroAddress.selector);
merkleAirdrop.recoverEther(payable(address(0)));

uint256 balance42Before = address(42).balance;
merkleAirdrop.recoverEther(payable(address(42)));
uint256 balance42After = address(42).balance;

assertEq(address(merkleAirdrop).balance, 0);
assertEq(balance42After - balance42Before, TOTAL_ETHER);

vm.stopPrank();
}
}

struct Claim {
Expand Down

0 comments on commit ef5da54

Please sign in to comment.