From 46a964e6032fbadf3769bec7992fc614adfb5065 Mon Sep 17 00:00:00 2001 From: vicnaum Date: Fri, 13 Oct 2023 19:00:09 +0200 Subject: [PATCH] misc: C4-168-N04 Allow to unfollow() for burnt target profiles T-16806 --- contracts/libraries/FollowLib.sol | 3 ++- test/UnfollowTest.t.sol | 25 +++++++++++++++++++------ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/contracts/libraries/FollowLib.sol b/contracts/libraries/FollowLib.sol index c3aedc4..f494370 100644 --- a/contracts/libraries/FollowLib.sol +++ b/contracts/libraries/FollowLib.sol @@ -63,10 +63,11 @@ library FollowLib { uint256 i; while (i < idsOfProfilesToUnfollow.length) { uint256 idOfProfileToUnfollow = idsOfProfilesToUnfollow[i]; - ValidationLib.validateProfileExists(idOfProfileToUnfollow); address followNFT = StorageLib.getProfile(idOfProfileToUnfollow).followNFT; + // We don't validate the profile exists because we want to allow unfollowing a burnt profile. + // Because, if the profile never existed, followNFT will be address(0) and the call will revert. if (followNFT == address(0)) { revert Errors.NotFollowing(); } diff --git a/test/UnfollowTest.t.sol b/test/UnfollowTest.t.sol index f8b9bc7..90694fd 100644 --- a/test/UnfollowTest.t.sol +++ b/test/UnfollowTest.t.sol @@ -78,7 +78,7 @@ contract UnfollowTest is BaseTest { assertTrue(hub.isFollowing(testUnfollowerProfileId, targetProfileId)); - vm.expectRevert(Errors.TokenDoesNotExist.selector); + vm.expectRevert(Errors.NotFollowing.selector); _unfollow({ pk: testUnfollowerProfileOwnerPk, @@ -190,6 +190,23 @@ contract UnfollowTest is BaseTest { assertFalse(hub.isFollowing(testUnfollowerProfileId, targetProfileId)); } + function testUnfollowIfTargetProfileWasBurned() public { + assertTrue(hub.isFollowing(testUnfollowerProfileId, targetProfileId)); + + _effectivelyDisableProfileGuardian(targetProfileOwner); + vm.prank(targetProfileOwner); + hub.burn(targetProfileId); + + _unfollow({ + pk: testUnfollowerProfileOwnerPk, + unfollowerProfileId: testUnfollowerProfileId, + idsOfProfilesToUnfollow: _toUint256Array(targetProfileId) + }); + + // Asserts that the unfollow operation was still a success. + assertFalse(hub.isFollowing(testUnfollowerProfileId, targetProfileId)); + } + function _unfollow( uint256 pk, uint256 unfollowerProfileId, @@ -238,11 +255,7 @@ contract UnfollowMetaTxTest is UnfollowTest, MetaTxNegatives { }); } - function _executeMetaTx( - uint256 signerPk, - uint256 nonce, - uint256 deadline - ) internal virtual override { + function _executeMetaTx(uint256 signerPk, uint256 nonce, uint256 deadline) internal virtual override { hub.unfollowWithSig({ unfollowerProfileId: testUnfollowerProfileId, idsOfProfilesToUnfollow: _toUint256Array(targetProfileId),