mirror of
https://github.com/lens-protocol/core.git
synced 2026-01-09 22:28:04 -05:00
test: Add tests for linking non existing tokens in TokenHandleRegistry
This commit is contained in:
@@ -45,8 +45,8 @@ contract TokenHandleRegistry is ITokenHandleRegistry {
|
||||
}
|
||||
|
||||
// Lens V1 to Lens V2 migration function
|
||||
// WARNING: Is able to link the Token and Handle even if they're not in the same wallet.
|
||||
// TODO: ^ Is that a problem?
|
||||
// WARNING: It is able to link the Token and Handle even if they're not in the same wallet.
|
||||
// But it is designed to be only called from LensHub migration function, which assures that they are.
|
||||
function migrationLink(uint256 handleId, uint256 tokenId) external {
|
||||
if (msg.sender != LENS_HUB) {
|
||||
revert RegistryErrors.OnlyLensHub();
|
||||
@@ -131,9 +131,6 @@ contract TokenHandleRegistry is ITokenHandleRegistry {
|
||||
return tokenToHandle[_tokenHash(token)];
|
||||
}
|
||||
|
||||
// WARNING: This function doesn't check for existence of the Handle or Token. Nor it checks if the Handle and Token
|
||||
// are in the same wallet.
|
||||
// TODO: ^ Is that a problem?
|
||||
function _link(RegistryTypes.Handle memory handle, RegistryTypes.Token memory token) internal {
|
||||
_deleteTokenToHandleLinkageIfAny(handle);
|
||||
handleToToken[_handleHash(handle)] = token;
|
||||
|
||||
@@ -64,6 +64,24 @@ contract TokenHandleRegistryTest is BaseTest {
|
||||
tokenHandleRegistry.link(handleId, profileId);
|
||||
}
|
||||
|
||||
function testCannot_Link_IfHandleDoesNotExist(uint256 nonexistingHandleId) public {
|
||||
vm.assume(!lensHandles.exists(nonexistingHandleId));
|
||||
|
||||
vm.expectRevert('ERC721: invalid token ID');
|
||||
|
||||
vm.prank(initialProfileHolder);
|
||||
tokenHandleRegistry.link(nonexistingHandleId, profileId);
|
||||
}
|
||||
|
||||
function testCannot_Link_IfProfileDoesNotExist(uint256 nonexistingProfileId) public {
|
||||
vm.assume(!hub.exists(nonexistingProfileId));
|
||||
|
||||
vm.expectRevert(Errors.TokenDoesNotExist.selector);
|
||||
|
||||
vm.prank(initialHandleHolder);
|
||||
tokenHandleRegistry.link(handleId, nonexistingProfileId);
|
||||
}
|
||||
|
||||
function testCannot_Unlink_IfNotHoldingProfileOrHandle(address otherAddress) public {
|
||||
vm.assume(otherAddress != lensHandles.ownerOf(handleId));
|
||||
vm.assume(otherAddress != hub.ownerOf(profileId));
|
||||
@@ -709,7 +727,4 @@ contract TokenHandleRegistryTest is BaseTest {
|
||||
vm.expectRevert(RegistryErrors.DoesNotExist.selector);
|
||||
tokenHandleRegistry.getDefaultHandle(profileId);
|
||||
}
|
||||
|
||||
// TODO:
|
||||
// - test migrationLink scenarios
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user