From 31bf0f85d7f149faab561b71ad71bd27223f4148 Mon Sep 17 00:00:00 2001 From: Igor Yalovoy Date: Thu, 5 Dec 2024 17:23:45 -0600 Subject: [PATCH] Add tests for single and batch transfer reverts in EngenBadges to ensure transfers are not allowed. --- test/unit/tokens/EngenBadges.t.sol | 57 ++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/test/unit/tokens/EngenBadges.t.sol b/test/unit/tokens/EngenBadges.t.sol index fe787e9a..0b40b089 100644 --- a/test/unit/tokens/EngenBadges.t.sol +++ b/test/unit/tokens/EngenBadges.t.sol @@ -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, ""); + } }