Skip to content

Commit

Permalink
failed test
Browse files Browse the repository at this point in the history
  • Loading branch information
panditdhamdhere committed Sep 12, 2024
1 parent 343ff09 commit c72f852
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/MerkleAirdrop.sol
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ contract MerkleAirdrop is EIP712 {
}

// check the signature
if (_isValidSignature(account, getMessage(account, amount), v, r, s)) {
if (_isValidSignature(account, getMessageHash(account, amount), v, r, s)) {
revert MerkleAirdrop__SignatureInvalid();
}

Expand All @@ -94,7 +94,7 @@ contract MerkleAirdrop is EIP712 {
i_airdropToken.safeTransfer(account, amount);
}

function getMessage(
function getMessageHash(
address account,
uint256 amount
) public view returns (bytes32) {
Expand Down
14 changes: 11 additions & 3 deletions test/MerkleAirdropTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ contract MerkleAirdropTest is ZkSyncChainChecker, Test {
0xe5ebd1e1b5a5478a944ecab36a9a954ac3b6b8216875f6524caa7a1d87096576;
bytes32[] public PROOF = [proofOne, proofTwo];

address public gasPayer;
address user;
uint256 userPrivKey;

Expand All @@ -34,15 +35,22 @@ contract MerkleAirdropTest is ZkSyncChainChecker, Test {
airdrop = new MerkleAirdrop(ROOT, token);
token.mint(token.owner(), AMOUNT_TO_SEND);
token.transfer(address(airdrop), AMOUNT_TO_SEND);
(user, userPrivKey) = makeAddrAndKey("user");
}
(user, userPrivKey) = makeAddrAndKey("user");
gasPayer = makeAddr("gasPayer");
}

function testUsersCanClaim() public {
uint256 startingBalance = token.balanceOf(user);
bytes32 digest = airdrop.getMessageHash(user, AMOUNT_TO_CLAIM);

vm.prank(user);
airdrop.claim(user, AMOUNT_TO_CLAIM, PROOF);
// vm.prank(user);
// sign a message
(uint8 v, bytes32 r, bytes32 s) = vm.sign(userPrivKey, digest);

// gaspayer calls claim using the signed message
vm.prank(gasPayer);
airdrop.claim(user, AMOUNT_TO_CLAIM, PROOF, v, r, s);

uint256 endingBalance = token.balanceOf(user);
console.log("airdrop address this tokens:", endingBalance);
Expand Down

0 comments on commit c72f852

Please sign in to comment.