Skip to content

Commit 97d7628

Browse files
authored
Sdk tests (#208)
* extension tests * tests: TokenBundle, TokenStore * tests: Permissions, PermissionsEnumerable * tests: BatchMintMetadata, LazyMint * tests: PrimarySale * tests: DropSinglePhase * tests: PlatformFee * tests: ERC721Base, BaseUtilTest * tests: ERC721DelayedReveal * tests: ERC721LazyMint * tests: ERC721SignatureMint * tests: ERC721Drop * tests, setup roles ERC721Multiwrap * override tokenURI ERC721Multiwrap * disable mintTo and batchMintTo in ERC721Multiwrap * roles ERC721Multiwrap * run prettier
1 parent 692b41c commit 97d7628

25 files changed

+3169
-16
lines changed

contracts/base/ERC721Multiwrap.sol

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ contract ERC721Multiwrap is Multicall, TokenStore, SoulboundERC721A, ERC721Base
7373
uint128 _royaltyBps,
7474
address _nativeTokenWrapper
7575
) ERC721Base(_name, _symbol, _royaltyRecipient, _royaltyBps) TokenStore(_nativeTokenWrapper) {
76+
_setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
77+
_setupRole(MINTER_ROLE, msg.sender);
78+
_setupRole(TRANSFER_ROLE, msg.sender);
79+
80+
_setupRole(ASSET_ROLE, address(0));
81+
_setupRole(UNWRAP_ROLE, address(0));
82+
7683
restrictTransfers(false);
7784
}
7885

@@ -94,6 +101,15 @@ contract ERC721Multiwrap is Multicall, TokenStore, SoulboundERC721A, ERC721Base
94101
interfaceId == type(IERC1155Receiver).interfaceId;
95102
}
96103

104+
/*//////////////////////////////////////////////////////////////
105+
Overriden ERC721 logic
106+
//////////////////////////////////////////////////////////////*/
107+
108+
/// @dev Returns the URI for a given tokenId.
109+
function tokenURI(uint256 _tokenId) public view override returns (string memory) {
110+
return getUriOfBundle(_tokenId);
111+
}
112+
97113
/*///////////////////////////////////////////////////////////////
98114
Wrapping / Unwrapping logic
99115
//////////////////////////////////////////////////////////////*/
@@ -162,4 +178,21 @@ contract ERC721Multiwrap is Multicall, TokenStore, SoulboundERC721A, ERC721Base
162178
function _canRestrictTransfers() internal virtual override returns (bool) {
163179
return msg.sender == owner();
164180
}
181+
182+
/*///////////////////////////////////////////////////////////////
183+
Miscellaneous
184+
//////////////////////////////////////////////////////////////*/
185+
186+
function mintTo(address, string memory) public virtual override {
187+
revert("Not implemented for Multiwrap");
188+
}
189+
190+
function batchMintTo(
191+
address,
192+
uint256,
193+
string memory,
194+
bytes memory
195+
) public virtual override {
196+
revert("Not implemented for Multiwrap");
197+
}
165198
}

docs/ERC721Multiwrap.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -103,21 +103,21 @@ function balanceOf(address owner) external view returns (uint256)
103103
### batchMintTo
104104

105105
```solidity
106-
function batchMintTo(address _to, uint256 _quantity, string _baseURI, bytes _data) external nonpayable
106+
function batchMintTo(address, uint256, string, bytes) external nonpayable
107107
```
108108

109-
Lets an authorized address mint multiple NFTs at once to a recipient.
110109

111-
*The logic in the `_canMint` function determines whether the caller is authorized to mint NFTs.*
110+
111+
112112

113113
#### Parameters
114114

115115
| Name | Type | Description |
116116
|---|---|---|
117-
| _to | address | The recipient of the NFT to mint.
118-
| _quantity | uint256 | The number of NFTs to mint.
119-
| _baseURI | string | The baseURI for the `n` number of NFTs minted. The metadata for each NFT is `baseURI/tokenId`
120-
| _data | bytes | Additional data to pass along during the minting of the NFT.
117+
| _0 | address | undefined
118+
| _1 | uint256 | undefined
119+
| _2 | string | undefined
120+
| _3 | bytes | undefined
121121

122122
### burn
123123

@@ -500,19 +500,19 @@ Returns whether a given address is the owner, or approved to transfer an NFT.
500500
### mintTo
501501

502502
```solidity
503-
function mintTo(address _to, string _tokenURI) external nonpayable
503+
function mintTo(address, string) external nonpayable
504504
```
505505

506-
Lets an authorized address mint an NFT to a recipient.
507506

508-
*The logic in the `_canMint` function determines whether the caller is authorized to mint NFTs.*
507+
508+
509509

510510
#### Parameters
511511

512512
| Name | Type | Description |
513513
|---|---|---|
514-
| _to | address | The recipient of the NFT to mint.
515-
| _tokenURI | string | The full metadata URI for the NFT minted.
514+
| _0 | address | undefined
515+
| _1 | string | undefined
516516

517517
### multicall
518518

