|
| 1 | +import '@nomiclabs/hardhat-ethers'; |
| 2 | +import { expect } from 'chai'; |
| 3 | +import { ZERO_ADDRESS } from '../helpers/constants'; |
| 4 | +import { ERRORS } from '../helpers/errors'; |
| 5 | +import { ProfileCreationProxy, ProfileCreationProxy__factory } from '../../typechain-types'; |
| 6 | +import { |
| 7 | + deployer, |
| 8 | + FIRST_PROFILE_ID, |
| 9 | + governance, |
| 10 | + lensHub, |
| 11 | + makeSuiteCleanRoom, |
| 12 | + MOCK_FOLLOW_NFT_URI, |
| 13 | + MOCK_PROFILE_URI, |
| 14 | + user, |
| 15 | + userAddress, |
| 16 | + deployerAddress, |
| 17 | +} from '../__setup.spec'; |
| 18 | +import { BigNumber } from 'ethers'; |
| 19 | +import { TokenDataStructOutput } from '../../typechain-types/LensHub'; |
| 20 | +import { getTimestamp } from '../helpers/utils'; |
| 21 | + |
| 22 | +makeSuiteCleanRoom('Profile Creation Proxy', function () { |
| 23 | + const REQUIRED_SUFFIX = '.lens'; |
| 24 | + const MINIMUM_LENGTH = 5; |
| 25 | + |
| 26 | + let profileCreationProxy: ProfileCreationProxy; |
| 27 | + beforeEach(async function () { |
| 28 | + profileCreationProxy = await new ProfileCreationProxy__factory(deployer).deploy( |
| 29 | + deployerAddress, |
| 30 | + lensHub.address |
| 31 | + ); |
| 32 | + await expect( |
| 33 | + lensHub.connect(governance).whitelistProfileCreator(profileCreationProxy.address, true) |
| 34 | + ).to.not.be.reverted; |
| 35 | + }); |
| 36 | + |
| 37 | + context('Negatives', function () { |
| 38 | + it('Should fail to create profile if handle length before suffix does not reach minimum length', async function () { |
| 39 | + const handle = 'a'.repeat(MINIMUM_LENGTH - 1); |
| 40 | + await expect( |
| 41 | + profileCreationProxy.proxyCreateProfile({ |
| 42 | + to: userAddress, |
| 43 | + handle: handle, |
| 44 | + imageURI: MOCK_PROFILE_URI, |
| 45 | + followModule: ZERO_ADDRESS, |
| 46 | + followModuleInitData: [], |
| 47 | + followNFTURI: MOCK_FOLLOW_NFT_URI, |
| 48 | + }) |
| 49 | + ).to.be.revertedWith(ERRORS.INVALID_HANDLE_LENGTH); |
| 50 | + }); |
| 51 | + |
| 52 | + it('Should fail to create profile if handle contains an invalid character before the suffix', async function () { |
| 53 | + await expect( |
| 54 | + profileCreationProxy.proxyCreateProfile({ |
| 55 | + to: userAddress, |
| 56 | + handle: 'dots.are.invalid', |
| 57 | + imageURI: MOCK_PROFILE_URI, |
| 58 | + followModule: ZERO_ADDRESS, |
| 59 | + followModuleInitData: [], |
| 60 | + followNFTURI: MOCK_FOLLOW_NFT_URI, |
| 61 | + }) |
| 62 | + ).to.be.revertedWith(ERRORS.HANDLE_CONTAINS_INVALID_CHARACTERS); |
| 63 | + }); |
| 64 | + |
| 65 | + it('Should fail to create profile if handle starts with a dash, underscore or period', async function () { |
| 66 | + await expect( |
| 67 | + profileCreationProxy.proxyCreateProfile({ |
| 68 | + to: userAddress, |
| 69 | + handle: '.abcdef', |
| 70 | + imageURI: MOCK_PROFILE_URI, |
| 71 | + followModule: ZERO_ADDRESS, |
| 72 | + followModuleInitData: [], |
| 73 | + followNFTURI: MOCK_FOLLOW_NFT_URI, |
| 74 | + }) |
| 75 | + ).to.be.revertedWith(ERRORS.HANDLE_FIRST_CHARACTER_INVALID); |
| 76 | + |
| 77 | + await expect( |
| 78 | + profileCreationProxy.proxyCreateProfile({ |
| 79 | + to: userAddress, |
| 80 | + handle: '-abcdef', |
| 81 | + imageURI: MOCK_PROFILE_URI, |
| 82 | + followModule: ZERO_ADDRESS, |
| 83 | + followModuleInitData: [], |
| 84 | + followNFTURI: MOCK_FOLLOW_NFT_URI, |
| 85 | + }) |
| 86 | + ).to.be.revertedWith(ERRORS.HANDLE_FIRST_CHARACTER_INVALID); |
| 87 | + |
| 88 | + await expect( |
| 89 | + profileCreationProxy.proxyCreateProfile({ |
| 90 | + to: userAddress, |
| 91 | + handle: '_abcdef', |
| 92 | + imageURI: MOCK_PROFILE_URI, |
| 93 | + followModule: ZERO_ADDRESS, |
| 94 | + followModuleInitData: [], |
| 95 | + followNFTURI: MOCK_FOLLOW_NFT_URI, |
| 96 | + }) |
| 97 | + ).to.be.revertedWith(ERRORS.HANDLE_FIRST_CHARACTER_INVALID); |
| 98 | + }); |
| 99 | + }); |
| 100 | + |
| 101 | + context('Scenarios', function () { |
| 102 | + it('Should be able to create a profile using the whitelisted proxy, received NFT should be valid', async function () { |
| 103 | + let timestamp: any; |
| 104 | + let owner: string; |
| 105 | + let totalSupply: BigNumber; |
| 106 | + let profileId: BigNumber; |
| 107 | + let mintTimestamp: BigNumber; |
| 108 | + let tokenData: TokenDataStructOutput; |
| 109 | + const validHandleBeforeSuffix = 'v_al-id'; |
| 110 | + const expectedHandle = 'v_al-id'.concat(REQUIRED_SUFFIX); |
| 111 | + |
| 112 | + await expect( |
| 113 | + profileCreationProxy.proxyCreateProfile({ |
| 114 | + to: userAddress, |
| 115 | + handle: validHandleBeforeSuffix, |
| 116 | + imageURI: MOCK_PROFILE_URI, |
| 117 | + followModule: ZERO_ADDRESS, |
| 118 | + followModuleInitData: [], |
| 119 | + followNFTURI: MOCK_FOLLOW_NFT_URI, |
| 120 | + }) |
| 121 | + ).to.not.be.reverted; |
| 122 | + |
| 123 | + timestamp = await getTimestamp(); |
| 124 | + owner = await lensHub.ownerOf(FIRST_PROFILE_ID); |
| 125 | + totalSupply = await lensHub.totalSupply(); |
| 126 | + profileId = await lensHub.getProfileIdByHandle(expectedHandle); |
| 127 | + mintTimestamp = await lensHub.mintTimestampOf(FIRST_PROFILE_ID); |
| 128 | + tokenData = await lensHub.tokenDataOf(FIRST_PROFILE_ID); |
| 129 | + expect(owner).to.eq(userAddress); |
| 130 | + expect(totalSupply).to.eq(FIRST_PROFILE_ID); |
| 131 | + expect(profileId).to.eq(FIRST_PROFILE_ID); |
| 132 | + expect(mintTimestamp).to.eq(timestamp); |
| 133 | + expect(tokenData.owner).to.eq(userAddress); |
| 134 | + expect(tokenData.mintTimestamp).to.eq(timestamp); |
| 135 | + }); |
| 136 | + }); |
| 137 | +}); |
0 commit comments