1use alloy_primitives::{hex, Bytes};
2
3fn format_test_file(test_names: String, call_data: String, test_size: usize) -> String {
4 format!(
5 r#"
6// SPDX-License-Identifier: Unlicense
7pragma solidity ^0.8.15;
8
9import "forge-std/Test.sol";
10import "forge-std/console.sol";
11
12import {{ERC20}} from "./mocks/ERC20.sol";
13import {{MultiCaller}} from "./Interface.sol";
14import {{TestHelper, SwapTest}} from "./Helper.sol";
15
16contract MulticallerGasBench is Test, TestHelper, SwapTest {{
17
18 string[{test_size}] testname = [
19{test_names}
20];
21
22 bytes[{test_size}] callsdata = [
23{call_data}
24];
25
26
27 function get_call_data(uint256 i) internal override returns (bytes memory) {{
28 return callsdata[i];
29 }}
30
31 function get_test_name(uint256 i) internal override returns (string memory) {{
32 return testname[i];
33 }}
34
35 function get_count() internal override returns (uint256) {{
36 return callsdata.length;
37 }}
38
39 function get_swap_token() internal override returns (address) {{
40 return address(weth);
41 }}
42
43 function get_multicaller() internal override returns (address) {{
44 return address(TestHelper.multicaller);
45 }}
46
47 function test_combo() public {{
48 run_test_all();
49 }}
50
51 function test_single() public {{
52 run_test_one(0);
53 }}
54
55
56
57
58}}
59 "#
60 )
61}
62
63pub fn create_sol_test(requests_vec: Vec<(String, Bytes)>) -> String {
64 let requests_vec = requests_vec;
65 let req_len = requests_vec.len();
66 let (names, data_vec): (Vec<String>, Vec<Bytes>) = requests_vec.into_iter().unzip();
67 let names_string_vec: Vec<String> = names.into_iter().map(|x| format!("\t\"{x}\"")).collect();
68 let names_string = names_string_vec.join(",\n");
69 let calldata_string_vec: Vec<String> = data_vec.into_iter().map(|x| format!("\tbytes(hex\"{}\")", hex::encode(x))).collect();
70 let calldata_string = calldata_string_vec.join(",\n");
71 format_test_file(names_string, calldata_string, req_len)
72}