@@ -908,15 +908,15 @@ function symbol() external view returns (string)
908908
function tokenURI(uint256 _tokenId) external view returns (string)
909909
```
910910

911-
Returns the metadata URI for an NFT.
912911

913-
*See `BatchMintMetadata` for handling of metadata in this contract.*
912+
913+
*Returns the URI for a given tokenId.*
914914

915915
#### Parameters
916916

917917
| Name | Type | Description |
918918
|---|---|---|
919-
| _tokenId | uint256 | The tokenId of an NFT.
919+
| _tokenId | uint256 | undefined
920920

921921
#### Returns
922922

lib/forge-std

src/test/sdk/base/BaseUtilTest.sol

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity ^0.8.11;
3+
4+
import "@std/Test.sol";
5+
import "@ds-test/test.sol";
6+
import "../../utils/Wallet.sol";
7+
import "../../mocks/WETH9.sol";
8+
import "../../mocks/MockERC20.sol";
9+
import "../../mocks/MockERC721.sol";
10+
import "../../mocks/MockERC1155.sol";
11+
import "contracts/Forwarder.sol";
12+
import "contracts/lib/TWStrings.sol";
13+
14+
import "contracts/mock/Mock.sol";
15+
16+
abstract contract BaseUtilTest is DSTest, Test {
17+
string public constant NAME = "NAME";
18+
string public constant SYMBOL = "SYMBOL";
19+
string public constant CONTRACT_URI = "CONTRACT_URI";
20+
address public constant NATIVE_TOKEN = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
21+
22+
MockERC20 public erc20;
23+
MockERC721 public erc721;
24+
MockERC1155 public erc1155;
25+
WETH9 public weth;
26+
27+
address public forwarder;
28+
29+
address public deployer = address(0x20000);
30+
address public saleRecipient = address(0x30000);
31+
address public royaltyRecipient = address(0x30001);
32+
address public platformFeeRecipient = address(0x30002);
33+
uint128 public royaltyBps = 500; // 5%
34+
uint128 public platformFeeBps = 500; // 5%
35+
uint256 public constant MAX_BPS = 10_000; // 100%
36+
37+
uint256 public privateKey = 1234;
38+
address public signer;
39+
40+
mapping(bytes32 => address) public contracts;
41+
42+
function setUp() public virtual {
43+
signer = vm.addr(privateKey);
44+
45+
erc20 = new MockERC20();
46+
erc721 = new MockERC721();
47+
erc1155 = new MockERC1155();
48+
weth = new WETH9();
49+
forwarder = address(new Forwarder());
50+
}
51+
52+
function getActor(uint160 _index) public pure returns (address) {
53+
return address(uint160(0x50000 + _index));
54+
}
55+
56+
function getWallet() public returns (Wallet wallet) {
57+
wallet = new Wallet();
58+
}
59+
60+
function assertIsOwnerERC721(
61+
address _token,
62+
address _owner,
63+
uint256[] memory _tokenIds
64+
) internal {
65+
for (uint256 i = 0; i < _tokenIds.length; i += 1) {
66+
bool isOwnerOfToken = MockERC721(_token).ownerOf(_tokenIds[i]) == _owner;
67+
assertTrue(isOwnerOfToken);
68+
}
69+
}
70+
71+
function assertIsNotOwnerERC721(
72+
address _token,
73+
address _owner,
74+
uint256[] memory _tokenIds
75+
) internal {
76+
for (uint256 i = 0; i < _tokenIds.length; i += 1) {
77+
bool isOwnerOfToken = MockERC721(_token).ownerOf(_tokenIds[i]) == _owner;
78+
assertTrue(!isOwnerOfToken);
79+
}
80+
}
81+
82+
function assertBalERC1155Eq(
83+
address _token,
84+
address _owner,
85+
uint256[] memory _tokenIds,
86+
uint256[] memory _amounts
87+
) internal {
88+
require(_tokenIds.length == _amounts.length, "unequal lengths");
89+
90+
for (uint256 i = 0; i < _tokenIds.length; i += 1) {
91+
assertEq(MockERC1155(_token).balanceOf(_owner, _tokenIds[i]), _amounts[i]);
92+
}
93+
}
94+
95+
function assertBalERC1155Gte(
96+
address _token,
97+
address _owner,
98+
uint256[] memory _tokenIds,
99+
uint256[] memory _amounts
100+
) internal {
101+
require(_tokenIds.length == _amounts.length, "unequal lengths");
102+
103+
for (uint256 i = 0; i < _tokenIds.length; i += 1) {
104+
assertTrue(MockERC1155(_token).balanceOf(_owner, _tokenIds[i]) >= _amounts[i]);
105+
}
106+
}
107+
108+
function assertBalERC20Eq(
109+
address _token,
110+
address _owner,
111+
uint256 _amount
112+
) internal {
113+
assertEq(MockERC20(_token).balanceOf(_owner), _amount);
114+
}
115+
116+
function assertBalERC20Gte(
117+
address _token,
118+
address _owner,
119+
uint256 _amount
120+
) internal {
121+
assertTrue(MockERC20(_token).balanceOf(_owner) >= _amount);
122+
}
123+
124+
function forwarders() public view returns (address[] memory) {
125+
address[] memory _forwarders = new address[](1);
126+
_forwarders[0] = forwarder;
127+
return _forwarders;
128+
}
129+
}

0 commit comments

Comments
 (0)