Skip to content

Commit

Permalink
added mint and setTokenUri functionality, transfer needs some work ba…
Browse files Browse the repository at this point in the history
…sed on requirements
  • Loading branch information
JacobHomanics committed Feb 2, 2024
1 parent d925d97 commit 3be6122
Show file tree
Hide file tree
Showing 5 changed files with 255 additions and 100 deletions.
47 changes: 47 additions & 0 deletions packages/foundry/contracts/ATXDAOPartnershipNft.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//SPDX-License-Identifier: MIT
pragma solidity >=0.8.0 <0.9.0;

// Useful for debugging. Remove when deploying to a live network.
import "forge-std/console.sol";
import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import {ERC721URIStorage} from "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol";

contract ATXDAOPartnershipNft is ERC721URIStorage, AccessControl {
constructor(address[] memory admins) ERC721("ADNDN", "ATX") {
for (uint256 i = 0; i < admins.length; i++) {
_grantRole(DEFAULT_ADMIN_ROLE, admins[i]);
}
}

uint256 mintCount;

function mint(address target) external onlyRole(DEFAULT_ADMIN_ROLE) {
_mint(target, mintCount);
mintCount++;
}

error ATXDAOPartnershipNft__NotValidOperator();

function setTokenURI(uint256 tokenId, string memory tokenUri) external {
if (msg.sender != ownerOf(tokenId)) {
if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {
revert ATXDAOPartnershipNft__NotValidOperator();
}
}

_setTokenURI(tokenId, tokenUri);
}

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

function supportsInterface(
bytes4 interfaceId
) public view override(ERC721URIStorage, AccessControl) returns (bool) {
return super.supportsInterface(interfaceId);
}
}
84 changes: 0 additions & 84 deletions packages/foundry/contracts/YourContract.sol

This file was deleted.

135 changes: 135 additions & 0 deletions packages/foundry/lcov.info
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
TN:
SF:contracts/ATXDAOPartnershipNft.sol
FN:19,ATXDAOPartnershipNft.mint
FNDA:3,ATXDAOPartnershipNft.mint
DA:20,3
DA:21,3
FN:26,ATXDAOPartnershipNft.setTokenURI
FNDA:3,ATXDAOPartnershipNft.setTokenURI
DA:27,3
BRDA:27,0,0,1
BRDA:27,0,1,1
DA:28,2
BRDA:28,1,0,1
BRDA:28,1,1,1
DA:29,1
DA:33,2
FN:36,ATXDAOPartnershipNft.supportsInterface
FNDA:0,ATXDAOPartnershipNft.supportsInterface
DA:39,0
FNF:3
FNH:2
LF:7
LH:6
BRF:4
BRH:4
end_of_record
TN:
SF:script/DeployHelpers.s.sol
FN:19,ScaffoldETHDeploy.setupLocalhostEnv
FNDA:0,ScaffoldETHDeploy.setupLocalhostEnv
DA:23,0
BRDA:23,0,0,-
BRDA:23,0,1,-
DA:24,0
DA:25,0
DA:26,0
DA:27,0
DA:28,0
DA:29,0
DA:31,0
FN:35,ScaffoldETHDeploy.exportDeployments
FNDA:0,ScaffoldETHDeploy.exportDeployments
DA:37,0
DA:38,0
DA:39,0
DA:40,0
DA:42,0
DA:44,0
DA:46,0
DA:47,0
DA:54,0
DA:56,0
DA:61,0
DA:62,0
FN:65,ScaffoldETHDeploy.getChain
FNDA:0,ScaffoldETHDeploy.getChain
DA:66,0
FN:69,ScaffoldETHDeploy.findChainName
FNDA:0,ScaffoldETHDeploy.findChainName
DA:70,0
DA:71,0
DA:72,0
DA:73,0
DA:81,0
FNF:4
FNH:0
LF:26
LH:0
BRF:2
BRH:0
end_of_record
TN:
SF:script/VerifyAll.s.sol
FN:27,VerifyAll.run
FNDA:0,VerifyAll.run
DA:28,0
DA:29,0
DA:35,0
DA:37,0
DA:38,0
DA:39,0
FN:43,VerifyAll._verifyIfContractDeployment
FNDA:0,VerifyAll._verifyIfContractDeployment
DA:44,0
DA:51,0
BRDA:51,0,0,-
BRDA:51,0,1,-
DA:52,0
FN:56,VerifyAll._verifyContract
FNDA:0,VerifyAll._verifyContract
DA:57,0
DA:64,0
DA:71,0
DA:78,0
DA:85,0
DA:91,0
DA:92,0
DA:93,0
DA:94,0
DA:95,0
DA:96,0
DA:97,0
DA:98,0
DA:99,0
DA:100,0
DA:102,0
DA:104,0
BRDA:104,1,0,-
BRDA:104,1,1,-
DA:105,0
DA:111,0
DA:113,0
DA:115,0
FN:118,VerifyAll.nextTransaction
FNDA:0,VerifyAll.nextTransaction
DA:121,0
FN:128,VerifyAll._getCompiledBytecode
FNDA:0,VerifyAll._getCompiledBytecode
DA:131,0
DA:132,0
DA:140,0
FN:143,VerifyAll.getTransactionFromRaw
FNDA:0,VerifyAll.getTransactionFromRaw
DA:147,0
FN:150,VerifyAll.searchStr
FNDA:0,VerifyAll.searchStr
DA:154,0
DA:155,0
FNF:7
FNH:0
LF:37
LH:0
BRF:4
BRH:0
end_of_record
13 changes: 9 additions & 4 deletions packages/foundry/script/Deploy.s.sol
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import "../contracts/YourContract.sol";
import "../contracts/ATXDAOPartnershipNft.sol";
import "./DeployHelpers.s.sol";

