From ce5ed772183fdc9ff3280dbdb6a5a5817c054de8 Mon Sep 17 00:00:00 2001 From: itzelot01 Date: Mon, 4 Dec 2023 23:26:25 +0000 Subject: [PATCH 1/8] Adding some ToDo tasks --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 3611e80..564f0dd 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,10 @@ URI Data structure: - [x] Smart Contract Creating ERC721 - [ ] Properties and registry of CCTokens (Research) - [ ] Basic ERC721 Test Script + - [ ] Add NFTs and IPFS Gateway from .env + - [x] Basic ERC721 tests + - [ ] Test enumerable + - [ ] Document .env Structure - [ ] Auction Contract ( Owner of ERC721 ) - [ ] Random GiveAway Function - [ ] Giveaway Function (testing) From 4745da5330784b524ceaf996b28871eac38bd671 Mon Sep 17 00:00:00 2001 From: itzelot01 Date: Mon, 4 Dec 2023 23:27:17 +0000 Subject: [PATCH 2/8] Add Printing the Deployed Contract Address --- script/DCO2s.s.sol | 1 + 1 file changed, 1 insertion(+) diff --git a/script/DCO2s.s.sol b/script/DCO2s.s.sol index 50eeda7..b42ed23 100644 --- a/script/DCO2s.s.sol +++ b/script/DCO2s.s.sol @@ -9,6 +9,7 @@ contract DCO2sScript is Script { function setUp() public { dco2sc = new DCO2s(0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266, 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266, "DCO2s", "DCO2"); + console.log("The DCO2s contract address is: {}", address(dco2sc)); } // run is the entry point From 368f029a7732b088cce7202a66c5664bab549923 Mon Sep 17 00:00:00 2001 From: itzelot01 Date: Mon, 4 Dec 2023 23:28:06 +0000 Subject: [PATCH 3/8] Test Enumerable first test --- test/DCO2s.t.sol | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/test/DCO2s.t.sol b/test/DCO2s.t.sol index cc2076b..9bc5638 100644 --- a/test/DCO2s.t.sol +++ b/test/DCO2s.t.sol @@ -6,9 +6,11 @@ import {DCO2s} from "../src/DCO2s.sol"; contract DCO2sTest is Test { DCO2s public dco2sc; + string public baseURL; function setUp() public { dco2sc = new DCO2s(address(this), address(this), "DCO2s", "DCO2"); + baseURL = "https://gateway.decentralizedscience.org/ipfs/"; } // @notice this code safe mints an NFT to address 0x1 @@ -18,14 +20,29 @@ contract DCO2sTest is Test { assertEq(dco2sc.ownerOf(0), to, "Token should be minted to specified address."); } + function testMintFromEnv() public { + address to = address(0x1); + string memory nft68 = vm.envString("NFT68"); + dco2sc.safeMint(to,nft68); + 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 tokenURI = dco2sc.tokenURI(0); + console.log(tokenURI); + assertEq(tokenURI, string.concat(baseURL, URI)); + } + // @notice: here we test getting the Base and full URIS function testGetURI() public { - string memory _baseURL = "https://gateway.decentralizedscience.org/ipfs/"; string memory URI = "bafkreibc6p3y36yjmeqqnttqfrpb2yttxa6aonoywxwdxl7nqym4jj3jwa"; dco2sc.safeMint(address(1), URI); string memory tokenURI = dco2sc.tokenURI(0); console.log(tokenURI); - assertEq(tokenURI, string.concat(_baseURL,URI)); + assertEq(tokenURI, string.concat(baseURL,URI)); } @@ -41,6 +58,33 @@ contract DCO2sTest is Test { // @notice use the basic Enumerable properties // function testEnumerable() public {} + function testEnumerableTokenByIndex() public { + string[5] memory nfts = [ + "bafkreibc6p3y36yjmeqqnttqfrpb2yttxa6aonoywxwdxl7nqym4jj3jwa", + "bafkreifqztiwfutjik4wfs3gyfdyrff7cugi4mcctluunrrbp5cgareisq", + "bafkreibffiehtv4ntajq5vjwpl7q44i6cjbg54lm5hkoa665ue2taspiyu", + "bafkreidcf5baqb5wevs6vyd7dtd3j7rzrq65uyqasj4dbkcy6na4ig3ay", + "bafkreiglyvpxwrxdvruit3oiw2lvkxqqxn7ojquw4gl7ck6szewz6t6cam"]; + + for(uint i; i < nfts.length; i++){ + dco2sc.safeMint(address(1), nfts[i]); + } + + assertEq(nfts.length, dco2sc.totalSupply()); + + // Test for token By Index 4 + uint tokenID = dco2sc.tokenByIndex(4); + assertEq(nfts[4], nfts[tokenID]); + + // 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: testFailMintToZeroAddress test that cannot safe mint to address 0 function testFailMintToZeroAddress() public { From e6fd2a58a86fa9b13fccb3fce5d44755a8b9a3c1 Mon Sep 17 00:00:00 2001 From: itzelot01 Date: Tue, 5 Dec 2023 22:43:18 +0000 Subject: [PATCH 4/8] Remove test code from foundry --- script/Counter.s.sol | 12 ------------ src/Counter.sol | 14 -------------- test/Counter.t.sol | 24 ------------------------ 3 files changed, 50 deletions(-) delete mode 100644 script/Counter.s.sol delete mode 100644 src/Counter.sol delete mode 100644 test/Counter.t.sol diff --git a/script/Counter.s.sol b/script/Counter.s.sol deleted file mode 100644 index 1a47b40..0000000 --- a/script/Counter.s.sol +++ /dev/null @@ -1,12 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.13; - -import {Script, console2} from "forge-std/Script.sol"; - -contract CounterScript is Script { - function setUp() public {} - - function run() public { - vm.broadcast(); - } -} diff --git a/src/Counter.sol b/src/Counter.sol deleted file mode 100644 index aded799..0000000 --- a/src/Counter.sol +++ /dev/null @@ -1,14 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.13; - -contract Counter { - uint256 public number; - - function setNumber(uint256 newNumber) public { - number = newNumber; - } - - function increment() public { - number++; - } -} diff --git a/test/Counter.t.sol b/test/Counter.t.sol deleted file mode 100644 index e9b9e6a..0000000 --- a/test/Counter.t.sol +++ /dev/null @@ -1,24 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.13; - -import {Test, console2} from "forge-std/Test.sol"; -import {Counter} from "../src/Counter.sol"; - -contract CounterTest is Test { - Counter public counter; - - function setUp() public { - counter = new Counter(); - counter.setNumber(0); - } - - function test_Increment() public { - counter.increment(); - assertEq(counter.number(), 1); - } - - function testFuzz_SetNumber(uint256 x) public { - counter.setNumber(x); - assertEq(counter.number(), x); - } -} From 73b3806f387aeb5f034deff213f5d0f63219400b Mon Sep 17 00:00:00 2001 From: itzelot01 Date: Tue, 5 Dec 2023 22:44:17 +0000 Subject: [PATCH 5/8] Use console 2 standard and remove typo --- script/DCO2s.s.sol | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/script/DCO2s.s.sol b/script/DCO2s.s.sol index b42ed23..97959ea 100644 --- a/script/DCO2s.s.sol +++ b/script/DCO2s.s.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.13; -import "forge-std/Script.sol"; +import {Script, console2} from "forge-std/Script.sol"; import { DCO2s } from "src/DCO2s.sol"; contract DCO2sScript is Script { @@ -9,7 +9,7 @@ contract DCO2sScript is Script { function setUp() public { dco2sc = new DCO2s(0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266, 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266, "DCO2s", "DCO2"); - console.log("The DCO2s contract address is: {}", address(dco2sc)); + console2.log("The DCO2s contract address is: ", address(dco2sc)); } // run is the entry point @@ -20,7 +20,7 @@ contract DCO2sScript is Script { string memory URI = "bafkreibc6p3y36yjmeqqnttqfrpb2yttxa6aonoywxwdxl7nqym4jj3jwa"; dco2sc.safeMint(0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266, URI); string memory tokenURI = dco2sc.tokenURI(0); - console.log(tokenURI); + console2.log("Token0 URI is:", tokenURI); vm.stopBroadcast(); } } From c5c3edaf0ef0e4cb6e364012ff85d9e3c092b4c5 Mon Sep 17 00:00:00 2001 From: itzelot01 Date: Tue, 5 Dec 2023 22:45:47 +0000 Subject: [PATCH 6/8] Add some Test and Env Sections --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 564f0dd..ec3659d 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,7 @@ URI Data structure: - [ ] Basic ERC721 Test Script - [ ] Add NFTs and IPFS Gateway from .env - [x] Basic ERC721 tests - - [ ] Test enumerable + - [x] Test enumerable - [ ] Document .env Structure - [ ] Auction Contract ( Owner of ERC721 ) - [ ] Random GiveAway Function From fb1d35663b71ab9165ade1a7bea8b45c74595b2b Mon Sep 17 00:00:00 2001 From: itzelot01 Date: Tue, 5 Dec 2023 22:48:07 +0000 Subject: [PATCH 7/8] 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"); From 9362939b70b92612bf331bfc2dd192d9d3073010 Mon Sep 17 00:00:00 2001 From: itzelot01 Date: Tue, 19 Dec 2023 23:37:05 +0000 Subject: [PATCH 8/8] set .env nftsURIs as parameters on constructor, baseURI in constructor of ERC721(DCO2s.sol) --- script/DCO2s.s.sol | 8 +- src/AA.sol | 61 ++++++++++- src/DCO2s.sol | 7 +- test/AA.t.sol | 35 ++++++ test/DCO2s.t.sol | 264 ++++++++++++++++++++++----------------------- 5 files changed, 236 insertions(+), 139 deletions(-) create mode 100644 test/AA.t.sol diff --git a/script/DCO2s.s.sol b/script/DCO2s.s.sol index 97959ea..ea028bc 100644 --- a/script/DCO2s.s.sol +++ b/script/DCO2s.s.sol @@ -6,9 +6,15 @@ import { DCO2s } from "src/DCO2s.sol"; contract DCO2sScript is Script { DCO2s public dco2sc; + string public baseURI; function setUp() public { - dco2sc = new DCO2s(0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266, 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266, "DCO2s", "DCO2"); + baseURI = "https://gateway.decentralizedscience.org/ipfs/"; + dco2sc = new DCO2s(0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266, + 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266, + baseURI, + "DCO2s", + "DCO2"); console2.log("The DCO2s contract address is: ", address(dco2sc)); } diff --git a/src/AA.sol b/src/AA.sol index 0b86cba..a014c52 100644 --- a/src/AA.sol +++ b/src/AA.sol @@ -6,10 +6,67 @@ import { DCO2s } from "./DCO2s.sol"; contract AA is Ownable { DCO2s public dco2sc; + string[] nfts; - constructor(string memory name, string memory symbol) Ownable(msg.sender) { - dco2sc = new DCO2s(address(this),address(this), name, symbol); + mapping (address => bool) public airdropped; + address[] public allowed; + + constructor(string memory name, + string memory symbol, + string memory baseURI, + string [] memory nftURIs + ) Ownable(msg.sender) { + dco2sc = new DCO2s(address(this),address(this), baseURI, name, symbol); + nfts = nftURIs; } + + // Auction Logic + // modifier to start and finish auction + // ToDo Check blockchain bid example + // function bid and lock tokens + // function cashback + + // Mint Function + // Simplify + function _mint(address to, string memory uri) public onlyOwner { + dco2sc.safeMint(to, uri); + } + + // @notice Random giveaway function + function airdrop() public { + //require(eligible(msg.sender)); + require(!airdropped[msg.sender], "address already airdropped"); + // top 20 is for Auction + uint256 randomURI = getRandomNumber() % nfts.length - 20; + dco2sc.safeMint(msg.sender, nfts[randomURI]); + // Require remove the URI so that is not mintable again + airdropped[msg.sender] = true; + + } + + // @eligible + function eligible(address to) public view returns (bool winner) { + // require( callable until specific date) + // Activity + // Longest Holders + // Top Holders + // or Allowed Wallets() + } + + // @notice allowed addresses that supports DECA + function allow(address supporter) public onlyOwner { + //require(eligible(supporter)); + require(!airdropped[supporter], "address already airdropped"); + allowed.push(supporter); + } + + + // @notice Returns a randon number calculated from previews block randao + // @dev This only works after the merge + function getRandomNumber() public view returns (uint randomNumber) { + randomNumber = block.prevrandao; + } + } diff --git a/src/DCO2s.sol b/src/DCO2s.sol index 2ba21d9..be7b5e3 100644 --- a/src/DCO2s.sol +++ b/src/DCO2s.sol @@ -10,18 +10,21 @@ import "@openzeppelin/contracts/access/AccessControl.sol"; contract DCO2s is ERC721, ERC721Enumerable, ERC721URIStorage, AccessControl { bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE"); uint256 private _nextTokenId; + string bURI; constructor( address defaultAdmin, address minter, + string memory baseURI, string memory name, string memory symbol) ERC721(name, symbol) { _grantRole(DEFAULT_ADMIN_ROLE, defaultAdmin); _grantRole(MINTER_ROLE, minter); + bURI = baseURI; } - function _baseURI() internal pure override returns (string memory) { - return "https://gateway.decentralizedscience.org/ipfs/"; + function _baseURI() internal view override returns (string memory) { + return bURI; } function safeMint(address to, string memory uri) public onlyRole(MINTER_ROLE) { diff --git a/test/AA.t.sol b/test/AA.t.sol new file mode 100644 index 0000000..5ed08c7 --- /dev/null +++ b/test/AA.t.sol @@ -0,0 +1,35 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.23; + +import {Test, console} from "forge-std/Test.sol"; +import {AA} from "../src/AA.sol"; +//import {nfts} from "../.env"; + +contract AATest is Test { + AA public aaContract; + string public baseURI; + string[] public nfts; + + function setUp() public { + baseURI = "https://gateway.decentralizedscience.org/ipfs/"; + // Import nfts array from .env and split by ' ' + nfts = vm.envString("nfts", ' '); + aaContract = new AA("DCO2s", "DCO2", baseURI, nfts); + } + + // @notice this code safe mints an NFT to address 0x1 + function testMint() public { + address to = address(0x1); + aaContract._mint(to,nfts[0]); + console.log("hola"); + //assertEq(aaContract.ownerOf(0), to, "Token should be minted to specified address."); + } + + // @notice: here we test getting the Base and full URIS + //function testGetURI68() public { + // aaContract._mint(address(0x1), nfts[68]); + // string memory tokenURI = aaContract.tokenURI(0); + // console.log(tokenURI); + // assertEq(tokenURI, string.concat(baseURI, nfts[68])); + //} +} diff --git a/test/DCO2s.t.sol b/test/DCO2s.t.sol index 2e138d8..97c63e5 100644 --- a/test/DCO2s.t.sol +++ b/test/DCO2s.t.sol @@ -3,52 +3,42 @@ pragma solidity ^0.8.23; import {Test, console} from "forge-std/Test.sol"; import {DCO2s} from "../src/DCO2s.sol"; +//import {nfts} from "../.env"; contract DCO2sTest is Test { DCO2s public dco2sc; - string public baseURL; + string public baseURI; + string[] public nfts; function setUp() public { - dco2sc = new DCO2s(address(this), address(this), "DCO2s", "DCO2"); - baseURL = "https://gateway.decentralizedscience.org/ipfs/"; + baseURI = "https://gateway.decentralizedscience.org/ipfs/"; + dco2sc = new DCO2s(address(this), address(this), baseURI, "DCO2s", "DCO2"); + // Import nfts array from .env and split by ' ' + nfts = vm.envString("nfts", ' '); } // @notice this code safe mints an NFT to address 0x1 function testMint() public { address to = address(0x1); - dco2sc.safeMint(to,"bafkreibc6p3y36yjmeqqnttqfrpb2yttxa6aonoywxwdxl7nqym4jj3jwa"); - assertEq(dco2sc.ownerOf(0), to, "Token should be minted to specified address."); - } - - function testMintFromEnv() public { - address to = address(0x1); - string memory nft0 = vm.envString("nfts"); - dco2sc.safeMint(to,nft0); + dco2sc.safeMint(to,nfts[0]); 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 URIs = vm.envString("nfts", ' '); - dco2sc.safeMint(address(1), URIs[68]); + dco2sc.safeMint(address(0x1), nfts[68]); string memory tokenURI = dco2sc.tokenURI(0); //console.log(tokenURI); - assertEq(tokenURI, string.concat(baseURL, URIs[68])); + assertEq(tokenURI, string.concat(baseURI, nfts[68])); } - // @notice: here we test getting the Base and full URIS - function testGetURI() public { - string memory URI = "bafkreibc6p3y36yjmeqqnttqfrpb2yttxa6aonoywxwdxl7nqym4jj3jwa"; - dco2sc.safeMint(address(1), URI); - string memory tokenURI = dco2sc.tokenURI(0); - //console.log(tokenURI); - assertEq(tokenURI, string.concat(baseURL,URI)); - } // @notice: checkFailed token Index function testFailTokenIndex() view public { dco2sc.tokenURI(0); } + + // Todo How to verify bytes message error // @notice: checkFailed token Index //function testTokenIndex() public { // vm.expectRevert(bytes("ERC721NonexistentToken(0)")); @@ -56,59 +46,59 @@ contract DCO2sTest is Test { //} // @notice use basic Enumerable properties totalSupply + // Find a more efficient way mintedNFTs = nfts[:5];? function testEnumerableTotalSupply() public { - string[5] memory nfts = [ - "bafkreibc6p3y36yjmeqqnttqfrpb2yttxa6aonoywxwdxl7nqym4jj3jwa", - "bafkreifqztiwfutjik4wfs3gyfdyrff7cugi4mcctluunrrbp5cgareisq", - "bafkreibffiehtv4ntajq5vjwpl7q44i6cjbg54lm5hkoa665ue2taspiyu", - "bafkreidcf5baqb5wevs6vyd7dtd3j7rzrq65uyqasj4dbkcy5na4ig3ay", - "bafkreiglyvpxwrxdvruit3oiw2lvkxqqxn7ojquw4gl7ck6szewz6t6cam"]; + string[5] memory mintedNFTs; - for(uint i; i < nfts.length; i++){ - dco2sc.safeMint(address(1), nfts[i]); - } + for(uint i = 0; i < 5; i++){ + mintedNFTs[i] = nfts[i]; + } - assertEq(nfts.length, dco2sc.totalSupply()); + // mint 5 nfts + for(uint i = 0; i < mintedNFTs.length; i++){ + dco2sc.safeMint(address(1), mintedNFTs[i]); + } + + assertEq(mintedNFTs.length, dco2sc.totalSupply()); + } // @notice use the basic Enumerable property tokenByIndex function testEnumerableTokenByIndex() public { - string[5] memory nfts = [ - "bafkreibc6p3y36yjmeqqnttqfrpb2yttxa6aonoywxwdxl7nqym4jj3jwa", - "bafkreifqztiwfutjik4wfs3gyfdyrff7cugi4mcctluunrrbp5cgareisq", - "bafkreibffiehtv4ntajq5vjwpl7q44i6cjbg54lm5hkoa665ue2taspiyu", - "bafkreidcf5baqb5wevs6vyd7dtd3j7rzrq65uyqasj4dbkcy5na4ig3ay", - "bafkreiglyvpxwrxdvruit3oiw2lvkxqqxn7ojquw4gl7ck6szewz6t6cam"]; + string[5] memory nftsSlice; - for(uint i; i < nfts.length; i++){ - dco2sc.safeMint(address(1), nfts[i]); + for(uint i = 0; i < 5; i++){ + nftsSlice[i] = nfts[i]; } - assertEq(nfts.length, dco2sc.totalSupply()); + for(uint i; i < nftsSlice.length; i++){ + dco2sc.safeMint(address(1), nftsSlice[i]); + } + + assertEq(nftsSlice.length, dco2sc.totalSupply()); // Test for token By Index 4 uint tokenID = dco2sc.tokenByIndex(4); - assertEq(nfts[4], nfts[tokenID]); + assertEq(nftsSlice[4], nftsSlice[tokenID]); // Test for token By Index 3 tokenID = dco2sc.tokenByIndex(3); - assertEq(nfts[3], nfts[tokenID]); + assertEq(nftsSlice[3], nftsSlice[tokenID]); } // @notice use the basic Enumerable property TokenOfOwnerByIndex function testEnumerableTokenOfOwnerByIndex() public { - string[5] memory nfts = [ - "bafkreibc6p3y36yjmeqqnttqfrpb2yttxa6aonoywxwdxl7nqym4jj3jwa", - "bafkreifqztiwfutjik4wfs3gyfdyrff7cugi4mcctluunrrbp5cgareisq", - "bafkreibffiehtv4ntajq5vjwpl7q44i6cjbg54lm5hkoa665ue2taspiyu", - "bafkreidcf5baqb5wevs6vyd7dtd3j7rzrq65uyqasj4dbkcy5na4ig3ay", - "bafkreiglyvpxwrxdvruit3oiw2lvkxqqxn7ojquw4gl7ck6szewz6t6cam"]; + string[5] memory nftsSlice; - for(uint i; i < nfts.length; i++){ + for(uint i = 0; i < 5; i++){ + nftsSlice[i] = nfts[i]; + } + + for(uint i; i < nftsSlice.length; i++){ if(i % 2 == 0) { - dco2sc.safeMint(address(1), nfts[i]); + dco2sc.safeMint(address(1), nftsSlice[i]); } else { - dco2sc.safeMint(address(2), nfts[i]); + dco2sc.safeMint(address(2), nftsSlice[i]); } } @@ -120,7 +110,7 @@ contract DCO2sTest is Test { // 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])); + assertEq(dco2sc.tokenURI(token_id), string.concat(baseURI, nftsSlice[token_id])); } } @@ -128,90 +118,96 @@ contract DCO2sTest is Test { // @notice: testFailMintToZeroAddress test that cannot safe mint to address 0 function testFailMintToZeroAddress() public { - dco2sc.safeMint(address(0),"bafkreibc6p3y36yjmeqqnttqfrpb2yttxa6aonoywxwdxl7nqym4jj3jwa"); + dco2sc.safeMint(address(0), nfts[0]); } - // @notice testMintAll mints all the NFTs URIS and distribute to wallets - // then it assertEq that it is properly minted to the wallet and the correct URI - // function testMintAll() public { - // string[68] memory NFts = ["bafkreibc6p3y36yjmeqqnttqfrpb2yttxa6aonoywxwdxl7nqym4jj3jwa", - // "bafkreidcf5baqb5wevs6avyd7dtd3j7rzrq65uyqasj4dbkcy6na4ig3ay", - // "bafkreibffiehtv4ntajq5vjwpl7q44i6cjbg54lm5hkoa665ue2taspiyu", - // "bafkreifqztiwfutjik4wfs3gyfdyrff7cugi4mcctluunrrbp5cgareisq", - // "bafkreiglyvpxwrxdvruit3oiw2lvkxqqxn7ojquw4gl7ck6szewz6t6cam", - // "bafkreiakd4xtuw3toe4wnez2ndmdadqv3oszaoffoha4tw2hqr3sjnsmge", - // "bafkreigx2isd63yflf6toeg7nfqw33hf6vvllcxfnzn7ymd7u4okflivbi", - // "bafkreidrsjlcajbz35crgs6dpog6ophcochrgrrqgejxfye4m6lbw5mdde", - // "bafkreihwi7xoak3p3mmofdln4pc4wqkkbdwyyz2yxbpfvpzvvxa2ogbaxi", - // "bafkreiclhcy3n5iq3ka2jwxhvedpdewonwoujgu77y7rgnkddheioemcsi", - // "bafkreic3vdshhst65qtzkwfbqzfpmuqbsyizxguarixobrp3scwaiq5jre", - // "bafkreifv5xyis2kuveyfoc662zxeol2zdyiue4h3sznosef7ihrsmjexwm", - // "bafkreifqyk6255h2ppobog33fzifsosbcnn2tanqi3ezjcwis6gya4sfoi", - // "bafkreigend4j42oanbjxltwuyizmufdhqbngf6fbe5hgnlxs3yhzgpvay4", - // "bafkreiextgvmtg23rx3lq2s6psebqln6ojlgosc544jch72baq3yt3dryu", - // "bafkreihlkfwt5ntpnwf3c37d4lsf4y6czxojyffqet5ujvzw374x7ainoi", - // "bafkreievuhvdru7p3lxht3of67xdri6urrrsjxr2e6rzulwg2574ye3dji", - // "bafkreidqa6xuekp34iu7cqmngdbe7knzia47s7gwn3zczr5vwso57nrtx4", - // "bafkreiglo5jhcem4ogswylqi37bx2wmn65cy6blwbwxcvuzklpfr6vhmke", - // "bafkreibz353bqq76gjvswt7eebyffi3nkke5bzrvsjzem3is6x4ptpnqvi", - // "bafkreif2dohcblqea4t4z5qjfxtdzz6vmtxs4325yuf6jz6e2sdxf366ni", - // "bafkreib265gzsjgprktabq4c3glrdl5noebegibwupchwuwbswohum3ap4", - // "bafkreicfaqdpgnrnebvqxyvg7s7eqgipbw5bg3hdticvghcpivjmvjx364", - // "bafkreiabmontlvf2ah3vngpaf3cmg5ejinyqe6yl5pcl4lfrtvduwnuqcq", - // "bafkreidvyf5txqmcizexdexdaqsbr4fxclcpfn6npgkngm6rclaszjll4q", - // "bafkreib4wysvkug2bbzfpuey7hazqkezqtstv2n3yzccw7z77n2urcb6ye", - // "bafkreiailtryy3cg7anain2evahiaox6babpxd4dp4kl67jqeoabh6ndwi", - // "bafkreid32knw3kptbognoamqxcu5a2r3hzlzcb5a4tbouzfob5j2hhww6y", - // "bafkreifprm74saobjxnang72smgtrevwvsxyps46kbc6ehhk3veqqpprte", - // "bafkreif6wbrqmlqihivdasweh5opjjixinupsqfqmyflo2he3tdibx26mq", - // "bafkreig75yruw2hkfqdfhmjm7lfenojvgv6emxfgkwolajhnjsokcc3vv4", - // "bafkreihxvojrjrzigupwtncsrwsswju4cwh2sz5z2evqt6qlgcd7siptqi", - // "bafkreifmcjsvyou6ml6khq7d7iglchh4a4clqvzf7t4ky6sxyoml6ixvj4", - // "bafkreieyrrsp4lgoqqfrynp64cdif2jrnnzwc3lv4j5wlm4glszhjltp24", - // "bafkreicpw7ytfbzakmg23wkuhrpumcdtoh75po7j6fu627vru3hgl6kpay", - // "bafkreifrdsfw2vazhleexjkcd6f6t73aqvrobq5nwyeqa2rmykqtsef2o4", - // "bafkreicdmr2bet7omb3u5zrgvubq2nxwbzlo6kqkjy6swey4u5yavqsf3y", - // "bafkreihupkyebtf3rybziatp7p242gbyza7rf7s6noj3wun6fwd2sr6qhq", - // "bafkreibrlybbkiiutohvwj3q6j3drs7llaxliz7dhiflipq34e4guzcbhu", - // "bafkreieuseajoxy4ouo2u2upxz7lssoivcb63r64ada6n6pbxtupwnp6fa", - // "bafkreid53wwrea4erd5hm7gjgkgpp6oddjqnctffewf3nay2grs2nhmh5y", - // "bafkreigzrzugp7aqn6u6yqyaeu7v5lou4ldvkc5gfstr3p3otaf4afg56y", - // "bafkreibqdmemeh57bkszki7oypxelqlihuy26eaeoi664epsqr5543q3je", - // "bafkreiga4wd7vxjn46eovsktpmg2ugrd545sckdu2ibytvyjmj44rxjo5a", - // "bafkreibef52rjpwrhfoaewbb4x7w5nthexsxzanoh5g7l3wzikubw6t4j4", - // "bafkreihbkxbmbxk5xcujr3vwoo3qnnkubqmrkytjml76f2be4rfdi3kwiy", - // "bafkreibh5fgjwuzcnyrpdcyxzpcjndrppeelgrjccfq2s7jg52dvcmk4cy", - // "bafkreiea7k7u6kq76a4zysht5ri62jabvbuf6uk2emptxua2lkfmpleqqu", - // "bafkreibietep53mtdq5kpk442x5djcaiwkirgltemomaaa6in6j375agfe", - // "bafkreifwho3vue5x3yus3bcl2vs46b2ehgnhokmk4363dyptcqkcjuwtwm", - // "bafkreicb662izefhwuvv7u6yh4rav76od4r4nkm6h7mgkflb77bt5wkimm", - // "bafkreihlls4pkcjtjaasxmvctafrslucawm5lrffz5ho57azdaiapo2evq", - // "bafkreih4ncyemyptx3nxe5qvxn6keiv7m36avhg5t2z6uvohs22he6q5zi", - // "bafkreibxx4deq65og67be3oliqz2u4j6tacczarf74lbusbblflnp3c46a", - // "bafkreibyegb4yn3yzxsnq5rggwra2x4nnd4eojvzdtxnl6lixq4f7cbdmm", - // "bafkreiaygw7455yt6siqsqjs5bfhrrbxa5ezlktcwdnyeqikuq66irm5me", - // "bafkreiaqj7xiukqacs6genv7s5bewucuag3d2lnn6kwqmkcnsngtrn2p5i", - // "bafkreigm4czjurpcdgqapwj3ilzg7o3qx6wiyfd74hitm5hklyxbx52ujy", - // "bafkreifgtz7hpaeuendeah37ny363ppx3klctkycol665lk65nkolvtj7q", - // "bafkreicje4abjqh52oz35ble2yvasjkxemsptjnvla73greqzz5jwfkhiu", - // "bafkreiebelxzjwxdvyvvj6cmqcn6cdnetrfxnw4bf4zaqkbh4myvu3a6qu", - // "bafkreibg5fatnupr4u66zp5xabgyav65aik3bwv7ms73xjig37qz7ffura", - // "bafkreigkgv36pc4gc35vlm7axlrtvbpwxl54pnq6mjovvre7n6vsqyfrp4", - // "bafkreiekiefyw55qxsoqvbv2zbrjhbvrybo5qsamhsvk6rst4kzxmrxioq", - // "bafkreifv2zmtj54mezqqbdfcc6z2anexctcumvs64abo2cvqgo47d6qk4q", - // "bafkreibjlhludpjooxikum7cjw7c6rczgwbekaiusjm4xu5nyodwr3zjnm", - // "bafkreib5z3fllsfv32fjhgvkao3csi4r2dhsegji52aqmfp4x2s6qb7734", - // "bafkreiajnquwgsapxpesee4yyjz3hbwkopbr5pkpydbhjo4iwcpxolzrfy"]; + // // @notice testMintAll mints all the NFTs URIS and distribute to wallets + // // then it assertEq that it is properly minted to the wallet and the correct URI + // function testMintAll() public { + // string[68] memory mintedNFTs; - // for ( uint i; i < NFts.length; i++) { - // dco2sc.safeMint(address(i+1), NFts[i]); - // } - // // assert that each NFT gets minted with the proper URI - // // and addrress - // for ( uint i; i < NFts.length; i++) { - // assertEq(NFTs[i], dco2sc.) - // } - // } + // for(uint i = 0; i < 68; i++){ + // mintedNFTs[i] = nfts[i]; + // } + // //= ["bafkreibc6p3y36yjmeqqnttqfrpb2yttxa6aonoywxwdxl7nqym4jj3jwa", + // // "bafkreidcf5baqb5wevs6avyd7dtd3j7rzrq65uyqasj4dbkcy6na4ig3ay", + // // "bafkreibffiehtv4ntajq5vjwpl7q44i6cjbg54lm5hkoa665ue2taspiyu", + // // "bafkreifqztiwfutjik4wfs3gyfdyrff7cugi4mcctluunrrbp5cgareisq", + // // "bafkreiglyvpxwrxdvruit3oiw2lvkxqqxn7ojquw4gl7ck6szewz6t6cam", + // // "bafkreiakd4xtuw3toe4wnez2ndmdadqv3oszaoffoha4tw2hqr3sjnsmge", + // // "bafkreigx2isd63yflf6toeg7nfqw33hf6vvllcxfnzn7ymd7u4okflivbi", + // // "bafkreidrsjlcajbz35crgs6dpog6ophcochrgrrqgejxfye4m6lbw5mdde", + // // "bafkreihwi7xoak3p3mmofdln4pc4wqkkbdwyyz2yxbpfvpzvvxa2ogbaxi", + // // "bafkreiclhcy3n5iq3ka2jwxhvedpdewonwoujgu77y7rgnkddheioemcsi", + // // "bafkreic3vdshhst65qtzkwfbqzfpmuqbsyizxguarixobrp3scwaiq5jre", + // // "bafkreifv5xyis2kuveyfoc662zxeol2zdyiue4h3sznosef7ihrsmjexwm", + // // "bafkreifqyk6255h2ppobog33fzifsosbcnn2tanqi3ezjcwis6gya4sfoi", + // // "bafkreigend4j42oanbjxltwuyizmufdhqbngf6fbe5hgnlxs3yhzgpvay4", + // // "bafkreiextgvmtg23rx3lq2s6psebqln6ojlgosc544jch72baq3yt3dryu", + // // "bafkreihlkfwt5ntpnwf3c37d4lsf4y6czxojyffqet5ujvzw374x7ainoi", + // // "bafkreievuhvdru7p3lxht3of67xdri6urrrsjxr2e6rzulwg2574ye3dji", + // // "bafkreidqa6xuekp34iu7cqmngdbe7knzia47s7gwn3zczr5vwso57nrtx4", + // // "bafkreiglo5jhcem4ogswylqi37bx2wmn65cy6blwbwxcvuzklpfr6vhmke", + // // "bafkreibz353bqq76gjvswt7eebyffi3nkke5bzrvsjzem3is6x4ptpnqvi", + // // "bafkreif2dohcblqea4t4z5qjfxtdzz6vmtxs4325yuf6jz6e2sdxf366ni", + // // "bafkreib265gzsjgprktabq4c3glrdl5noebegibwupchwuwbswohum3ap4", + // // "bafkreicfaqdpgnrnebvqxyvg7s7eqgipbw5bg3hdticvghcpivjmvjx364", + // // "bafkreiabmontlvf2ah3vngpaf3cmg5ejinyqe6yl5pcl4lfrtvduwnuqcq", + // // "bafkreidvyf5txqmcizexdexdaqsbr4fxclcpfn6npgkngm6rclaszjll4q", + // // "bafkreib4wysvkug2bbzfpuey7hazqkezqtstv2n3yzccw7z77n2urcb6ye", + // // "bafkreiailtryy3cg7anain2evahiaox6babpxd4dp4kl67jqeoabh6ndwi", + // // "bafkreid32knw3kptbognoamqxcu5a2r3hzlzcb5a4tbouzfob5j2hhww6y", + // // "bafkreifprm74saobjxnang72smgtrevwvsxyps46kbc6ehhk3veqqpprte", + // // "bafkreif6wbrqmlqihivdasweh5opjjixinupsqfqmyflo2he3tdibx26mq", + // // "bafkreig75yruw2hkfqdfhmjm7lfenojvgv6emxfgkwolajhnjsokcc3vv4", + // // "bafkreihxvojrjrzigupwtncsrwsswju4cwh2sz5z2evqt6qlgcd7siptqi", + // // "bafkreifmcjsvyou6ml6khq7d7iglchh4a4clqvzf7t4ky6sxyoml6ixvj4", + // // "bafkreieyrrsp4lgoqqfrynp64cdif2jrnnzwc3lv4j5wlm4glszhjltp24", + // // "bafkreicpw7ytfbzakmg23wkuhrpumcdtoh75po7j6fu627vru3hgl6kpay", + // // "bafkreifrdsfw2vazhleexjkcd6f6t73aqvrobq5nwyeqa2rmykqtsef2o4", + // // "bafkreicdmr2bet7omb3u5zrgvubq2nxwbzlo6kqkjy6swey4u5yavqsf3y", + // // "bafkreihupkyebtf3rybziatp7p242gbyza7rf7s6noj3wun6fwd2sr6qhq", + // // "bafkreibrlybbkiiutohvwj3q6j3drs7llaxliz7dhiflipq34e4guzcbhu", + // // "bafkreieuseajoxy4ouo2u2upxz7lssoivcb63r64ada6n6pbxtupwnp6fa", + // // "bafkreid53wwrea4erd5hm7gjgkgpp6oddjqnctffewf3nay2grs2nhmh5y", + // // "bafkreigzrzugp7aqn6u6yqyaeu7v5lou4ldvkc5gfstr3p3otaf4afg56y", + // // "bafkreibqdmemeh57bkszki7oypxelqlihuy26eaeoi664epsqr5543q3je", + // // "bafkreiga4wd7vxjn46eovsktpmg2ugrd545sckdu2ibytvyjmj44rxjo5a", + // // "bafkreibef52rjpwrhfoaewbb4x7w5nthexsxzanoh5g7l3wzikubw6t4j4", + // // "bafkreihbkxbmbxk5xcujr3vwoo3qnnkubqmrkytjml76f2be4rfdi3kwiy", + // // "bafkreibh5fgjwuzcnyrpdcyxzpcjndrppeelgrjccfq2s7jg52dvcmk4cy", + // // "bafkreiea7k7u6kq76a4zysht5ri62jabvbuf6uk2emptxua2lkfmpleqqu", + // // "bafkreibietep53mtdq5kpk442x5djcaiwkirgltemomaaa6in6j375agfe", + // // "bafkreifwho3vue5x3yus3bcl2vs46b2ehgnhokmk4363dyptcqkcjuwtwm", + // // "bafkreicb662izefhwuvv7u6yh4rav76od4r4nkm6h7mgkflb77bt5wkimm", + // // "bafkreihlls4pkcjtjaasxmvctafrslucawm5lrffz5ho57azdaiapo2evq", + // // "bafkreih4ncyemyptx3nxe5qvxn6keiv7m36avhg5t2z6uvohs22he6q5zi", + // // "bafkreibxx4deq65og67be3oliqz2u4j6tacczarf74lbusbblflnp3c46a", + // // "bafkreibyegb4yn3yzxsnq5rggwra2x4nnd4eojvzdtxnl6lixq4f7cbdmm", + // // "bafkreiaygw7455yt6siqsqjs5bfhrrbxa5ezlktcwdnyeqikuq66irm5me", + // // "bafkreiaqj7xiukqacs6genv7s5bewucuag3d2lnn6kwqmkcnsngtrn2p5i", + // // "bafkreigm4czjurpcdgqapwj3ilzg7o3qx6wiyfd74hitm5hklyxbx52ujy", + // // "bafkreifgtz7hpaeuendeah37ny363ppx3klctkycol665lk65nkolvtj7q", + // // "bafkreicje4abjqh52oz35ble2yvasjkxemsptjnvla73greqzz5jwfkhiu", + // // "bafkreiebelxzjwxdvyvvj6cmqcn6cdnetrfxnw4bf4zaqkbh4myvu3a6qu", + // // "bafkreibg5fatnupr4u66zp5xabgyav65aik3bwv7ms73xjig37qz7ffura", + // // "bafkreigkgv36pc4gc35vlm7axlrtvbpwxl54pnq6mjovvre7n6vsqyfrp4", + // // "bafkreiekiefyw55qxsoqvbv2zbrjhbvrybo5qsamhsvk6rst4kzxmrxioq", + // // "bafkreifv2zmtj54mezqqbdfcc6z2anexctcumvs64abo2cvqgo47d6qk4q", + // // "bafkreibjlhludpjooxikum7cjw7c6rczgwbekaiusjm4xu5nyodwr3zjnm", + // // "bafkreib5z3fllsfv32fjhgvkao3csi4r2dhsegji52aqmfp4x2s6qb7734", + // // "bafkreiajnquwgsapxpesee4yyjz3hbwkopbr5pkpydbhjo4iwcpxolzrfy"]; + // //assign to 68 addresses + + // for ( uint i = 0; i < mintedNFTs.length; i++) { + // dco2sc.safeMint(address(this), mintedNFTs[i]); + // } + // // assert that each NFT gets minted with the proper URI + // // and addrress + // for ( uint i; i < mintedNFTs.length; i++) { + // assertEq(mintedNFTs[i], dco2sc.tokenURI(token_id)); + // } + // } }