2023-11-21 22:45:27 +00:00
|
|
|
// SPDX-License-Identifier: UNLICENSED
|
|
|
|
pragma solidity ^0.8.23;
|
|
|
|
|
2023-11-30 06:48:48 +00:00
|
|
|
import {Test, console} from "forge-std/Test.sol";
|
2023-11-21 22:45:27 +00:00
|
|
|
import {DCO2s} from "../src/DCO2s.sol";
|
|
|
|
|
|
|
|
contract DCO2sTest is Test {
|
|
|
|
DCO2s public dco2sc;
|
2024-04-25 02:10:02 +00:00
|
|
|
string public name;
|
2024-04-25 00:21:13 +00:00
|
|
|
string public symbol;
|
2023-12-19 23:37:05 +00:00
|
|
|
string public baseURI;
|
|
|
|
string[] public nfts;
|
2023-11-21 22:45:27 +00:00
|
|
|
|
|
|
|
function setUp() public {
|
2024-04-25 00:21:13 +00:00
|
|
|
baseURI = vm.envString("BASE_URI");
|
|
|
|
name = vm.envString("NAME");
|
|
|
|
symbol = vm.envString("SYMBOL");
|
|
|
|
dco2sc = new DCO2s(address(this), address(this), baseURI, name, symbol);
|
2023-12-19 23:37:05 +00:00
|
|
|
// Import nfts array from .env and split by ' '
|
2024-04-25 02:10:02 +00:00
|
|
|
nfts = vm.envString("nfts", " ");
|
2023-11-21 22:45:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// @notice this code safe mints an NFT to address 0x1
|
|
|
|
function testMint() public {
|
|
|
|
address to = address(0x1);
|
2024-04-25 02:10:02 +00:00
|
|
|
dco2sc.safeMint(to, nfts[0]);
|
2023-12-04 23:28:06 +00:00
|
|
|
assertEq(dco2sc.ownerOf(0), to, "Token should be minted to specified address.");
|
|
|
|
}
|
|
|
|
|
|
|
|
// @notice: here we test getting the Base and full URIS
|
2024-04-25 00:21:13 +00:00
|
|
|
function testGetURI15() public {
|
|
|
|
dco2sc.safeMint(address(0x1), nfts[15]);
|
2023-12-04 23:28:06 +00:00
|
|
|
string memory tokenURI = dco2sc.tokenURI(0);
|
2023-12-05 22:48:07 +00:00
|
|
|
//console.log(tokenURI);
|
2024-04-25 00:21:13 +00:00
|
|
|
assertEq(tokenURI, string.concat(baseURI, nfts[15]));
|
2023-12-04 23:28:06 +00:00
|
|
|
}
|
|
|
|
|
2023-11-30 06:48:48 +00:00
|
|
|
// @notice: checkFailed token Index
|
2024-04-25 02:10:02 +00:00
|
|
|
function testFailTokenIndex() public view {
|
2023-11-30 06:48:48 +00:00
|
|
|
dco2sc.tokenURI(0);
|
|
|
|
}
|
2023-12-19 23:37:05 +00:00
|
|
|
|
|
|
|
// Todo How to verify bytes message error
|
2023-11-30 06:48:48 +00:00
|
|
|
// @notice: checkFailed token Index
|
|
|
|
//function testTokenIndex() public {
|
|
|
|
// vm.expectRevert(bytes("ERC721NonexistentToken(0)"));
|
|
|
|
// dco2sc.tokenURI(0);
|
|
|
|
//}
|
2023-11-21 22:45:27 +00:00
|
|
|
|
2023-12-05 22:48:07 +00:00
|
|
|
// @notice use basic Enumerable properties totalSupply
|
2023-12-19 23:37:05 +00:00
|
|
|
// Find a more efficient way mintedNFTs = nfts[:5];?
|
2023-12-05 22:48:07 +00:00
|
|
|
function testEnumerableTotalSupply() public {
|
2023-12-19 23:37:05 +00:00
|
|
|
string[5] memory mintedNFTs;
|
2023-12-05 22:48:07 +00:00
|
|
|
|
2024-04-25 02:10:02 +00:00
|
|
|
for (uint256 i = 0; i < 5; i++) {
|
2023-12-19 23:37:05 +00:00
|
|
|
mintedNFTs[i] = nfts[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
// mint 5 nfts
|
2024-04-25 02:10:02 +00:00
|
|
|
for (uint256 i = 0; i < mintedNFTs.length; i++) {
|
2023-12-19 23:37:05 +00:00
|
|
|
dco2sc.safeMint(address(1), mintedNFTs[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
assertEq(mintedNFTs.length, dco2sc.totalSupply());
|
2023-12-05 22:48:07 +00:00
|
|
|
}
|
|
|
|
|
2024-04-25 00:21:13 +00:00
|
|
|
// @notice: use the basic Enumerable property tokenByIndex
|
|
|
|
// @notice: All nfts in the .env
|
2023-12-04 23:28:06 +00:00
|
|
|
function testEnumerableTokenByIndex() public {
|
2024-04-25 02:10:02 +00:00
|
|
|
for (uint256 i; i < nfts.length; i++) {
|
2024-04-25 00:21:13 +00:00
|
|
|
dco2sc.safeMint(address(1), nfts[i]);
|
2023-12-19 23:37:05 +00:00
|
|
|
}
|
|
|
|
|
2024-04-25 00:21:13 +00:00
|
|
|
assertEq(nfts.length, dco2sc.totalSupply());
|
2023-12-04 23:28:06 +00:00
|
|
|
|
|
|
|
// Test for token By Index 4
|
2024-04-25 02:10:02 +00:00
|
|
|
uint256 tokenID = dco2sc.tokenByIndex(4);
|
2024-04-25 00:21:13 +00:00
|
|
|
assertEq(nfts[4], nfts[tokenID]);
|
2023-12-04 23:28:06 +00:00
|
|
|
|
|
|
|
// Test for token By Index 3
|
|
|
|
tokenID = dco2sc.tokenByIndex(3);
|
2024-04-25 00:21:13 +00:00
|
|
|
assertEq(nfts[3], nfts[tokenID]);
|
2023-12-05 22:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// @notice use the basic Enumerable property TokenOfOwnerByIndex
|
2024-04-25 00:21:13 +00:00
|
|
|
// @notice: All nfts in the .env
|
2023-12-05 22:48:07 +00:00
|
|
|
function testEnumerableTokenOfOwnerByIndex() public {
|
2024-04-25 00:21:13 +00:00
|
|
|
// mints pair to address 1
|
2024-04-25 02:10:02 +00:00
|
|
|
for (uint256 i; i < nfts.length; i++) {
|
|
|
|
if (i % 2 == 0) {
|
2024-04-25 00:21:13 +00:00
|
|
|
dco2sc.safeMint(address(1), nfts[i]);
|
2023-12-05 22:48:07 +00:00
|
|
|
} else {
|
2024-04-25 00:21:13 +00:00
|
|
|
dco2sc.safeMint(address(2), nfts[i]);
|
2023-12-05 22:48:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-25 00:21:13 +00:00
|
|
|
// Get the balance of NFTs of the account 1 pairs are 8
|
2024-04-25 02:10:02 +00:00
|
|
|
uint256 account1_balance = dco2sc.balanceOf(address(1));
|
2024-04-25 00:21:13 +00:00
|
|
|
assertEq(account1_balance, 8);
|
2023-12-05 22:48:07 +00:00
|
|
|
|
2024-04-25 02:10:02 +00:00
|
|
|
for (uint256 i; i < account1_balance; i++) {
|
2023-12-05 22:48:07 +00:00
|
|
|
// get the TokenID from account NFTs Index
|
2024-04-25 02:10:02 +00:00
|
|
|
uint256 token_id = dco2sc.tokenOfOwnerByIndex(address(1), i);
|
2024-04-25 00:21:13 +00:00
|
|
|
assertEq(dco2sc.tokenURI(token_id), string.concat(baseURI, nfts[token_id]));
|
2023-12-05 22:48:07 +00:00
|
|
|
}
|
2023-12-04 23:28:06 +00:00
|
|
|
}
|
2023-11-21 22:45:27 +00:00
|
|
|
|
|
|
|
// @notice: testFailMintToZeroAddress test that cannot safe mint to address 0
|
|
|
|
function testFailMintToZeroAddress() public {
|
2023-12-19 23:37:05 +00:00
|
|
|
dco2sc.safeMint(address(0), nfts[0]);
|
2023-11-21 22:45:27 +00:00
|
|
|
}
|
|
|
|
|
2024-04-25 02:10:02 +00:00
|
|
|
// @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 {
|
|
|
|
//assign to nfts.lenght addresses each one 1 NFT
|
|
|
|
for (uint256 i; i < nfts.length; i++) {
|
|
|
|
dco2sc.safeMint(address(uint160(i + 1)), nfts[i]);
|
2024-04-25 00:21:13 +00:00
|
|
|
}
|
|
|
|
// assert that each NFT gets minted with the proper URI
|
|
|
|
// and address
|
2024-04-25 02:10:02 +00:00
|
|
|
for (uint256 i; i < nfts.length; i++) {
|
|
|
|
uint256 token_id = dco2sc.tokenOfOwnerByIndex(address(uint160(i + 1)), 0);
|
2024-04-25 00:21:13 +00:00
|
|
|
assertEq(string.concat(baseURI, nfts[i]), dco2sc.tokenURI(token_id));
|
|
|
|
}
|
|
|
|
}
|
2023-11-21 22:45:27 +00:00
|
|
|
}
|