Skip to content

Instantly share code, notes, and snippets.

@adeolu98
Created July 30, 2023 17:08
Show Gist options
  • Save adeolu98/4b3b737c9f4ebbb8d7a9565338ef0318 to your computer and use it in GitHub Desktop.
Save adeolu98/4b3b737c9f4ebbb8d7a9565338ef0318 to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
import 'test/base/BaseTest.t.sol';
import {ProfileLib} from 'contracts/libraries/ProfileLib.sol';
import {MockFollowModuleWithRevertFlag} from 'test/mocks/MockFollowModuleWithRevertFlag.sol';
import {IFollowModule} from 'contracts/interfaces/IFollowModule.sol';
import {ValidationLib} from 'contracts/libraries/ValidationLib.sol';
import {TokenGatedReferenceModule, GateParams} from 'contracts/modules/reference/TokenGatedReferenceModule.sol';
import {Types} from 'contracts/libraries/constants/Types.sol';
import 'test/mocks/MockCurrency.sol';
contract LensHubTest is BaseTest {
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
function setUp() public override {
super.setUp();
}
function testSpammerIdea() public {
//make erc20 for tokenGated reference module
MockCurrency gatedToken = new MockCurrency();
//deploy new TokenGatedReferenceModule;
TokenGatedReferenceModule _tokenGatedReferenceModule = new TokenGatedReferenceModule(address(hub));
// get test accounts and mint them the gated tokens
TestAccount memory userOne = _loadAccountAs('PUBLISHER');
gatedToken.mint(userOne.owner, 10);
TestAccount memory userTwo = _loadAccountAs('ANOTHER_PUBLISHER');
gatedToken.mint(userTwo.owner, 10);
// whitelist addresses and reference module
vm.startPrank(governance);
hub.whitelistProfileCreator(userOne.owner, true);
hub.whitelistProfileCreator(userTwo.owner, true);
hub.whitelistReferenceModule(address(_tokenGatedReferenceModule), true);
// create postParams
Types.PostParams memory postParams = _getDefaultPostParams();
postParams.referenceModule = address(_tokenGatedReferenceModule);
postParams.referenceModuleInitData = abi.encode(
GateParams({tokenAddress: address(gatedToken), minThreshold: 1})
);
postParams.profileId = userOne.profileId;
//user 1 makes a post
vm.startPrank(userOne.owner);
uint userOnePostPubIdAssigned = hub.post(postParams);
//userTwo, a spammer blocks user 1 so user1 cant notice his comment.
vm.startPrank(userTwo.owner);
hub.setBlockStatus({
byProfileId: userTwo.profileId,
idsOfProfilesToSetBlockStatus: _toUint256Array(userOne.profileId),
blockStatus: _toBoolArray(true)
});
//usertwo comments his spam message on user1 post after blocking user 1
Types.CommentParams memory UserTwoCommentParams = _getDefaultCommentParams();
UserTwoCommentParams.profileId = userTwo.profileId;
UserTwoCommentParams.pointedProfileId = userOne.profileId;
UserTwoCommentParams.pointedPubId = userOnePostPubIdAssigned;
UserTwoCommentParams.referenceModule = address(_tokenGatedReferenceModule);
UserTwoCommentParams.referenceModuleInitData = abi.encode(
GateParams({tokenAddress: address(gatedToken), minThreshold: 1})
);
uint userTwoCommentPubId = hub.comment(UserTwoCommentParams);
assert(userTwoCommentPubId != 0);
//userOne cannot comment under the comment of user two the spammer because user two has blocked user one
vm.startPrank(userOne.owner);
vm.expectRevert(Errors.Blocked.selector);
Types.CommentParams memory UserOneCommentParams = _getDefaultCommentParams();
UserOneCommentParams.profileId = userOne.profileId;
UserOneCommentParams.pointedProfileId = userTwo.profileId;
UserOneCommentParams.pointedPubId = userTwoCommentPubId;
UserOneCommentParams.referenceModule = address(_tokenGatedReferenceModule);
UserOneCommentParams.referenceModuleInitData = abi.encode(
GateParams({tokenAddress: address(gatedToken), minThreshold: 1})
);
uint userOneCommentPubId = hub.comment(UserOneCommentParams);
assert(userOneCommentPubId == 0);
//userOne cannot quote the spam comment of user two the spammer because user two has blocked user one
vm.expectRevert(Errors.Blocked.selector);
Types.QuoteParams memory UserOneQuoteParams = _getDefaultQuoteParams();
UserOneQuoteParams.profileId = userOne.profileId;
UserOneQuoteParams.pointedProfileId = userTwo.profileId;
UserOneQuoteParams.pointedPubId = userTwoCommentPubId;
UserOneQuoteParams.referenceModule = address(_tokenGatedReferenceModule);
UserOneQuoteParams.referenceModuleInitData = abi.encode(
GateParams({tokenAddress: address(gatedToken), minThreshold: 1})
);
uint userOneQuotePubId = hub.quote(UserOneQuoteParams);
assert(userOneQuotePubId == 0);
}
}
@adeolu98
Copy link
Author

run test with forge test --mc LensHubTest --mt testSpammerIdea -vvv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment