Skip to content

Commit

Permalink
feat: Updated LensPeriphery function names to be more explicit, added…
Browse files Browse the repository at this point in the history
… tests and moved all LensPeriphery tests to the misc test file.
  • Loading branch information
Zer0dot committed Apr 1, 2022
1 parent 6e96132 commit 1bb3856
Show file tree
Hide file tree
Showing 6 changed files with 594 additions and 333 deletions.
46 changes: 29 additions & 17 deletions contracts/misc/LensPeriphery.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ contract LensPeriphery {
);
bytes32 internal constant SET_PROFILE_METADATA_WITH_SIG_TYPEHASH =
keccak256(
'SetProfileMetadataWithSig(uint256 profileId,string metadata,uint256 nonce,uint256 deadline)'
'SetProfileMetadataURIWithSig(uint256 profileId,string metadata,uint256 nonce,uint256 deadline)'
);

ILensHub public immutable HUB;
Expand All @@ -48,13 +48,10 @@ contract LensPeriphery {
* @param profileId The profile ID to set the metadata for.
* @param metadata The metadata string to set for the profile and owner.
*/
function dispatcherSetProfileMetadata(uint256 profileId, string calldata metadata) external {
function dispatcherSetProfileMetadataURI(uint256 profileId, string calldata metadata) external {
address owner = IERC721Time(address(HUB)).ownerOf(profileId);
if (msg.sender == HUB.getDispatcher(profileId)) {
_setProfileMetadata(owner, profileId, metadata);
} else {
revert Errors.NotDispatcher();
}
if (msg.sender != HUB.getDispatcher(profileId)) revert Errors.NotDispatcher();
_setProfileMetadataURI(owner, profileId, metadata);
}

/**
Expand All @@ -63,8 +60,8 @@ contract LensPeriphery {
* @param profileId The profile ID to set the metadata for.
* @param metadata The metadata string to set for the profile and message sender.
*/
function setProfileMetadata(uint256 profileId, string calldata metadata) external {
_setProfileMetadata(msg.sender, profileId, metadata);
function setProfileMetadataURI(uint256 profileId, string calldata metadata) external {
_setProfileMetadataURI(msg.sender, profileId, metadata);
}

/**
Expand All @@ -73,7 +70,7 @@ contract LensPeriphery {
* @param vars A SetProfileMetadataWithSigData struct containingthe regular parameters as well as the user address
* and an EIP712Signature struct.
*/
function setProfileMetadataWithSig(DataTypes.SetProfileMetadataWithSigData calldata vars)
function setProfileMetadataURIWithSig(DataTypes.SetProfileMetadataWithSigData calldata vars)
external
{
_validateRecoveredAddress(
Expand All @@ -91,7 +88,7 @@ contract LensPeriphery {
vars.user,
vars.sig
);
_setProfileMetadata(vars.user, vars.profileId, vars.metadata);
_setProfileMetadataURI(vars.user, vars.profileId, vars.metadata);
}

/**
Expand Down Expand Up @@ -131,25 +128,40 @@ contract LensPeriphery {
_toggleFollow(vars.follower, vars.profileIds, vars.enables);
}

function getProfileMetadata(uint256 profileId) external view returns (string memory) {
/**
* @notice Returns the metadata URI of a profile for its current owner.
*
* @param profileId The profile ID to query the metadata URI for.
*
* @return string The metadata associated with that profile ID and the profile's current owner.
*/
function getProfileMetadataURI(uint256 profileId) external view returns (string memory) {
address owner = IERC721Time(address(HUB)).ownerOf(profileId);
return _metadataByProfileByOwner[owner][profileId];
}

function getProfileMetadataByOwner(address owner, uint256 profileId)
/**
* @notice Returns the metadata URI of a profile for a given user. Note that the user does not *need* to own the
* profile in order to have associated metadata.
*
* @param user The user to query the profile metadata URI for.
* @param profileId The profile ID to query the metadata URI for.
*/
function getProfileMetadataURIByOwner(address user, uint256 profileId)
external
view
returns (string memory)
{
return _metadataByProfileByOwner[owner][profileId];
return _metadataByProfileByOwner[user][profileId];
}

function _setProfileMetadata(
address owner,
function _setProfileMetadataURI(
address user,
uint256 profileId,
string calldata metadata
) internal {
_metadataByProfileByOwner[owner][profileId] = metadata;
_metadataByProfileByOwner[user][profileId] = metadata;
emit Events.ProfileMetadataSet(user, profileId, metadata, block.timestamp);
}

function _toggleFollow(
Expand Down
5 changes: 2 additions & 3 deletions test/__setup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,8 @@ before(async function () {
lensHub = LensHub__factory.connect(proxy.address, user);

// LensPeriphery
lensPeriphery = await new LensPeriphery__factory(deployer).deploy(
lensHub.address
);
lensPeriphery = await new LensPeriphery__factory(deployer).deploy(lensHub.address);
lensPeriphery = lensPeriphery.connect(user);

// Currency
currency = await new Currency__factory(deployer).deploy();
Expand Down
1 change: 1 addition & 0 deletions test/helpers/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const ERRORS = {
FOLLOW_NOT_APPROVED: 'FollowNotApproved()',
ARRAY_MISMATCH: 'ArrayMismatch()',
CANNOT_COMMENT_ON_SELF: 'CannotCommentOnSelf',
NOT_DISPATCHER: 'NotDispatcher()',
ERC721_NOT_OWN: 'ERC721: transfer of token that is not own',
ERC721_TRANSFER_NOT_OWNER_OR_APPROVED: 'ERC721: transfer caller is not owner nor approved',
ERC721_QUERY_FOR_NONEXISTENT_TOKEN: 'ERC721: owner query for nonexistent token',
Expand Down
38 changes: 38 additions & 0 deletions test/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,16 @@ export async function getToggleFollowWithSigParts(
return await getSig(msgParams);
}

export async function getSetProfileMetadataURIWithSigParts(
profileId: string | number,
metadata: string,
nonce: number,
deadline: string
): Promise<{ v: number; r: string; s: string }> {
const msgParams = buildSetProfileMetadataURIWithSigParams(profileId, metadata, nonce, deadline);
return await getSig(msgParams);
}

export async function getCollectWithSigParts(
profileId: BigNumberish,
pubId: string,
Expand Down Expand Up @@ -863,6 +873,34 @@ const buildToggleFollowWithSigParams = (
},
});

const buildSetProfileMetadataURIWithSigParams = (
profileId: string | number,
metadata: string,
nonce: number,
deadline: string
) => ({
types: {
SetProfileMetadataURIWithSig: [
{ name: 'profileId', type: 'uint256' },
{ name: 'metadata', type: 'string' },
{ name: 'nonce', type: 'uint256' },
{ name: 'deadline', type: 'uint256' },
],
},
domain: {
name: LENS_PERIPHERY_NAME,
version: '1',
chainId: getChainId(),
verifyingContract: lensPeriphery.address,
},
value: {
profileId: profileId,
metadata: metadata,
nonce: nonce,
deadline: deadline,
},
});

const buildCollectWithSigParams = (
profileId: BigNumberish,
pubId: string,
Expand Down
Loading

0 comments on commit 1bb3856

Please sign in to comment.