Skip to content

Commit

Permalink
Add tests for single and batch transfer reverts in EngenBadges to ens…
Browse files Browse the repository at this point in the history
…ure transfers are not allowed.
  • Loading branch information
ylv-io committed Dec 5, 2024
1 parent 30dac63 commit 31bf0f8
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions test/unit/tokens/EngenBadges.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -344,4 +344,61 @@ contract EngenBadgesTest is SharedSetup {
vm.expectRevert(abi.encodeWithSelector(EngenBadges.BurnTooManyAddresses.selector));
_engenBadges.burnBadgesBatch(accounts, ids, amounts);
}

function testTransfer_RevertWhen_SingleTransfer() public {
// First mint a badge to alice
uint256[] memory ids = new uint256[](1);
ids[0] = 1;

UserOperation[] memory userOps = new UserOperation[](1);
userOps[0] = _createUserOperation(
address(_kintoWallet),
address(_engenBadges),
_kintoWallet.getNonce(),
privateKeys,
abi.encodeWithSignature("mintBadges(address,uint256[])", alice, ids),
address(_paymaster)
);

_entryPoint.handleOps(userOps, payable(_owner));
assertEq(_engenBadges.balanceOf(alice, 1), 1);

// Try to transfer from alice to bob
vm.prank(alice);
vm.expectRevert(EngenBadges.TransferNotAllowed.selector);
_engenBadges.safeTransferFrom(alice, bob, 1, 1, "");
}

function testTransfer_RevertWhen_BatchTransfer() public {
// First mint multiple badges to alice
uint256[] memory ids = new uint256[](2);
ids[0] = 1;
ids[1] = 2;

UserOperation[] memory userOps = new UserOperation[](1);
userOps[0] = _createUserOperation(
address(_kintoWallet),
address(_engenBadges),
_kintoWallet.getNonce(),
privateKeys,
abi.encodeWithSignature("mintBadges(address,uint256[])", alice, ids),
address(_paymaster)
);

_entryPoint.handleOps(userOps, payable(_owner));
assertEq(_engenBadges.balanceOf(alice, 1), 1);
assertEq(_engenBadges.balanceOf(alice, 2), 1);

// Try to batch transfer from alice to bob
uint256[] memory transferIds = new uint256[](2);
transferIds[0] = 1;
transferIds[1] = 2;
uint256[] memory amounts = new uint256[](2);
amounts[0] = 1;
amounts[1] = 1;

vm.prank(alice);
vm.expectRevert(EngenBadges.TransferNotAllowed.selector);
_engenBadges.safeBatchTransferFrom(alice, bob, transferIds, amounts, "");
}
}

0 comments on commit 31bf0f8

Please sign in to comment.