diff --git a/src/MerkleAirdrop.sol b/src/MerkleAirdrop.sol index d09c049..013b7b4 100644 --- a/src/MerkleAirdrop.sol +++ b/src/MerkleAirdrop.sol @@ -9,6 +9,7 @@ import "./@openzeppelin/utils/Address.sol"; error MerkleAirdrop__AlreadyClaimed(); error MerkleAirdrop__InvalidProof(); +error MerkleAirdrop__SameRoot(); contract MerkleAirdrop is Ownable2Step { bytes32 public merkleRoot; @@ -24,6 +25,10 @@ contract MerkleAirdrop is Ownable2Step { } function setMerkleRoot(bytes32 _merkleRoot) external onlyOwner { + if (_merkleRoot == merkleRoot) { + revert MerkleAirdrop__SameRoot(); + } + merkleRoot = _merkleRoot; emit MerkleAirdrop__MerkleRootSet(_merkleRoot); } diff --git a/test/TestMerkleAirdrop.sol b/test/TestMerkleAirdrop.sol index 11bc345..2554e5d 100644 --- a/test/TestMerkleAirdrop.sol +++ b/test/TestMerkleAirdrop.sol @@ -91,6 +91,21 @@ contract TestMerkleAirdrop is Test { assertEq(balanceAfter - balanceBefore, claims[i].amount); } } + + function test_SetMerkleRoot() external { + vm.startPrank(deployer); + merkleAirdrop.transferOwnership(owner); + vm.stopPrank(); + + vm.startPrank(owner); + merkleAirdrop.acceptOwnership(); + + vm.expectRevert(MerkleAirdrop__SameRoot.selector); + merkleAirdrop.setMerkleRoot(root); + + merkleAirdrop.setMerkleRoot(bytes32(uint256(42))); + vm.stopPrank(); + } } struct Claim {