Skip to content

BTT TokenERC1155 #552

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
148 changes: 148 additions & 0 deletions src/test/tokenerc1155-BTT/burn-batch/burnBatch.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;

import "../../utils/BaseTest.sol";

import { TWProxy } from "contracts/infra/TWProxy.sol";

contract MyTokenERC1155 is TokenERC1155 {}

contract TokenERC1155Test_BurnBatch is BaseTest {
address public implementation;
address public proxy;
address public caller;
address public recipient;
string public uri;
uint256 public amount;

MyTokenERC1155 internal tokenContract;

function setUp() public override {
super.setUp();

// Deploy implementation.
implementation = address(new MyTokenERC1155());
caller = getActor(1);
recipient = getActor(2);

// Deploy proxy pointing to implementaion.
vm.prank(deployer);
proxy = address(
new TWProxy(
implementation,
abi.encodeCall(
TokenERC1155.initialize,
(
deployer,
NAME,
SYMBOL,
CONTRACT_URI,
forwarders(),
saleRecipient,
royaltyRecipient,
royaltyBps,
platformFeeBps,
platformFeeRecipient
)
)
)
);

tokenContract = MyTokenERC1155(proxy);
uri = "uri";
amount = 100;

vm.prank(deployer);
tokenContract.grantRole(keccak256("MINTER_ROLE"), caller);
}

function test_burn_whenNotOwnerNorApproved() public {
// mint two tokenIds
vm.startPrank(caller);
tokenContract.mintTo(recipient, type(uint256).max, uri, amount);
tokenContract.mintTo(recipient, type(uint256).max, uri, amount);
vm.stopPrank();

uint256[] memory ids = new uint256[](2);
uint256[] memory amounts = new uint256[](2);

ids[0] = 0;
ids[1] = 1;
amounts[0] = 10;
amounts[1] = 10;

// burn
vm.expectRevert("ERC1155: caller is not owner nor approved.");
tokenContract.burnBatch(recipient, ids, amounts);
}

function test_burn_whenOwner_invalidAmount() public {
// mint two tokenIds
vm.startPrank(caller);
tokenContract.mintTo(recipient, type(uint256).max, uri, amount);
tokenContract.mintTo(recipient, type(uint256).max, uri, amount);
vm.stopPrank();

uint256[] memory ids = new uint256[](2);
uint256[] memory amounts = new uint256[](2);

ids[0] = 0;
ids[1] = 1;
amounts[0] = 1000 ether;
amounts[1] = 10;

// burn
vm.prank(recipient);
vm.expectRevert();
tokenContract.burnBatch(recipient, ids, amounts);
}

function test_burn_whenOwner() public {
// mint two tokenIds
vm.startPrank(caller);
tokenContract.mintTo(recipient, type(uint256).max, uri, amount);
tokenContract.mintTo(recipient, type(uint256).max, uri, amount);
vm.stopPrank();

uint256[] memory ids = new uint256[](2);
uint256[] memory amounts = new uint256[](2);

ids[0] = 0;
ids[1] = 1;
amounts[0] = 10;
amounts[1] = 10;

// burn
vm.prank(recipient);
tokenContract.burnBatch(recipient, ids, amounts);

assertEq(tokenContract.balanceOf(recipient, ids[0]), amount - amounts[0]);
assertEq(tokenContract.balanceOf(recipient, ids[1]), amount - amounts[1]);
}

function test_burn_whenApproved() public {
// mint two tokenIds
vm.startPrank(caller);
tokenContract.mintTo(recipient, type(uint256).max, uri, amount);
tokenContract.mintTo(recipient, type(uint256).max, uri, amount);
vm.stopPrank();

uint256[] memory ids = new uint256[](2);
uint256[] memory amounts = new uint256[](2);

ids[0] = 0;
ids[1] = 1;
amounts[0] = 10;
amounts[1] = 10;

vm.prank(recipient);
tokenContract.setApprovalForAll(caller, true);

// burn
vm.prank(caller);
tokenContract.burnBatch(recipient, ids, amounts);

assertEq(tokenContract.balanceOf(recipient, ids[0]), amount - amounts[0]);
assertEq(tokenContract.balanceOf(recipient, ids[1]), amount - amounts[1]);
}
}
14 changes: 14 additions & 0 deletions src/test/tokenerc1155-BTT/burn-batch/burnBatch.tree
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
burnBatch(
address account,
uint256[] memory ids,
uint256[] memory values
)
├── when the caller isn't `account` or `account` hasn't approved tokens to caller
│ └── it should revert ✅
└── when the caller is `account` with balances less than `values` for corresponding `ids`
│ └── it should revert ✅
└── when the caller is `account` with balances greater than or equal to `values`
│ └── it should burn `values` amounts of `ids` tokens from account ✅
└── when the `account` has approved `values` amount of tokens to caller
└── it should burn the token ✅

