test: Add tests for linking non existing tokens in TokenHandleRegistry

This commit is contained in:
vicnaum
2023-06-06 18:57:33 +02:00
parent 8d3b22a92e
commit 89701ca36a
2 changed files with 20 additions and 8 deletions

View File

@@ -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;

View File

@@ -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
}