gasbench/
soltest.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use alloy_primitives::{hex, Bytes};

fn format_test_file(test_names: String, call_data: String, test_size: usize) -> String {
    format!(
        r#"
// SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.15;

contract MulticallerCallData  {{

    string[{}] testname = [
{}
];

    bytes[{}] callsdata = [
{}
];


    function get_call_data(uint256 i ) internal returns (bytes memory) {{
        return callsdata[i];
    }}

    function get_test_name(uint256 i ) internal returns (string memory) {{
        return testname[i];
    }}

}}
        "#,
        test_size, test_names, test_size, call_data
    )
}

pub fn create_sol_test(requests_vec: Vec<(String, Bytes)>) -> String {
    let requests_vec = requests_vec;
    let req_len = requests_vec.len();
    let (names, data_vec): (Vec<String>, Vec<Bytes>) = requests_vec.into_iter().unzip();
    let names_string_vec: Vec<String> = names.into_iter().map(|x| format!("\t\"{}\"", x)).collect();
    let names_string = names_string_vec.join(",\n");
    let calldata_string_vec: Vec<String> = data_vec.into_iter().map(|x| format!("\tbytes(hex\"{}\")", hex::encode(x))).collect();
    let calldata_string = calldata_string_vec.join(",\n");
    format_test_file(names_string, calldata_string, req_len)
}