Skip to content

Commit 6d44826

Browse files
Krishang NadgaudaKrishang Nadgauda
Krishang Nadgauda
authored and
Krishang Nadgauda
committed
Add benchmark tests for push Airdrops
1 parent 024f8b5 commit 6d44826

File tree

3 files changed

+247
-0
lines changed

3 files changed

+247
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity ^0.8.0;
3+
4+
import "contracts/airdrop/AirdropERC1155.sol";
5+
6+
// Test imports
7+
import { Wallet } from "../utils/Wallet.sol";
8+
import "../utils/BaseTest.sol";
9+
10+
contract AirdropERC1155BenchmarkTest is BaseTest {
11+
AirdropERC1155 internal drop;
12+
13+
Wallet internal tokenOwner;
14+
15+
address[] internal _recipients;
16+
uint256[] internal _amounts;
17+
uint256[] internal _tokenIds;
18+
19+
uint256[] internal _amounts_one;
20+
address[] internal _recipients_one;
21+
uint256[] internal _tokenIds_one;
22+
23+
uint256[] internal _amounts_two;
24+
address[] internal _recipients_two;
25+
uint256[] internal _tokenIds_two;
26+
27+
uint256[] internal _amounts_five;
28+
address[] internal _recipients_five;
29+
uint256[] internal _tokenIds_five;
30+
31+
function setUp() public override {
32+
super.setUp();
33+
34+
drop = AirdropERC1155(getContract("AirdropERC1155"));
35+
36+
tokenOwner = getWallet();
37+
38+
erc1155.mint(address(tokenOwner), 0, 1000);
39+
erc1155.mint(address(tokenOwner), 1, 2000);
40+
erc1155.mint(address(tokenOwner), 2, 3000);
41+
erc1155.mint(address(tokenOwner), 3, 4000);
42+
erc1155.mint(address(tokenOwner), 4, 5000);
43+
44+
tokenOwner.setApprovalForAllERC1155(address(erc1155), address(drop), true);
45+
46+
for (uint256 i = 0; i < 1000; i++) {
47+
if (i < 1) {
48+
_amounts_one.push(i);
49+
_tokenIds_one.push(i % 5);
50+
_recipients_one.push(getActor(uint160(i)));
51+
}
52+
53+
if (i < 2) {
54+
_amounts_two.push(i);
55+
_tokenIds_two.push(i % 5);
56+
_recipients_two.push(getActor(uint160(i)));
57+
}
58+
59+
if (i < 5) {
60+
_amounts_five.push(i);
61+
_tokenIds_five.push(i % 5);
62+
_recipients_five.push(getActor(uint160(i)));
63+
}
64+
65+
_recipients.push(getActor(uint160(i)));
66+
_tokenIds.push(i % 5);
67+
_amounts.push(5);
68+
}
69+
70+
vm.startPrank(deployer);
71+
}
72+
73+
function test_benchmark_airdrop_one() public {
74+
drop.airdrop(address(erc1155), address(tokenOwner), _recipients_one, _amounts_one, _tokenIds_one);
75+
}
76+
77+
function test_benchmark_airdrop_two() public {
78+
drop.airdrop(address(erc1155), address(tokenOwner), _recipients_two, _amounts_two, _tokenIds_two);
79+
}
80+
81+
function test_benchmark_airdrop_five() public {
82+
drop.airdrop(address(erc1155), address(tokenOwner), _recipients_five, _amounts_five, _tokenIds_five);
83+
}
84+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity ^0.8.0;
3+
4+
import "contracts/airdrop/AirdropERC20.sol";
5+
6+
// Test imports
7+
import { Wallet } from "../utils/Wallet.sol";
8+
import "../utils/BaseTest.sol";
9+
10+
contract AirdropERC20BenchmarkTest is BaseTest {
11+
AirdropERC20 internal drop;
12+
13+
Wallet internal tokenOwner;
14+
15+
uint256[] internal _amounts;
16+
address[] internal _recipients;
17+
18+
uint256[] internal _amounts_one;
19+
address[] internal _recipients_one;
20+
21+
uint256[] internal _amounts_two;
22+
address[] internal _recipients_two;
23+
24+
uint256[] internal _amounts_five;
25+
address[] internal _recipients_five;
26+
27+
function setUp() public override {
28+
super.setUp();
29+
30+
drop = AirdropERC20(getContract("AirdropERC20"));
31+
32+
tokenOwner = getWallet();
33+
34+
erc20.mint(address(tokenOwner), 10_000 ether);
35+
tokenOwner.setAllowanceERC20(address(erc20), address(drop), type(uint256).max);
36+
37+
for (uint256 i = 0; i < 1000; i++) {
38+
if (i < 1) {
39+
_amounts_one.push(1 ether);
40+
_recipients_one.push(getActor(uint160(i)));
41+
}
42+
43+
if (i < 2) {
44+
_amounts_two.push(1 ether);
45+
_recipients_two.push(getActor(uint160(i)));
46+
}
47+
48+
if (i < 5) {
49+
_amounts_five.push(1 ether);
50+
_recipients_five.push(getActor(uint160(i)));
51+
}
52+
53+
_amounts.push(1 ether);
54+
_recipients.push(getActor(uint160(i)));
55+
}
56+
57+
vm.deal(deployer, 10_000 ether);
58+
vm.startPrank(deployer);
59+
}
60+
61+
/*///////////////////////////////////////////////////////////////
62+
Unit tests: `createPack`
63+
//////////////////////////////////////////////////////////////*/
64+
65+
function test_benchmark_airdrop_one_ERC20() public {
66+
drop.airdrop(address(erc20), address(tokenOwner), _recipients_one, _amounts_one);
67+
}
68+
69+
function test_benchmark_airdrop_one_nativeToken() public {
70+
drop.airdrop{ value: 1 ether }(NATIVE_TOKEN, deployer, _recipients_one, _amounts_one);
71+
}
72+
73+
function test_benchmark_airdrop_two_ERC20() public {
74+
drop.airdrop(address(erc20), address(tokenOwner), _recipients_two, _amounts_two);
75+
}
76+
77+
function test_benchmark_airdrop_two_nativeToken() public {
78+
drop.airdrop{ value: 2 ether }(NATIVE_TOKEN, deployer, _recipients_two, _amounts_two);
79+
}
80+
81+
function test_benchmark_airdrop_five_ERC20() public {
82+
drop.airdrop(address(erc20), address(tokenOwner), _recipients_five, _amounts_five);
83+
}
84+
85+
function test_benchmark_airdrop_five_nativeToken() public {
86+
drop.airdrop{ value: 5 ether }(NATIVE_TOKEN, deployer, _recipients_five, _amounts_five);
87+
}
88+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity ^0.8.0;
3+
4+
import "contracts/airdrop/AirdropERC721.sol";
5+
6+
// Test imports
7+
import { Wallet } from "../utils/Wallet.sol";
8+
import "../utils/BaseTest.sol";
9+
10+
contract AirdropERC721BenchmarkTest is BaseTest {
11+
AirdropERC721 internal drop;
12+
13+
Wallet internal tokenOwner;
14+
15+
uint256[] internal _tokenIds;
16+
address[] internal _recipients;
17+
18+
uint256[] internal _amounts_one;
19+
address[] internal _recipients_one;
20+
21+
uint256[] internal _amounts_two;
22+
address[] internal _recipients_two;
23+
24+
uint256[] internal _amounts_five;
25+
address[] internal _recipients_five;
26+
27+
function setUp() public override {
28+
super.setUp();
29+
30+
drop = AirdropERC721(getContract("AirdropERC721"));
31+
32+
tokenOwner = getWallet();
33+
34+
erc721.mint(address(tokenOwner), 1000);
35+
tokenOwner.setApprovalForAllERC721(address(erc721), address(drop), true);
36+
37+
for (uint256 i = 0; i < 1000; i++) {
38+
if (i < 1) {
39+
_amounts_one.push(i);
40+
_recipients_one.push(getActor(uint160(i)));
41+
}
42+
43+
if (i < 2) {
44+
_amounts_two.push(i);
45+
_recipients_two.push(getActor(uint160(i)));
46+
}
47+
48+
if (i < 5) {
49+
_amounts_five.push(i);
50+
_recipients_five.push(getActor(uint160(i)));
51+
}
52+
53+
_tokenIds.push(i);
54+
_recipients.push(getActor(uint160(i)));
55+
}
56+
57+
vm.startPrank(deployer);
58+
}
59+
60+
/*///////////////////////////////////////////////////////////////
61+
Unit tests: `createPack`
62+
//////////////////////////////////////////////////////////////*/
63+
64+
function test_benchmark_airdrop_one_ERC721() public {
65+
drop.airdrop(address(erc721), address(tokenOwner), _recipients_one, _amounts_one);
66+
}
67+
68+
function test_benchmark_airdrop_two_ERC721() public {
69+
drop.airdrop(address(erc721), address(tokenOwner), _recipients_two, _amounts_two);
70+
}
71+
72+
function test_benchmark_airdrop_five_ERC721() public {
73+
drop.airdrop(address(erc721), address(tokenOwner), _recipients_five, _amounts_five);
74+
}
75+
}

0 commit comments

Comments
 (0)