Skip to content

Commit

Permalink
add back deleting reservations / remove duplicate tests / add test ca…
Browse files Browse the repository at this point in the history
…se to verifyPoi
  • Loading branch information
nour-karoui committed Oct 31, 2024
1 parent fd7539c commit 5edc1bf
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 17 deletions.
10 changes: 9 additions & 1 deletion src/IPNFT.sol
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ contract IPNFT is ERC721URIStorageUpgradeable, ERC721BurnableUpgradeable, IReser
whenNotPaused
returns (uint256)
{
bool isPoi = reservationId > type(uint128).max;
bool isPoi = _verifyPoi(reservationId);
if (!isPoi && reservations[reservationId] != _msgSender()) {
revert NotOwningReservation(reservationId);
}
Expand All @@ -134,6 +134,10 @@ contract IPNFT is ERC721URIStorageUpgradeable, ERC721BurnableUpgradeable, IReser
if (!mintAuthorizer.authorizeMint(_msgSender(), to, abi.encode(SignedMintAuthorization(reservationId, _tokenURI, authorization)))) {
revert Unauthorized();
}
if(!isPoi) {
delete reservations[reservationId];
}

symbol[reservationId] = _symbol;
mintAuthorizer.redeem(authorization);

Expand Down Expand Up @@ -202,6 +206,10 @@ contract IPNFT is ERC721URIStorageUpgradeable, ERC721BurnableUpgradeable, IReser
super._burn(tokenId);
}

function _verifyPoi(uint256 poi) internal pure returns (bool) {
return poi > type(uint128).max;
}

/// @inheritdoc ERC721Upgradeable
function tokenURI(uint256 tokenId) public view virtual override(ERC721URIStorageUpgradeable, ERC721Upgradeable) returns (string memory) {
return super.tokenURI(tokenId);
Expand Down
14 changes: 7 additions & 7 deletions subgraph/subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ dataSources:
file: ./src/swapMapping.ts
- kind: ethereum/contract
name: Tokenizer
network: foundry
network: mainnet
source:
abi: Tokenizer
address: "0xB7f8BC63BbcaD18155201308C8f3540b07f84F5e"
Expand All @@ -84,7 +84,7 @@ dataSources:
file: ./src/tokenizerMapping.ts
- kind: ethereum/contract
name: CrowdSale
network: foundry
network: mainnet
source:
abi: CrowdSale
address: "0x7a2088a1bFc9d81c55368AE168C2C02570cB814F"
Expand Down Expand Up @@ -121,7 +121,7 @@ dataSources:
file: ./src/crowdSaleMapping.ts
- kind: ethereum/contract
name: StakedLockingCrowdSale
network: foundry
network: mainnet
source:
abi: StakedLockingCrowdSale
address: "0x0B306BF915C4d645ff596e518fAf3F9669b97016"
Expand Down Expand Up @@ -167,7 +167,7 @@ dataSources:
file: ./src/stakedLockingCrowdSaleMapping.ts
- kind: ethereum/contract
name: TermsAcceptedPermissioner
network: foundry
network: mainnet
source:
abi: TermsAcceptedPermissioner
address: "0x8A791620dd6260079BF849Dc5567aDC3F2FdC318"
Expand All @@ -188,7 +188,7 @@ dataSources:
templates:
- name: IPToken
kind: ethereum/contract
network: foundry
network: mainnet
source:
abi: IPToken
mapping:
Expand All @@ -208,7 +208,7 @@ templates:
handler: handleCapped
- name: TimelockedToken
kind: ethereum/contract
network: foundry
network: mainnet
source:
abi: TimelockedToken
mapping:
Expand Down Expand Up @@ -240,4 +240,4 @@ templates:
abis:
- name: IPNFT
file: ./abis/IPNFT.json
network: foundry
network: mainnet
17 changes: 8 additions & 9 deletions test/IPNFT.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -72,33 +72,32 @@ contract IPNFTTest is IPNFTMintHelper {
assertEq(ipnft.reservations(2), bob);
}

function testVerifyPoi() public {
uint256 tokenId = uint256(0x073cb54264ef688e56531a2d09ab47b14086b5c7813e3a23a2bd7b1bb6458a52);
bool isPoi = verifyPoi(tokenId);
assertEq(isPoi, true);
}

function testMintWithPoi() public {
bytes32 poiHash = 0x073cb54264ef688e56531a2d09ab47b14086b5c7813e3a23a2bd7b1bb6458a52;
uint256 tokenId = uint256(poiHash);
(, uint256 maliciousSignerPk) = makeAddrAndKey("malicious");
bytes32 authMessageHash = ECDSA.toEthSignedMessageHash(keccak256(abi.encodePacked(alice, alice, tokenId, ipfsUri)));
(uint8 v, bytes32 r, bytes32 s) = vm.sign(maliciousSignerPk, authMessageHash);
bytes memory maliciousAuthorization = abi.encodePacked(r, s, v);

vm.startPrank(deployer);
ipnft.setAuthorizer(new SignedMintAuthorizer(deployer));
vm.stopPrank();

vm.startPrank(alice);
vm.expectRevert(IPNFT.MintingFeeTooLow.selector);
ipnft.mintReservation(alice, tokenId, ipfsUri, DEFAULT_SYMBOL, maliciousAuthorization);

vm.expectRevert(IPNFT.Unauthorized.selector);
ipnft.mintReservation{ value: MINTING_FEE }(alice, tokenId, ipfsUri, DEFAULT_SYMBOL, maliciousAuthorization);

(v, r, s) = vm.sign(deployerPk, authMessageHash);
(uint8 v, bytes32 r, bytes32 s) = vm.sign(deployerPk, authMessageHash);
bytes memory authorization = abi.encodePacked(r, s, v);
vm.expectEmit(true, true, false, true);
emit IPNFTMinted(alice, tokenId, ipfsUri, DEFAULT_SYMBOL);
ipnft.mintReservation{ value: MINTING_FEE }(alice, tokenId, ipfsUri, DEFAULT_SYMBOL, authorization);
assertEq(ipnft.ownerOf(tokenId), alice);
assertEq(ipnft.tokenURI(tokenId), ipfsUri);
assertEq(ipnft.symbol(tokenId), DEFAULT_SYMBOL);

vm.stopPrank();
}

Expand Down
4 changes: 4 additions & 0 deletions test/IPNFTMintHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,8 @@ abstract contract IPNFTMintHelper is Test {
vm.stopPrank();
return reservationId;
}

function verifyPoi(uint256 tokenId) public pure returns (bool) {
return tokenId > type(uint128).max;
}
}

0 comments on commit 5edc1bf

Please sign in to comment.