Skip to content

Commit 6a6771b

Browse files
authored
BTT TokenERC1155 (#552)
* test initialize * test burn * test mintTo * test other functions * test owner * test setContractURI * test uri * test setRoyaltyInfoForToken * test setPrimarySaleRecipient * test setOwner * test setDefaultRoyaltyInfo * test verify * test setPlatformFeeInfo * test setFlatPlatformFeeInfo * test setPlatformFeeType * test mintWithSignature * test burnBatch --------- Signed-off-by: Yash <72552910+kumaryash90@users.noreply.github.com>
1 parent 1ad2caa commit 6a6771b

34 files changed

+3383
-0
lines changed
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity ^0.8.0;
3+
4+
import "../../utils/BaseTest.sol";
5+
6+
import { TWProxy } from "contracts/infra/TWProxy.sol";
7+
8+
contract MyTokenERC1155 is TokenERC1155 {}
9+
10+
contract TokenERC1155Test_BurnBatch is BaseTest {
11+
address public implementation;
12+
address public proxy;
13+
address public caller;
14+
address public recipient;
15+
string public uri;
16+
uint256 public amount;
17+
18+
MyTokenERC1155 internal tokenContract;
19+
20+
function setUp() public override {
21+
super.setUp();
22+
23+
// Deploy implementation.
24+
implementation = address(new MyTokenERC1155());
25+
caller = getActor(1);
26+
recipient = getActor(2);
27+
28+
// Deploy proxy pointing to implementaion.
29+
vm.prank(deployer);
30+
proxy = address(
31+
new TWProxy(
32+
implementation,
33+
abi.encodeCall(
34+
TokenERC1155.initialize,
35+
(
36+
deployer,
37+
NAME,
38+
SYMBOL,
39+
CONTRACT_URI,
40+
forwarders(),
41+
saleRecipient,
42+
royaltyRecipient,
43+
royaltyBps,
44+
platformFeeBps,
45+
platformFeeRecipient
46+
)
47+
)
48+
)
49+
);
50+
51+
tokenContract = MyTokenERC1155(proxy);
52+
uri = "uri";
53+
amount = 100;
54+
55+
vm.prank(deployer);
56+
tokenContract.grantRole(keccak256("MINTER_ROLE"), caller);
57+
}
58+
59+
function test_burn_whenNotOwnerNorApproved() public {
60+
// mint two tokenIds
61+
vm.startPrank(caller);
62+
tokenContract.mintTo(recipient, type(uint256).max, uri, amount);
63+
tokenContract.mintTo(recipient, type(uint256).max, uri, amount);
64+
vm.stopPrank();
65+
66+
uint256[] memory ids = new uint256[](2);
67+
uint256[] memory amounts = new uint256[](2);
68+
69+
ids[0] = 0;
70+
ids[1] = 1;
71+
amounts[0] = 10;
72+
amounts[1] = 10;
73+
74+
// burn
75+
vm.expectRevert("ERC1155: caller is not owner nor approved.");
76+
tokenContract.burnBatch(recipient, ids, amounts);
77+
}
78+
79+
function test_burn_whenOwner_invalidAmount() public {
80+
// mint two tokenIds
81+
vm.startPrank(caller);
82+
tokenContract.mintTo(recipient, type(uint256).max, uri, amount);
83+
tokenContract.mintTo(recipient, type(uint256).max, uri, amount);
84+
vm.stopPrank();
85+
86+
uint256[] memory ids = new uint256[](2);
87+
uint256[] memory amounts = new uint256[](2);
88+
89+
ids[0] = 0;
90+
ids[1] = 1;
91+
amounts[0] = 1000 ether;
92+
amounts[1] = 10;
93+
94+
// burn
95+
vm.prank(recipient);
96+
vm.expectRevert();
97+
tokenContract.burnBatch(recipient, ids, amounts);
98+
}
99+
100+
function test_burn_whenOwner() public {
101+
// mint two tokenIds
102+
vm.startPrank(caller);
103+
tokenContract.mintTo(recipient, type(uint256).max, uri, amount);
104+
tokenContract.mintTo(recipient, type(uint256).max, uri, amount);
105+
vm.stopPrank();
106+
107+
uint256[] memory ids = new uint256[](2);
108+
uint256[] memory amounts = new uint256[](2);
109+
110+
ids[0] = 0;
111+
ids[1] = 1;
112+
amounts[0] = 10;
113+
amounts[1] = 10;
114+
115+
// burn
116+
vm.prank(recipient);
117+
tokenContract.burnBatch(recipient, ids, amounts);
118+
119+
assertEq(tokenContract.balanceOf(recipient, ids[0]), amount - amounts[0]);
120+
assertEq(tokenContract.balanceOf(recipient, ids[1]), amount - amounts[1]);
121+
}
122+
123+
function test_burn_whenApproved() public {
124+
// mint two tokenIds
125+
vm.startPrank(caller);
126+
tokenContract.mintTo(recipient, type(uint256).max, uri, amount);
127+
tokenContract.mintTo(recipient, type(uint256).max, uri, amount);
128+
vm.stopPrank();
129+
130+
uint256[] memory ids = new uint256[](2);
131+
uint256[] memory amounts = new uint256[](2);
132+
133+
ids[0] = 0;
134+
ids[1] = 1;
135+
amounts[0] = 10;
136+
amounts[1] = 10;
137+
138+
vm.prank(recipient);
139+
tokenContract.setApprovalForAll(caller, true);
140+
141+
// burn
142+
vm.prank(caller);
143+
tokenContract.burnBatch(recipient, ids, amounts);
144+
145+
assertEq(tokenContract.balanceOf(recipient, ids[0]), amount - amounts[0]);
146+
assertEq(tokenContract.balanceOf(recipient, ids[1]), amount - amounts[1]);
147+
}
148+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
burnBatch(
2+
address account,
3+
uint256[] memory ids,
4+
uint256[] memory values
5+
)
6+
├── when the caller isn't `account` or `account` hasn't approved tokens to caller
7+
│ └── it should revert ✅
8+
└── when the caller is `account` with balances less than `values` for corresponding `ids`
9+
│ └── it should revert ✅
10+
└── when the caller is `account` with balances greater than or equal to `values`
11+
│ └── it should burn `values` amounts of `ids` tokens from account ✅
12+
└── when the `account` has approved `values` amount of tokens to caller
13+
└── it should burn the token ✅
14+
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity ^0.8.0;
3+
4+
import "../../utils/BaseTest.sol";
5+
6+
import { TWProxy } from "contracts/infra/TWProxy.sol";
7+
8+
contract MyTokenERC1155 is TokenERC1155 {}
9+
10+
contract TokenERC1155Test_Burn is BaseTest {
11+
address public implementation;
12+
address public proxy;
13+
address public caller;
14+
address public recipient;
15+
string public uri;
16+
uint256 public amount;
17+
18+
MyTokenERC1155 internal tokenContract;
19+
20+
event MetadataUpdate(uint256 _tokenId);
21+
event TokensMinted(address indexed mintedTo, uint256 indexed tokenIdMinted, string uri);
22+
23+
function setUp() public override {
24+
super.setUp();
25+
26+
// Deploy implementation.
27+
implementation = address(new MyTokenERC1155());
28+
caller = getActor(1);
29+
recipient = getActor(2);
30+
31+
// Deploy proxy pointing to implementaion.
32+
vm.prank(deployer);
33+
proxy = address(
34+
new TWProxy(
35+
implementation,
36+
abi.encodeCall(
37+
TokenERC1155.initialize,
38+
(
39+
deployer,
40+
NAME,
41+
SYMBOL,
42+
CONTRACT_URI,
43+
forwarders(),
44+
saleRecipient,
45+
royaltyRecipient,
46+
royaltyBps,
47+
platformFeeBps,
48+
platformFeeRecipient
49+
)
50+
)
51+
)
52+
);
53+
54+
tokenContract = MyTokenERC1155(proxy);
55+
uri = "uri";
56+
amount = 100;
57+
58+
vm.prank(deployer);
59+
tokenContract.grantRole(keccak256("MINTER_ROLE"), caller);
60+
}
61+
62+
function test_burn_whenNotOwnerNorApproved() public {
63+
// state before
64+
uint256 _tokenIdToMint = tokenContract.nextTokenIdToMint();
65+
66+
// mint
67+
vm.prank(caller);
68+
tokenContract.mintTo(recipient, type(uint256).max, uri, amount);
69+
70+
// burn
71+
vm.expectRevert("ERC1155: caller is not owner nor approved.");
72+
tokenContract.burn(recipient, _tokenIdToMint, amount);
73+
}
74+
75+
function test_burn_whenOwner_invalidAmount() public {
76+
// state before
77+
uint256 _tokenIdToMint = tokenContract.nextTokenIdToMint();
78+
79+
// mint
80+
vm.prank(caller);
81+
tokenContract.mintTo(recipient, type(uint256).max, uri, amount);
82+
83+
// burn
84+
vm.prank(recipient);
85+
vm.expectRevert();
86+
tokenContract.burn(recipient, _tokenIdToMint, amount + 1);
87+
}
88+
89+
function test_burn_whenOwner() public {
90+
// state before
91+
uint256 _tokenIdToMint = tokenContract.nextTokenIdToMint();
92+
93+
// mint
94+
vm.prank(caller);
95+
tokenContract.mintTo(recipient, type(uint256).max, uri, amount);
96+
97+
// burn
98+
vm.prank(recipient);
99+
tokenContract.burn(recipient, _tokenIdToMint, amount);
100+
101+
assertEq(tokenContract.balanceOf(recipient, _tokenIdToMint), 0);
102+
}
103+
104+
function test_burn_whenApproved() public {
105+
// state before
106+
uint256 _tokenIdToMint = tokenContract.nextTokenIdToMint();
107+
108+
// mint
109+
vm.prank(caller);
110+
tokenContract.mintTo(recipient, type(uint256).max, uri, amount);
111+
112+
vm.prank(recipient);
113+
tokenContract.setApprovalForAll(caller, true);
114+
115+
// burn
116+
vm.prank(caller);
117+
tokenContract.burn(recipient, _tokenIdToMint, amount);
118+
119+
assertEq(tokenContract.balanceOf(recipient, _tokenIdToMint), 0);
120+
}
121+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
burn(
2+
address account,
3+
uint256 id,
4+
uint256 value
5+
)
6+
├── when the caller isn't `account` or `account` hasn't approved tokens to caller
7+
│ └── it should revert ✅
8+
└── when the caller is `account` with balance less than `value`
9+
│ └── it should revert ✅
10+
└── when the caller is `account` with balance greater than or equal to `value`
11+
│ └── it should burn `value` amount of `id` tokens from ✅
12+
└── when the `account` has approved `value` amount of tokens to caller
13+
└── it should burn the token ✅
14+

0 commit comments

Comments
 (0)