Skip to content

Commit

Permalink
Clean up metadata storage params and add setMetadataParams test
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderattar committed Apr 30, 2024
1 parent 79e3801 commit d92da6f
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/token/CountdownERC721.sol
Original file line number Diff line number Diff line change
Expand Up @@ -75,31 +75,31 @@ contract CountdownERC721 is NonReentrant, ContractMetadata, ERC721H, ICustomERC7

/// @notice Getter for the base image URI
/// @dev This storage variable is set during the init and can be updated by the owner
string public IMAGE_URI = "ar://o8eyC27OuSZF0z-zIen5NTjJOKTzOQzKJzIe3F7Lmg0/1.png";
string public IMAGE_URI;

/// @notice Getter for the base animation URI
/// @dev This storage variable is set during the init and can be updated by the owner
string public ANIMATION_URI = ""; // Define if you have a specific animation URI
string public ANIMATION_URI;

/// @notice Getter for the external url
/// @dev This storage variable is set during the init and can be updated by the owner
string public EXTERNAL_URL = "https://your-nft-project.com";
string public EXTERNAL_URL;

/// @notice Getter for the encrypted media URI
/// @dev This storage variable is set during the init and can be updated by the owner
string public ENCRYPTED_MEDIA_URL = "ar://encryptedMediaUriHere";
string public ENCRYPTED_MEDIA_URL;

/// @notice Getter for the decryption key
/// @dev This storage variable is set during the init and can be updated by the owner
string public DECRYPTION_KEY = "decryptionKeyHere";
string public DECRYPTION_KEY;

/// @notice Getter for the hash
/// @dev This storage variable is set during the init and can be updated by the owner
string public HASH = "uniqueNftHashHere";
string public HASH;

/// @notice Getter for the decrypted media URI
/// @dev This storage variable is set during the init and can be updated by the owner
string public DECRYPTED_MEDIA_URI = "ar://decryptedMediaUriHere";
string public DECRYPTED_MEDIA_URI;

/* -------------------------------------------------------------------------- */

Expand Down Expand Up @@ -386,7 +386,6 @@ contract CountdownERC721 is NonReentrant, ContractMetadata, ERC721H, ICustomERC7
* @notice Returns the metadata params for the contract
*/
function setMetadataParams(MetadataParams memory params) external onlyOwner {
DESCRIPTION = params.description;
IMAGE_URI = params.imageURI;
ANIMATION_URI = params.animationURI;
EXTERNAL_URL = params.externalUrl;
Expand Down
71 changes: 71 additions & 0 deletions test/foundry/CountdownERC721/CountdownERC721.tokenUri.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {CountdownERC721Fixture} from "test/foundry/fixtures/CountdownERC721Fixtu
import {Vm} from "forge-std/Test.sol";
import {console} from "forge-std/console.sol";

import {MetadataParams} from "src/struct/MetadataParams.sol";

import {DEFAULT_BASE_URI, DEFAULT_PLACEHOLDER_URI, DEFAULT_ENCRYPT_DECRYPT_KEY, DEFAULT_MAX_SUPPLY} from "test/foundry/CountdownERC721/utils/Constants.sol";

import {ICountdownERC721} from "src/interface/ICountdownERC721.sol";
Expand Down Expand Up @@ -60,4 +62,73 @@ contract CountdownERC721PurchaseTest is CountdownERC721Fixture, ICustomERC721Err

assertEq(base64TokenUri, expectedTokenUri, "Incorrect tokenURI for newly minted token");
}

function test_setMetadataParams() public setupTestCountdownErc721(DEFAULT_MAX_SUPPLY) setUpPurchase {
/* -------------------------------- Purchase -------------------------------- */
vm.prank(address(TEST_ACCOUNT));
vm.deal(address(TEST_ACCOUNT), totalCost);
uint256 tokenId = countdownErc721.purchase{value: totalCost}(1);

// First token ID is this long number due to the chain id prefix
require(erc721Enforcer.ownerOf(tokenId) == address(TEST_ACCOUNT), "Incorrect owner for newly minted token");
assertEq(address(sourceContractAddress).balance, nativePrice);

/* ----------------------------- Check tokenURI ----------------------------- */

// assertEq(base64TokenUri, expectedTokenUri, "Incorrect tokenURI for newly minted token");

/* ----------------------------- Set Metadata Params ----------------------------- */

// Expected token URI for newly minted token
// {
// "name": "Contract Name 115792089183396302089269705419353877679230723318366275194376439045705909141505",
// "description": "Description of the token",
// "external_url": "https://example.com",
// "image": ar://o8eyC27OuSZF0z-zIen5NTjJOKTzOQzKJzIe3F7Lmg0/1.png",
// "encrypted_media_url": "ar://encryptedMediaUriHere",
// "decryption_key": "decryptionKeyHere",
// "hash": "uniqueHashHere",
// "decrypted_media_url": "ar://decryptedMediaUriHere",
// "animation_url": "ar://animationUriHere",
// "properties": {
// "number": 115792089183396302089269705419353877679230723318366275194376439045705909141505,
// "name": "Contract Name"
// }
// }
string memory expectedTokenUri = NFTMetadataRenderer.encodeMetadataJSON(
'{"name": "Contract Name 115792089183396302089269705419353877679230723318366275194376439045705909141505", "description": "Description of the token", "external_url": "https://example.com", "image": "ar://o8eyC27OuSZF0z-zIen5NTjJOKTzOQzKJzIe3F7Lmg0/1.png", "encrypted_media_url": "ar://encryptedMediaUriHere", "decryption_key": "decryptionKeyHere", "hash": "uniqueHashHere", "decrypted_media_url": "ar://decryptedMediaUriHere", "animation_url": "ar://animationUriHere", "properties": {"number": 115792089183396302089269705419353877679230723318366275194376439045705909141505, "name": "Contract Name"}}'
);

// string name;
// string description;
// string imageURI;
// string animationURI;
// string externalUrl;
// string encryptedMediaUrl;
// string decryptionKey;
// string hash;
// string decryptedMediaUrl;
// uint256 tokenOfEdition;
// uint256 editionSize;

MetadataParams memory metadataParams = MetadataParams({
name: "Contract Name", // NOT USED
description: "Description of the token", // NOT USED
tokenOfEdition: 0, // NOT USED
editionSize: 0, // NOT USED
imageURI: "ar://o8eyC27OuSZF0z-zIen5NTjJOKTzOQzKJzIe3F7Lmg0/1.png",
animationURI: "",
externalUrl: "https://example.com",
encryptedMediaUrl: "ar://encryptedMediaUriHere",
decryptionKey: "decryptionKeyHere",
hash: "uniqueHashHere",
decryptedMediaUrl: "ar://decryptedMediaUriHere"
});

vm.prank(address(DEFAULT_OWNER_ADDRESS));
countdownErc721.setMetadataParams(metadataParams);

string memory base64TokenUri = countdownErc721.tokenURI(tokenId);
console.log("base64TokenUri: ", base64TokenUri);
}
}

0 comments on commit d92da6f

Please sign in to comment.