contract DeployScript is ScaffoldETHDeploy {
error InvalidPrivateKey(string);

address admin = makeAddr("Admin");

function run() external {
uint256 deployerPrivateKey = setupLocalhostEnv();
if (deployerPrivateKey == 0) {
Expand All @@ -15,9 +17,12 @@ contract DeployScript is ScaffoldETHDeploy {
);
}
vm.startBroadcast(deployerPrivateKey);
YourContract yourContract = new YourContract(
vm.addr(deployerPrivateKey)
);

address[] memory admins = new address[](1);
admins[0] = admin;

ATXDAOPartnershipNft yourContract = new ATXDAOPartnershipNft(admins);

console.logString(
string.concat(
"YourContract deployed at: ",
Expand Down
76 changes: 64 additions & 12 deletions packages/foundry/test/YourContract.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,79 @@
pragma solidity ^0.8.13;

import "forge-std/Test.sol";
import "../contracts/YourContract.sol";
import {ATXDAOPartnershipNft} from "../contracts/ATXDAOPartnershipNft.sol";

contract YourContractTest is Test {
YourContract public yourContract;
ATXDAOPartnershipNft public nftCollection;

address user = makeAddr("User");
address user2 = makeAddr("User2");
address admin = makeAddr("Admin");

function setUp() public {
yourContract = new YourContract(vm.addr(1));
console.log("User: ", user);
console.log("User 2: ", user2);
console.log("Admin: ", admin);

address[] memory admins = new address[](1);
admins[0] = admin;

nftCollection = new ATXDAOPartnershipNft(admins);
}

function testMessageOnDeployment() public view {
require(
keccak256(bytes(yourContract.greeting())) ==
keccak256("Building Unstoppable Apps!!!")
function testSetTokenUriAsOwner() public {
vm.prank(admin);
nftCollection.mint(user);

vm.prank(user);
nftCollection.setTokenURI(
0,
"ipfs://bafybeiaz55w6kf7ar2g5vzikfbft2qoexknstfouu524l7q3mliutns2u4/0"
);

assertEq(
nftCollection.tokenURI(0),
"ipfs://bafybeiaz55w6kf7ar2g5vzikfbft2qoexknstfouu524l7q3mliutns2u4/0"
);
}

function testSetNewMessage() public {
yourContract.setGreeting("Learn Scaffold-ETH 2! :)");
require(
keccak256(bytes(yourContract.greeting())) ==
keccak256("Learn Scaffold-ETH 2! :)")
function testSetTokenUriAsAdmin() public {
vm.prank(admin);
nftCollection.mint(user);

vm.startPrank(admin);
nftCollection.setTokenURI(
0,
"ipfs://bafybeiaz55w6kf7ar2g5vzikfbft2qoexknstfouu524l7q3mliutns2u4/0"
);
vm.stopPrank();

assertEq(
nftCollection.tokenURI(0),
"ipfs://bafybeiaz55w6kf7ar2g5vzikfbft2qoexknstfouu524l7q3mliutns2u4/0"
);
}

function testRevertIfNotOwner() public {
vm.prank(admin);
nftCollection.mint(user);

vm.startPrank(user2);
vm.expectRevert();
nftCollection.setTokenURI(
0,
"ipfs://bafybeiaz55w6kf7ar2g5vzikfbft2qoexknstfouu524l7q3mliutns2u4/0"
);
vm.stopPrank();
}

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

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

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

0 comments on commit 3be6122

Please sign in to comment.