mirror of
https://github.com/lens-protocol/core.git
synced 2026-04-22 03:02:03 -04:00
test: Added executor tests for follow NFT URI and profile image URI setting.
This commit is contained in:
@@ -22,7 +22,7 @@ contract CollectTest is BaseTest {
|
||||
}
|
||||
|
||||
function testCollectNotExecutorFails() public {
|
||||
vm.prank(otherUser);
|
||||
vm.prank(otherSigner);
|
||||
vm.expectRevert(Errors.ExecutorInvalid.selector);
|
||||
hub.collect(me, firstProfileId, 1, '');
|
||||
}
|
||||
@@ -48,9 +48,9 @@ contract CollectTest is BaseTest {
|
||||
}
|
||||
|
||||
function testExecutorCollect() public {
|
||||
hub.setDelegatedExecutorApproval(otherUser, true);
|
||||
hub.setDelegatedExecutorApproval(otherSigner, true);
|
||||
|
||||
vm.prank(otherUser);
|
||||
vm.prank(otherSigner);
|
||||
uint256 nftId = hub.collect(me, firstProfileId, 1, '');
|
||||
|
||||
CollectNFT nft = CollectNFT(hub.getCollectNFT(firstProfileId, 1));
|
||||
@@ -95,9 +95,9 @@ contract CollectTest is BaseTest {
|
||||
})
|
||||
);
|
||||
|
||||
hub.setDelegatedExecutorApproval(otherUser, true);
|
||||
hub.setDelegatedExecutorApproval(otherSigner, true);
|
||||
|
||||
vm.prank(otherUser);
|
||||
vm.prank(otherSigner);
|
||||
uint256 nftId = hub.collect(me, firstProfileId, 2, '');
|
||||
|
||||
// Ensure the mirror doesn't have an associated collect NFT.
|
||||
|
||||
@@ -6,7 +6,7 @@ import './base/BaseTest.t.sol';
|
||||
contract FollowTest is BaseTest {
|
||||
// Negatives
|
||||
function testFollowNotExecutorFails() public {
|
||||
vm.prank(otherUser);
|
||||
vm.prank(otherSigner);
|
||||
vm.expectRevert(Errors.ExecutorInvalid.selector);
|
||||
hub.follow(me, _toUint256Array(firstProfileId), _toBytesArray(''));
|
||||
}
|
||||
@@ -34,9 +34,9 @@ contract FollowTest is BaseTest {
|
||||
}
|
||||
|
||||
function testExecutorFollow() public {
|
||||
hub.setDelegatedExecutorApproval(otherUser, true);
|
||||
hub.setDelegatedExecutorApproval(otherSigner, true);
|
||||
|
||||
vm.prank(otherUser);
|
||||
vm.prank(otherSigner);
|
||||
uint256[] memory nftIds = hub.follow(
|
||||
me,
|
||||
_toUint256Array(firstProfileId),
|
||||
|
||||
@@ -15,6 +15,16 @@ contract MiscTest is BaseTest {
|
||||
hub.setDefaultProfile(profileOwner, firstProfileId);
|
||||
}
|
||||
|
||||
function testSetProfileImageURINotExecutorFails() public {
|
||||
vm.expectRevert(Errors.ExecutorInvalid.selector);
|
||||
hub.setProfileImageURI(firstProfileId, mockURI);
|
||||
}
|
||||
|
||||
function testSetFollowNFTURINotExecutorFails() public {
|
||||
vm.expectRevert(Errors.ExecutorInvalid.selector);
|
||||
hub.setFollowNFTURI(firstProfileId, mockURI);
|
||||
}
|
||||
|
||||
// Positives
|
||||
function testExecutorSetFollowModule() public {
|
||||
vm.prank(profileOwner);
|
||||
@@ -32,6 +42,22 @@ contract MiscTest is BaseTest {
|
||||
hub.setDefaultProfile(profileOwner, firstProfileId);
|
||||
}
|
||||
|
||||
function testExecutorSetProfileImageURI() public {
|
||||
vm.prank(profileOwner);
|
||||
hub.setDelegatedExecutorApproval(otherSigner, true);
|
||||
|
||||
vm.prank(otherSigner);
|
||||
hub.setProfileImageURI(firstProfileId, mockURI);
|
||||
}
|
||||
|
||||
function testExecutorSetFollowNFTURI() public {
|
||||
vm.prank(profileOwner);
|
||||
hub.setDelegatedExecutorApproval(otherSigner, true);
|
||||
|
||||
vm.prank(otherSigner);
|
||||
hub.setFollowNFTURI(firstProfileId, mockURI);
|
||||
}
|
||||
|
||||
// Meta-tx
|
||||
// Negatives
|
||||
function testSetFollowModuleWithSigInvalidSignerFails() public {
|
||||
@@ -122,6 +148,80 @@ contract MiscTest is BaseTest {
|
||||
);
|
||||
}
|
||||
|
||||
function testSetProfileImageURIWithSigInvalidSignerFails() public {
|
||||
uint256 nonce = 0;
|
||||
uint256 deadline = type(uint256).max;
|
||||
bytes32 digest = _getSetProfileImageURITypedDataHash(
|
||||
firstProfileId,
|
||||
mockURI,
|
||||
nonce,
|
||||
deadline
|
||||
);
|
||||
|
||||
vm.expectRevert(Errors.SignatureInvalid.selector);
|
||||
hub.setProfileImageURIWithSig(
|
||||
DataTypes.SetProfileImageURIWithSigData({
|
||||
delegatedSigner: address(0),
|
||||
profileId: firstProfileId,
|
||||
imageURI: mockURI,
|
||||
sig: _getSigStruct(otherSignerKey, digest, deadline)
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
function testSetProfileImageURIWithSigNotExecutorFails() public {
|
||||
uint256 nonce = 0;
|
||||
uint256 deadline = type(uint256).max;
|
||||
bytes32 digest = _getSetProfileImageURITypedDataHash(
|
||||
firstProfileId,
|
||||
mockURI,
|
||||
nonce,
|
||||
deadline
|
||||
);
|
||||
|
||||
vm.expectRevert(Errors.ExecutorInvalid.selector);
|
||||
hub.setProfileImageURIWithSig(
|
||||
DataTypes.SetProfileImageURIWithSigData({
|
||||
delegatedSigner: otherSigner,
|
||||
profileId: firstProfileId,
|
||||
imageURI: mockURI,
|
||||
sig: _getSigStruct(otherSignerKey, digest, deadline)
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
function testSetFollowNFTURIWithSigInvalidSignerFails() public {
|
||||
uint256 nonce = 0;
|
||||
uint256 deadline = type(uint256).max;
|
||||
bytes32 digest = _getSetFollowNFTURITypedDatahash(firstProfileId, mockURI, nonce, deadline);
|
||||
|
||||
vm.expectRevert(Errors.SignatureInvalid.selector);
|
||||
hub.setFollowNFTURIWithSig(
|
||||
DataTypes.SetFollowNFTURIWithSigData({
|
||||
delegatedSigner: address(0),
|
||||
profileId: firstProfileId,
|
||||
followNFTURI: mockURI,
|
||||
sig: _getSigStruct(otherSignerKey, digest, deadline)
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
function testSetFollowNFTURIWithSigNotExecutorFails() public {
|
||||
uint256 nonce = 0;
|
||||
uint256 deadline = type(uint256).max;
|
||||
bytes32 digest = _getSetFollowNFTURITypedDatahash(firstProfileId, mockURI, nonce, deadline);
|
||||
|
||||
vm.expectRevert(Errors.ExecutorInvalid.selector);
|
||||
hub.setFollowNFTURIWithSig(
|
||||
DataTypes.SetFollowNFTURIWithSigData({
|
||||
delegatedSigner: otherSigner,
|
||||
profileId: firstProfileId,
|
||||
followNFTURI: mockURI,
|
||||
sig: _getSigStruct(otherSignerKey, digest, deadline)
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
// Postivies
|
||||
function testExecutorSetFollowModuleWithSig() public {
|
||||
vm.prank(profileOwner);
|
||||
|
||||
@@ -29,9 +29,9 @@ contract PublishingTest is BaseTest {
|
||||
// positives
|
||||
function testExecutorPost() public {
|
||||
vm.prank(profileOwner);
|
||||
hub.setDelegatedExecutorApproval(otherUser, true);
|
||||
hub.setDelegatedExecutorApproval(otherSigner, true);
|
||||
|
||||
vm.prank(otherUser);
|
||||
vm.prank(otherSigner);
|
||||
uint256 pubId = hub.post(mockPostData);
|
||||
assertEq(pubId, 1);
|
||||
}
|
||||
@@ -39,10 +39,10 @@ contract PublishingTest is BaseTest {
|
||||
function testExecutorComment() public {
|
||||
vm.startPrank(profileOwner);
|
||||
hub.post(mockPostData);
|
||||
hub.setDelegatedExecutorApproval(otherUser, true);
|
||||
hub.setDelegatedExecutorApproval(otherSigner, true);
|
||||
vm.stopPrank();
|
||||
|
||||
vm.prank(otherUser);
|
||||
vm.prank(otherSigner);
|
||||
uint256 pubId = hub.comment(mockCommentData);
|
||||
assertEq(pubId, 2);
|
||||
}
|
||||
@@ -50,10 +50,10 @@ contract PublishingTest is BaseTest {
|
||||
function testExecutorMirror() public {
|
||||
vm.startPrank(profileOwner);
|
||||
hub.post(mockPostData);
|
||||
hub.setDelegatedExecutorApproval(otherUser, true);
|
||||
hub.setDelegatedExecutorApproval(otherSigner, true);
|
||||
vm.stopPrank();
|
||||
|
||||
vm.prank(otherUser);
|
||||
vm.prank(otherSigner);
|
||||
uint256 pubId = hub.mirror(mockMirrorData);
|
||||
assertEq(pubId, 2);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,42 @@ pragma solidity ^0.8.13;
|
||||
import './TestSetup.t.sol';
|
||||
|
||||
contract BaseTest is TestSetup {
|
||||
function _getSetFollowNFTURITypedDatahash(
|
||||
uint256 profileId,
|
||||
string memory followNFTURI,
|
||||
uint256 nonce,
|
||||
uint256 deadline
|
||||
) internal view returns (bytes32) {
|
||||
bytes32 structHash = keccak256(
|
||||
abi.encode(
|
||||
SET_FOLLOW_NFT_URI_WITH_SIG_TYPEHASH,
|
||||
profileId,
|
||||
keccak256(bytes(followNFTURI)),
|
||||
nonce,
|
||||
deadline
|
||||
)
|
||||
);
|
||||
return _calculateDigest(structHash);
|
||||
}
|
||||
|
||||
function _getSetProfileImageURITypedDataHash(
|
||||
uint256 profileId,
|
||||
string memory imageURI,
|
||||
uint256 nonce,
|
||||
uint256 deadline
|
||||
) internal view returns (bytes32) {
|
||||
bytes32 structHash = keccak256(
|
||||
abi.encode(
|
||||
SET_PROFILE_IMAGE_URI_WITH_SIG_TYPEHASH,
|
||||
profileId,
|
||||
keccak256(bytes(imageURI)),
|
||||
nonce,
|
||||
deadline
|
||||
)
|
||||
);
|
||||
return _calculateDigest(structHash);
|
||||
}
|
||||
|
||||
function _getSetDefaultProfileTypedDataHash(
|
||||
address wallet,
|
||||
uint256 profileId,
|
||||
@@ -13,7 +49,6 @@ contract BaseTest is TestSetup {
|
||||
bytes32 structHash = keccak256(
|
||||
abi.encode(SET_DEFAULT_PROFILE_WITH_SIG_TYPEHASH, wallet, profileId, nonce, deadline)
|
||||
);
|
||||
|
||||
return _calculateDigest(structHash);
|
||||
}
|
||||
|
||||
@@ -168,8 +203,8 @@ contract BaseTest is TestSetup {
|
||||
return _calculateDigest(structHash);
|
||||
}
|
||||
|
||||
function _calculateDigest(bytes32 hashedMessage) internal view returns (bytes32) {
|
||||
bytes32 digest = keccak256(abi.encodePacked('\x19\x01', domainSeparator, hashedMessage));
|
||||
function _calculateDigest(bytes32 structHash) internal view returns (bytes32) {
|
||||
bytes32 digest = keccak256(abi.encodePacked('\x19\x01', domainSeparator, structHash));
|
||||
return digest;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,8 +19,7 @@ contract TestSetup is Test {
|
||||
uint256 constant firstProfileId = 1;
|
||||
address constant deployer = address(1);
|
||||
// UserOne is the test address, replaced with "me."
|
||||
address constant otherUser = address(2);
|
||||
address constant governance = address(3);
|
||||
address constant governance = address(2);
|
||||
|
||||
string constant mockHandle = 'handle.lens';
|
||||
string constant mockURI = 'ipfs://QmUXfQWe43RKx31VzA2BnbwhSMW8WuaJvszFWChD59m76U';
|
||||
|
||||
Reference in New Issue
Block a user