add more foundry tests for edge cases

This commit is contained in:
EmperorOrokuSaki 2022-12-08 01:31:39 +03:30
parent a0adff1702
commit e828ae9f63
3 changed files with 343 additions and 9 deletions

4
.gitignore vendored
View File

@ -9,5 +9,5 @@ artifacts
package-lock.json package-lock.json
# Foundry # Foundry
./out out
./forge-cache forge-cache

3
test/foundry/README.md Normal file
View File

@ -0,0 +1,3 @@
# Foundry Tests
This directory contains the code for all Foundry Forge Solidity tests of the FleekERC721 contract.

View File

@ -18,10 +18,6 @@ contract FleekTest is Test {
assertEq(fleekContract.symbol(), 'FLKAPS'); assertEq(fleekContract.symbol(), 'FLKAPS');
} }
function test() public {
assertEq(fleekContract.symbol(), 'FLKAPS');
}
function testMint() public { function testMint() public {
uint256 mint = fleekContract.mint( uint256 mint = fleekContract.mint(
DEPLOYER, DEPLOYER,
@ -140,7 +136,7 @@ contract FleekTest is Test {
'{', '{',
'"name":"Foundry Test App",', '"name":"Foundry Test App",',
'"description":"This is a test application submitted by foundry tests.",', '"description":"This is a test application submitted by foundry tests.",',
'"owner":"DEPLOYER",', '"owner":"',Strings.toHexString(uint160(DEPLOYER), 20),'",',
'"external_url":"https://fleek.xyz",', '"external_url":"https://fleek.xyz",',
'"image":"https://fleek.xyz",', '"image":"https://fleek.xyz",',
'"attributes": [', '"attributes": [',
@ -155,12 +151,98 @@ contract FleekTest is Test {
assertEq(tokenURI, string(abi.encodePacked("data:application/json;base64,", Base64.encode((dataURI))))); assertEq(tokenURI, string(abi.encodePacked("data:application/json;base64,", Base64.encode((dataURI)))));
} }
function testCallingTokenURIAfterChangingAllPossibleFields() public {
uint256 mint = fleekContract.mint(
DEPLOYER,
'Foundry Test App',
'This is a test application submitted by foundry tests.',
'https://fleek.xyz',
'https://fleek.xyz',
'fleek_xyz',
'afff3f6',
'https://github.com/fleekxyz/contracts'
);
assertEq(mint, 0);
fleekContract.setTokenName(mint, 'Foundry Test App 2');
fleekContract.setTokenDescription(mint, 'This is a test application submitted by foundry tests. 2');
fleekContract.setTokenImage(mint, 'https://fleek2.xyz');
fleekContract.setTokenExternalURL(mint, 'https://fleek2.xyz');
fleekContract.setTokenENS(mint, 'fleek_xyz2');
fleekContract.setTokenBuild(mint, 'afff3f62', 'https://github.com/fleekxyz/contracts2');
string memory tokenURI = fleekContract.tokenURI(mint);
bytes memory dataURI = abi.encodePacked(
'{',
'"name":"Foundry Test App 2",',
'"description":"This is a test application submitted by foundry tests. 2",',
'"owner":"',Strings.toHexString(uint160(DEPLOYER), 20),'",',
'"external_url":"https://fleek2.xyz",',
'"image":"https://fleek2.xyz",',
'"attributes": [',
'{"trait_type": "ENS", "value":"fleek_xyz2"},',
'{"trait_type": "Commit Hash", "value":"afff3f62"},',
'{"trait_type": "Repository", "value":"https://github.com/fleekxyz/contracts2"},',
'{"trait_type": "Version", "value":"1"}',
']',
'}'
);
assertEq(tokenURI, string(abi.encodePacked("data:application/json;base64,", Base64.encode((dataURI)))));
}
function testFailChangingAllPossibleFieldsOnAnotherUsersTokenWithoutAccess() public {
uint256 mint = fleekContract.mint(
DEPLOYER,
'Foundry Test App',
'This is a test application submitted by foundry tests.',
'https://fleek.xyz',
'https://fleek.xyz',
'fleek_xyz',
'afff3f6',
'https://github.com/fleekxyz/contracts'
);
assertEq(mint, 0);
vm.prank(address(0xb4c79daB8f259C7Aee6E5b2Aa729821864227e84));
fleekContract.setTokenName(mint, 'Foundry Test App 2');
fleekContract.setTokenDescription(mint, 'This is a test application submitted by foundry tests. 2');
fleekContract.setTokenImage(mint, 'https://fleek2.xyz');
fleekContract.setTokenExternalURL(mint, 'https://fleek2.xyz');
fleekContract.setTokenENS(mint, 'fleek_xyz2');
fleekContract.setTokenBuild(mint, 'afff3f62', 'https://github.com/fleekxyz/contracts2');
string memory tokenURI = fleekContract.tokenURI(mint);
bytes memory dataURI = abi.encodePacked(
'{',
'"name":"Foundry Test App 2",',
'"description":"This is a test application submitted by foundry tests. 2",',
'"owner":"',Strings.toHexString(uint160(DEPLOYER), 20),'",',
'"external_url":"https://fleek2.xyz",',
'"image":"https://fleek2.xyz",',
'"attributes": [',
'{"trait_type": "ENS", "value":"fleek_xyz2"},',
'{"trait_type": "Commit Hash", "value":"afff3f62"},',
'{"trait_type": "Repository", "value":"https://github.com/fleekxyz/contracts2"},',
'{"trait_type": "Version", "value":"1"}',
']',
'}'
);
assertEq(tokenURI, string(abi.encodePacked("data:application/json;base64,", Base64.encode((dataURI)))));
}
function testFailCallingTokenURIOnNonExistantToken() public { function testFailCallingTokenURIOnNonExistantToken() public {
bytes memory dataURI = abi.encodePacked( bytes memory dataURI = abi.encodePacked(
'{', '{',
'"name":"Foundry Test App",', '"name":"Foundry Test App",',
'"description":"This is a test application submitted by foundry tests.",', '"description":"This is a test application submitted by foundry tests.",',
'"owner":"DEPLOYER",', '"owner":"',Strings.toHexString(uint160(DEPLOYER), 20),'",',
'"external_url":"https://fleek.xyz",', '"external_url":"https://fleek.xyz",',
'"image":"https://fleek.xyz",', '"image":"https://fleek.xyz",',
'"attributes": [', '"attributes": [',
@ -196,6 +278,25 @@ contract FleekTest is Test {
fleekContract.burn(0); fleekContract.burn(0);
} }
function testFailBurnAnotherUsersTokenWithoutAccess() public {
uint256 mint = fleekContract.mint(
DEPLOYER,
'Foundry Test App',
'This is a test application submitted by foundry tests.',
'https://fleek.xyz',
'https://fleek.xyz',
'fleek_xyz',
'afff3f6',
'https://github.com/fleekxyz/contracts'
);
assertEq(mint, 0);
vm.prank(address(0xb4c79daB8f259C7Aee6E5b2Aa729821864227e84));
fleekContract.burn(mint);
}
function testSetTokenName() public { function testSetTokenName() public {
uint256 mint = fleekContract.mint( uint256 mint = fleekContract.mint(
DEPLOYER, DEPLOYER,
@ -213,6 +314,25 @@ contract FleekTest is Test {
fleekContract.setTokenName(mint, 'NEW TOKEN NAME!'); fleekContract.setTokenName(mint, 'NEW TOKEN NAME!');
} }
function testFailSetTokenNameOnAnotherUsersTokenWithoutAccess() public {
uint256 mint = fleekContract.mint(
DEPLOYER,
'Foundry Test App',
'This is a test application submitted by foundry tests.',
'https://fleek.xyz',
'https://fleek.xyz',
'fleek_xyz',
'afff3f6',
'https://github.com/fleekxyz/contracts'
);
assertEq(mint, 0);
vm.prank(address(0xb4c79daB8f259C7Aee6E5b2Aa729821864227e84));
fleekContract.setTokenName(mint, 'NEW TOKEN NAME!');
}
function testSetTokenDescription() public { function testSetTokenDescription() public {
uint256 mint = fleekContract.mint( uint256 mint = fleekContract.mint(
DEPLOYER, DEPLOYER,
@ -230,6 +350,26 @@ contract FleekTest is Test {
fleekContract.setTokenDescription(mint, 'NEW TOKEN NAME!'); fleekContract.setTokenDescription(mint, 'NEW TOKEN NAME!');
} }
function testFailSetTokenDescriptionOnAnotherUsersTokenWithoutAccess() public {
uint256 mint = fleekContract.mint(
DEPLOYER,
'Foundry Test App',
'This is a test application submitted by foundry tests.',
'https://fleek.xyz',
'https://fleek.xyz',
'fleek_xyz',
'afff3f6',
'https://github.com/fleekxyz/contracts'
);
assertEq(mint, 0);
vm.prank(address(0xb4c79daB8f259C7Aee6E5b2Aa729821864227e84));
fleekContract.setTokenDescription(mint, 'NEW TOKEN NAME!');
}
function testSetTokenImage() public { function testSetTokenImage() public {
uint256 mint = fleekContract.mint( uint256 mint = fleekContract.mint(
DEPLOYER, DEPLOYER,
@ -247,6 +387,25 @@ contract FleekTest is Test {
fleekContract.setTokenImage(mint, 'https://ethereum.org'); fleekContract.setTokenImage(mint, 'https://ethereum.org');
} }
function testFailSetTokenImageOnAnotherUsersTokenWithoutAccess() public {
uint256 mint = fleekContract.mint(
DEPLOYER,
'Foundry Test App',
'This is a test application submitted by foundry tests.',
'https://fleek.xyz',
'https://fleek.xyz',
'fleek_xyz',
'afff3f6',
'https://github.com/fleekxyz/contracts'
);
assertEq(mint, 0);
vm.prank(address(0xb4c79daB8f259C7Aee6E5b2Aa729821864227e84));
fleekContract.setTokenImage(mint, 'https://ethereum.org');
}
function testSetTokenExternalURL() public { function testSetTokenExternalURL() public {
uint256 mint = fleekContract.mint( uint256 mint = fleekContract.mint(
DEPLOYER, DEPLOYER,
@ -264,6 +423,25 @@ contract FleekTest is Test {
fleekContract.setTokenExternalURL(mint, 'https://ethereum.org'); fleekContract.setTokenExternalURL(mint, 'https://ethereum.org');
} }
function testFailSetTokenExternalURLOnAnotherUsersTokenWithoutAccess() public {
uint256 mint = fleekContract.mint(
DEPLOYER,
'Foundry Test App',
'This is a test application submitted by foundry tests.',
'https://fleek.xyz',
'https://fleek.xyz',
'fleek_xyz',
'afff3f6',
'https://github.com/fleekxyz/contracts'
);
assertEq(mint, 0);
vm.prank(address(0xb4c79daB8f259C7Aee6E5b2Aa729821864227e84));
fleekContract.setTokenExternalURL(mint, 'https://ethereum.org');
}
function testSetTokenBuild() public { function testSetTokenBuild() public {
uint256 mint = fleekContract.mint( uint256 mint = fleekContract.mint(
DEPLOYER, DEPLOYER,
@ -281,6 +459,25 @@ contract FleekTest is Test {
fleekContract.setTokenBuild(mint, 'aaaaaaa', 'https://github.com/fleekxyz/test_contracts'); fleekContract.setTokenBuild(mint, 'aaaaaaa', 'https://github.com/fleekxyz/test_contracts');
} }
function testFailSetTokenBuildOnAnotherUsersTokenWithoutAccess() public {
uint256 mint = fleekContract.mint(
DEPLOYER,
'Foundry Test App',
'This is a test application submitted by foundry tests.',
'https://fleek.xyz',
'https://fleek.xyz',
'fleek_xyz',
'afff3f6',
'https://github.com/fleekxyz/contracts'
);
assertEq(mint, 0);
vm.prank(address(0xb4c79daB8f259C7Aee6E5b2Aa729821864227e84));
fleekContract.setTokenBuild(mint, 'aaaaaaa', 'https://github.com/fleekxyz/test_contracts');
}
function testSetTokenENS() public { function testSetTokenENS() public {
uint256 mint = fleekContract.mint( uint256 mint = fleekContract.mint(
DEPLOYER, DEPLOYER,
@ -298,6 +495,25 @@ contract FleekTest is Test {
fleekContract.setTokenENS(mint, 'fleek_nfts'); fleekContract.setTokenENS(mint, 'fleek_nfts');
} }
function testFailSetTokenENSOnAnotherUsersTokenWithoutAccess() public {
uint256 mint = fleekContract.mint(
DEPLOYER,
'Foundry Test App',
'This is a test application submitted by foundry tests.',
'https://fleek.xyz',
'https://fleek.xyz',
'fleek_xyz',
'afff3f6',
'https://github.com/fleekxyz/contracts'
);
assertEq(mint, 0);
vm.prank(address(0xb4c79daB8f259C7Aee6E5b2Aa729821864227e84));
fleekContract.setTokenENS(mint, 'fleek_nfts');
}
function testAddTokenController() public { function testAddTokenController() public {
uint256 mint = fleekContract.mint( uint256 mint = fleekContract.mint(
DEPLOYER, DEPLOYER,
@ -315,8 +531,45 @@ contract FleekTest is Test {
fleekContract.addTokenController(mint, 0xb4c79daB8f259C7Aee6E5b2Aa729821864227e84); fleekContract.addTokenController(mint, 0xb4c79daB8f259C7Aee6E5b2Aa729821864227e84);
} }
function testFailAddTokenControllerOnAnotherUsersTokenWithoutAccess() public {
uint256 mint = fleekContract.mint(
DEPLOYER,
'Foundry Test App',
'This is a test application submitted by foundry tests.',
'https://fleek.xyz',
'https://fleek.xyz',
'fleek_xyz',
'afff3f6',
'https://github.com/fleekxyz/contracts'
);
assertEq(mint, 0);
vm.prank(address(0xb4c79daB8f259C7Aee6E5b2Aa729821864227e84));
fleekContract.addTokenController(mint, 0xb4c79daB8f259C7Aee6E5b2Aa729821864227e84);
}
function testFailAddTokenControllerTwice() public {
uint256 mint = fleekContract.mint(
DEPLOYER,
'Foundry Test App',
'This is a test application submitted by foundry tests.',
'https://fleek.xyz',
'https://fleek.xyz',
'fleek_xyz',
'afff3f6',
'https://github.com/fleekxyz/contracts'
);
assertEq(mint, 0);
fleekContract.addTokenController(mint, 0xb4c79daB8f259C7Aee6E5b2Aa729821864227e84);
fleekContract.addTokenController(mint, 0xb4c79daB8f259C7Aee6E5b2Aa729821864227e84);
}
function testRemoveTokenController() public { function testRemoveTokenController() public {
uint256 mint = fleekContract.mint( uint256 mint = fleekContract.mint(
DEPLOYER, DEPLOYER,
'Foundry Test App', 'Foundry Test App',
'This is a test application submitted by foundry tests.', 'This is a test application submitted by foundry tests.',
@ -333,4 +586,82 @@ contract FleekTest is Test {
fleekContract.removeTokenController(mint, 0xb4c79daB8f259C7Aee6E5b2Aa729821864227e84); fleekContract.removeTokenController(mint, 0xb4c79daB8f259C7Aee6E5b2Aa729821864227e84);
} }
function testFailRemoveTokenControllerOnAnotherUsersTokenWithoutAccess() public {
uint256 mint = fleekContract.mint(
DEPLOYER,
'Foundry Test App',
'This is a test application submitted by foundry tests.',
'https://fleek.xyz',
'https://fleek.xyz',
'fleek_xyz',
'afff3f6',
'https://github.com/fleekxyz/contracts'
);
assertEq(mint, 0);
fleekContract.addTokenController(mint, 0x91A425C1CA320A99a09BE1bee114Fce5d30153d9);
vm.prank(address(0xb4c79daB8f259C7Aee6E5b2Aa729821864227e84));
fleekContract.removeTokenController(mint, 0x91A425C1CA320A99a09BE1bee114Fce5d30153d9);
}
function testRemoveTokenControllerTwice() public {
uint256 mint = fleekContract.mint(
DEPLOYER,
'Foundry Test App',
'This is a test application submitted by foundry tests.',
'https://fleek.xyz',
'https://fleek.xyz',
'fleek_xyz',
'afff3f6',
'https://github.com/fleekxyz/contracts'
);
assertEq(mint, 0);
fleekContract.addTokenController(mint, 0xb4c79daB8f259C7Aee6E5b2Aa729821864227e84);
fleekContract.removeTokenController(mint, 0xb4c79daB8f259C7Aee6E5b2Aa729821864227e84);
fleekContract.removeTokenController(mint, 0xb4c79daB8f259C7Aee6E5b2Aa729821864227e84);
}
function testFailRemoveUnknownTokenController() public {
uint256 mint = fleekContract.mint(
DEPLOYER,
'Foundry Test App',
'This is a test application submitted by foundry tests.',
'https://fleek.xyz',
'https://fleek.xyz',
'fleek_xyz',
'afff3f6',
'https://github.com/fleekxyz/contracts'
);
assertEq(mint, 0);
fleekContract.removeTokenController(mint, 0xb4c79daB8f259C7Aee6E5b2Aa729821864227e84);
}
function testFailRemoveUnknownTokenControllerFromUnknownToken() public {
fleekContract.removeTokenController(0, 0xb4c79daB8f259C7Aee6E5b2Aa729821864227e84);
}
function testFailRemoveTokenOwnerByTokenController() public {
uint256 mint = fleekContract.mint(
DEPLOYER,
'Foundry Test App',
'This is a test application submitted by foundry tests.',
'https://fleek.xyz',
'https://fleek.xyz',
'fleek_xyz',
'afff3f6',
'https://github.com/fleekxyz/contracts'
);
assertEq(mint, 0);
fleekContract.addTokenController(mint, 0xb4c79daB8f259C7Aee6E5b2Aa729821864227e84);
vm.prank(address(0xb4c79daB8f259C7Aee6E5b2Aa729821864227e84));
fleekContract.removeTokenController(mint, DEPLOYER);
}
} }