Skip to content

Commit

Permalink
coverage for IShipyardContractMetadata, more misc coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanio committed Nov 15, 2023
1 parent 2a4e69d commit ed195d5
Show file tree
Hide file tree
Showing 19 changed files with 299 additions and 124 deletions.
1 change: 0 additions & 1 deletion script/DeployAndConfigure1155Receive.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {OfferItem, ConsiderationItem} from "seaport-types/src/lib/ConsiderationS
import {Campaign, CampaignParams, CampaignRequirements} from "../src/lib/RedeemablesStructs.sol";
import {BURN_ADDRESS} from "../src/lib/RedeemablesConstants.sol";
import {ERC721ShipyardRedeemableMintable} from "../src/extensions/ERC721ShipyardRedeemableMintable.sol";
import {ERC721OwnerMintable} from "../src/test/ERC721OwnerMintable.sol";
import {ERC1155ShipyardRedeemableMintable} from "../src/extensions/ERC1155ShipyardRedeemableMintable.sol";

contract DeployAndConfigure1155Receive is Script, Test {
Expand Down
8 changes: 4 additions & 4 deletions script/DeployAndRedeemTokens-CampaignOnReceiveToken.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ import {OfferItem, ConsiderationItem} from "seaport-types/src/lib/ConsiderationS
import {Campaign, CampaignParams, CampaignRequirements} from "../src/lib/RedeemablesStructs.sol";
import {BURN_ADDRESS} from "../src/lib/RedeemablesConstants.sol";
import {ERC721ShipyardRedeemableMintable} from "../src/extensions/ERC721ShipyardRedeemableMintable.sol";
import {ERC721OwnerMintable} from "../src/test/ERC721OwnerMintable.sol";
import {ERC721ShipyardRedeemableMintable} from "../src/extensions/ERC721ShipyardRedeemableMintable.sol";
import {ERC721ShipyardRedeemableOwnerMintable} from "../src/test/ERC721ShipyardRedeemableOwnerMintable.sol";

contract DeployAndRedeemTokens_CampaignOnReceiveToken is Script, Test {
function run() external {
vm.startBroadcast();

ERC721OwnerMintable redeemToken = new ERC721OwnerMintable();
ERC721ShipyardRedeemableOwnerMintable redeemToken =
new ERC721ShipyardRedeemableOwnerMintable("TestRedeemablesRedeemToken", "TEST-RDM");
ERC721ShipyardRedeemableMintable receiveToken =
new ERC721ShipyardRedeemableMintable("TestRedeemablesReceiveToken", "TEST");
new ERC721ShipyardRedeemableMintable("TestRedeemablesReceiveToken", "TEST-RCV");

// Configure the campaign.
OfferItem[] memory offer = new OfferItem[](1);
Expand Down
1 change: 0 additions & 1 deletion script/DeployAndRedeemTrait.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {OfferItem, ConsiderationItem} from "seaport-types/src/lib/ConsiderationS
import {IERC7496} from "shipyard-core/src/dynamic-traits/interfaces/IERC7496.sol";
import {Campaign, CampaignParams, CampaignRequirements, TraitRedemption} from "../src/lib/RedeemablesStructs.sol";
import {ERC721ShipyardRedeemableMintable} from "../src/extensions/ERC721ShipyardRedeemableMintable.sol";
import {ERC721ShipyardRedeemableMintable} from "../src/extensions/ERC721ShipyardRedeemableMintable.sol";
import {ERC721ShipyardRedeemableTraitSetters} from "../src/test/ERC721ShipyardRedeemableTraitSetters.sol";

contract DeployAndRedeemTrait is Script, Test {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import {OfferItem, ConsiderationItem} from "seaport-types/src/lib/ConsiderationS
import {Campaign, CampaignParams, CampaignRequirements} from "../src/lib/RedeemablesStructs.sol";
import {BURN_ADDRESS} from "../src/lib/RedeemablesConstants.sol";
import {ERC721ShipyardRedeemableMintable} from "../src/extensions/ERC721ShipyardRedeemableMintable.sol";
import {ERC721OwnerMintable} from "../src/test/ERC721OwnerMintable.sol";
import {ERC721ShipyardRedeemableMintable} from "../src/extensions/ERC721ShipyardRedeemableMintable.sol";
import {ERC721ShipyardRedeemableOwnerMintable} from "../src/test/ERC721ShipyardRedeemableOwnerMintable.sol";

contract DeployERC721ReceiveTokenWithPredeployedSeaDropRedeemToken is Script, Test {
function run() external {
Expand Down
2 changes: 1 addition & 1 deletion script/RedeemTokens.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {ItemType} from "seaport-types/src/lib/ConsiderationEnums.sol";
import {OfferItem, ConsiderationItem} from "seaport-types/src/lib/ConsiderationStructs.sol";
import {CampaignParams, CampaignRequirements} from "../src/lib/RedeemablesStructs.sol";
import {ERC721ShipyardRedeemableMintable} from "../src/extensions/ERC721ShipyardRedeemableMintable.sol";
import {ERC721OwnerMintable} from "../src/test/ERC721OwnerMintable.sol";
import {ERC721ShipyardRedeemableOwnerMintable} from "../src/test/ERC721ShipyardRedeemableOwnerMintable.sol";
import {ERC1155ShipyardRedeemableMintable} from "../src/extensions/ERC1155ShipyardRedeemableMintable.sol";

contract RedeemTokens is Script, Test {
Expand Down
10 changes: 0 additions & 10 deletions src/ERC1155SeaDropRedeemable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,6 @@ contract ERC1155SeaDropRedeemable is ERC1155SeaDrop, ERC7498NFTRedeemables {
DynamicTraits.setTrait(tokenId, traitKey, value);
}

function getTraitValue(uint256 tokenId, bytes32 traitKey)
public
view
virtual
override
returns (bytes32 traitValue)
{
traitValue = DynamicTraits.getTraitValue(tokenId, traitKey);
}

function _useInternalBurn() internal pure virtual override returns (bool) {
return true;
}
Expand Down
10 changes: 0 additions & 10 deletions src/ERC1155ShipyardRedeemable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,6 @@ contract ERC1155ShipyardRedeemable is ERC1155ShipyardContractMetadata, ERC7498NF
DynamicTraits.setTrait(tokenId, traitKey, value);
}

function getTraitValue(uint256 tokenId, bytes32 traitKey)
public
view
virtual
override
returns (bytes32 traitValue)
{
traitValue = DynamicTraits.getTraitValue(tokenId, traitKey);
}

function _useInternalBurn() internal pure virtual override returns (bool) {
return true;
}
Expand Down
12 changes: 12 additions & 0 deletions src/ERC721SeaDropRedeemable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ contract ERC721SeaDropRedeemable is ERC721SeaDrop, ERC7498NFTRedeemables {
traitValue = DynamicTraits.getTraitValue(tokenId, traitKey);
}

function getTraitValues(uint256 tokenId, bytes32[] calldata traitKeys)
public
view
virtual
override
returns (bytes32[] memory traitValues)
{
if (!_exists(tokenId)) revert TokenDoesNotExist();

traitValues = DynamicTraits.getTraitValues(tokenId, traitKeys);
}

function _useInternalBurn() internal pure virtual override returns (bool) {
return true;
}
Expand Down
12 changes: 12 additions & 0 deletions src/ERC721ShipyardRedeemable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ contract ERC721ShipyardRedeemable is ERC721ShipyardContractMetadata, ERC7498NFTR
traitValue = DynamicTraits.getTraitValue(tokenId, traitKey);
}

function getTraitValues(uint256 tokenId, bytes32[] calldata traitKeys)
public
view
virtual
override
returns (bytes32[] memory traitValues)
{
if (!_exists(tokenId)) revert TokenDoesNotExist();

traitValues = DynamicTraits.getTraitValues(tokenId, traitKeys);
}

function _useInternalBurn() internal pure virtual override returns (bool) {
return true;
}
Expand Down
37 changes: 37 additions & 0 deletions src/interfaces/IShipyardContractMetadata.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

interface IShipyardContractMetadata {
/// @dev Emit an event for token metadata reveals/updates, according to EIP-4906.
event BatchMetadataUpdate(uint256 _fromTokenId, uint256 _toTokenId);

/// @dev Emit an event when the URI for the collection-level metadata is updated.
event ContractURIUpdated(string uri);

/// @dev Emit an event when the provenance hash is updated.
event ProvenanceHashUpdated(bytes32 oldProvenanceHash, bytes32 newProvenanceHash);

/// @dev Emit an event when the royalties info is updated.
event RoyaltyInfoUpdated(address receiver, uint256 basisPoints);

/// @dev Revert with an error when attempting to set the provenance hash after it has already been set.
error ProvenanceHashCannotBeSetAfterAlreadyBeingSet();

function name() external view returns (string memory);

function symbol() external view returns (string memory);

function baseURI() external view returns (string memory);

function contractURI() external view returns (string memory);

function provenanceHash() external view returns (bytes32);

function setBaseURI(string calldata newURI) external;

function setContractURI(string calldata newURI) external;

function setProvenanceHash(bytes32 newProvenanceHash) external;

function setDefaultRoyalty(address receiver, uint96 feeNumerator) external;
}
25 changes: 8 additions & 17 deletions src/lib/ERC1155ShipyardContractMetadata.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ import {ERC1155ConduitPreapproved_Solady} from "shipyard-core/src/tokens/erc1155
import {ERC1155} from "solady/src/tokens/ERC1155.sol";
import {ERC2981} from "solady/src/tokens/ERC2981.sol";
import {Ownable} from "solady/src/auth/Ownable.sol";

contract ERC1155ShipyardContractMetadata is ERC1155ConduitPreapproved_Solady, ERC2981, Ownable {
import {IShipyardContractMetadata} from "../interfaces/IShipyardContractMetadata.sol";

contract ERC1155ShipyardContractMetadata is
ERC1155ConduitPreapproved_Solady,
IShipyardContractMetadata,
ERC2981,
Ownable
{
/// @dev The token name
string internal _name;

Expand All @@ -22,21 +28,6 @@ contract ERC1155ShipyardContractMetadata is ERC1155ConduitPreapproved_Solady, ER
/// @dev The provenance hash for guaranteeing metadata order for random reveals.
bytes32 public provenanceHash;

/// @dev Emit an event for token metadata reveals/updates, according to EIP-4906.
event BatchMetadataUpdate(uint256 _fromTokenId, uint256 _toTokenId);

/// @dev Emit an event when the URI for the collection-level metadata is updated.
event ContractURIUpdated(string uri);

/// @dev Emit an event when the provenance hash is updated.
event ProvenanceHashUpdated(bytes32 oldProvenanceHash, bytes32 newProvenanceHash);

/// @dev Emit an event when the royalties info is updated.
event RoyaltyInfoUpdated(address receiver, uint256 bps);

/// @dev Revert with an error when attempting to set the provenance hash after it has already been set.
error ProvenanceHashCannotBeSetAfterAlreadyBeingSet();

constructor(string memory name_, string memory symbol_) ERC1155ConduitPreapproved_Solady() {
// Set the token name and symbol.
_name = name_;
Expand Down
29 changes: 10 additions & 19 deletions src/lib/ERC721ShipyardContractMetadata.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ import {ERC721ConduitPreapproved_Solady} from "shipyard-core/src/tokens/erc721/E
import {ERC721} from "solady/src/tokens/ERC721.sol";
import {ERC2981} from "solady/src/tokens/ERC2981.sol";
import {Ownable} from "solady/src/auth/Ownable.sol";

contract ERC721ShipyardContractMetadata is ERC721ConduitPreapproved_Solady, ERC2981, Ownable {
import {IShipyardContractMetadata} from "../interfaces/IShipyardContractMetadata.sol";

contract ERC721ShipyardContractMetadata is
ERC721ConduitPreapproved_Solady,
IShipyardContractMetadata,
ERC2981,
Ownable
{
/// @dev The token name
string internal _name;

Expand All @@ -22,21 +28,6 @@ contract ERC721ShipyardContractMetadata is ERC721ConduitPreapproved_Solady, ERC2
/// @dev The provenance hash for guaranteeing metadata order for random reveals.
bytes32 public provenanceHash;

/// @dev Emit an event for token metadata reveals/updates, according to EIP-4906.
event BatchMetadataUpdate(uint256 _fromTokenId, uint256 _toTokenId);

/// @dev Emit an event when the URI for the collection-level metadata is updated.
event ContractURIUpdated(string uri);

/// @dev Emit an event when the provenance hash is updated.
event ProvenanceHashUpdated(bytes32 oldProvenanceHash, bytes32 newProvenanceHash);

/// @dev Emit an event when the royalties info is updated.
event RoyaltyInfoUpdated(address receiver, uint256 bps);

/// @dev Revert with an error when attempting to set the provenance hash after it has already been set.
error ProvenanceHashCannotBeSetAfterAlreadyBeingSet();

constructor(string memory name_, string memory symbol_) ERC721ConduitPreapproved_Solady() {
// Set the token name and symbol.
_name = name_;
Expand All @@ -49,14 +40,14 @@ contract ERC721ShipyardContractMetadata is ERC721ConduitPreapproved_Solady, ERC2
/**
* @notice Returns the name of this token contract.
*/
function name() public view override returns (string memory) {
function name() public view override(ERC721, IShipyardContractMetadata) returns (string memory) {
return _name;
}

/**
* @notice Returns the symbol of this token contract.
*/
function symbol() public view override returns (string memory) {
function symbol() public view override(ERC721, IShipyardContractMetadata) returns (string memory) {
return _symbol;
}

Expand Down
43 changes: 0 additions & 43 deletions src/test/ERC721OwnerMintable.sol

This file was deleted.

12 changes: 0 additions & 12 deletions src/test/ERC721ShipyardRedeemableTraitSetters.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,6 @@ contract ERC721ShipyardRedeemableTraitSetters is ERC721ShipyardRedeemableOwnerMi
DynamicTraits.setTrait(tokenId, traitKey, value);
}

function getTraitValue(uint256 tokenId, bytes32 traitKey)
public
view
virtual
override
returns (bytes32 traitValue)
{
if (!_exists(tokenId)) revert TokenDoesNotExist();

traitValue = DynamicTraits.getTraitValue(tokenId, traitKey);
}

function _requireAllowedTraitSetter() internal view {
// Allow the contract to call itself.
if (msg.sender == address(this)) return;
Expand Down
6 changes: 5 additions & 1 deletion test/ERC7498-RedemptionMintable.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {BaseRedeemablesTest} from "./utils/BaseRedeemablesTest.sol";
import {OfferItem, ConsiderationItem} from "seaport-types/src/lib/ConsiderationStructs.sol";
import {OfferItemLib} from "seaport-sol/src/lib/OfferItemLib.sol";
import {ConsiderationItemLib} from "seaport-sol/src/lib/ConsiderationItemLib.sol";
import {IRedemptionMintable} from "src/interfaces/IRedemptionMintable.sol";
import {IERC7498} from "../src/interfaces/IERC7498.sol";
import {IRedemptionMintable} from "../src/interfaces/IRedemptionMintable.sol";

contract TestERC7498_RedemptionMintable is BaseRedeemablesTest {
using OfferItemLib for OfferItem;
Expand All @@ -16,5 +17,8 @@ contract TestERC7498_RedemptionMintable is BaseRedeemablesTest {
function testSupportsInterfaceId() public {
assertTrue(receiveToken721.supportsInterface(type(IRedemptionMintable).interfaceId));
assertTrue(receiveToken1155.supportsInterface(type(IRedemptionMintable).interfaceId));

assertTrue(receiveToken721.supportsInterface(type(IERC7498).interfaceId));
assertTrue(receiveToken1155.supportsInterface(type(IERC7498).interfaceId));
}
}
14 changes: 14 additions & 0 deletions test/ERC7498-SimpleRedeem.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ contract ERC7498_SimpleRedeem is BaseRedeemablesTest {
campaign.params.endTime = uint32(block.timestamp + 1000);
context.erc7498Token.updateCampaign(campaignId, campaign, "");

// Clear the receiveToken mintRedemption allowed callers to check for error coverage.
receiveToken721.setRedeemablesContracts(new address[](0));
vm.expectRevert(abi.encodeWithSelector(InvalidCaller.selector, address(context.erc7498Token)));
context.erc7498Token.redeem(considerationTokenIds, address(0), extraData);
// Re-add allowed callers
receiveToken721.setRedeemablesContracts(erc7498Tokens);

vm.expectEmit(true, true, true, true);
emit Redemption(1, 0, bytes32(0), considerationTokenIds, defaultTraitRedemptionTokenIds, address(this));
// Using address(0) for recipient should assign to msg.sender.
Expand Down Expand Up @@ -352,6 +359,13 @@ contract ERC7498_SimpleRedeem is BaseRedeemablesTest {
);
uint256[] memory considerationTokenIds = Solarray.uint256s(tokenId);

// Clear the receiveToken mintRedemption allowed callers to check for error coverage.
receiveToken1155.setRedeemablesContracts(new address[](0));
vm.expectRevert(abi.encodeWithSelector(InvalidCaller.selector, erc7498Tokens[0]));
IERC7498(erc7498Tokens[0]).redeem(considerationTokenIds, address(0), extraData);
// Re-add allowed callers
receiveToken1155.setRedeemablesContracts(erc7498Tokens);

vm.expectEmit(true, true, true, true);
emit Redemption(1, 0, bytes32(0), considerationTokenIds, defaultTraitRedemptionTokenIds, address(this));
IERC7498(erc7498Tokens[0]).redeem(considerationTokenIds, address(this), extraData);
Expand Down
Loading

0 comments on commit ed195d5

Please sign in to comment.