mirror of
https://github.com/lens-protocol/core.git
synced 2026-04-22 03:02:03 -04:00
refactor: Refactored to simplify profile metadata setter into one function.
This commit is contained in:
@@ -42,17 +42,6 @@ contract LensPeriphery {
|
||||
HUB = hub;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice Sets profile metadata for a profile as its dispatcher.
|
||||
*
|
||||
* @param profileId The profile ID to set the metadata for.
|
||||
* @param metadata The metadata string to set for the profile.
|
||||
*/
|
||||
function dispatcherSetProfileMetadataURI(uint256 profileId, string calldata metadata) external {
|
||||
if (msg.sender != HUB.getDispatcher(profileId)) revert Errors.NotDispatcher();
|
||||
_setProfileMetadataURI(profileId, metadata);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice Sets the profile metadata for a given profile.
|
||||
*
|
||||
@@ -60,8 +49,7 @@ contract LensPeriphery {
|
||||
* @param metadata The metadata string to set for the profile.
|
||||
*/
|
||||
function setProfileMetadataURI(uint256 profileId, string calldata metadata) external {
|
||||
address owner = IERC721Time(address(HUB)).ownerOf(profileId);
|
||||
if (msg.sender != owner) revert Errors.NotProfileOwner();
|
||||
_validateCallerIsProfileOwnerOrDispatcher(profileId);
|
||||
_setProfileMetadataURI(profileId, metadata);
|
||||
}
|
||||
|
||||
@@ -167,6 +155,16 @@ contract LensPeriphery {
|
||||
emit Events.FollowsToggled(follower, profileIds, enables, block.timestamp);
|
||||
}
|
||||
|
||||
function _validateCallerIsProfileOwnerOrDispatcher(uint256 profileId) internal view {
|
||||
if (
|
||||
msg.sender == IERC721Time(address(HUB)).ownerOf(profileId) ||
|
||||
msg.sender == HUB.getDispatcher(profileId)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
revert Errors.NotProfileOwnerOrDispatcher();
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Wrapper for ecrecover to reduce code size, used in meta-tx specific functions.
|
||||
*/
|
||||
|
||||
@@ -1071,16 +1071,10 @@ makeSuiteCleanRoom('Misc', function () {
|
||||
});
|
||||
|
||||
context('Negatives', function () {
|
||||
it('User two should fail to set profile metadata URI for a profile that is not theirs', async function () {
|
||||
it('User two should fail to set profile metadata URI for a profile that is not theirs while they are not the dispatcher', async function () {
|
||||
await expect(
|
||||
lensPeriphery.connect(userTwo).setProfileMetadataURI(FIRST_PROFILE_ID, MOCK_DATA)
|
||||
).to.be.revertedWith(ERRORS.NOT_PROFILE_OWNER);
|
||||
});
|
||||
|
||||
it("User should fail to set profile metadata URI as dispatcher without being the profile's dispatcher", async function () {
|
||||
await expect(
|
||||
lensPeriphery.dispatcherSetProfileMetadataURI(FIRST_PROFILE_ID, MOCK_DATA)
|
||||
).to.be.revertedWith(ERRORS.NOT_DISPATCHER);
|
||||
).to.be.revertedWith(ERRORS.NOT_PROFILE_OWNER_OR_DISPATCHER);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1090,9 +1084,7 @@ makeSuiteCleanRoom('Misc', function () {
|
||||
lensHub.setDispatcher(FIRST_PROFILE_ID, userTwoAddress)
|
||||
).to.not.be.reverted;
|
||||
await expect(
|
||||
lensPeriphery
|
||||
.connect(userTwo)
|
||||
.dispatcherSetProfileMetadataURI(FIRST_PROFILE_ID, MOCK_DATA)
|
||||
lensPeriphery.connect(userTwo).setProfileMetadataURI(FIRST_PROFILE_ID, MOCK_DATA)
|
||||
).to.not.be.reverted;
|
||||
|
||||
expect(await lensPeriphery.getProfileMetadataURI(FIRST_PROFILE_ID)).to.eq(MOCK_DATA);
|
||||
@@ -1117,9 +1109,7 @@ makeSuiteCleanRoom('Misc', function () {
|
||||
).to.not.be.reverted;
|
||||
|
||||
const tx = await waitForTx(
|
||||
lensPeriphery
|
||||
.connect(userTwo)
|
||||
.dispatcherSetProfileMetadataURI(FIRST_PROFILE_ID, MOCK_DATA)
|
||||
lensPeriphery.connect(userTwo).setProfileMetadataURI(FIRST_PROFILE_ID, MOCK_DATA)
|
||||
);
|
||||
|
||||
matchEvent(tx, 'ProfileMetadataSet', [
|
||||
|
||||
Reference in New Issue
Block a user