Skip to content

Commit f0df3d9

Browse files
committed
test
1 parent afc9a32 commit f0df3d9

File tree

10 files changed

+671
-21
lines changed

10 files changed

+671
-21
lines changed
Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
pragma solidity ^0.8.0;
4+
5+
import { Pack } from "@thirdweb-dev/contracts/prebuilts/pack/Pack.sol";
6+
import { ITokenBundle } from "@thirdweb-dev/contracts/extension/interface/ITokenBundle.sol";
7+
8+
import { Wallet } from "./utils/Wallet.sol";
9+
import "@thirdweb-dev/dynamic-contracts/lib/forge-std/lib/ds-test/src/test.sol";
10+
import "@thirdweb-dev/dynamic-contracts/lib/forge-std/src/Test.sol";
11+
import "./mocks/MockERC20.sol";
12+
import "./mocks/MockERC721.sol";
13+
import "./mocks/MockERC1155.sol";
14+
import "./mocks/WETH9.sol";
15+
16+
import { Forwarder } from "@thirdweb-dev/contracts/infra/forwarder/Forwarder.sol";
17+
import { TWRegistry } from "@thirdweb-dev/contracts/infra/TWRegistry.sol";
18+
import { TWFactory } from "@thirdweb-dev/contracts/infra/TWFactory.sol";
19+
import { Pack } from "@thirdweb-dev/contracts/prebuilts/pack/Pack.sol";
20+
21+
22+
contract TestPack is DSTest, Test, Wallet {
23+
Pack internal pack;
24+
25+
Wallet internal tokenOwner;
26+
string internal packUri;
27+
ITokenBundle.Token[] internal packContents;
28+
uint256[] internal numOfRewardUnits;
29+
30+
string public constant NAME = "NAME";
31+
string public constant SYMBOL = "SYMBOL";
32+
string public constant CONTRACT_URI = "CONTRACT_URI";
33+
34+
MockERC20 public erc20;
35+
MockERC721 public erc721;
36+
MockERC1155 public erc1155;
37+
WETH9 public weth;
38+
39+
address public forwarder;
40+
address public registry;
41+
address public factory;
42+
address public fee;
43+
44+
address public royaltyRecipient = address(0x30001);
45+
uint128 public royaltyBps = 500; // 5%
46+
47+
function setUp(
48+
address _erc20,
49+
address _erc721,
50+
address _erc1155,
51+
address _weth,
52+
address _forwarder,
53+
address _registry,
54+
address _factory,
55+
address recipient
56+
) public {
57+
erc20 = MockERC20(_erc20);
58+
erc721 = MockERC721(_erc721);
59+
erc1155 = MockERC1155(_erc1155);
60+
weth = WETH9(payable(_weth));
61+
forwarder = _forwarder;
62+
registry = _registry;
63+
factory = _factory;
64+
65+
string memory _contractType = "Pack";
66+
bytes memory _initializer = abi.encodeCall(
67+
Pack.initialize,
68+
(address(this), NAME, SYMBOL, CONTRACT_URI, forwarders(), royaltyRecipient, royaltyBps)
69+
);
70+
address proxyAddress = TWFactory(factory).deployProxy(bytes32(bytes(_contractType)), _initializer);
71+
pack = Pack(payable(proxyAddress));
72+
tokenOwner = Wallet(address(this));
73+
packUri = "ipfs://";
74+
75+
packContents.push(
76+
ITokenBundle.Token({
77+
assetContract: address(erc721),
78+
tokenType: ITokenBundle.TokenType.ERC721,
79+
tokenId: 0,
80+
totalAmount: 1
81+
})
82+
);
83+
numOfRewardUnits.push(1);
84+
85+
packContents.push(
86+
ITokenBundle.Token({
87+
assetContract: address(erc1155),
88+
tokenType: ITokenBundle.TokenType.ERC1155,
89+
tokenId: 0,
90+
totalAmount: 100
91+
})
92+
);
93+
numOfRewardUnits.push(20);
94+
95+
packContents.push(
96+
ITokenBundle.Token({
97+
assetContract: address(erc20),
98+
tokenType: ITokenBundle.TokenType.ERC20,
99+
tokenId: 0,
100+
totalAmount: 1000 ether
101+
})
102+
);
103+
numOfRewardUnits.push(50);
104+
105+
packContents.push(
106+
ITokenBundle.Token({
107+
assetContract: address(erc721),
108+
tokenType: ITokenBundle.TokenType.ERC721,
109+
tokenId: 1,
110+
totalAmount: 1
111+
})
112+
);
113+
numOfRewardUnits.push(1);
114+
115+
packContents.push(
116+
ITokenBundle.Token({
117+
assetContract: address(erc721),
118+
tokenType: ITokenBundle.TokenType.ERC721,
119+
tokenId: 2,
120+
totalAmount: 1
121+
})
122+
);
123+
numOfRewardUnits.push(1);
124+
125+
packContents.push(
126+
ITokenBundle.Token({
127+
assetContract: address(erc20),
128+
tokenType: ITokenBundle.TokenType.ERC20,
129+
tokenId: 0,
130+
totalAmount: 1000 ether
131+
})
132+
);
133+
numOfRewardUnits.push(100);
134+
135+
packContents.push(
136+
ITokenBundle.Token({
137+
assetContract: address(erc721),
138+
tokenType: ITokenBundle.TokenType.ERC721,
139+
tokenId: 3,
140+
totalAmount: 1
141+
})
142+
);
143+
numOfRewardUnits.push(1);
144+
145+
packContents.push(
146+
ITokenBundle.Token({
147+
assetContract: address(erc721),
148+
tokenType: ITokenBundle.TokenType.ERC721,
149+
tokenId: 4,
150+
totalAmount: 1
151+
})
152+
);
153+
numOfRewardUnits.push(1);
154+
155+
packContents.push(
156+
ITokenBundle.Token({
157+
assetContract: address(erc721),
158+
tokenType: ITokenBundle.TokenType.ERC721,
159+
tokenId: 5,
160+
totalAmount: 1
161+
})
162+
);
163+
numOfRewardUnits.push(1);
164+
165+
packContents.push(
166+
ITokenBundle.Token({
167+
assetContract: address(erc1155),
168+
tokenType: ITokenBundle.TokenType.ERC1155,
169+
tokenId: 1,
170+
totalAmount: 500
171+
})
172+
);
173+
numOfRewardUnits.push(50);
174+
175+
erc20.mint(address(tokenOwner), 2000 ether);
176+
erc721.mint(address(tokenOwner), 6);
177+
erc1155.mint(address(tokenOwner), 0, 100);
178+
erc1155.mint(address(tokenOwner), 1, 500);
179+
180+
tokenOwner.setAllowanceERC20(address(erc20), address(pack), type(uint256).max);
181+
tokenOwner.setApprovalForAllERC721(address(erc721), address(pack), true);
182+
tokenOwner.setApprovalForAllERC1155(address(erc1155), address(pack), true);
183+
184+
// pack.grantRole(keccak256("MINTER_ROLE"), address(tokenOwner));
185+
(, uint256 totalSupply) = pack.createPack(packContents, numOfRewardUnits, packUri, 0, 2, recipient);
186+
}
187+
188+
189+
function getWallet() public returns (Wallet wallet) {
190+
wallet = new Wallet();
191+
}
192+
193+
function forwarders() public view returns (address[] memory) {
194+
address[] memory _forwarders = new address[](1);
195+
_forwarders[0] = forwarder;
196+
return _forwarders;
197+
}
198+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
pragma solidity ^0.8.0;
4+
5+
import "@openzeppelin/contracts/token/ERC1155/presets/ERC1155PresetMinterPauser.sol";
6+
7+
contract MockERC1155 is ERC1155PresetMinterPauser {
8+
constructor() ERC1155PresetMinterPauser("ipfs://BaseURI") {}
9+
10+
function mint(address to, uint256 id, uint256 amount) public virtual {
11+
_mint(to, id, amount, "");
12+
}
13+
14+
function hasRole(bytes32, address) public pure override(AccessControl, IAccessControl) returns (bool) {
15+
return true;
16+
}
17+
18+
function mintBatch(address to, uint256[] memory ids, uint256[] memory amounts) public virtual {
19+
require(hasRole(MINTER_ROLE, _msgSender()), "ERC1155PresetMinterPauser: must have minter role to mint");
20+
21+
_mintBatch(to, ids, amounts, "");
22+
}
23+
24+
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
25+
return super.supportsInterface(interfaceId);
26+
}
27+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
pragma solidity ^0.8.0;
4+
5+
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
6+
import "@openzeppelin/contracts/token/ERC20/presets/ERC20PresetMinterPauser.sol";
7+
import "@openzeppelin/contracts/token/ERC20/extensions/draft-ERC20Permit.sol";
8+
9+
contract MockERC20 is ERC20PresetMinterPauser, ERC20Permit {
10+
bool internal taxActive;
11+
12+
constructor() ERC20PresetMinterPauser("Mock Coin", "MOCK") ERC20Permit("Mock Coin") {}
13+
14+
function mint(address to, uint256 amount) public override(ERC20PresetMinterPauser) {
15+
_mint(to, amount);
16+
}
17+
18+
function toggleTax() external {
19+
taxActive = !taxActive;
20+
}
21+
22+
function _transfer(address from, address to, uint256 amount) internal override {
23+
if (taxActive) {
24+
uint256 tax = (amount * 10) / 100;
25+
amount -= tax;
26+
super._transfer(from, address(this), tax);
27+
}
28+
super._transfer(from, to, amount);
29+
}
30+
31+
function _beforeTokenTransfer(
32+
address from,
33+
address to,
34+
uint256 amount
35+
) internal override(ERC20PresetMinterPauser, ERC20) {
36+
super._beforeTokenTransfer(from, to, amount);
37+
}
38+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
pragma solidity ^0.8.0;
4+
5+
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Burnable.sol";
6+
7+
contract MockERC721 is ERC721Burnable {
8+
uint256 public nextTokenIdToMint;
9+
10+
constructor() ERC721("MockERC721", "MOCK") {}
11+
12+
function mint(address _receiver, uint256 _amount) external {
13+
uint256 tokenId = nextTokenIdToMint;
14+
nextTokenIdToMint += _amount;
15+
16+
for (uint256 i = 0; i < _amount; i += 1) {
17+
_mint(_receiver, tokenId);
18+
tokenId += 1;
19+
}
20+
}
21+
22+
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
23+
return super.supportsInterface(interfaceId);
24+
}
25+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
pragma solidity ^0.8.11;
4+
5+
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
6+
7+
contract WETH9 is ERC20 {
8+
event Deposit(address indexed sender, uint256 amount);
9+
event Withdrawal(address indexed sender, uint256 amount);
10+
11+
constructor() ERC20("Wrapped Ether", "WETH") {}
12+
13+
receive() external payable virtual {
14+
deposit();
15+
}
16+
17+
function deposit() public payable {
18+
_mint(msg.sender, msg.value);
19+
emit Deposit(msg.sender, msg.value);
20+
}
21+
22+
function withdraw(uint256 amount) public {
23+
_burn(msg.sender, amount);
24+
payable(msg.sender).transfer(amount);
25+
emit Withdrawal(msg.sender, amount);
26+
}
27+
28+
function totalSupply() public view override returns (uint256) {
29+
return address(this).balance;
30+
}
31+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
pragma solidity ^0.8.11;
4+
5+
import "@openzeppelin/contracts/token/ERC721/utils/ERC721Holder.sol";
6+
import "@openzeppelin/contracts/token/ERC1155/utils/ERC1155Holder.sol";
7+
8+
import "../mocks/MockERC20.sol";
9+
import "../mocks/MockERC721.sol";
10+
import "../mocks/MockERC1155.sol";
11+
12+
contract Wallet is ERC721Holder, ERC1155Holder {
13+
function transferERC20(address token, address to, uint256 amount) public {
14+
MockERC20(token).transfer(to, amount);
15+
}
16+
17+
function setAllowanceERC20(address token, address spender, uint256 allowanceAmount) public {
18+
MockERC20(token).approve(spender, allowanceAmount);
19+
}
20+
21+
function burnERC20(address token, uint256 amount) public {
22+
MockERC20(token).burn(amount);
23+
}
24+
25+
function transferERC721(address token, address to, uint256 tokenId) public {
26+
MockERC721(token).transferFrom(address(this), to, tokenId);
27+
}
28+
29+
function setApprovalForAllERC721(address token, address operator, bool toApprove) public {
30+
MockERC721(token).setApprovalForAll(operator, toApprove);
31+
}
32+
33+
function burnERC721(address token, uint256 tokenId) public {
34+
MockERC721(token).burn(tokenId);
35+
}
36+
37+
function transferERC1155(address token, address to, uint256 tokenId, uint256 amount, bytes calldata data) external {
38+
MockERC1155(token).safeTransferFrom(address(this), to, tokenId, amount, data);
39+
}
40+
41+
function setApprovalForAllERC1155(address token, address operator, bool toApprove) public {
42+
MockERC1155(token).setApprovalForAll(operator, toApprove);
43+
}
44+
45+
function burnERC1155(address token, uint256 tokenId, uint256 amount) public {
46+
MockERC1155(token).burn(address(this), tokenId, amount);
47+
}
48+
}

0 commit comments

Comments
 (0)