test: add and change tests to fuzz test (#128)

This commit is contained in:
Felipe Mendes 2023-02-20 11:46:46 -03:00 committed by GitHub
parent 70e9c14b05
commit 197a7a28c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 70 additions and 37 deletions

View File

@ -17,22 +17,24 @@ contract Test_FleekERC721_Burn is Test_FleekERC721_Base {
CuT.burn(tokenId); CuT.burn(tokenId);
} }
function test_cannotBurnAsNotOwner() public { function testFuzz_cannotBurnAsNotOwner(address account) public {
vm.prank(address(1)); vm.assume(account != deployer);
vm.prank(account);
expectRevertWithTokenRole(); expectRevertWithTokenRole();
CuT.burn(tokenId); CuT.burn(tokenId);
} }
function test_cannotBurnAsController() public { function testFuzz_cannotBurnAsController(address account) public {
address user = address(1); vm.assume(account != deployer);
CuT.grantTokenRole(tokenId, FleekAccessControl.Roles.Controller, user); CuT.grantTokenRole(tokenId, FleekAccessControl.Roles.Controller, account);
vm.prank(user); vm.prank(account);
expectRevertWithTokenRole(); expectRevertWithTokenRole();
CuT.burn(tokenId); CuT.burn(tokenId);
} }
function test_cannotBurnInexistentToken() public { function testFuzz_cannotBurnInexistentToken(uint256 _tokenId) public {
vm.assume(_tokenId != tokenId);
expectRevertWithTokenRole(); // Token role is tested first before if token exists expectRevertWithTokenRole(); // Token role is tested first before if token exists
CuT.burn(1); CuT.burn(_tokenId);
} }
} }

View File

@ -21,4 +21,12 @@ contract Test_FleekERC721_Deploy is Test_FleekERC721_Base {
function test_deployerShouldBeCollectionOwner() public { function test_deployerShouldBeCollectionOwner() public {
assertTrue(CuT.hasCollectionRole(FleekAccessControl.Roles.Owner, deployer)); assertTrue(CuT.hasCollectionRole(FleekAccessControl.Roles.Owner, deployer));
} }
function testFuzz_nameAndSymbol(string memory _name, string memory _symbol) public {
CuT = new FleekERC721();
CuT.initialize(_name, _symbol);
assertEq(CuT.name(), _name);
assertEq(CuT.symbol(), _symbol);
}
} }

View File

@ -32,13 +32,22 @@ contract Test_FleekERC721_GetToken is Test_FleekERC721_Base {
assertEq(currentBuild, 0); assertEq(currentBuild, 0);
} }
function test_getTokenAfterUpdate() public { function testFuzz_getTokenAfterUpdate(
CuT.setTokenName(tokenId, "New App Name"); string memory newAppName,
CuT.setTokenDescription(tokenId, "New description for the app."); string memory newDescription,
CuT.setTokenExternalURL(tokenId, "https://new-url.com"); string memory newExternalURL,
CuT.setTokenENS(tokenId, "new-ens.eth"); string memory newENS,
CuT.setTokenBuild(tokenId, "ce1a3fc141e29f8e1d00a654e156c4982d7711bf", "https://github.com/other/repo"); string memory newCommitHash,
CuT.setTokenLogoAndColor(tokenId, TestConstants.LOGO_1, 0x654321); string memory newRepository,
string memory newLogo,
uint24 newColor
) public {
CuT.setTokenName(tokenId, newAppName);
CuT.setTokenDescription(tokenId, newDescription);
CuT.setTokenExternalURL(tokenId, newExternalURL);
CuT.setTokenENS(tokenId, newENS);
CuT.setTokenBuild(tokenId, newCommitHash, newRepository);
CuT.setTokenLogoAndColor(tokenId, newLogo, newColor);
( (
string memory name, string memory name,
@ -49,25 +58,23 @@ contract Test_FleekERC721_GetToken is Test_FleekERC721_Base {
string memory logo, string memory logo,
uint24 color uint24 color
) = CuT.getToken(tokenId); ) = CuT.getToken(tokenId);
assertEq(name, "New App Name"); assertEq(name, newAppName);
assertEq(description, "New description for the app."); assertEq(description, newDescription);
assertEq(externalURL, "https://new-url.com"); assertEq(externalURL, newExternalURL);
assertEq(logo, TestConstants.LOGO_1); assertEq(logo, newLogo);
assertEq(color, 0x654321); assertEq(color, newColor);
assertEq(ENS, "new-ens.eth"); assertEq(ENS, newENS);
assertEq(currentBuild, 1); assertEq(currentBuild, 1);
} }
function test_getTokenForDifferentAddresses() public { function testFuzz_getTokenForDifferentAddresses(address account) public {
vm.prank(address(1)); vm.prank(account);
CuT.getToken(tokenId);
vm.prank(address(2));
CuT.getToken(tokenId);
vm.prank(address(3));
CuT.getToken(tokenId); CuT.getToken(tokenId);
} }
function testFail_tokenURIForNonExistentId() public view { function testFuzz_tokenURIForNonExistentId(uint256 _tokenId) public {
CuT.getToken(1); vm.assume(_tokenId != tokenId);
expectRevertWithInvalidTokenId();
CuT.getToken(_tokenId);
} }
} }

View File

@ -49,4 +49,22 @@ contract Test_FleekERC721_Mint is Test_FleekERC721_Base {
assertEq(CuT.balanceOf(deployer), 1); assertEq(CuT.balanceOf(deployer), 1);
} }
function testFuzz_mint(
address to,
string memory appName,
string memory description,
string memory externalURL,
string memory ens,
string memory commitHash,
string memory gitRepository,
string memory logo,
uint24 color
) public {
vm.assume(to != address(0));
uint256 tokenId = CuT.mint(to, appName, description, externalURL, ens, commitHash, gitRepository, logo, color);
assertEq(tokenId, 0);
assertEq(CuT.ownerOf(tokenId), to);
}
} }

View File

@ -66,17 +66,15 @@ contract Test_FleekERC721_TokenURI is Test_FleekERC721_Base, Test_FleekERC721_To
); );
} }
function test_tokenURIForDifferentAddresses() public { function testFuzz_tokenURIForDifferentAddresses(address account) public {
vm.prank(address(1)); vm.prank(account);
CuT.tokenURI(tokenId);
vm.prank(address(2));
CuT.tokenURI(tokenId);
vm.prank(address(3));
CuT.tokenURI(tokenId); CuT.tokenURI(tokenId);
} }
function testFail_tokenURIForInexistentId() public view { function testFuzz_tokenURIForInexistentId(uint256 _tokenId) public {
CuT.tokenURI(1); vm.assume(_tokenId != tokenId);
expectRevertWithInvalidTokenId();
CuT.tokenURI(_tokenId);
} }
function test_shouldEmitEventForMetadataChanges() public { function test_shouldEmitEventForMetadataChanges() public {