@@ -6,8 +6,12 @@ import { ISignatureMintERC721 } from "contracts/feature/interface/ISignatureMint
66
77// Test imports
88import "../utils/BaseTest.sol " ;
9+ import "@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol " ;
910
1011contract SignatureDropTest is BaseTest {
12+
13+ using StringsUpgradeable for uint256 ;
14+
1115 event TokensLazyMinted (uint256 startTokenId , uint256 endTokenId , string baseURI , bytes encryptedBaseURI );
1216 event TokenURIRevealed (uint256 index , string revealedURI );
1317
@@ -42,6 +46,55 @@ contract SignatureDropTest is BaseTest {
4246 Lazy Mint Tests
4347 //////////////////////////////////////////////////////////////*/
4448
49+ /*
50+ * note: Testing state changes; lazy mint a batch of tokens with no encrypted base URI.
51+ */
52+ function test_state_lazyMint_noEncryptedURI () public {
53+ uint256 amountToLazyMint = 100 ;
54+ string memory baseURI = "ipfs:// " ;
55+ bytes memory encryptedBaseURI = "" ;
56+
57+ uint256 nextTokenIdToMintBefore = sigdrop.nextTokenIdToMint ();
58+
59+ vm.startPrank (deployer_signer);
60+ uint256 batchId = sigdrop.lazyMint (amountToLazyMint, baseURI, encryptedBaseURI);
61+
62+ assertEq (nextTokenIdToMintBefore + amountToLazyMint, sigdrop.nextTokenIdToMint ());
63+ assertEq (nextTokenIdToMintBefore + amountToLazyMint, batchId);
64+
65+ for (uint256 i = 0 ; i < amountToLazyMint; i += 1 ) {
66+ string memory uri = sigdrop.tokenURI (i);
67+ console.log (uri);
68+ assertEq (uri, string (abi.encodePacked (baseURI, i.toString ())));
69+ }
70+
71+ vm.stopPrank ();
72+ }
73+
74+ /*
75+ * note: Testing state changes; lazy mint a batch of tokens with encrypted base URI.
76+ */
77+ function test_state_lazyMint_withEncryptedURI () public {
78+ uint256 amountToLazyMint = 100 ;
79+ string memory baseURI = "ipfs:// " ;
80+ bytes memory encryptedBaseURI = "encryptedBaseURI:// " ;
81+
82+ uint256 nextTokenIdToMintBefore = sigdrop.nextTokenIdToMint ();
83+
84+ vm.startPrank (deployer_signer);
85+ uint256 batchId = sigdrop.lazyMint (amountToLazyMint, baseURI, encryptedBaseURI);
86+
87+ assertEq (nextTokenIdToMintBefore + amountToLazyMint, sigdrop.nextTokenIdToMint ());
88+ assertEq (nextTokenIdToMintBefore + amountToLazyMint, batchId);
89+
90+ for (uint256 i = 0 ; i < amountToLazyMint; i += 1 ) {
91+ string memory uri = sigdrop.tokenURI (1 );
92+ assertEq (uri, string (abi.encodePacked (baseURI, "0 " )));
93+ }
94+
95+ vm.stopPrank ();
96+ }
97+
4598 /**
4699 * note: Testing revert condition; an address without MINTER_ROLE calls lazyMint function.
47100 */
@@ -58,92 +111,100 @@ contract SignatureDropTest is BaseTest {
58111 }
59112
60113 /*
61- * note: Testing state changes; a batch of tokens, and nextTokenIdToMint
114+ * note: Testing revert condition; calling tokenURI for invalid batch id.
62115 */
63- function test_state_lazyMint_batchMintAndNextTokenIdToMint () public {
116+ function test_revert_lazyMint_URIForNonLazyMintedToken () public {
64117 vm.startPrank (deployer_signer);
65118
66119 sigdrop.lazyMint (100 , "ipfs:// " , "" );
67120
68- uint256 slot = stdstore.target (address (sigdrop)).sig ("nextTokenIdToMint() " ).find ();
69- bytes32 loc = bytes32 (slot);
70- uint256 nextTokenIdToMint = uint256 (vm.load (address (sigdrop), loc));
121+ vm.expectRevert ("No batch id for token. " );
122+ sigdrop.tokenURI (100 );
71123
72- assertEq (nextTokenIdToMint, 100 );
73124 vm.stopPrank ();
74125 }
75126
76- /*
77- * note: Fuzz testing; a batch of tokens, and nextTokenIdToMint
127+ /**
128+ * note: Testing event emission; tokens lazy minted.
78129 */
79- function test_fuzz_lazyMint_batchMintAndNextTokenIdToMint ( uint256 x ) public {
130+ function test_event_lazyMint_TokensLazyMinted ( ) public {
80131 vm.startPrank (deployer_signer);
81132
82- sigdrop.lazyMint (x, "ipfs:// " , "" );
83-
84- uint256 slot = stdstore.target (address (sigdrop)).sig ("nextTokenIdToMint() " ).find ();
85- bytes32 loc = bytes32 (slot);
86- uint256 nextTokenIdToMint = uint256 (vm.load (address (sigdrop), loc));
133+ vm.expectEmit (false , false , false , true );
134+ emit TokensLazyMinted (0 , 100 , "ipfs:// " , "" );
135+ sigdrop.lazyMint (100 , "ipfs:// " , "" );
87136
88- assertEq (nextTokenIdToMint, x);
89137 vm.stopPrank ();
90138 }
91139
92140 /*
93- * note: Testing state changes; a batch of tokens, and associated baseURI for tokens
141+ * note: Fuzz testing state changes; lazy mint a batch of tokens with no encrypted base URI.
94142 */
95- function test_state_lazyMint_batchMintAndTokenURI () public {
96- vm.startPrank (deployer_signer);
143+ function test_fuzz_lazyMint_noEncryptedURI (uint256 x ) public {
97144
98- sigdrop. lazyMint ( 100 , " ipfs:// " , "" );
145+ vm. assume (x > 0 );
99146
100- string memory uri = sigdrop.tokenURI (1 );
101- assertEq (uri, "ipfs://1 " );
102-
103- uri = sigdrop.tokenURI (99 );
104- assertEq (uri, "ipfs://99 " );
147+ uint256 amountToLazyMint = x;
148+ string memory baseURI = "ipfs:// " ;
149+ bytes memory encryptedBaseURI = "" ;
105150
106- vm.stopPrank ();
107- }
151+ uint256 nextTokenIdToMintBefore = sigdrop.nextTokenIdToMint ();
108152
109- /*
110- * note: Testing revert condition; calling tokenURI for invalid batch id.
111- */
112- function test_revert_lazyMint_batchMintAndTokenURI () public {
113153 vm.startPrank (deployer_signer);
154+ uint256 batchId = sigdrop.lazyMint (amountToLazyMint, baseURI, encryptedBaseURI);
114155
115- sigdrop.lazyMint (100 , "ipfs:// " , "" );
156+ assertEq (nextTokenIdToMintBefore + amountToLazyMint, sigdrop.nextTokenIdToMint ());
157+ assertEq (nextTokenIdToMintBefore + amountToLazyMint, batchId);
116158
117- vm.expectRevert ("No batch id for token. " );
118- sigdrop.tokenURI (100 );
159+ string memory uri = sigdrop.tokenURI (0 );
160+ assertEq (uri, string (abi.encodePacked (baseURI, uint (0 ).toString ())));
161+
162+ uri = sigdrop.tokenURI (x-1 );
163+ assertEq (uri, string (abi.encodePacked (baseURI, uint (x-1 ).toString ())));
164+
165+ /**
166+ * note: this loop takes too long to run with fuzz tests.
167+ */
168+ // for(uint256 i = 0; i < amountToLazyMint; i += 1) {
169+ // string memory uri = sigdrop.tokenURI(i);
170+ // console.log(uri);
171+ // assertEq(uri, string(abi.encodePacked(baseURI, i.toString())));
172+ // }
119173
120174 vm.stopPrank ();
121175 }
122176
123177 /*
124- * note: Testing state changes; a batch of tokens with encrypted base URI, and associated URI for tokens
178+ * note: Fuzz testing state changes; lazy mint a batch of tokens with encrypted base URI.
125179 */
126- function test_state_lazyMint_setEncryptedBaseURIAndTokenURI () public {
127- vm.startPrank (deployer_signer);
128-
129- bytes memory encryptedURI = sigdrop.encryptDecrypt ("ipfs:// " , "key " );
130- sigdrop.lazyMint (100 , "" , encryptedURI);
180+ function test_fuzz_lazyMint_withEncryptedURI (uint256 x ) public {
181+ vm.assume (x > 0 );
131182
132- string memory uri = sigdrop.tokenURI (1 );
133- assertEq (uri, "0 " );
183+ uint256 amountToLazyMint = x;
184+ string memory baseURI = "ipfs:// " ;
185+ bytes memory encryptedBaseURI = "encryptedBaseURI:// " ;
134186
135- vm.stopPrank ();
136- }
187+ uint256 nextTokenIdToMintBefore = sigdrop.nextTokenIdToMint ();
137188
138- /**
139- * note: Testing event emission; tokens lazy minted.
140- */
141- function test_event_lazyMint_event () public {
142189 vm.startPrank (deployer_signer);
190+ uint256 batchId = sigdrop.lazyMint (amountToLazyMint, baseURI, encryptedBaseURI);
143191
144- vm.expectEmit (false , false , false , true );
145- emit TokensLazyMinted (0 , 100 , "ipfs:// " , "" );
146- sigdrop.lazyMint (100 , "ipfs:// " , "" );
192+ assertEq (nextTokenIdToMintBefore + amountToLazyMint, sigdrop.nextTokenIdToMint ());
193+ assertEq (nextTokenIdToMintBefore + amountToLazyMint, batchId);
194+
195+ string memory uri = sigdrop.tokenURI (0 );
196+ assertEq (uri, string (abi.encodePacked (baseURI, "0 " )));
197+
198+ uri = sigdrop.tokenURI (x-1 );
199+ assertEq (uri, string (abi.encodePacked (baseURI, "0 " )));
200+
201+ /**
202+ * note: this loop takes too long to run with fuzz tests.
203+ */
204+ // for(uint256 i = 0; i < amountToLazyMint; i += 1) {
205+ // string memory uri = sigdrop.tokenURI(1);
206+ // assertEq(uri, string(abi.encodePacked(baseURI, "0")));
207+ // }
147208
148209 vm.stopPrank ();
149210 }
0 commit comments