Merge pull request #136 from lens-protocol/fix/c4-fixes

Fix: c4 fixes
This commit is contained in:
Victor Naumik
2023-10-05 16:51:23 +02:00
committed by GitHub
15 changed files with 296 additions and 103 deletions

View File

@@ -384,7 +384,7 @@ contract LensHub is
uint256[] calldata idsOfProfilesToSetBlockStatus,
bool[] calldata blockStatus
) external override whenNotPaused onlyProfileOwnerOrDelegatedExecutor(msg.sender, byProfileId) {
return ProfileLib.setBlockStatus(byProfileId, idsOfProfilesToSetBlockStatus, blockStatus, msg.sender);
ProfileLib.setBlockStatus(byProfileId, idsOfProfilesToSetBlockStatus, blockStatus, msg.sender);
}
/// @inheritdoc ILensProtocol
@@ -395,7 +395,7 @@ contract LensHub is
Types.EIP712Signature calldata signature
) external override whenNotPaused onlyProfileOwnerOrDelegatedExecutor(signature.signer, byProfileId) {
MetaTxLib.validateSetBlockStatusSignature(signature, byProfileId, idsOfProfilesToSetBlockStatus, blockStatus);
return ProfileLib.setBlockStatus(byProfileId, idsOfProfilesToSetBlockStatus, blockStatus, signature.signer);
ProfileLib.setBlockStatus(byProfileId, idsOfProfilesToSetBlockStatus, blockStatus, signature.signer);
}
/// @inheritdoc ILensProtocol

View File

