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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
// Copyright (c) The Diem Core Contributors
// SPDX-License-Identifier: Apache-2.0

use crate::FuzzTargetImpl;
use diem_json_rpc::{
    fuzzing::{fuzzer, generate_corpus, method_fuzzer},
    gen_request_params,
};
use diem_proptest_helpers::ValueGenerator;

const ADDRESS: &str = "000000000000000000000000000000dd";

#[derive(Clone, Debug, Default)]
pub struct JsonRpcSubmitTransactionRequest;

impl FuzzTargetImpl for JsonRpcSubmitTransactionRequest {
    fn description(&self) -> &'static str {
        "JSON RPC submit transaction request"
    }

    fn generate(&self, _idx: usize, gen: &mut ValueGenerator) -> Option<Vec<u8>> {
        Some(generate_corpus(gen))
    }

    fn fuzz(&self, data: &[u8]) {
        fuzzer(data);
    }
}

#[derive(Clone, Debug, Default)]
pub struct JsonRpcGetAccountRequest;

impl FuzzTargetImpl for JsonRpcGetAccountRequest {
    fn description(&self) -> &'static str {
        "JSON RPC get account request"
    }

    fn generate(&self, _idx: usize, _gen: &mut ValueGenerator) -> Option<Vec<u8>> {
        Some(gen_request_params!([ADDRESS]))
    }

    fn fuzz(&self, data: &[u8]) {
        method_fuzzer(data, "get_account");
    }
}

#[derive(Clone, Debug, Default)]
pub struct JsonRpcGetAccountTransactionRequest;

impl FuzzTargetImpl for JsonRpcGetAccountTransactionRequest {
    fn description(&self) -> &'static str {
        "JSON RPC get_account_transaction request"
    }

    fn generate(&self, _idx: usize, _gen: &mut ValueGenerator) -> Option<Vec<u8>> {
        Some(gen_request_params!([ADDRESS, 0, true]))
    }

    fn fuzz(&self, data: &[u8]) {
        method_fuzzer(data, "get_account_transaction");
    }
}

#[derive(Clone, Debug, Default)]
pub struct JsonRpcGetAccountTransactionsRequest;

impl FuzzTargetImpl for JsonRpcGetAccountTransactionsRequest {
    fn description(&self) -> &'static str {
        "JSON RPC get_account_transactions request"
    }

    fn generate(&self, _idx: usize, _gen: &mut ValueGenerator) -> Option<Vec<u8>> {
        Some(gen_request_params!([ADDRESS, 0, 1, true]))
    }

    fn fuzz(&self, data: &[u8]) {
        method_fuzzer(data, "get_account_transactions");
    }
}

#[derive(Clone, Debug, Default)]
pub struct JsonRpcGetTransactionsRequest;

impl FuzzTargetImpl for JsonRpcGetTransactionsRequest {
    fn description(&self) -> &'static str {
        "JSON RPC get_transactions request"
    }

    fn generate(&self, _idx: usize, _gen: &mut ValueGenerator) -> Option<Vec<u8>> {
        Some(gen_request_params!([0, 1, true]))
    }

    fn fuzz(&self, data: &[u8]) {
        method_fuzzer(data, "get_transactions");
    }
}

#[derive(Clone, Debug, Default)]
pub struct JsonRpcGetEventsRequest;

impl FuzzTargetImpl for JsonRpcGetEventsRequest {
    fn description(&self) -> &'static str {
        "JSON RPC get_events request"
    }

    fn generate(&self, _idx: usize, _gen: &mut ValueGenerator) -> Option<Vec<u8>> {
        Some(gen_request_params!([
            "00000000000000000000000000000000000000000a550c18",
            0,
            10
        ]))
    }

    fn fuzz(&self, data: &[u8]) {
        method_fuzzer(data, "get_events");
    }
}

#[derive(Clone, Debug, Default)]
pub struct JsonRpcGetMetadataRequest;

impl FuzzTargetImpl for JsonRpcGetMetadataRequest {
    fn description(&self) -> &'static str {
        "JSON RPC get_metadata request"
    }

    fn generate(&self, _idx: usize, _gen: &mut ValueGenerator) -> Option<Vec<u8>> {
        Some(gen_request_params!([0]))
    }

    fn fuzz(&self, data: &[u8]) {
        method_fuzzer(data, "get_metadata");
    }
}

#[derive(Clone, Debug, Default)]
pub struct JsonRpcGetCurrenciesRequest;

impl FuzzTargetImpl for JsonRpcGetCurrenciesRequest {
    fn description(&self) -> &'static str {
        "JSON RPC get_currencies request"
    }

    fn generate(&self, _idx: usize, _gen: &mut ValueGenerator) -> Option<Vec<u8>> {
        Some(gen_request_params!([]))
    }

    fn fuzz(&self, data: &[u8]) {
        method_fuzzer(data, "get_currencies");
    }
}

#[derive(Clone, Debug, Default)]
pub struct JsonRpcGetStateProofRequest;

impl FuzzTargetImpl for JsonRpcGetStateProofRequest {
    fn description(&self) -> &'static str {
        "JSON RPC get_state_proof request"
    }

    fn generate(&self, _idx: usize, _gen: &mut ValueGenerator) -> Option<Vec<u8>> {
        Some(gen_request_params!([1]))
    }

    fn fuzz(&self, data: &[u8]) {
        method_fuzzer(data, "get_state_proof");
    }
}

#[derive(Clone, Debug, Default)]
pub struct JsonRpcGetAccountStateWithProofRequest;

impl FuzzTargetImpl for JsonRpcGetAccountStateWithProofRequest {
    fn description(&self) -> &'static str {
        "JSON RPC get_account_state_with_proof request"
    }

    fn generate(&self, _idx: usize, _gen: &mut ValueGenerator) -> Option<Vec<u8>> {
        Some(gen_request_params!([ADDRESS, 0, 1]))
    }

    fn fuzz(&self, data: &[u8]) {
        method_fuzzer(data, "get_account_state_with_proof");
    }
}

#[derive(Clone, Debug, Default)]
pub struct JsonRpcGetNetworkStatusRequest;

impl FuzzTargetImpl for JsonRpcGetNetworkStatusRequest {
    fn description(&self) -> &'static str {
        "JSON RPC get_network_status request"
    }

    fn generate(&self, _idx: usize, _gen: &mut ValueGenerator) -> Option<Vec<u8>> {
        Some(gen_request_params!([]))
    }

    fn fuzz(&self, data: &[u8]) {
        method_fuzzer(data, "get_network_status");
    }
}