-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from ProjectOpenSea/ryan/add-burn
add burn fns to shipyard redeemable
- Loading branch information
Showing
5 changed files
with
106 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.19; | ||
|
||
import {Solarray} from "solarray/Solarray.sol"; | ||
import {BaseRedeemablesTest} from "./utils/BaseRedeemablesTest.sol"; | ||
import {ERC1155} from "solady/src/tokens/ERC1155.sol"; | ||
import {ERC1155ShipyardRedeemableOwnerMintable} from "../src/test/ERC1155ShipyardRedeemableOwnerMintable.sol"; | ||
|
||
contract TestERC1155ShipyardRedeemable is BaseRedeemablesTest { | ||
event TransferBatch( | ||
address indexed operator, address indexed from, address indexed to, uint256[] ids, uint256[] amounts | ||
); | ||
|
||
function testBurn() public { | ||
uint256 tokenId = 1; | ||
ERC1155ShipyardRedeemableOwnerMintable token = new ERC1155ShipyardRedeemableOwnerMintable("Test", "TEST"); | ||
address fred = makeAddr("fred"); | ||
_mintToken(address(token), tokenId, fred); | ||
|
||
vm.expectRevert(ERC1155.InsufficientBalance.selector); | ||
token.burn(address(this), tokenId, 1); | ||
|
||
vm.expectEmit(true, true, true, true); | ||
emit TransferSingle(fred, fred, address(0), tokenId, 1); | ||
vm.prank(fred); | ||
token.burn(fred, tokenId, 1); | ||
|
||
vm.prank(fred); | ||
vm.expectRevert(ERC1155.InsufficientBalance.selector); | ||
token.burn(fred, tokenId + 1, 1); | ||
|
||
_mintToken(address(token), tokenId + 1, fred); | ||
_mintToken(address(token), tokenId + 2, fred); | ||
|
||
uint256[] memory ids = Solarray.uint256s(tokenId + 1, tokenId + 2); | ||
uint256[] memory amounts = Solarray.uint256s(1, 1); | ||
vm.expectRevert(ERC1155.NotOwnerNorApproved.selector); | ||
token.batchBurn(fred, ids, amounts); | ||
|
||
vm.prank(fred); | ||
token.setApprovalForAll(address(this), true); | ||
|
||
vm.expectEmit(true, true, true, true); | ||
emit TransferBatch(address(this), fred, address(0), ids, amounts); | ||
token.batchBurn(fred, ids, amounts); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.19; | ||
|
||
import {Test} from "forge-std/Test.sol"; | ||
import {ERC721} from "solady/src/tokens/ERC721.sol"; | ||
import {ERC721ShipyardRedeemableOwnerMintable} from "../src/test/ERC721ShipyardRedeemableOwnerMintable.sol"; | ||
|
||
contract TestERC721ShipyardRedeemable is Test { | ||
// This Transfer event is different than the one in BaseOrderTest, since `id` is indexed. | ||
// We don't inherit BaseRedeemablesTest to avoid this conflict. | ||
// For more details see https://github.com/ethereum/solidity/issues/4168#issuecomment-1819912098 | ||
event Transfer(address indexed from, address indexed to, uint256 indexed id); | ||
|
||
function testBurn() public { | ||
uint256 tokenId = 1; | ||
ERC721ShipyardRedeemableOwnerMintable token = new ERC721ShipyardRedeemableOwnerMintable("Test", "TEST"); | ||
address fred = makeAddr("fred"); | ||
_mintToken(address(token), tokenId, fred); | ||
|
||
vm.expectRevert(ERC721.NotOwnerNorApproved.selector); | ||
token.burn(tokenId); | ||
|
||
vm.expectEmit(true, true, false, false); | ||
emit Transfer(fred, address(0), tokenId); | ||
vm.prank(fred); | ||
token.burn(tokenId); | ||
|
||
vm.expectRevert(ERC721.TokenDoesNotExist.selector); | ||
token.burn(tokenId + 1); | ||
|
||
_mintToken(address(token), tokenId + 1, fred); | ||
vm.expectRevert(ERC721.NotOwnerNorApproved.selector); | ||
token.burn(tokenId + 1); | ||
|
||
vm.prank(fred); | ||
token.setApprovalForAll(address(this), true); | ||
|
||
vm.expectEmit(true, true, false, false); | ||
emit Transfer(fred, address(0), tokenId + 1); | ||
token.burn(tokenId + 1); | ||
} | ||
|
||
function _mintToken(address token, uint256 tokenId, address recipient) internal { | ||
ERC721ShipyardRedeemableOwnerMintable(address(token)).mint(recipient, tokenId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters