Skip to content

Commit

Permalink
addedtesting for returnToDao function
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobHomanics committed Feb 2, 2024
1 parent 40ec410 commit d4c725c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 22 deletions.
13 changes: 4 additions & 9 deletions packages/foundry/contracts/ATXDAOPartnershipNft.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ contract ATXDAOPartnershipNft is ERC721URIStorage, AccessControl {
}

function returnToDao(
uint256 tokenId
uint256 tokenId,
address receiver
) external onlyRole(DEFAULT_ADMIN_ROLE) {
transferFrom(ownerOf(tokenId), msg.sender, tokenId);
transferFrom(ownerOf(tokenId), receiver, tokenId);
}

function _checkAuthorized(
Expand All @@ -45,13 +46,7 @@ contract ATXDAOPartnershipNft is ERC721URIStorage, AccessControl {
uint256 tokenId
) internal view override {
if (!hasRole(DEFAULT_ADMIN_ROLE, spender)) {
if (!_isAuthorized(owner, spender, tokenId)) {
if (owner == address(0)) {
revert ERC721NonexistentToken(tokenId);
} else {
revert ERC721InsufficientApproval(spender, tokenId);
}
}
super._checkAuthorized(owner, spender, tokenId);
}
}

Expand Down
31 changes: 20 additions & 11 deletions packages/foundry/lcov.info
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
TN:
SF:contracts/ATXDAOPartnershipNft.sol
FN:19,ATXDAOPartnershipNft.mint
FNDA:3,ATXDAOPartnershipNft.mint
DA:20,3
DA:21,3
FNDA:6,ATXDAOPartnershipNft.mint
DA:20,6
DA:21,6
FN:26,ATXDAOPartnershipNft.setTokenURI
FNDA:3,ATXDAOPartnershipNft.setTokenURI
DA:27,3
Expand All @@ -14,15 +14,24 @@ BRDA:28,1,0,1
BRDA:28,1,1,1
DA:29,1
DA:33,2
FN:36,ATXDAOPartnershipNft.supportsInterface
FN:36,ATXDAOPartnershipNft.returnToDao
FNDA:2,ATXDAOPartnershipNft.returnToDao
DA:40,1
FN:43,ATXDAOPartnershipNft._checkAuthorized
FNDA:2,ATXDAOPartnershipNft._checkAuthorized
DA:48,2
BRDA:48,2,0,1
BRDA:48,2,1,2
DA:49,1
FN:53,ATXDAOPartnershipNft.supportsInterface
FNDA:0,ATXDAOPartnershipNft.supportsInterface
DA:39,0
FNF:3
FNH:2
LF:7
LH:6
BRF:4
BRH:4
DA:56,0
FNF:5
FNH:4
LF:10
LH:9
BRF:6
BRH:6
end_of_record
TN:
SF:script/DeployHelpers.s.sol
Expand Down
24 changes: 22 additions & 2 deletions packages/foundry/test/YourContract.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ contract YourContractTest is Test {
address user = makeAddr("User");
address user2 = makeAddr("User2");
address admin = makeAddr("Admin");
address multisig = makeAddr("Multisig");

function setUp() public {
console.log("User: ", user);
Expand Down Expand Up @@ -72,9 +73,28 @@ contract YourContractTest is Test {
vm.startPrank(admin);
nftCollection.mint(user);

nftCollection.returnToDao(0);
nftCollection.returnToDao(0, multisig);
vm.stopPrank();

console.log("owner of 0: ", nftCollection.ownerOf(0));
assertEq(nftCollection.ownerOf(0), multisig);
}

function testRevert__ReturnToDao__IfNotAdmin() public {
vm.startPrank(admin);
nftCollection.mint(user);
vm.stopPrank();

vm.prank(user);
vm.expectRevert();
nftCollection.returnToDao(0, multisig);
}

function testTransfer() public {
vm.startPrank(admin);
nftCollection.mint(user);
vm.stopPrank();

vm.prank(user);
nftCollection.transferFrom(user, user2, 0);
}
}

0 comments on commit d4c725c

Please sign in to comment.