From ded7f35f5a08b023476fd50d49d7b30be00a469e Mon Sep 17 00:00:00 2001 From: donosonaumczuk Date: Mon, 9 Jan 2023 22:47:59 -0300 Subject: [PATCH] feat: Avoid self-following --- contracts/libraries/Errors.sol | 1 + contracts/libraries/helpers/InteractionHelpers.sol | 4 ++++ test/foundry/FollowTest.t.sol | 13 +++++++++++++ 3 files changed, 18 insertions(+) diff --git a/contracts/libraries/Errors.sol b/contracts/libraries/Errors.sol index b1d02c7..15936d0 100644 --- a/contracts/libraries/Errors.sol +++ b/contracts/libraries/Errors.sol @@ -61,6 +61,7 @@ library Errors { error ExecutorInvalid(); error Blocked(); error NotFollowing(); + error SelfFollow(); // Module Errors error InitParamsInvalid(); diff --git a/contracts/libraries/helpers/InteractionHelpers.sol b/contracts/libraries/helpers/InteractionHelpers.sol index 24f93c4..6417168 100644 --- a/contracts/libraries/helpers/InteractionHelpers.sol +++ b/contracts/libraries/helpers/InteractionHelpers.sol @@ -53,6 +53,10 @@ library InteractionHelpers { _validateNotBlocked(followerProfileId, idsOfProfilesToFollow[i]); + if (followerProfileId == idsOfProfilesToFollow[i]) { + revert Errors.SelfFollow(); + } + followTokenIdsAssigned[i] = _follow( followerProfileId, executor, diff --git a/test/foundry/FollowTest.t.sol b/test/foundry/FollowTest.t.sol index e9dff1f..7f71c51 100644 --- a/test/foundry/FollowTest.t.sol +++ b/test/foundry/FollowTest.t.sol @@ -199,6 +199,19 @@ contract FollowTest is BaseTest, AssumptionHelpers { }); } + function testCannotSelfFollow() public { + vm.expectRevert(Errors.SelfFollow.selector); + + _follow({ + pk: targetProfileOwnerPk, + isFollowerProfileOwner: true, + followerProfileId: targetProfileId, + idsOfProfilesToFollow: _toUint256Array(targetProfileId), + followTokenIds: _toUint256Array(MINT_NEW_TOKEN), + datas: _toBytesArray('') + }); + } + // Positives function testFollowAsFollowerOwner() public {