121 changes: 121 additions & 0 deletions src/test/tokenerc1155-BTT/burn/burn.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;

import "../../utils/BaseTest.sol";

import { TWProxy } from "contracts/infra/TWProxy.sol";

contract MyTokenERC1155 is TokenERC1155 {}

contract TokenERC1155Test_Burn is BaseTest {
address public implementation;
address public proxy;
address public caller;
address public recipient;
string public uri;
uint256 public amount;

MyTokenERC1155 internal tokenContract;

event MetadataUpdate(uint256 _tokenId);
event TokensMinted(address indexed mintedTo, uint256 indexed tokenIdMinted, string uri);

function setUp() public override {
super.setUp();

// Deploy implementation.
implementation = address(new MyTokenERC1155());
caller = getActor(1);
recipient = getActor(2);

// Deploy proxy pointing to implementaion.
vm.prank(deployer);
proxy = address(
new TWProxy(
implementation,
abi.encodeCall(
TokenERC1155.initialize,
(
deployer,
NAME,
SYMBOL,
CONTRACT_URI,
forwarders(),
saleRecipient,
royaltyRecipient,
royaltyBps,
platformFeeBps,
platformFeeRecipient
)
)
)
);

tokenContract = MyTokenERC1155(proxy);
uri = "uri";
amount = 100;

vm.prank(deployer);
tokenContract.grantRole(keccak256("MINTER_ROLE"), caller);
}

function test_burn_whenNotOwnerNorApproved() public {
// state before
uint256 _tokenIdToMint = tokenContract.nextTokenIdToMint();

// mint
vm.prank(caller);
tokenContract.mintTo(recipient, type(uint256).max, uri, amount);

// burn
vm.expectRevert("ERC1155: caller is not owner nor approved.");
tokenContract.burn(recipient, _tokenIdToMint, amount);
}

function test_burn_whenOwner_invalidAmount() public {
// state before
uint256 _tokenIdToMint = tokenContract.nextTokenIdToMint();

// mint
vm.prank(caller);
tokenContract.mintTo(recipient, type(uint256).max, uri, amount);

// burn
vm.prank(recipient);
vm.expectRevert();
tokenContract.burn(recipient, _tokenIdToMint, amount + 1);
}

function test_burn_whenOwner() public {
// state before
uint256 _tokenIdToMint = tokenContract.nextTokenIdToMint();

// mint
vm.prank(caller);
tokenContract.mintTo(recipient, type(uint256).max, uri, amount);

// burn
vm.prank(recipient);
tokenContract.burn(recipient, _tokenIdToMint, amount);

assertEq(tokenContract.balanceOf(recipient, _tokenIdToMint), 0);
}

function test_burn_whenApproved() public {
// state before
uint256 _tokenIdToMint = tokenContract.nextTokenIdToMint();

// mint
vm.prank(caller);
tokenContract.mintTo(recipient, type(uint256).max, uri, amount);

vm.prank(recipient);
tokenContract.setApprovalForAll(caller, true);

// burn
vm.prank(caller);
tokenContract.burn(recipient, _tokenIdToMint, amount);

assertEq(tokenContract.balanceOf(recipient, _tokenIdToMint), 0);
}
}
14 changes: 14 additions & 0 deletions src/test/tokenerc1155-BTT/burn/burn.tree
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
burn(
address account,
uint256 id,
uint256 value
)
├── when the caller isn't `account` or `account` hasn't approved tokens to caller
│ └── it should revert ✅
└── when the caller is `account` with balance less than `value`
│ └── it should revert ✅
└── when the caller is `account` with balance greater than or equal to `value`
│ └── it should burn `value` amount of `id` tokens from ✅
└── when the `account` has approved `value` amount of tokens to caller
└── it should burn the token ✅

Loading