Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
stephankmin committed Nov 1, 2023
1 parent dd0d99f commit dc41bb1
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 363 deletions.
44 changes: 11 additions & 33 deletions test/ERC7498-DynamicTraits.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import {CampaignParams, CampaignRequirements, TraitRedemption} from "../src/lib/
import {ERC721RedemptionMintable} from "../src/extensions/ERC721RedemptionMintable.sol";
import {ERC721ShipyardRedeemableOwnerMintable} from "../src/test/ERC721ShipyardRedeemableOwnerMintable.sol";
import {ERC1155ShipyardRedeemableOwnerMintable} from "../src/test/ERC1155ShipyardRedeemableOwnerMintable.sol";
import {ERC721ShipyardRedeemablePreapprovedTraitSetters} from "../src/test/ERC721ShipyardRedeemablePreapprovedTraitSetters.sol";
import {ERC721ShipyardRedeemablePreapprovedTraitSetters} from
"../src/test/ERC721ShipyardRedeemablePreapprovedTraitSetters.sol";
import {ERC1155ShipyardRedeemableMintable} from "../src/extensions/ERC1155ShipyardRedeemableMintable.sol";

contract ERC7498_DynamicTraits is BaseRedeemablesTest {
Expand All @@ -47,12 +48,9 @@ contract ERC7498_DynamicTraits is BaseRedeemablesTest {

function testErc721TraitRedemptionForErc721() public {
for (uint256 i; i < erc7498Tokens.length; i++) {
bool isErc7498Token721 = IERC165(address(erc7498Tokens[i]))
.supportsInterface(type(IERC721).interfaceId);
bool isErc7498Token721 = IERC165(address(erc7498Tokens[i])).supportsInterface(type(IERC721).interfaceId);

bool isErc7498TokenSeaDrop = _isErc7498TokenSeaDrop(
address(erc7498Tokens[i])
);
bool isErc7498TokenSeaDrop = _isErc7498TokenSeaDrop(address(erc7498Tokens[i]));
testRedeemable(
this.erc721TraitRedemptionSubstandardOneForErc721,
RedeemablesContext({
Expand All @@ -64,13 +62,12 @@ contract ERC7498_DynamicTraits is BaseRedeemablesTest {
}
}

function erc721TraitRedemptionSubstandardOneForErc721(
RedeemablesContext memory context
) public {
function erc721TraitRedemptionSubstandardOneForErc721(RedeemablesContext memory context) public {
address[] memory allowedTraitSetters = new address[](1);
allowedTraitSetters[0] = address(context.erc7498Token);

ERC721ShipyardRedeemablePreapprovedTraitSetters redeemToken = new ERC721ShipyardRedeemablePreapprovedTraitSetters(
ERC721ShipyardRedeemablePreapprovedTraitSetters redeemToken =
new ERC721ShipyardRedeemablePreapprovedTraitSetters(
"",
"",
allowedTraitSetters
Expand Down Expand Up @@ -126,33 +123,14 @@ contract ERC7498_DynamicTraits is BaseRedeemablesTest {
// traitRedemptionTokenIds: traitRedemptionTokenIds
// salt: 0
// signature: bytes(0)
bytes memory extraData = abi.encode(
1,
0,
bytes32(0),
traitRedemptionTokenIds,
uint256(0),
bytes("")
);
bytes memory extraData = abi.encode(1, 0, bytes32(0), traitRedemptionTokenIds, uint256(0), bytes(""));

vm.expectEmit(true, true, true, true);
emit Redemption(
1,
0,
bytes32(0),
considerationTokenIds,
traitRedemptionTokenIds,
address(this)
);
emit Redemption(1, 0, bytes32(0), considerationTokenIds, traitRedemptionTokenIds, address(this));

context.erc7498Token.redeem(
considerationTokenIds,
address(this),
extraData
);
context.erc7498Token.redeem(considerationTokenIds, address(this), extraData);

bytes32 actualTraitValue = DynamicTraits(address(redeemToken))
.getTraitValue(tokenId, traitKey);
bytes32 actualTraitValue = DynamicTraits(address(redeemToken)).getTraitValue(tokenId, traitKey);

assertEq(bytes32(uint256(1)), actualTraitValue);

Expand Down
106 changes: 22 additions & 84 deletions test/ERC7498-MultiRedeem.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,9 @@ contract ERC7498_MultiRedeem is BaseRedeemablesTest {

function testBurnMultiErc721OrErc1155RedeemSingleErc721() public {
for (uint256 i; i < erc7498Tokens.length; i++) {
bool isErc7498Token721 = IERC165(address(erc7498Tokens[i]))
.supportsInterface(type(IERC721).interfaceId);
bool isErc7498Token721 = IERC165(address(erc7498Tokens[i])).supportsInterface(type(IERC721).interfaceId);

bool isErc7498TokenSeaDrop = _isErc7498TokenSeaDrop(
address(erc7498Tokens[i])
);
bool isErc7498TokenSeaDrop = _isErc7498TokenSeaDrop(address(erc7498Tokens[i]));
testRedeemable(
this.burnMultiErc721OrErc1155RedeemSingleErc721,
RedeemablesContext({
Expand All @@ -62,13 +59,10 @@ contract ERC7498_MultiRedeem is BaseRedeemablesTest {
}
}

function burnMultiErc721OrErc1155RedeemSingleErc721(
RedeemablesContext memory context
) public {
function burnMultiErc721OrErc1155RedeemSingleErc721(RedeemablesContext memory context) public {
address secondRedeemTokenAddress;
if (context.isErc7498Token721) {
ERC721ShipyardRedeemableOwnerMintable(address(context.erc7498Token))
.mint(address(this), tokenId);
ERC721ShipyardRedeemableOwnerMintable(address(context.erc7498Token)).mint(address(this), tokenId);

ERC721ShipyardRedeemableOwnerMintable secondRedeemToken721 = new ERC721ShipyardRedeemableOwnerMintable(
"",
Expand All @@ -78,24 +72,16 @@ contract ERC7498_MultiRedeem is BaseRedeemablesTest {
secondRedeemToken721.mint(address(this), tokenId);

vm.label(address(secondRedeemToken721), "secondRedeemToken721");
secondRedeemToken721.setApprovalForAll(
address(context.erc7498Token),
true
);
secondRedeemToken721.setApprovalForAll(address(context.erc7498Token), true);
} else {
ERC1155ShipyardRedeemableOwnerMintable(
address(context.erc7498Token)
).mint(address(this), tokenId, 1);
ERC1155ShipyardRedeemableOwnerMintable(address(context.erc7498Token)).mint(address(this), tokenId, 1);
ERC1155ShipyardRedeemableOwnerMintable secondRedeemToken1155 = new ERC1155ShipyardRedeemableOwnerMintable(
"",
""
);
secondRedeemTokenAddress = address(secondRedeemToken1155);
secondRedeemToken1155.mint(address(this), tokenId, 1);
secondRedeemToken1155.setApprovalForAll(
address(context.erc7498Token),
true
);
secondRedeemToken1155.setApprovalForAll(address(context.erc7498Token), true);
}

ERC721RedemptionMintable receiveToken = new ERC721RedemptionMintable(
Expand All @@ -105,14 +91,8 @@ contract ERC7498_MultiRedeem is BaseRedeemablesTest {
);

ConsiderationItem[] memory consideration = new ConsiderationItem[](2);
consideration[0] = _getCampaignConsiderationItem(
address(context.erc7498Token),
context.isErc7498Token721
);
consideration[1] = _getCampaignConsiderationItem(
secondRedeemTokenAddress,
context.isErc7498Token721
);
consideration[0] = _getCampaignConsiderationItem(address(context.erc7498Token), context.isErc7498Token721);
consideration[1] = _getCampaignConsiderationItem(secondRedeemTokenAddress, context.isErc7498Token721);

CampaignRequirements[] memory requirements = new CampaignRequirements[](
1
Expand All @@ -135,49 +115,28 @@ contract ERC7498_MultiRedeem is BaseRedeemablesTest {
// campaignId: 1
// requirementsIndex: 0
// redemptionHash: bytes32(0)
bytes memory extraData = abi.encode(
1,
0,
bytes32(0),
defaultTraitRedemptionTokenIds,
uint256(0),
bytes("")
);
bytes memory extraData = abi.encode(1, 0, bytes32(0), defaultTraitRedemptionTokenIds, uint256(0), bytes(""));
consideration[0].identifierOrCriteria = tokenId;

uint256[] memory tokenIds = Solarray.uint256s(tokenId, tokenId);

IERC7498(context.erc7498Token).redeem(
tokenIds,
address(this),
extraData
);
IERC7498(context.erc7498Token).redeem(tokenIds, address(this), extraData);

_checkTokenDoesNotExist(
address(context.erc7498Token),
tokenId,
context.isErc7498Token721,
context.isErc7498TokenSeaDrop
address(context.erc7498Token), tokenId, context.isErc7498Token721, context.isErc7498TokenSeaDrop
);

_checkTokenSentToBurnAddress(
secondRedeemTokenAddress,
tokenId,
context.isErc7498Token721
);
_checkTokenSentToBurnAddress(secondRedeemTokenAddress, tokenId, context.isErc7498Token721);

assertEq(receiveToken.ownerOf(1), address(this));
assertEq(receiveToken.balanceOf(address(this)), 1);
}

function testBurnOneErc721OrErc1155RedeemMultiErc1155() public {
for (uint256 i; i < erc7498Tokens.length; i++) {
bool isErc7498Token721 = IERC165(address(erc7498Tokens[i]))
.supportsInterface(type(IERC721).interfaceId);
bool isErc7498Token721 = IERC165(address(erc7498Tokens[i])).supportsInterface(type(IERC721).interfaceId);

bool isErc7498TokenSeaDrop = _isErc7498TokenSeaDrop(
address(erc7498Tokens[i])
);
bool isErc7498TokenSeaDrop = _isErc7498TokenSeaDrop(address(erc7498Tokens[i]));
testRedeemable(
this.burnOneErc721OrErc1155RedeemMultiErc1155,
RedeemablesContext({
Expand All @@ -189,26 +148,18 @@ contract ERC7498_MultiRedeem is BaseRedeemablesTest {
}
}

function burnOneErc721OrErc1155RedeemMultiErc1155(
RedeemablesContext memory context
) public {
function burnOneErc721OrErc1155RedeemMultiErc1155(RedeemablesContext memory context) public {
if (context.isErc7498Token721) {
ERC721ShipyardRedeemableOwnerMintable(address(context.erc7498Token))
.mint(address(this), tokenId);
ERC721ShipyardRedeemableOwnerMintable(address(context.erc7498Token)).mint(address(this), tokenId);
} else {
ERC1155ShipyardRedeemableOwnerMintable(
address(context.erc7498Token)
).mint(address(this), tokenId, 1);
ERC1155ShipyardRedeemableOwnerMintable(address(context.erc7498Token)).mint(address(this), tokenId, 1);
}

ERC1155ShipyardRedeemableMintable receiveToken = new ERC1155ShipyardRedeemableMintable(
"TestRedeemablesReceive1155SequentialIds",
"TEST"
);
ERC721(address(context.erc7498Token)).setApprovalForAll(
address(receiveToken),
true
);
ERC721(address(context.erc7498Token)).setApprovalForAll(address(receiveToken), true);

OfferItem[] memory offer = new OfferItem[](3);
offer[0] = OfferItem({
Expand All @@ -234,10 +185,7 @@ contract ERC7498_MultiRedeem is BaseRedeemablesTest {
});

ConsiderationItem[] memory consideration = new ConsiderationItem[](1);
consideration[0] = _getCampaignConsiderationItem(
address(context.erc7498Token),
context.isErc7498Token721
);
consideration[0] = _getCampaignConsiderationItem(address(context.erc7498Token), context.isErc7498Token721);

CampaignRequirements[] memory requirements = new CampaignRequirements[](
1
Expand All @@ -258,25 +206,15 @@ contract ERC7498_MultiRedeem is BaseRedeemablesTest {
// campaignId: 1
// requirementsIndex: 0
// redemptionHash: bytes32(0)
bytes memory extraData = abi.encode(
1,
0,
bytes32(0),
defaultTraitRedemptionTokenIds,
uint256(0),
bytes("")
);
bytes memory extraData = abi.encode(1, 0, bytes32(0), defaultTraitRedemptionTokenIds, uint256(0), bytes(""));
consideration[0].identifierOrCriteria = tokenId;

uint256[] memory tokenIds = Solarray.uint256s(tokenId);

IERC7498(receiveToken).redeem(tokenIds, address(this), extraData);

_checkTokenDoesNotExist(
address(context.erc7498Token),
tokenId,
context.isErc7498Token721,
context.isErc7498TokenSeaDrop
address(context.erc7498Token), tokenId, context.isErc7498Token721, context.isErc7498TokenSeaDrop
);

assertEq(receiveToken.balanceOf(address(this), 1), 1);
Expand Down
Loading

0 comments on commit dc41bb1

Please sign in to comment.