Skip to content

Commit 08fc02a

Browse files
Krishang NadgaudaKrishang Nadgauda
authored andcommitted
Add rough benchmark file
1 parent 5137896 commit 08fc02a

File tree

1 file changed

+123
-0
lines changed

1 file changed

+123
-0
lines changed
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity ^0.8.0;
3+
4+
import "../utils/BaseTest.sol";
5+
import "../utils/Wallet.sol";
6+
import "../mocks/MockERC20.sol";
7+
import "../mocks/MockERC721.sol";
8+
import "../mocks/MockERC1155.sol";
9+
10+
import "contracts/Multiwrap.sol";
11+
import "contracts/interfaces/IMultiwrap.sol";
12+
13+
contract MultiwrapBenchmarkTest is BaseTest {
14+
// Target contract
15+
Multiwrap internal multiwrap;
16+
17+
// Actors
18+
Wallet internal tokenOwner;
19+
Wallet internal wrappedTokenRecipient;
20+
21+
// Benchmark parameters
22+
string internal uriForWrappedToken = "ipfs://wrappedNFT";
23+
IMultiwrap.Token[] internal wrappedContents;
24+
25+
uint256 internal erc721TokenId = 0;
26+
uint256 internal erc1155TokenId = 0;
27+
uint256 internal erc1155Amount = 50;
28+
uint256 internal erc20Amount = 100 ether;
29+
30+
IMultiwrap.Token[] internal fiveERC721NFts;
31+
IMultiwrap.Token[] internal oneERC721NFTWithERC20Token;
32+
IMultiwrap.Token[] internal allThreeKindsOfTokens;
33+
34+
// ===== Set up =====
35+
function setUp() public override {
36+
super.setUp();
37+
38+
// Get Multiwrap contract.
39+
multiwrap = Multiwrap(getContract("Multiwrap"));
40+
41+
vm.label(address(erc20), "ERC20");
42+
vm.label(address(erc721), "ERC721");
43+
vm.label(address(erc1155), "ERC1155");
44+
vm.label(address(multiwrap), "Multiwrap");
45+
46+
// Get test actors.
47+
tokenOwner = new Wallet();
48+
wrappedTokenRecipient = new Wallet();
49+
50+
// Grant MINTER_ROLE to `tokenOwner`
51+
vm.prank(deployer);
52+
multiwrap.grantRole(keccak256("MINTER_ROLE"), address(tokenOwner));
53+
54+
// Mint mock ERC20/721/1155 tokens to `tokenOwner`
55+
56+
erc20.mint(address(tokenOwner), erc20Amount);
57+
erc721.mint(address(tokenOwner), 5);
58+
erc1155.mint(address(tokenOwner), erc1155TokenId, erc1155Amount);
59+
60+
// Allow Multiwrap to transfer tokens.
61+
tokenOwner.setAllowanceERC20(address(erc20), address(multiwrap), erc20Amount);
62+
tokenOwner.setApprovalForAllERC721(address(erc721), address(multiwrap), true);
63+
tokenOwner.setApprovalForAllERC1155(address(erc1155), address(multiwrap), true);
64+
65+
// Prepare wrapped contents.
66+
67+
for(uint256 i = 0; i < 5; i += 1) {
68+
fiveERC721NFts.push(IMultiwrap.Token({
69+
assetContract: address(erc721),
70+
tokenType: IMultiwrap.TokenType.ERC721,
71+
tokenId: i,
72+
amount: 1
73+
}));
74+
75+
}
76+
77+
wrappedContents.push(IMultiwrap.Token({
78+
assetContract: address(erc20),
79+
tokenType: IMultiwrap.TokenType.ERC20,
80+
tokenId: 0,
81+
amount: erc20Amount
82+
}));
83+
wrappedContents.push(IMultiwrap.Token({
84+
assetContract: address(erc721),
85+
tokenType: IMultiwrap.TokenType.ERC721,
86+
tokenId: erc721TokenId,
87+
amount: 1
88+
}));
89+
wrappedContents.push(IMultiwrap.Token({
90+
assetContract: address(erc1155),
91+
tokenType: IMultiwrap.TokenType.ERC1155,
92+
tokenId: erc1155TokenId,
93+
amount: erc1155Amount
94+
}));
95+
96+
oneERC721NFTWithERC20Token.push(IMultiwrap.Token({
97+
assetContract: address(erc20),
98+
tokenType: IMultiwrap.TokenType.ERC20,
99+
tokenId: 0,
100+
amount: erc20Amount
101+
}));
102+
oneERC721NFTWithERC20Token.push(IMultiwrap.Token({
103+
assetContract: address(erc721),
104+
tokenType: IMultiwrap.TokenType.ERC721,
105+
tokenId: erc721TokenId,
106+
amount: 1
107+
}));
108+
109+
vm.startPrank(address(tokenOwner));
110+
}
111+
112+
function testGas_wrap_fiveERC721NFTs() public {
113+
multiwrap.wrap(fiveERC721NFts, uriForWrappedToken, address(wrappedTokenRecipient));
114+
}
115+
116+
function testGas_wrap_oneERC721NFTWithERC20Token() public {
117+
multiwrap.wrap(oneERC721NFTWithERC20Token, uriForWrappedToken, address(wrappedTokenRecipient));
118+
}
119+
120+
function testGas_wrap_allThreeKindsOfTokens() public {
121+
multiwrap.wrap(allThreeKindsOfTokens, uriForWrappedToken, address(wrappedTokenRecipient));
122+
}
123+
}

0 commit comments

Comments
 (0)