From fb1d35663b71ab9165ade1a7bea8b45c74595b2b Mon Sep 17 00:00:00 2001 From: itzelot01 Date: Tue, 5 Dec 2023 22:48:07 +0000 Subject: [PATCH] Add test for the enumerate ERC721 Extension and .env import URIs examples --- test/DCO2s.t.sol | 74 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 57 insertions(+), 17 deletions(-) diff --git a/test/DCO2s.t.sol b/test/DCO2s.t.sol index 9bc5638..2e138d8 100644 --- a/test/DCO2s.t.sol +++ b/test/DCO2s.t.sol @@ -22,18 +22,18 @@ contract DCO2sTest is Test { function testMintFromEnv() public { address to = address(0x1); - string memory nft68 = vm.envString("NFT68"); - dco2sc.safeMint(to,nft68); + string memory nft0 = vm.envString("nfts"); + dco2sc.safeMint(to,nft0); assertEq(dco2sc.ownerOf(0), to, "Token should be minted to specified address."); } // @notice: here we test getting the Base and full URIS function testGetURI68() public { - string memory URI = vm.envString("NFT68"); - dco2sc.safeMint(address(1), URI); + string[] memory URIs = vm.envString("nfts", ' '); + dco2sc.safeMint(address(1), URIs[68]); string memory tokenURI = dco2sc.tokenURI(0); - console.log(tokenURI); - assertEq(tokenURI, string.concat(baseURL, URI)); + //console.log(tokenURI); + assertEq(tokenURI, string.concat(baseURL, URIs[68])); } // @notice: here we test getting the Base and full URIS @@ -41,13 +41,12 @@ contract DCO2sTest is Test { string memory URI = "bafkreibc6p3y36yjmeqqnttqfrpb2yttxa6aonoywxwdxl7nqym4jj3jwa"; dco2sc.safeMint(address(1), URI); string memory tokenURI = dco2sc.tokenURI(0); - console.log(tokenURI); + //console.log(tokenURI); assertEq(tokenURI, string.concat(baseURL,URI)); - } // @notice: checkFailed token Index - function testFailTokenIndex() public { + function testFailTokenIndex() view public { dco2sc.tokenURI(0); } // @notice: checkFailed token Index @@ -56,14 +55,29 @@ contract DCO2sTest is Test { // dco2sc.tokenURI(0); //} - // @notice use the basic Enumerable properties - // function testEnumerable() public {} + // @notice use basic Enumerable properties totalSupply + function testEnumerableTotalSupply() public { + string[5] memory nfts = [ + "bafkreibc6p3y36yjmeqqnttqfrpb2yttxa6aonoywxwdxl7nqym4jj3jwa", + "bafkreifqztiwfutjik4wfs3gyfdyrff7cugi4mcctluunrrbp5cgareisq", + "bafkreibffiehtv4ntajq5vjwpl7q44i6cjbg54lm5hkoa665ue2taspiyu", + "bafkreidcf5baqb5wevs6vyd7dtd3j7rzrq65uyqasj4dbkcy5na4ig3ay", + "bafkreiglyvpxwrxdvruit3oiw2lvkxqqxn7ojquw4gl7ck6szewz6t6cam"]; + + for(uint i; i < nfts.length; i++){ + dco2sc.safeMint(address(1), nfts[i]); + } + + assertEq(nfts.length, dco2sc.totalSupply()); + } + + // @notice use the basic Enumerable property tokenByIndex function testEnumerableTokenByIndex() public { string[5] memory nfts = [ "bafkreibc6p3y36yjmeqqnttqfrpb2yttxa6aonoywxwdxl7nqym4jj3jwa", "bafkreifqztiwfutjik4wfs3gyfdyrff7cugi4mcctluunrrbp5cgareisq", "bafkreibffiehtv4ntajq5vjwpl7q44i6cjbg54lm5hkoa665ue2taspiyu", - "bafkreidcf5baqb5wevs6vyd7dtd3j7rzrq65uyqasj4dbkcy6na4ig3ay", + "bafkreidcf5baqb5wevs6vyd7dtd3j7rzrq65uyqasj4dbkcy5na4ig3ay", "bafkreiglyvpxwrxdvruit3oiw2lvkxqqxn7ojquw4gl7ck6szewz6t6cam"]; for(uint i; i < nfts.length; i++){ @@ -79,13 +93,39 @@ contract DCO2sTest is Test { // Test for token By Index 3 tokenID = dco2sc.tokenByIndex(3); assertEq(nfts[3], nfts[tokenID]); - - // Test tokenURI from by ID3 - string memory tokenURI = dco2sc.tokenURI(tokenID); - console.log(tokenURI); - assertEq(tokenURI, string.concat(baseURL,nfts[3])); } + // @notice use the basic Enumerable property TokenOfOwnerByIndex + function testEnumerableTokenOfOwnerByIndex() public { + string[5] memory nfts = [ + "bafkreibc6p3y36yjmeqqnttqfrpb2yttxa6aonoywxwdxl7nqym4jj3jwa", + "bafkreifqztiwfutjik4wfs3gyfdyrff7cugi4mcctluunrrbp5cgareisq", + "bafkreibffiehtv4ntajq5vjwpl7q44i6cjbg54lm5hkoa665ue2taspiyu", + "bafkreidcf5baqb5wevs6vyd7dtd3j7rzrq65uyqasj4dbkcy5na4ig3ay", + "bafkreiglyvpxwrxdvruit3oiw2lvkxqqxn7ojquw4gl7ck6szewz6t6cam"]; + + for(uint i; i < nfts.length; i++){ + if(i % 2 == 0) { + dco2sc.safeMint(address(1), nfts[i]); + } else { + dco2sc.safeMint(address(2), nfts[i]); + } + } + + // Get the balance of NFTs of the account 1 + uint account1_balance = dco2sc.balanceOf(address(1)); + assertEq(account1_balance, 3); + + for(uint i; i < account1_balance; i++){ + // get the TokenID from account NFTs Index + uint token_id = dco2sc.tokenOfOwnerByIndex(address(1), i); + // console.log("Token ID ", token_id, " has URI: ", dco2sc.tokenURI(token_id)); + assertEq(dco2sc.tokenURI(token_id), string.concat(baseURL, nfts[token_id])); + } + + } + + // @notice: testFailMintToZeroAddress test that cannot safe mint to address 0 function testFailMintToZeroAddress() public { dco2sc.safeMint(address(0),"bafkreibc6p3y36yjmeqqnttqfrpb2yttxa6aonoywxwdxl7nqym4jj3jwa");