@@ -43,15 +43,11 @@ abstract contract ERC2981CollectionRoyalties is IERC2981 {
function _setRoyalty(uint256 royaltiesInBasisPoints) internal virtual {
if (royaltiesInBasisPoints > BASIS_POINTS) {
revert Errors.InvalidParameter();
} else {
_storeRoyaltiesInBasisPoints(royaltiesInBasisPoints);
}
_storeRoyaltiesInBasisPoints(royaltiesInBasisPoints);
}
function _getRoyaltyAmount(
uint256, /* tokenId */
uint256 salePrice
) internal view virtual returns (uint256) {
function _getRoyaltyAmount(uint256 /* tokenId */, uint256 salePrice) internal view virtual returns (uint256) {
return (salePrice * _loadRoyaltiesInBasisPoints()) / BASIS_POINTS;
}

View File

@@ -132,7 +132,7 @@ interface ILensProtocol {
* Comments can have these types of modules initialized:
* - Action modules: any number of publication actions (e.g. collect, tip, etc.)
* - Reference module: a module handling the rules when referencing this comment (e.g. token-gated mirrors)
* Comments can have referrers (e.g. publications or profiles that allowed to discover the pointed publication).
* Comments can have referrers (e.g. publications or profiles that helped to discover the pointed publication).
* @custom:permissions Profile Owner or Delegated Executor.
*
* @param commentParams A CommentParams struct containing the needed parameters.

View File

@@ -92,7 +92,7 @@ library FollowLib {
* @return address The address of the deployed Follow NFT contract.
*/
function _deployFollowNFT(uint256 profileId) private returns (address) {
bytes memory functionData = abi.encodeWithSelector(IFollowNFT.initialize.selector, profileId);
bytes memory functionData = abi.encodeCall(IFollowNFT.initialize, profileId);
address followNFT = address(new FollowNFTProxy(functionData));
emit Events.FollowNFTDeployed(profileId, followNFT, block.timestamp);

View File

@@ -52,15 +52,17 @@ library GovernanceLib {
function setState(Types.ProtocolState newState) external {
// NOTE: This does not follow the CEI-pattern, but there is no interaction and this allows to abstract `_setState` logic.
Types.ProtocolState prevState = _setState(newState);
// If the sender is the emergency admin, prevent them from reducing restrictions.
if (msg.sender == StorageLib.getEmergencyAdmin()) {
if (newState <= prevState) {
revert Errors.EmergencyAdminCanOnlyPauseFurther();
if (msg.sender != StorageLib.getGovernance()) {
// If the sender is the emergency admin, prevent them from reducing restrictions.
if (msg.sender == StorageLib.getEmergencyAdmin()) {
if (newState <= prevState) {
revert Errors.EmergencyAdminCanOnlyPauseFurther();
}
} else {
revert Errors.NotGovernanceOrEmergencyAdmin();
}
} else if (msg.sender != StorageLib.getGovernance()) {
revert Errors.NotGovernanceOrEmergencyAdmin();
}
emit Events.StateSet(msg.sender, prevState, newState, block.timestamp);
}
function _setState(Types.ProtocolState newState) private returns (Types.ProtocolState) {

View File

@@ -39,6 +39,8 @@ library LegacyCollectLib {
uint256 referrerProfileId,
uint256 referrerPubId,
bytes collectModuleData,
uint256 tokenId,
address nftRecipient,
uint256 timestamp
);
@@ -106,6 +108,8 @@ library LegacyCollectLib {
referrerProfileId: collectParams.referrerProfileId,
referrerPubId: collectParams.referrerPubId,
collectModuleData: collectParams.collectModuleData,
tokenId: tokenId,
nftRecipient: collectorProfileOwner,
timestamp: block.timestamp
});

View File

@@ -349,7 +349,7 @@ library MetaTxLib {
* @dev Wrapper for ecrecover to reduce code size, used in meta-tx specific functions.
*/
function _validateRecoveredAddress(bytes32 digest, Types.EIP712Signature calldata signature) private view {
if (signature.deadline < block.timestamp) revert Errors.SignatureExpired();
if (block.timestamp > signature.deadline) revert Errors.SignatureExpired();
// If the expected address is a contract, check the signature there.
if (signature.signer.code.length != 0) {
bytes memory concatenatedSig = abi.encodePacked(signature.r, signature.s, signature.v);

View File

@@ -261,7 +261,7 @@ library Events {
* @param followerProfileId The ID of the profile that executed the follow.
* @param idOfProfileFollowed The ID of the profile that was followed.
* @param followTokenIdAssigned The ID of the follow token assigned to the follower.
* @param followModuleData The data to passed to the follow module, if any.
* @param followModuleData The data to pass to the follow module, if any.
* @param processFollowModuleReturnData The data returned by the followed profile follow module's processFollow
* function, if the followed profile has a reference module set.
* @param transactionExecutor The address of the account that executed this operation.

View File

@@ -99,7 +99,6 @@ library Types {
* @param __DEPRECATED__followNFTURI DEPRECATED in V2: The URI used for the follow NFT image.
* @param metadataURI MetadataURI is used to store the profile's metadata, for example: displayed name, description,
* interests, etc.
* @param metadataURI The URI to be used for the profile's metadata.
*/
struct Profile {
uint256 pubCount; // offset 0

View File

@@ -18,8 +18,8 @@ contract ControllableByContract is Ownable {
_;
}
constructor(address owner) Ownable() {
_transferOwnership(owner);
constructor(address owner_) Ownable() {
_transferOwnership(owner_);
}
function clearControllerContract() external onlyOwnerOrControllerContract {

View File

@@ -18,8 +18,9 @@ import {FollowValidationLib} from 'contracts/modules/libraries/FollowValidationL
* @param quotesRestricted Indicates if the quote operation is restricted or open to everyone.
* @param mirrorsRestricted Indicates if the mirror operation is restricted or open to everyone.
* @param degreesOfSeparation The max degrees of separation allowed for restricted operations.
* @param sourceProfile The ID of the profile from where the follower path should be started. Expected to be set as the
* author of the root publication.
* @param sourceProfile The ID of the profile from where the follower path should be started. Usually it will match the
* `originalAuthorProfile`.
* @param originalAuthorProfile Original author of the Post or Quote when the degrees restriction was first applied.
*/
struct ModuleConfig {
bool setUp;
@@ -27,7 +28,8 @@ struct ModuleConfig {
bool quotesRestricted;
bool mirrorsRestricted;
uint8 degreesOfSeparation;
uint128 sourceProfile;
uint96 sourceProfile;
uint96 originalAuthorProfile;
}
/**
@@ -64,7 +66,7 @@ contract DegreesOfSeparationReferenceModule is HubRestricted, IReferenceModule {
* - bool quotesRestricted: Indicates if the quote operation is restricted or open to everyone.
* - bool mirrorsRestricted: Indicates if the mirror operation is restricted or open to everyone.
* - uint8 degreesOfSeparation: The max degrees of separation allowed for restricted operations.
* - uint128 sourceProfile The ID of the profile from where the follower path should be started. Expected to be set
* - uint96 sourceProfile: The ID of the profile from where the follower path should be started. Expected to be set
* as the author of the root publication.
*/
function initializeReferenceModule(
@@ -78,23 +80,38 @@ contract DegreesOfSeparationReferenceModule is HubRestricted, IReferenceModule {
bool quotesRestricted,
bool mirrorsRestricted,
uint8 degreesOfSeparation,
uint128 sourceProfile
) = abi.decode(data, (bool, bool, bool, uint8, uint128));
uint96 sourceProfile
) = abi.decode(data, (bool, bool, bool, uint8, uint96));
if (degreesOfSeparation > MAX_DEGREES_OF_SEPARATION) {
revert InvalidDegreesOfSeparation();
}
if (!IERC721Timestamped(HUB).exists(sourceProfile)) {
revert Errors.TokenDoesNotExist();
}
uint96 originalAuthorProfile;
Types.PublicationMemory memory pub = ILensHub(HUB).getPublication(profileId, pubId);
if (pub.pubType == Types.PublicationType.Comment) {
ModuleConfig memory parentConfig = _moduleConfig[pub.pointedProfileId][pub.pointedPubId];
if (!parentConfig.setUp) {
// Comments cannot restrict degrees of separation, unless the pointed publication has it enabled too.
revert OperationDisabled();
}
originalAuthorProfile = parentConfig.originalAuthorProfile;
} else {
originalAuthorProfile = uint96(profileId);
}
_moduleConfig[profileId][pubId] = ModuleConfig(
true,
commentsRestricted,
quotesRestricted,
mirrorsRestricted,
degreesOfSeparation,
sourceProfile
sourceProfile,
originalAuthorProfile
);
return '';
return data;
}
/**
@@ -114,6 +131,7 @@ contract DegreesOfSeparationReferenceModule is HubRestricted, IReferenceModule {
if (config.commentsRestricted) {
_validateDegreesOfSeparationRestriction({
sourceProfile: config.sourceProfile,
originalAuthorProfile: config.originalAuthorProfile,
profileId: processCommentParams.profileId,
degreesOfSeparation: config.degreesOfSeparation,
profilePath: abi.decode(processCommentParams.data, (uint256[]))
@@ -136,13 +154,15 @@ contract DegreesOfSeparationReferenceModule is HubRestricted, IReferenceModule {
function processQuote(
Types.ProcessQuoteParams calldata processQuoteParams
) external view override onlyHub returns (bytes memory) {
if (_moduleConfig[processQuoteParams.pointedProfileId][processQuoteParams.pointedPubId].quotesRestricted) {
ModuleConfig memory config = _moduleConfig[processQuoteParams.pointedProfileId][
processQuoteParams.pointedPubId
];
if (config.quotesRestricted) {
_validateDegreesOfSeparationRestriction({
sourceProfile: _moduleConfig[processQuoteParams.pointedProfileId][processQuoteParams.pointedPubId]
.sourceProfile,
sourceProfile: config.sourceProfile,
originalAuthorProfile: config.originalAuthorProfile,
profileId: processQuoteParams.profileId,
degreesOfSeparation: _moduleConfig[processQuoteParams.pointedProfileId][processQuoteParams.pointedPubId]
.degreesOfSeparation,
degreesOfSeparation: config.degreesOfSeparation,
profilePath: abi.decode(processQuoteParams.data, (uint256[]))
});
}
@@ -159,14 +179,15 @@ contract DegreesOfSeparationReferenceModule is HubRestricted, IReferenceModule {
function processMirror(
Types.ProcessMirrorParams calldata processMirrorParams
) external view override onlyHub returns (bytes memory) {
if (_moduleConfig[processMirrorParams.pointedProfileId][processMirrorParams.pointedPubId].mirrorsRestricted) {
ModuleConfig memory config = _moduleConfig[processMirrorParams.pointedProfileId][
processMirrorParams.pointedPubId
];
if (config.mirrorsRestricted) {
_validateDegreesOfSeparationRestriction({
sourceProfile: _moduleConfig[processMirrorParams.pointedProfileId][processMirrorParams.pointedPubId]
.sourceProfile,
sourceProfile: config.sourceProfile,
originalAuthorProfile: config.originalAuthorProfile,
profileId: processMirrorParams.profileId,
degreesOfSeparation: _moduleConfig[processMirrorParams.pointedProfileId][
processMirrorParams.pointedPubId
].degreesOfSeparation,
degreesOfSeparation: config.degreesOfSeparation,
profilePath: abi.decode(processMirrorParams.data, (uint256[]))
});
}
@@ -203,20 +224,24 @@ contract DegreesOfSeparationReferenceModule is HubRestricted, IReferenceModule {
*/
function _validateDegreesOfSeparationRestriction(
uint256 sourceProfile,
uint256 originalAuthorProfile,
uint256 profileId,
uint8 degreesOfSeparation,
uint256[] memory profilePath
) internal view {
// Unrestricted if the profile authoring the publication is the source or the original author profile.
if (profileId == sourceProfile || profileId == originalAuthorProfile) {
return;
}
// Here we only have cases where the source profile is not the same as the profile authoring the new publication.
if (degreesOfSeparation == 0) {
// If `degreesOfSeparation` was set to zero, only `sourceProfile` is allowed to interact.
if (profileId == sourceProfile) {
return;
} else {
revert OperationDisabled();
}
revert OperationDisabled();
} else if (profilePath.length > degreesOfSeparation - 1) {
revert ProfilePathExceedsDegreesOfSeparation();
}
if (profilePath.length > 0) {
// Checks that the source profile follows the first profile in the path.
// In the previous notation: sourceProfile --> path[0]

View File

@@ -126,7 +126,7 @@ contract TokenHandleRegistry is ITokenHandleRegistry {
* @dev Wrapper for ecrecover to reduce code size, used in meta-tx specific functions.
*/
function _validateRecoveredAddress(bytes32 digest, Types.EIP712Signature calldata signature) private view {
if (signature.deadline < block.timestamp) revert Errors.SignatureExpired();
if (block.timestamp > signature.deadline) revert Errors.SignatureExpired();
// If the expected address is a contract, check the signature there.
if (signature.signer.code.length != 0) {
bytes memory concatenatedSig = abi.encodePacked(signature.r, signature.s, signature.v);

View File

@@ -130,6 +130,18 @@ contract GovernanceFunctionsTest is BaseTest {
assertEq(uint8(hub.getState()), newState);
}
function testSetState_IfGovernance_AndItIsSameAsEmergencyAdmin(uint8 newState) public {
vm.prank(governance);
hub.setEmergencyAdmin(governance);
newState = uint8(bound(newState, uint8(Types.ProtocolState.Unpaused), uint8(Types.ProtocolState.Paused)));
vm.prank(governance);
hub.setState(Types.ProtocolState(newState));
assertEq(uint8(hub.getState()), newState);
}
function testWhitelistProfileCreator(address profileCreator, bool shouldWhitelist) public {
vm.prank(governance);
hub.whitelistProfileCreator(profileCreator, shouldWhitelist);

View File

@@ -251,6 +251,8 @@ contract LegacyCollectTest is BaseTest, ReferralSystemTest {
vm.expectEmit(true, true, true, true, predictedCollectNFT);
emit Transfer(address(0), hub.ownerOf(defaultCollectParams.collectorProfileId), 1);
uint256 expectedTokenId = 1; // TODO: fix this if needed
vm.expectEmit(true, true, true, true, address(hub));
emit LegacyCollectLib.CollectedLegacy({
publicationCollectedProfileId: defaultCollectParams.publicationCollectedProfileId,
@@ -259,11 +261,13 @@ contract LegacyCollectTest is BaseTest, ReferralSystemTest {
referrerProfileId: defaultCollectParams.referrerProfileId,
referrerPubId: defaultCollectParams.referrerPubId,
collectModuleData: defaultCollectParams.collectModuleData,
tokenId: expectedTokenId,
nftRecipient: hub.ownerOf(defaultCollectParams.collectorProfileId),
timestamp: block.timestamp
});
uint256 collectTokenId = _collect(defaultAccount.ownerPk, defaultCollectParams);
assertEq(collectTokenId, 1);
assertEq(collectTokenId, expectedTokenId);
string memory expectedCollectNftName = string.concat(
'Lens Collect | Profile #',
@@ -297,6 +301,8 @@ contract LegacyCollectTest is BaseTest, ReferralSystemTest {
referrerProfileId: defaultCollectParams.referrerProfileId,
referrerPubId: defaultCollectParams.referrerPubId,
collectModuleData: defaultCollectParams.collectModuleData,
tokenId: collectTokenId + 1,
nftRecipient: hub.ownerOf(defaultCollectParams.collectorProfileId),
timestamp: block.timestamp
});

View File

@@ -49,7 +49,7 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
bool quotesRestricted,
bool mirrorsRestricted,
uint8 degreesOfSeparation,
uint128 sourceProfile
uint96 sourceProfile
) private pure returns (bytes memory) {
return abi.encode(commentsRestricted, quotesRestricted, mirrorsRestricted, degreesOfSeparation, sourceProfile);
}
@@ -70,7 +70,7 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
quotesRestricted: true,
mirrorsRestricted: true,
degreesOfSeparation: MAX_DEGREES_OF_SEPARATION,
sourceProfile: uint128(originalPublisher.profileId)
sourceProfile: uint96(originalPublisher.profileId)
})
);
}
@@ -90,7 +90,7 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
quotesRestricted: true,
mirrorsRestricted: true,
degreesOfSeparation: unallowedDegreesValue,
sourceProfile: uint128(originalPublisher.profileId)
sourceProfile: uint96(originalPublisher.profileId)
})
);
}
@@ -104,7 +104,7 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
module.initializeReferenceModule(originalPublisher.profileId, 1, originalPublisher.owner, wrongData);
}
function testCannotInitialize_IfSourceProfileDoesNotExist(uint128 unexistentProfileId) public {
function testCannotInitialize_IfSourceProfileDoesNotExist(uint96 unexistentProfileId) public {
vm.assume(!hub.exists(unexistentProfileId));
vm.expectRevert(Errors.TokenDoesNotExist.selector);
@@ -142,7 +142,7 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
quotesRestricted: quotesRestricted,
mirrorsRestricted: mirrorsRestricted,
degreesOfSeparation: degrees,
sourceProfile: uint128(originalPublisher.profileId)
sourceProfile: uint96(originalPublisher.profileId)
})
);
@@ -153,7 +153,7 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
assertEq(config.quotesRestricted, quotesRestricted);
assertEq(config.mirrorsRestricted, mirrorsRestricted);
assertEq(config.degreesOfSeparation, degrees);
assertEq(config.sourceProfile, uint128(originalPublisher.profileId));
assertEq(config.sourceProfile, uint96(originalPublisher.profileId));
}
function testCannotProcessComment_IfDegreesOfSeparationRestrictionIsNotMet_PathLength(uint8 degrees) public {
@@ -171,7 +171,7 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
quotesRestricted: false,
mirrorsRestricted: false,
degreesOfSeparation: degrees,
sourceProfile: uint128(originalPublisher.profileId)
sourceProfile: uint96(originalPublisher.profileId)
})
);
@@ -189,7 +189,7 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
quotesRestricted: true,
mirrorsRestricted: true,
degreesOfSeparation: degrees,
sourceProfile: uint128(originalPublisher.profileId)
sourceProfile: uint96(originalPublisher.profileId)
})
);
@@ -226,7 +226,7 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
quotesRestricted: false,
mirrorsRestricted: true,
degreesOfSeparation: degrees,
sourceProfile: uint128(originalPublisher.profileId)
sourceProfile: uint96(originalPublisher.profileId)
})
);
@@ -244,7 +244,7 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
quotesRestricted: true,
mirrorsRestricted: true,
degreesOfSeparation: degrees,
sourceProfile: uint128(originalPublisher.profileId)
sourceProfile: uint96(originalPublisher.profileId)
})
);
@@ -281,7 +281,7 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
quotesRestricted: true,
mirrorsRestricted: false,
degreesOfSeparation: degrees,
sourceProfile: uint128(originalPublisher.profileId)
sourceProfile: uint96(originalPublisher.profileId)
})
);
@@ -299,7 +299,7 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
quotesRestricted: false,
mirrorsRestricted: false,
degreesOfSeparation: degrees,
sourceProfile: uint128(originalPublisher.profileId)
sourceProfile: uint96(originalPublisher.profileId)
})
);
@@ -338,7 +338,7 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
quotesRestricted: true,
mirrorsRestricted: true,
degreesOfSeparation: degrees,
sourceProfile: uint128(originalPublisher.profileId)
sourceProfile: uint96(originalPublisher.profileId)
})
);
@@ -356,7 +356,7 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
quotesRestricted: true,
mirrorsRestricted: true,
degreesOfSeparation: degrees,
sourceProfile: uint128(originalPublisher.profileId)
sourceProfile: uint96(originalPublisher.profileId)
})
);
@@ -395,7 +395,7 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
quotesRestricted: true,
mirrorsRestricted: true,
degreesOfSeparation: degrees,
sourceProfile: uint128(originalPublisher.profileId)
sourceProfile: uint96(originalPublisher.profileId)
})
);
@@ -413,7 +413,7 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
quotesRestricted: true,
mirrorsRestricted: true,
degreesOfSeparation: degrees,
sourceProfile: uint128(originalPublisher.profileId)
sourceProfile: uint96(originalPublisher.profileId)
})
);
@@ -452,7 +452,7 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
quotesRestricted: true,
mirrorsRestricted: true,
degreesOfSeparation: degrees,
sourceProfile: uint128(originalPublisher.profileId)
sourceProfile: uint96(originalPublisher.profileId)
})
);
@@ -470,7 +470,7 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
quotesRestricted: true,
mirrorsRestricted: true,
degreesOfSeparation: degrees,
sourceProfile: uint128(originalPublisher.profileId)
sourceProfile: uint96(originalPublisher.profileId)
})
);
@@ -509,7 +509,7 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
quotesRestricted: true,
mirrorsRestricted: true,
degreesOfSeparation: degrees,
sourceProfile: uint128(originalPublisher.profileId)
sourceProfile: uint96(originalPublisher.profileId)
})
);
@@ -527,7 +527,7 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
quotesRestricted: true,
mirrorsRestricted: true,
degreesOfSeparation: degrees,
sourceProfile: uint128(originalPublisher.profileId)
sourceProfile: uint96(originalPublisher.profileId)
})
);
@@ -566,7 +566,7 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
quotesRestricted: true,
mirrorsRestricted: true,
degreesOfSeparation: degrees,
sourceProfile: uint128(originalPublisher.profileId)
sourceProfile: uint96(originalPublisher.profileId)
})
);
@@ -584,7 +584,7 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
quotesRestricted: true,
mirrorsRestricted: true,
degreesOfSeparation: degrees,
sourceProfile: uint128(originalPublisher.profileId)
sourceProfile: uint96(originalPublisher.profileId)
})
);
@@ -623,7 +623,7 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
quotesRestricted: true,
mirrorsRestricted: true,
degreesOfSeparation: degrees,
sourceProfile: uint128(originalPublisher.profileId)
sourceProfile: uint96(originalPublisher.profileId)
})
);
@@ -641,7 +641,7 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
quotesRestricted: true,
mirrorsRestricted: true,
degreesOfSeparation: degrees,
sourceProfile: uint128(originalPublisher.profileId)
sourceProfile: uint96(originalPublisher.profileId)
})
);
@@ -677,7 +677,7 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
// quotesRestricted: true,
// mirrorsRestricted: true,
// degreesOfSeparation: MAX_DEGREES_OF_SEPARATION,
// sourceProfile: uint128(originalPublisher.profileId)
// sourceProfile: uint96(originalPublisher.profileId)
// })
// );
@@ -700,7 +700,7 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
// quotesRestricted: true,
// mirrorsRestricted: true,
// degreesOfSeparation: MAX_DEGREES_OF_SEPARATION,
// sourceProfile: uint128(originalPublisher.profileId)
// sourceProfile: uint96(originalPublisher.profileId)
// })
// );
@@ -736,7 +736,7 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
// quotesRestricted: true,
// mirrorsRestricted: true,
// degreesOfSeparation: MAX_DEGREES_OF_SEPARATION,
// sourceProfile: uint128(originalPublisher.profileId)
// sourceProfile: uint96(originalPublisher.profileId)
// })
// );
@@ -759,7 +759,7 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
// quotesRestricted: true,
// mirrorsRestricted: true,
// degreesOfSeparation: MAX_DEGREES_OF_SEPARATION,
// sourceProfile: uint128(originalPublisher.profileId)
// sourceProfile: uint96(originalPublisher.profileId)
// })
// );
@@ -795,7 +795,7 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
// quotesRestricted: true,
// mirrorsRestricted: true,
// degreesOfSeparation: MAX_DEGREES_OF_SEPARATION,
// sourceProfile: uint128(originalPublisher.profileId)
// sourceProfile: uint96(originalPublisher.profileId)
// })
// );
@@ -818,7 +818,7 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
// quotesRestricted: true,
// mirrorsRestricted: true,
// degreesOfSeparation: MAX_DEGREES_OF_SEPARATION,
// sourceProfile: uint128(originalPublisher.profileId)
// sourceProfile: uint96(originalPublisher.profileId)
// })
// );
@@ -854,7 +854,7 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
quotesRestricted: true,
mirrorsRestricted: true,
degreesOfSeparation: degrees,
sourceProfile: uint128(originalPublisher.profileId)
sourceProfile: uint96(originalPublisher.profileId)
})
);
@@ -893,7 +893,7 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
quotesRestricted: true,
mirrorsRestricted: true,
degreesOfSeparation: degrees,
sourceProfile: uint128(originalPublisher.profileId)
sourceProfile: uint96(originalPublisher.profileId)
})
);
@@ -910,7 +910,7 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
quotesRestricted: true,
mirrorsRestricted: true,
degreesOfSeparation: degrees,
sourceProfile: uint128(originalPublisher.profileId)
sourceProfile: uint96(originalPublisher.profileId)
})
);
@@ -934,11 +934,11 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
function testCannotProcessComment_IfNotInheritingConfig_WrongSourceProfile(
uint8 degrees,
uint128 wrongSourceProfile
uint96 wrongSourceProfile
) public {
degrees = uint8(bound(degrees, 1, MAX_DEGREES_OF_SEPARATION));
vm.assume(hub.exists(wrongSourceProfile));
vm.assume(wrongSourceProfile != uint128(originalPublisher.profileId));
vm.assume(wrongSourceProfile != uint96(originalPublisher.profileId));
// Initializes module for (profile: originalPublisher.profileId, pubId: 1)
vm.prank(hubAddress);
@@ -951,7 +951,7 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
quotesRestricted: true,
mirrorsRestricted: true,
degreesOfSeparation: degrees,
sourceProfile: uint128(originalPublisher.profileId)
sourceProfile: uint96(originalPublisher.profileId)
})
);
@@ -1006,7 +1006,7 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
quotesRestricted: true,
mirrorsRestricted: true,
degreesOfSeparation: degrees,
sourceProfile: uint128(originalPublisher.profileId)
sourceProfile: uint96(originalPublisher.profileId)
})
);
@@ -1023,7 +1023,7 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
quotesRestricted: true,
mirrorsRestricted: true,
degreesOfSeparation: wrongDegrees,
sourceProfile: uint128(originalPublisher.profileId)
sourceProfile: uint96(originalPublisher.profileId)
})
);
@@ -1059,7 +1059,7 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
quotesRestricted: true,
mirrorsRestricted: true,
degreesOfSeparation: degrees,
sourceProfile: uint128(originalPublisher.profileId)
sourceProfile: uint96(originalPublisher.profileId)
})
);
@@ -1098,7 +1098,7 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
quotesRestricted: true,
mirrorsRestricted: true,
degreesOfSeparation: degrees,
sourceProfile: uint128(originalPublisher.profileId)
sourceProfile: uint96(originalPublisher.profileId)
})
);
@@ -1137,7 +1137,7 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
quotesRestricted: true,
mirrorsRestricted: true,
degreesOfSeparation: degrees,
sourceProfile: uint128(originalPublisher.profileId)
sourceProfile: uint96(originalPublisher.profileId)
})
);
@@ -1176,7 +1176,7 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
quotesRestricted: true,
mirrorsRestricted: false,
degreesOfSeparation: degrees,
sourceProfile: uint128(originalPublisher.profileId)
sourceProfile: uint96(originalPublisher.profileId)
})
);
@@ -1215,7 +1215,7 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
quotesRestricted: false,
mirrorsRestricted: true,
degreesOfSeparation: degrees,
sourceProfile: uint128(originalPublisher.profileId)
sourceProfile: uint96(originalPublisher.profileId)
})
);
@@ -1252,7 +1252,7 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
quotesRestricted: true,
mirrorsRestricted: true,
degreesOfSeparation: 0,
sourceProfile: uint128(originalPublisher.profileId)
sourceProfile: uint96(originalPublisher.profileId)
})
);
@@ -1267,7 +1267,55 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
quotesRestricted: true,
mirrorsRestricted: true,
degreesOfSeparation: 0,
sourceProfile: uint128(originalPublisher.profileId)
sourceProfile: uint96(originalPublisher.profileId)
})
);
_mockLensHubPubCountResponse({account: originalPublisher, pubCount: 2});
vm.prank(hubAddress);
module.processComment(
Types.ProcessCommentParams({
profileId: originalPublisher.profileId,
transactionExecutor: originalPublisher.owner,
pointedProfileId: originalPublisher.profileId,
pointedPubId: 1,
referrerProfileIds: _emptyUint256Array(),
referrerPubIds: _emptyUint256Array(),
referrerPubTypes: _emptyPubTypesArray(),
data: abi.encode(_emptyUint256Array())
})
);
}
function testProcessComment_WhenRestricted_ButCurrentPublisherIsSourceProfile() public {
// Initializes module for (profile: originalPublisher.profileId, pubId: 1)
vm.prank(hubAddress);
module.initializeReferenceModule(
originalPublisher.profileId,
1,
originalPublisher.owner,
_getInitData({
commentsRestricted: true,
quotesRestricted: true,
mirrorsRestricted: true,
degreesOfSeparation: 2,
sourceProfile: uint96(originalPublisher.profileId)
})
);
// Initializes module for (profile: originalPublisher.profileId, pubId: 2)
vm.prank(hubAddress);
module.initializeReferenceModule(
originalPublisher.profileId,
2,
originalPublisher.owner,
_getInitData({
commentsRestricted: true,
quotesRestricted: true,
mirrorsRestricted: true,
degreesOfSeparation: 2,
sourceProfile: uint96(originalPublisher.profileId)
})
);
@@ -1300,7 +1348,7 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
quotesRestricted: true,
mirrorsRestricted: true,
degreesOfSeparation: 0,
sourceProfile: uint128(originalPublisher.profileId)
sourceProfile: uint96(originalPublisher.profileId)
})
);
@@ -1315,7 +1363,55 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
quotesRestricted: true,
mirrorsRestricted: true,
degreesOfSeparation: 0,
sourceProfile: uint128(originalPublisher.profileId)
sourceProfile: uint96(originalPublisher.profileId)
})
);
_mockLensHubPubCountResponse({account: originalPublisher, pubCount: 2});
vm.prank(hubAddress);
module.processMirror(
Types.ProcessMirrorParams({
profileId: originalPublisher.profileId,
transactionExecutor: originalPublisher.owner,
pointedProfileId: originalPublisher.profileId,
pointedPubId: 1,
referrerProfileIds: _emptyUint256Array(),
referrerPubIds: _emptyUint256Array(),
referrerPubTypes: _emptyPubTypesArray(),
data: abi.encode(_emptyUint256Array())
})
);
}
function testProcessMirror_WhenRestricted_ButCurrentPublisherIsSourceProfile() public {
// Initializes module for (profile: originalPublisher.profileId, pubId: 1)
vm.prank(hubAddress);
module.initializeReferenceModule(
originalPublisher.profileId,
1,
originalPublisher.owner,
_getInitData({
commentsRestricted: true,
quotesRestricted: true,
mirrorsRestricted: true,
degreesOfSeparation: 2,
sourceProfile: uint96(originalPublisher.profileId)
})
);
// Initializes module for (profile: originalPublisher.profileId, pubId: 2)
vm.prank(hubAddress);
module.initializeReferenceModule(
originalPublisher.profileId,
2,
originalPublisher.owner,
_getInitData({
commentsRestricted: true,
quotesRestricted: true,
mirrorsRestricted: true,
degreesOfSeparation: 2,
sourceProfile: uint96(originalPublisher.profileId)
})
);
@@ -1348,7 +1444,7 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
quotesRestricted: true,
mirrorsRestricted: true,
degreesOfSeparation: 0,
sourceProfile: uint128(originalPublisher.profileId)
sourceProfile: uint96(originalPublisher.profileId)
})
);
@@ -1363,7 +1459,55 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
quotesRestricted: true,
mirrorsRestricted: true,
degreesOfSeparation: 0,
sourceProfile: uint128(originalPublisher.profileId)
sourceProfile: uint96(originalPublisher.profileId)
})
);
_mockLensHubPubCountResponse({account: originalPublisher, pubCount: 2});
vm.prank(hubAddress);
module.processQuote(
Types.ProcessQuoteParams({
profileId: originalPublisher.profileId,
transactionExecutor: originalPublisher.owner,
pointedProfileId: originalPublisher.profileId,
pointedPubId: 1,
referrerProfileIds: _emptyUint256Array(),
referrerPubIds: _emptyUint256Array(),
referrerPubTypes: _emptyPubTypesArray(),
data: abi.encode(_emptyUint256Array())
})
);
}
function testProcessQuote_WhenRestricted_ButCurrentPublisherIsSourceProfile() public {
// Initializes module for (profile: originalPublisher.profileId, pubId: 1)
vm.prank(hubAddress);
module.initializeReferenceModule(
originalPublisher.profileId,
1,
originalPublisher.owner,
_getInitData({
commentsRestricted: true,
quotesRestricted: true,
mirrorsRestricted: true,
degreesOfSeparation: 2,
sourceProfile: uint96(originalPublisher.profileId)
})
);
// Initializes module for (profile: originalPublisher.profileId, pubId: 2)
vm.prank(hubAddress);
module.initializeReferenceModule(
originalPublisher.profileId,
2,
originalPublisher.owner,
_getInitData({
commentsRestricted: true,
quotesRestricted: true,
mirrorsRestricted: true,
degreesOfSeparation: 2,
sourceProfile: uint96(originalPublisher.profileId)
})
);
@@ -1396,7 +1540,7 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
quotesRestricted: true,
mirrorsRestricted: true,
degreesOfSeparation: 0,
sourceProfile: uint128(originalPublisher.profileId)
sourceProfile: uint96(originalPublisher.profileId)
})
);
@@ -1414,7 +1558,7 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
quotesRestricted: true,
mirrorsRestricted: true,
degreesOfSeparation: 0,
sourceProfile: uint128(originalPublisher.profileId)
sourceProfile: uint96(originalPublisher.profileId)
})
);
@@ -1448,7 +1592,7 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
quotesRestricted: true,
mirrorsRestricted: true,
degreesOfSeparation: 0,
sourceProfile: uint128(originalPublisher.profileId)
sourceProfile: uint96(originalPublisher.profileId)
})
);
@@ -1466,7 +1610,7 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
quotesRestricted: true,
mirrorsRestricted: true,
degreesOfSeparation: 0,
sourceProfile: uint128(originalPublisher.profileId)
sourceProfile: uint96(originalPublisher.profileId)
})
);
@@ -1500,7 +1644,7 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
quotesRestricted: true,
mirrorsRestricted: true,
degreesOfSeparation: 0,
sourceProfile: uint128(originalPublisher.profileId)
sourceProfile: uint96(originalPublisher.profileId)
})
);
@@ -1518,7 +1662,7 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
quotesRestricted: true,
mirrorsRestricted: true,
degreesOfSeparation: 0,
sourceProfile: uint128(originalPublisher.profileId)
sourceProfile: uint96(originalPublisher.profileId)
})
);
@@ -1540,6 +1684,11 @@ contract DegreesOfSeparationReferenceModuleTest is BaseTest {
);
}
// TODO - test the new logic:
// - if the current publisher is the originalAuthor or source profile, then it can reply without restrictions
// - you cannot init degrees on a comment, only on post and quote
// etc
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function _mockLensHubPubCountResponse(TestAccount memory account, uint256 pubCount) internal {