Skip to content
This repository has been archived by the owner on Sep 29, 2023. It is now read-only.

Commit

Permalink
Merge pull request #3 from ProjectOpenSea/dan/2023/09/add-dynamic-met…
Browse files Browse the repository at this point in the history
…adata-test

Dan/2023/09/add dynamic metadata test
  • Loading branch information
DJViau authored Sep 26, 2023
2 parents 78ea690 + 1213692 commit c5f21a3
Show file tree
Hide file tree
Showing 6 changed files with 354 additions and 41 deletions.
8 changes: 4 additions & 4 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
auto_detect_solc = false
solc = '0.8.20'
src = "src"
test = "test"
out = "out"
libs = ["lib"]
remappings = [
'forge-std/=lib/forge-std/src',
'solady/=lib/solady/src/',
'solady-test/=lib/solady/test/',
'openzeppelin-contracts/=lib/openzeppelin-contracts/contracts/',
'seaport-types/=lib/seaport-types/src/',
'shipyard-core/=lib/shipyard-core/src/',
'seaport-types/=lib/seaport-types/src/'
'solady-test/=lib/solady/test/',
'solady/=lib/solady/src/'
]
# use realistic numbers in tests
block_number = 17722462
Expand Down
38 changes: 38 additions & 0 deletions script/DeleteTrait.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;

import "forge-std/Script.sol";

interface DeleteTraitInterface {
function deleteTrait(bytes32 traitKey, uint256 tokenId) external;
}

/**
* @title DeleteTraitScript
* @notice This script deletes a trait for a given traitKey and tokenId. Note
* That this is not permissible if the trait is required to have a
* value. Check the current tokenURI response for token 1 by running
* `cast call --rpc-url $GOERLI_RPC_URL
* <the_address_of_the_target_contract> "tokenURI(uint256)(string)" 1`.
* It should return the base64 encoded json for the NFT. Then run
* `forge script script/DeleteTrait.s.sol --tc DeleteTraitScript
* --sender <the_deployer_address> --fork-url $GOERLI_RPC_URL -vvvv` to
* simulate the tx. To run it for real, change it to `forge script
* script/DeleteTrait.s.sol --tc DeleteTraitScript --private-key
* $MY_ACTUAL_PK_BE_CAREFUL --fork-url $GOERLI_RPC_URL --broadcast`.
*/
contract DeleteTraitScript is Script {
DeleteTraitInterface targetContract;

function setUp() public {
// Add the address of the target contract to the script here.
targetContract = DeleteTraitInterface(address(0));
}

function run() public {
// Call the function to delete the trait on token ID 1.
vm.startBroadcast();

targetContract.deleteTrait(bytes32("test.scriptTest"), 1);
}
}
38 changes: 38 additions & 0 deletions script/Mint.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;

import "forge-std/Script.sol";

interface MintInterface {
function mint(address to) external;
}

/**
* @title MintScript
* @notice This script mints a token. Simulate running it by entering `forge
* script script/Mint.s.sol --tc MintScript --sender
* <the_caller_address> --fork-url $GOERLI_RPC_URL -vvvv` in the
* terminal. To run it for real, change it to `forge script
* script/Mint.s.sol --tc MintScript --private-key
* $MY_ACTUAL_PK_BE_CAREFUL --fork-url $GOERLI_RPC_URL --broadcast`.
*
*/
contract MintScript is Script {
MintInterface targetContract;

function setUp() public {
// Replace the address of the target NFT contract here.
targetContract = MintInterface(address(0));
}

function run() public {
// Call the function to mint a token. Note that the mint function on the
// Dockmaster contract can only be called by an address with two leading
// zeros in its address.
vm.broadcast();

// Replace the address below with the address that should recieve the
// token.
targetContract.mint(address(0));
}
}
34 changes: 34 additions & 0 deletions script/SetTrait.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;

import "forge-std/Script.sol";

interface SetTraitInterface {
function setTrait(bytes32 traitKey, uint256 tokenId, bytes32 trait)
external;
}

/**
* @title SetTraitScript
* @notice This script sets a trait on a Dynamic Traits contract. Check the
* current tokenURI response for token 1 by running `cast call --rpc-url
* $GOERLI_RPC_URL <the_address_of_the_target_contract>
* "tokenURI(uint256)(string)" 1`. It should return the base64 encoded
* json for the NFT. Then run `forge script script/SetTrait.s.sol --tc
* SetTraitScript --sender <the_deployer_address> --fork-url
* $GOERLI_RPC_URL -vvvv` to simulate the tx.
*/
contract SetTraitScript is Script {
SetTraitInterface targetContract;

function setUp() public {
// Replace the address of the target NFT contract here.
targetContract = SetTraitInterface(address(0));
}

function run() public {
// Call the function to set the trait on token ID 1.
vm.broadcast();
targetContract.setTrait(bytes32("test.scriptTest"), 1, "First Value");
}
}
63 changes: 63 additions & 0 deletions script/SetTraitLabel.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;

import "forge-std/Script.sol";
import {
AllowedEditor,
DisplayType,
Editors,
FullTraitValue,
TraitLabel,
EditorsLib
} from "shipyard-core/dynamic-traits/lib/TraitLabelLib.sol";

interface SetTraitLabelInterface {
function setTraitLabel(bytes32 traitKey, TraitLabel memory _traitLabel)
external;
}

/**
* @title SetTraitLabelScript
* @notice This script sets a trait label on a DynamicTraits contract. Simulate
* running it by entering `forge script script/SetTraitLabel.s.sol --tc
* SetTraitLabelScript --sender <the_deployer_address> --fork-url
* $GOERLI_RPC_URL -vvvv` in your terminal. To run it for real,
* change it to `forge script script/SetTraitLabel.s.sol --tc
* SetTraitLabelScript --private-key $MY_ACTUAL_PK_BE_CAREFUL --fork-url
* $GOERLI_RPC_URL --broadcast`.
*/
contract SetTraitLabelScript is Script {
SetTraitLabelInterface targetContract;

function setUp() public {
// Replace the address of the target contract here.
targetContract = SetTraitLabelInterface(address(0));
}

function run() public {
// Build the trait label.
string[] memory acceptableValues = new string[](2);
acceptableValues[0] = "First Value";
acceptableValues[1] = "Second Value";

AllowedEditor[] memory allowedEditorRoles = new AllowedEditor[](2);
allowedEditorRoles[0] = AllowedEditor.Self;
allowedEditorRoles[1] = AllowedEditor.TokenOwner;

Editors editors = EditorsLib.aggregate(allowedEditorRoles);

TraitLabel memory label = TraitLabel({
fullTraitKey: "Script test trait",
traitLabel: "Script test trait",
acceptableValues: acceptableValues,
fullTraitValues: new FullTraitValue[](0),
displayType: DisplayType.String,
editors: editors,
required: false
});

// Call the function to add the new label.
vm.broadcast();
targetContract.setTraitLabel(bytes32("test.scriptTest"), label);
}
}
Loading

0 comments on commit c5f21a3

Please sign in to comment.