Skip to content

Commit e06a324

Browse files
authored
BTT: OpenEditionERC721 (#545)
* init file structure and trees * tree: initialize * tree misc * tree _transferTokensOnClaim * tree _beforeTokenTransfer * tree canSet * tree _collectPriceOnClaim * test: initialize * test misc * test _beforeTokenTransfers * test transferTokensOnClaim * test _canSetFunctions * update tests * clean tests + lint
1 parent 9e843f5 commit e06a324

File tree

12 files changed

+1128
-0
lines changed

12 files changed

+1128
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity ^0.8.0;
3+
4+
import { OpenEditionERC721 } from "contracts/prebuilts/open-edition/OpenEditionERC721.sol";
5+
import { TWProxy } from "contracts/infra/TWProxy.sol";
6+
7+
// Test imports
8+
import "src/test/utils/BaseTest.sol";
9+
10+
contract OpenEditionERC721Harness is OpenEditionERC721 {
11+
function beforeTokenTransfers(
12+
address from,
13+
address to,
14+
uint256 startTokenId_,
15+
uint256 quantity
16+
) public {
17+
_beforeTokenTransfers(from, to, startTokenId_, quantity);
18+
}
19+
}
20+
21+
contract OpenEditionERC721Test_beforeTokenTransfers is BaseTest {
22+
OpenEditionERC721Harness public openEdition;
23+
24+
address private openEditionImpl;
25+
26+
function setUp() public override {
27+
super.setUp();
28+
openEditionImpl = address(new OpenEditionERC721Harness());
29+
vm.prank(deployer);
30+
openEdition = OpenEditionERC721Harness(
31+
address(
32+
new TWProxy(
33+
openEditionImpl,
34+
abi.encodeCall(
35+
OpenEditionERC721.initialize,
36+
(
37+
deployer,
38+
NAME,
39+
SYMBOL,
40+
CONTRACT_URI,
41+
forwarders(),
42+
saleRecipient,
43+
royaltyRecipient,
44+
royaltyBps
45+
)
46+
)
47+
)
48+
)
49+
);
50+
}
51+
52+
/*///////////////////////////////////////////////////////////////
53+
Unit tests: misc
54+
//////////////////////////////////////////////////////////////*/
55+
56+
function test_revert_transfersRestricted() public {
57+
address from = address(0x1);
58+
address to = address(0x2);
59+
bytes32 role = keccak256("TRANSFER_ROLE");
60+
vm.prank(deployer);
61+
openEdition.revokeRole(role, address(0));
62+
63+
vm.expectRevert(bytes("!T"));
64+
openEdition.beforeTokenTransfers(from, to, 0, 1);
65+
}
66+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function _beforeTokenTransfers(
2+
address from,
3+
address to,
4+
uint256 startTokenId_,
5+
uint256 quantity
6+
)
7+
└── when address(0) does not have the transfer role
8+
└── when from does not equal address(0)
9+
└── when to does not equal address(0)
10+
└── when from does not have the transfer role
11+
└── when to does not have the transfer role
12+
└── it should revert ✅
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity ^0.8.0;
3+
4+
import { OpenEditionERC721 } from "contracts/prebuilts/open-edition/OpenEditionERC721.sol";
5+
import { TWProxy } from "contracts/infra/TWProxy.sol";
6+
7+
// Test imports
8+
import "src/test/utils/BaseTest.sol";
9+
10+
contract OpenEditionERC721Harness is OpenEditionERC721 {
11+
function canSetPrimarySaleRecipient() external view returns (bool) {
12+
return _canSetPrimarySaleRecipient();
13+
}
14+
15+
function canSetOwner() external view returns (bool) {
16+
return _canSetOwner();
17+
}
18+
19+
/// @dev Checks whether royalty info can be set in the given execution context.
20+
function canSetRoyaltyInfo() external view returns (bool) {
21+
return _canSetRoyaltyInfo();
22+
}
23+
24+
/// @dev Checks whether contract metadata can be set in the given execution context.
25+
function canSetContractURI() external view returns (bool) {
26+
return _canSetContractURI();
27+
}
28+
29+
/// @dev Checks whether platform fee info can be set in the given execution context.
30+
function canSetClaimConditions() external view returns (bool) {
31+
return _canSetClaimConditions();
32+
}
33+
34+
/// @dev Returns whether the shared metadata of tokens can be set in the given execution context.
35+
function canSetSharedMetadata() external view virtual returns (bool) {
36+
return _canSetSharedMetadata();
37+
}
38+
}
39+
40+
contract OpenEditionERC721Test_canSetFunctions is BaseTest {
41+
OpenEditionERC721Harness public openEdition;
42+
43+
address private openEditionImpl;
44+
45+
function setUp() public override {
46+
super.setUp();
47+
openEditionImpl = address(new OpenEditionERC721Harness());
48+
vm.prank(deployer);
49+
openEdition = OpenEditionERC721Harness(
50+
address(
51+
new TWProxy(
52+
openEditionImpl,
53+
abi.encodeCall(
54+
OpenEditionERC721.initialize,
55+
(
56+
deployer,
57+
NAME,
58+
SYMBOL,
59+
CONTRACT_URI,
60+
forwarders(),
61+
saleRecipient,
62+
royaltyRecipient,
63+
royaltyBps
64+
)
65+
)
66+
)
67+
)
68+
);
69+
}
70+
71+
/*///////////////////////////////////////////////////////////////
72+
Unit tests: misc
73+
//////////////////////////////////////////////////////////////*/
74+
75+
function test_canSetPrimarySaleRecipient_returnTrue() public {
76+
vm.prank(deployer);
77+
assertTrue(openEdition.canSetPrimarySaleRecipient());
78+
}
79+
80+
function test_canSetPrimarySaleRecipient_returnFalse() public {
81+
assertFalse(openEdition.canSetPrimarySaleRecipient());
82+
}
83+
84+
function test_canSetOwner_returnTrue() public {
85+
vm.prank(deployer);
86+
assertTrue(openEdition.canSetOwner());
87+
}
88+
89+
function test_canSetOwner_returnFalse() public {
90+
assertFalse(openEdition.canSetOwner());
91+
}
92+
93+
function test_canSetRoyaltyInfo_returnTrue() public {
94+
vm.prank(deployer);
95+
assertTrue(openEdition.canSetRoyaltyInfo());
96+
}
97+
98+
function test_canSetRoyaltyInfo_returnFalse() public {
99+
assertFalse(openEdition.canSetRoyaltyInfo());
100+
}
101+
102+
function test_canSetContractURI_returnTrue() public {
103+
vm.prank(deployer);
104+
assertTrue(openEdition.canSetContractURI());
105+
}
106+
107+
function test_canSetContractURI_returnFalse() public {
108+
assertFalse(openEdition.canSetContractURI());
109+
}
110+
111+
function test_canSetClaimConditions_returnTrue() public {
112+
vm.prank(deployer);
113+
assertTrue(openEdition.canSetClaimConditions());
114+
}
115+
116+
function test_canSetClaimConditions_returnFalse() public {
117+
assertFalse(openEdition.canSetClaimConditions());
118+
}
119+
120+
function test_canSetSharedMetadata_returnTrue() public {
121+
vm.prank(deployer);
122+
assertTrue(openEdition.canSetSharedMetadata());
123+
}
124+
125+
function test_canSetSharedMetadata_returnFalse() public {
126+
assertFalse(openEdition.canSetSharedMetadata());
127+
}
128+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
function _canSetPrimarySaleRecipient()
2+
├── when _msgSender has DEFAULT_ADMIN_ROLE
3+
│ └── it should return true ✅
4+
└── when _msgSender does not have DEFAULT_ADMIN_ROLE
5+
└── it should return false ✅
6+
7+
function _canSetOwner()
8+
├── when _msgSender has DEFAULT_ADMIN_ROLE
9+
│ └── it should return true ✅
10+
└── when _msgSender does not have DEFAULT_ADMIN_ROLE
11+
└── it should return false ✅
12+
13+
14+
function _canSetRoyaltyInfo()
15+
├── when _msgSender has DEFAULT_ADMIN_ROLE
16+
│ └── it should return true ✅
17+
└── when _msgSender does not have DEFAULT_ADMIN_ROLE
18+
└── it should return false ✅
19+
20+
21+
function _canSetContractURI()
22+
├── when _msgSender has DEFAULT_ADMIN_ROLE
23+
│ └── it should return true ✅
24+
└── when _msgSender does not have DEFAULT_ADMIN_ROLE
25+
└── it should return false ✅
26+
27+
28+
function _canSetClaimConditions()
29+
├── when _msgSender has DEFAULT_ADMIN_ROLE
30+
│ └── it should return true ✅
31+
└── when _msgSender does not have DEFAULT_ADMIN_ROLE
32+
└── it should return false ✅
33+
34+
35+
function _canSetSharedMetadata()
36+
├── when _msgSender has minter role
37+
│ └── it should return true ✅
38+
└── when _msgSender does not have minter role
39+
└── it should return false ✅

0 commit comments

Comments
 (0)