test: improve foundry test with best practices (#102)

* test: add FleekERC721 test base mint and uri

* chore: update forge-std version

* test: add FleekERC721 burn tests

* test: fix role getter

* test: add access tests for random address

* test: add access tests for owner address

* test: add test revert assertions

* test: apply revert assertions

* test: remove already split tests

* fix: wrong renamed file

* test: move access point tests

* test: refactor access control tests

* test: add deploy test cases

* test: add balance before and after mint test

* test: remove old testsuit

* chore: update foundry test folder strcture

* test: add assertion to verify added role for random address

* test: fix test functions names

* test: remove test_addAccessPoint

* test: add assertion for appAccessPoints length

* test: remove unnecessary assertions on test_tokenURI

* test: rename test files

* test: refactor testFail to test
This commit is contained in:
Felipe Mendes 2023-02-08 17:27:39 -03:00 committed by GitHub
parent 33ebac510c
commit 3e1373682f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 814 additions and 1089 deletions

View File

@ -5,7 +5,7 @@
"private": "false",
"scripts": {
"test": "hardhat test && forge test --via-ir",
"test:foundry": "forge test --via-ir",
"test:foundry": "forge test --via-ir -vvv",
"test:hardhat": "hardhat test",
"format": "prettier --write \"./**/*.{js,json,sol,ts}\"",
"node:hardhat": "hardhat node",

View File

@ -0,0 +1,428 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
import "./TestBase.sol";
import {FleekAccessControl} from "contracts/FleekAccessControl.sol";
contract Test_FleekERC721_AccessControl is Test_FleekERC721_Base {
uint256 internal tokenId;
address internal collectionOwner = address(1);
address internal collectionController = address(2);
address internal tokenOwner = address(3);
address internal tokenController = address(4);
address internal anyAddress = address(5);
function setUp() public {
baseSetUp();
// Set collectionOwner
CuT.grantCollectionRole(FleekAccessControl.Roles.Owner, collectionOwner);
// Set collectionController
CuT.grantCollectionRole(FleekAccessControl.Roles.Controller, collectionController);
// Mint to tokenOwner to set tokenOwner
mintDefault(tokenOwner);
// Set tokenController to minted token
vm.prank(tokenOwner);
CuT.grantTokenRole(tokenId, FleekAccessControl.Roles.Controller, tokenController);
}
function test_setUp() public {
// Check collectionOwner
assertTrue(CuT.hasCollectionRole(FleekAccessControl.Roles.Owner, collectionOwner));
assertFalse(CuT.hasCollectionRole(FleekAccessControl.Roles.Controller, collectionOwner));
assertFalse(CuT.hasTokenRole(tokenId, FleekAccessControl.Roles.Owner, collectionOwner));
assertFalse(CuT.hasTokenRole(tokenId, FleekAccessControl.Roles.Controller, collectionOwner));
// Check collectionController
assertFalse(CuT.hasCollectionRole(FleekAccessControl.Roles.Owner, collectionController));
assertTrue(CuT.hasCollectionRole(FleekAccessControl.Roles.Controller, collectionController));
assertFalse(CuT.hasTokenRole(tokenId, FleekAccessControl.Roles.Owner, collectionController));
assertFalse(CuT.hasTokenRole(tokenId, FleekAccessControl.Roles.Controller, collectionController));
// Check tokenOwner
assertFalse(CuT.hasCollectionRole(FleekAccessControl.Roles.Owner, tokenOwner));
assertFalse(CuT.hasCollectionRole(FleekAccessControl.Roles.Controller, tokenOwner));
assertTrue(CuT.hasTokenRole(tokenId, FleekAccessControl.Roles.Owner, tokenOwner));
assertFalse(CuT.hasTokenRole(tokenId, FleekAccessControl.Roles.Controller, tokenOwner));
// Check tokenController
assertFalse(CuT.hasCollectionRole(FleekAccessControl.Roles.Owner, tokenController));
assertFalse(CuT.hasCollectionRole(FleekAccessControl.Roles.Controller, tokenController));
assertFalse(CuT.hasTokenRole(tokenId, FleekAccessControl.Roles.Owner, tokenController));
assertTrue(CuT.hasTokenRole(tokenId, FleekAccessControl.Roles.Controller, tokenController));
// Check anyAddress
assertFalse(CuT.hasCollectionRole(FleekAccessControl.Roles.Owner, anyAddress));
assertFalse(CuT.hasCollectionRole(FleekAccessControl.Roles.Controller, anyAddress));
assertFalse(CuT.hasTokenRole(tokenId, FleekAccessControl.Roles.Owner, anyAddress));
assertFalse(CuT.hasTokenRole(tokenId, FleekAccessControl.Roles.Controller, anyAddress));
}
function test_grantAndRevokeCollectionRole() public {
address randomAddress = address(99);
// CollectionOwner
vm.startPrank(collectionOwner);
CuT.grantCollectionRole(FleekAccessControl.Roles.Controller, randomAddress);
assertTrue(CuT.hasCollectionRole(FleekAccessControl.Roles.Controller, randomAddress));
CuT.revokeCollectionRole(FleekAccessControl.Roles.Controller, randomAddress);
assertFalse(CuT.hasCollectionRole(FleekAccessControl.Roles.Controller, randomAddress));
vm.stopPrank();
// CollectionController
vm.startPrank(collectionController);
expectRevertWithCollectionRole();
CuT.grantCollectionRole(FleekAccessControl.Roles.Controller, randomAddress);
expectRevertWithCollectionRole();
CuT.revokeCollectionRole(FleekAccessControl.Roles.Controller, randomAddress);
vm.stopPrank();
// TokenOwner
vm.startPrank(tokenOwner);
expectRevertWithCollectionRole();
CuT.grantCollectionRole(FleekAccessControl.Roles.Controller, randomAddress);
expectRevertWithCollectionRole();
CuT.revokeCollectionRole(FleekAccessControl.Roles.Controller, randomAddress);
vm.stopPrank();
// TokenController
vm.startPrank(tokenController);
expectRevertWithCollectionRole();
CuT.grantCollectionRole(FleekAccessControl.Roles.Controller, randomAddress);
expectRevertWithCollectionRole();
CuT.revokeCollectionRole(FleekAccessControl.Roles.Controller, randomAddress);
vm.stopPrank();
// AnyAddress
vm.startPrank(anyAddress);
expectRevertWithCollectionRole();
CuT.grantCollectionRole(FleekAccessControl.Roles.Controller, randomAddress);
expectRevertWithCollectionRole();
CuT.revokeCollectionRole(FleekAccessControl.Roles.Controller, randomAddress);
vm.stopPrank();
}
function test_grantAndRevokeTokenRole() public {
address randomAddress = address(99);
// CollectionOwner
vm.startPrank(collectionOwner);
expectRevertWithTokenRole();
CuT.grantTokenRole(tokenId, FleekAccessControl.Roles.Controller, randomAddress);
expectRevertWithTokenRole();
CuT.revokeTokenRole(tokenId, FleekAccessControl.Roles.Controller, randomAddress);
vm.stopPrank();
// CollectionController
vm.startPrank(collectionController);
expectRevertWithTokenRole();
CuT.grantTokenRole(tokenId, FleekAccessControl.Roles.Controller, randomAddress);
expectRevertWithTokenRole();
CuT.revokeTokenRole(tokenId, FleekAccessControl.Roles.Controller, randomAddress);
vm.stopPrank();
// TokenOwner
vm.startPrank(tokenOwner);
CuT.grantTokenRole(tokenId, FleekAccessControl.Roles.Controller, randomAddress);
assertTrue(CuT.hasTokenRole(tokenId, FleekAccessControl.Roles.Controller, randomAddress));
CuT.revokeTokenRole(tokenId, FleekAccessControl.Roles.Controller, randomAddress);
assertFalse(CuT.hasTokenRole(tokenId, FleekAccessControl.Roles.Controller, randomAddress));
vm.stopPrank();
// TokenController
vm.startPrank(tokenController);
expectRevertWithTokenRole();
CuT.grantTokenRole(tokenId, FleekAccessControl.Roles.Controller, randomAddress);
expectRevertWithTokenRole();
CuT.revokeTokenRole(tokenId, FleekAccessControl.Roles.Controller, randomAddress);
vm.stopPrank();
// AnyAddress
vm.startPrank(anyAddress);
expectRevertWithTokenRole();
CuT.grantTokenRole(tokenId, FleekAccessControl.Roles.Controller, randomAddress);
expectRevertWithTokenRole();
CuT.revokeTokenRole(tokenId, FleekAccessControl.Roles.Controller, randomAddress);
vm.stopPrank();
}
function test_mint() public {
address randomAddress = address(99);
// CollectionOwner
vm.startPrank(collectionOwner);
mintDefault(randomAddress);
vm.stopPrank();
// CollectionController
vm.startPrank(collectionController);
expectRevertWithCollectionRole();
mintDefault(randomAddress);
vm.stopPrank();
// TokenOwner
vm.startPrank(tokenOwner);
expectRevertWithCollectionRole();
mintDefault(randomAddress);
vm.stopPrank();
// TokenController
vm.startPrank(tokenController);
expectRevertWithCollectionRole();
mintDefault(randomAddress);
vm.stopPrank();
// AnyAddress
vm.startPrank(anyAddress);
expectRevertWithCollectionRole();
mintDefault(randomAddress);
vm.stopPrank();
}
function test_tokenURI() public {
// Anyone can get the tokenURI
vm.prank(anyAddress);
CuT.tokenURI(tokenId);
}
function test_setTokenExternalURL() public {
string memory externalURL = "https://externalurl.com";
// ColletionOwner
vm.prank(collectionOwner);
expectRevertWithTokenRole();
CuT.setTokenExternalURL(tokenId, externalURL);
// CollectionController
vm.prank(collectionController);
expectRevertWithTokenRole();
CuT.setTokenExternalURL(tokenId, externalURL);
// TokenOwner
vm.prank(tokenOwner);
CuT.setTokenExternalURL(tokenId, externalURL);
// TokenController
vm.prank(tokenController);
CuT.setTokenExternalURL(tokenId, externalURL);
// AnyAddress
vm.prank(anyAddress);
expectRevertWithTokenRole();
CuT.setTokenExternalURL(tokenId, externalURL);
}
function test_setTokenENS() public {
string memory ens = "ens";
// ColletionOwner
vm.prank(collectionOwner);
expectRevertWithTokenRole();
CuT.setTokenENS(tokenId, ens);
// CollectionController
vm.prank(collectionController);
expectRevertWithTokenRole();
CuT.setTokenENS(tokenId, ens);
// TokenOwner
vm.prank(tokenOwner);
CuT.setTokenENS(tokenId, ens);
// TokenController
vm.prank(tokenController);
CuT.setTokenENS(tokenId, ens);
// AnyAddress
vm.prank(anyAddress);
expectRevertWithTokenRole();
CuT.setTokenENS(tokenId, ens);
}
function test_setTokenName() public {
string memory name = "name";
// ColletionOwner
vm.prank(collectionOwner);
expectRevertWithTokenRole();
CuT.setTokenName(tokenId, name);
// CollectionController
vm.prank(collectionController);
expectRevertWithTokenRole();
CuT.setTokenName(tokenId, name);
// TokenOwner
vm.prank(tokenOwner);
CuT.setTokenName(tokenId, name);
// TokenController
vm.prank(tokenController);
CuT.setTokenName(tokenId, name);
// AnyAddress
vm.prank(anyAddress);
expectRevertWithTokenRole();
CuT.setTokenName(tokenId, name);
}
function test_setTokenDescription() public {
string memory description = "description";
// ColletionOwner
vm.prank(collectionOwner);
expectRevertWithTokenRole();
CuT.setTokenDescription(tokenId, description);
// CollectionController
vm.prank(collectionController);
expectRevertWithTokenRole();
CuT.setTokenDescription(tokenId, description);
// TokenOwner
vm.prank(tokenOwner);
CuT.setTokenDescription(tokenId, description);
// TokenController
vm.prank(tokenController);
CuT.setTokenDescription(tokenId, description);
// AnyAddress
vm.prank(anyAddress);
expectRevertWithTokenRole();
CuT.setTokenDescription(tokenId, description);
}
function test_setTokenLogo() public {
string memory logo = "logo";
// ColletionOwner
vm.prank(collectionOwner);
expectRevertWithTokenRole();
CuT.setTokenLogo(tokenId, logo);
// CollectionController
vm.prank(collectionController);
expectRevertWithTokenRole();
CuT.setTokenLogo(tokenId, logo);
// TokenOwner
vm.prank(tokenOwner);
CuT.setTokenLogo(tokenId, logo);
// TokenController
vm.prank(tokenController);
CuT.setTokenLogo(tokenId, logo);
// AnyAddress
vm.prank(anyAddress);
expectRevertWithTokenRole();
CuT.setTokenLogo(tokenId, logo);
}
function test_setTokenColor() public {
uint24 color = 0x000000;
// ColletionOwner
vm.prank(collectionOwner);
expectRevertWithTokenRole();
CuT.setTokenColor(tokenId, color);
// CollectionController
vm.prank(collectionController);
expectRevertWithTokenRole();
CuT.setTokenColor(tokenId, color);
// TokenOwner
vm.prank(tokenOwner);
CuT.setTokenColor(tokenId, color);
// TokenController
vm.prank(tokenController);
CuT.setTokenColor(tokenId, color);
// AnyAddress
vm.prank(anyAddress);
expectRevertWithTokenRole();
CuT.setTokenColor(tokenId, color);
}
function test_setTokenLogoAndColor() public {
string memory logo = "logo";
uint24 color = 0x000000;
// ColletionOwner
vm.prank(collectionOwner);
expectRevertWithTokenRole();
CuT.setTokenLogoAndColor(tokenId, logo, color);
// CollectionController
vm.prank(collectionController);
expectRevertWithTokenRole();
CuT.setTokenLogoAndColor(tokenId, logo, color);
// TokenOwner
vm.prank(tokenOwner);
CuT.setTokenLogoAndColor(tokenId, logo, color);
// TokenController
vm.prank(tokenController);
CuT.setTokenLogoAndColor(tokenId, logo, color);
// AnyAddress
vm.prank(anyAddress);
expectRevertWithTokenRole();
CuT.setTokenLogoAndColor(tokenId, logo, color);
}
function test_setTokenBuild() public {
string memory commitHash = "commitHash";
string memory gitRepository = "gitRepository";
// ColletionOwner
vm.prank(collectionOwner);
expectRevertWithTokenRole();
CuT.setTokenBuild(tokenId, commitHash, gitRepository);
// CollectionController
vm.prank(collectionController);
expectRevertWithTokenRole();
CuT.setTokenBuild(tokenId, commitHash, gitRepository);
// TokenOwner
vm.prank(tokenOwner);
CuT.setTokenBuild(tokenId, commitHash, gitRepository);
// TokenController
vm.prank(tokenController);
CuT.setTokenBuild(tokenId, commitHash, gitRepository);
// AnyAddress
vm.prank(anyAddress);
expectRevertWithTokenRole();
CuT.setTokenBuild(tokenId, commitHash, gitRepository);
}
function test_testBurn() public {
// ColletionOwner
vm.prank(collectionOwner);
expectRevertWithTokenRole();
CuT.burn(tokenId);
// CollectionController
vm.prank(collectionController);
expectRevertWithTokenRole();
CuT.burn(tokenId);
// TokenController
vm.prank(tokenController);
expectRevertWithTokenRole();
CuT.burn(tokenId);
// AnyAddress
vm.prank(anyAddress);
expectRevertWithTokenRole();
CuT.burn(tokenId);
// TokenOwner
vm.prank(tokenOwner);
CuT.burn(tokenId);
}
}

View File

@ -0,0 +1,139 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
import "./TestBase.sol";
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
import {FleekAccessControl} from "contracts/FleekAccessControl.sol";
contract Test_FleekERC721_AccessPoint is Test_FleekERC721_Base {
using Strings for address;
uint256 internal tokenId;
function assertAccessPointJSON(
string memory accessPointName,
string memory _tokenId,
string memory score,
string memory nameVerified,
string memory contentVerified,
address owner
) internal {
string memory current = CuT.getAccessPointJSON(accessPointName);
// prettier-ignore
string memory expectedJSON = string(abi.encodePacked('{"tokenId":', _tokenId, ',"score":', score, ',"nameVerified":', nameVerified, ',"contentVerified":', contentVerified, ',"owner":"', owner.toHexString(), '"}'));
assertEq(current, expectedJSON);
}
function setUp() public {
baseSetUp();
tokenId = mintDefault(deployer);
}
function test_getAccessPointJSON() public {
string memory accessPointName = "accesspoint.com";
CuT.addAccessPoint(tokenId, accessPointName);
assertAccessPointJSON(accessPointName, "0", "0", "false", "false", deployer);
}
function test_removeAccessPoint() public {
string memory accessPointName = "accesspoint.com";
CuT.addAccessPoint(tokenId, accessPointName);
CuT.removeAccessPoint(accessPointName);
expectRevertWithInvalidAP();
CuT.getAccessPointJSON(accessPointName);
}
function test_cannotRemoveNonexistentAccessPoint() public {
expectRevertWithInvalidAP();
CuT.removeAccessPoint("accesspoint.com");
}
function test_cannotTwiceRemoveAccessPoint() public {
string memory accessPointName = "accesspoint.com";
CuT.addAccessPoint(tokenId, accessPointName);
CuT.removeAccessPoint(accessPointName);
expectRevertWithInvalidAP();
CuT.removeAccessPoint(accessPointName);
}
function test_isAccessPointNameVerified() public {
string memory accessPointName = "accesspoint.com";
CuT.addAccessPoint(tokenId, accessPointName);
assertFalse(CuT.isAccessPointNameVerified(accessPointName));
CuT.setAccessPointNameVerify(accessPointName, true);
}
function test_increaseAccessPointScore() public {
string memory accessPointName = "accesspoint.com";
CuT.addAccessPoint(tokenId, accessPointName);
assertAccessPointJSON(accessPointName, "0", "0", "false", "false", deployer);
CuT.increaseAccessPointScore(accessPointName);
assertAccessPointJSON(accessPointName, "0", "1", "false", "false", deployer);
CuT.increaseAccessPointScore(accessPointName);
assertAccessPointJSON(accessPointName, "0", "2", "false", "false", deployer);
}
function test_cannotDecreaseAccessPointScoreToMinusOne() public {
string memory accessPointName = "accesspoint.com";
CuT.addAccessPoint(tokenId, accessPointName);
assertAccessPointJSON(accessPointName, "0", "0", "false", "false", deployer);
expectRevertWithMinimalScore();
CuT.decreaseAccessPointScore(accessPointName);
}
function test_decreaseAccessPointScore() public {
string memory accessPointName = "accesspoint.com";
CuT.addAccessPoint(tokenId, accessPointName);
assertAccessPointJSON(accessPointName, "0", "0", "false", "false", deployer);
CuT.increaseAccessPointScore(accessPointName);
assertAccessPointJSON(accessPointName, "0", "1", "false", "false", deployer);
CuT.decreaseAccessPointScore(accessPointName);
assertAccessPointJSON(accessPointName, "0", "0", "false", "false", deployer);
}
function test_appAccessPoints() public {
CuT.addAccessPoint(tokenId, "accesspoint1.com");
CuT.addAccessPoint(tokenId, "accesspoint2.com");
CuT.addAccessPoint(tokenId, "accesspoint3.com");
string[] memory accessPoints = CuT.appAccessPoints(tokenId);
assertEq(accessPoints[0], "accesspoint1.com");
assertEq(accessPoints[1], "accesspoint2.com");
assertEq(accessPoints[2], "accesspoint3.com");
assertEq(accessPoints.length, 3);
}
function test_cannotAddAccessPointToNonexistentToken() public {
expectRevertWithInvalidTokenId();
CuT.addAccessPoint(1, "accesspoint.com");
}
function test_setAccessPointVerifiesWithCorrectRole() public {
string memory accessPointName = "accesspoint.com";
address randomAddress = address(12);
CuT.addAccessPoint(tokenId, accessPointName);
vm.startPrank(randomAddress);
expectRevertWithTokenRole();
CuT.setAccessPointNameVerify(accessPointName, true);
expectRevertWithTokenRole();
CuT.setAccessPointContentVerify(accessPointName, true);
vm.stopPrank();
CuT.grantTokenRole(tokenId, FleekAccessControl.Roles.Controller, randomAddress);
vm.startPrank(randomAddress);
CuT.setAccessPointNameVerify(accessPointName, true);
CuT.setAccessPointContentVerify(accessPointName, true);
vm.stopPrank();
assertAccessPointJSON(accessPointName, "0", "0", "true", "true", deployer);
}
}

View File

@ -0,0 +1,38 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
import "./TestBase.sol";
import {FleekAccessControl} from "contracts/FleekAccessControl.sol";
contract Test_FleekERC721_Burn is Test_FleekERC721_Base {
uint256 internal tokenId;
function setUp() public {
baseSetUp();
tokenId = mintDefault(deployer);
}
function test_burn() public {
CuT.burn(tokenId);
}
function test_cannotBurnAsNotOwner() public {
vm.prank(address(1));
expectRevertWithTokenRole();
CuT.burn(tokenId);
}
function test_cannotBurnAsController() public {
address user = address(1);
CuT.grantTokenRole(tokenId, FleekAccessControl.Roles.Controller, user);
vm.prank(user);
expectRevertWithTokenRole();
CuT.burn(tokenId);
}
function test_cannotBurnInexistentToken() public {
expectRevertWithTokenRole(); // Token role is tested first before if token exists
CuT.burn(1);
}
}

View File

@ -1,4 +1,22 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
library TestConstants {
string public constant APP_NAME = "Foundry Test App";
string public constant APP_DESCRIPTION = "This is a test application submitted by foundry tests.";
string public constant APP_EXTERNAL_URL = "https://foundry.test";
string public constant APP_ENS = "foundry.eth";
string public constant APP_COMMIT_HASH = "afff3f6";
string public constant APP_GIT_REPOSITORY = "https://github.com/fleekxyz/non-fungible-apps";
uint24 public constant APP_COLOR = 0x123456;
string public constant LOGO_0 =
"data:image/svg+xml;base64,PHN2ZyBmaWxsPSJub25lIiBoZWlnaHQ9IjI1MDAiIHdpZHRoPSIyMTgzIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMjQgMTQxLjUzMTk5OTk5OTk5OTk4Ij48cGF0aCBkPSJNMTAuMzgzIDEyNi44OTRMMCAwbDEyNCAuMjU1LTEwLjk3OSAxMjYuNjM5LTUwLjU1MyAxNC42Mzh6IiBmaWxsPSIjZTM0ZjI2Ii8+PHBhdGggZD0iTTYyLjQ2OCAxMjkuMjc3VjEyLjA4NWw1MS4wNjQuMTctOS4xMDYgMTA0Ljg1MXoiIGZpbGw9IiNlZjY1MmEiLz48cGF0aCBkPSJNOTkuNDkgNDEuMzYybDEuNDQ2LTE1LjQ5SDIyLjM4M2w0LjM0IDQ3LjQ5aDU0LjIxM0w3OC44MSA5My42MTdsLTE3LjM2MiA0LjY4LTE3LjYxNy01LjEwNi0uOTM2LTEyLjA4NUgyNy4zMTlsMi4xMjggMjQuNjgxIDMyIDguOTM2IDMyLjI1NS04LjkzNiA0LjM0LTQ4LjE3SDQxLjEwN0wzOS40OSA0MS4zNjJ6IiBmaWxsPSIjZmZmIi8+PC9zdmc+";

View File

@ -0,0 +1,24 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
import "./TestBase.sol";
import {FleekAccessControl} from "contracts/FleekAccessControl.sol";
contract Test_FleekERC721_Deploy is Test_FleekERC721_Base {
function setUp() public {
baseSetUp();
}
function test_name() public {
assertEq(CuT.name(), "Test Contract");
}
function test_symbol() public {
assertEq(CuT.symbol(), "FLKAPS");
}
function test_deployerShouldBeCollectionOwner() public {
assertTrue(CuT.hasCollectionRole(FleekAccessControl.Roles.Owner, deployer));
}
}

View File

@ -0,0 +1,52 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
import "./TestBase.sol";
contract Test_FleekERC721_Mint is Test_FleekERC721_Base {
function setUp() public {
baseSetUp();
}
function test_mint() public {
uint256 mint = mintDefault(deployer);
assertEq(mint, 0);
assertEq(CuT.ownerOf(mint), deployer);
}
function test_mintingMintedToken() public {
uint256 firstMint = mintDefault(deployer);
uint256 secondMint = mintDefault(deployer);
assertEq(firstMint, 0);
assertEq(secondMint, 1);
}
function test_mintTwoTokensForTwoAddresses() public {
uint256 firstMint = mintDefault(deployer);
uint256 secondMint = CuT.mint(
address(12),
"Different App Name",
"This is a different description for another app.",
"https://fleek.xyz",
"fleek.eth",
"94e8ba38568aea4fb277a37a4c472d94a6ce880a",
"https://github.com/a-different/repository",
TestConstants.LOGO_1,
0x654321
);
assertEq(firstMint, 0);
assertEq(secondMint, 1);
}
function test_balanceOfDeployerAfterAndBeforeMinting() public {
assertEq(CuT.balanceOf(deployer), 0);
mintDefault(deployer);
assertEq(CuT.balanceOf(deployer), 1);
}
}

View File

@ -0,0 +1,64 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
import "forge-std/Test.sol";
import {FleekERC721} from "contracts/FleekERC721.sol";
import {TestConstants} from "./Constants.sol";
abstract contract Test_FleekERC721_Assertions is Test {
function expectRevertWithTokenRole() public {
vm.expectRevert("FleekAccessControl: must have token role");
}
function expectRevertWithCollectionRole() public {
vm.expectRevert("FleekAccessControl: must have collection role");
}
function expectRevertWithAPAlreadyExists() public {
vm.expectRevert("FleekERC721: AP already exists");
}
function expectRevertWithMustBeAPOwner() public {
vm.expectRevert("FleekERC721: must be AP owner");
}
function expectRevertWithInvalidAP() public {
vm.expectRevert("FleekERC721: invalid AP");
}
function expectRevertWithMinimalScore() public {
vm.expectRevert("FleekERC721: score cant be lower");
}
function expectRevertWithInvalidTokenId() public {
vm.expectRevert("ERC721: invalid token ID");
}
}
abstract contract Test_FleekERC721_Base is Test, Test_FleekERC721_Assertions {
FleekERC721 internal CuT; // Contract Under Test
address internal deployer;
function baseSetUp() internal {
CuT = new FleekERC721();
CuT.initialize("Test Contract", "FLKAPS");
deployer = address(this);
}
function mintDefault(address to) internal returns (uint256) {
uint256 mint = CuT.mint(
to,
TestConstants.APP_NAME,
TestConstants.APP_DESCRIPTION,
TestConstants.APP_EXTERNAL_URL,
TestConstants.APP_ENS,
TestConstants.APP_COMMIT_HASH,
TestConstants.APP_GIT_REPOSITORY,
TestConstants.LOGO_0,
TestConstants.APP_COLOR
);
return mint;
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long