Coverage Report

Created: 2024-05-16 12:16

/__w/smoldot/smoldot/repo/full-node/tests/json-rpc-general-requests.rs
Line
Count
Source (jump to first uncovered line)
1
// Smoldot
2
// Copyright (C) 2023  Pierre Krieger
3
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
4
5
// This program is free software: you can redistribute it and/or modify
6
// it under the terms of the GNU General Public License as published by
7
// the Free Software Foundation, either version 3 of the License, or
8
// (at your option) any later version.
9
10
// This program is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
// GNU General Public License for more details.
14
15
// You should have received a copy of the GNU General Public License
16
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18
use smoldot::json_rpc;
19
use std::sync::Arc;
20
21
19
async fn start_client() -> smoldot_full_node::Client {
22
19
    smoldot_full_node::start(smoldot_full_node::Config {
23
19
        chain: smoldot_full_node::ChainConfig {
24
19
            chain_spec: (&include_bytes!("./substrate-node-template.json")[..]).into(),
25
19
            additional_bootnodes: Vec::new(),
26
19
            keystore_memory: vec![],
27
19
            sqlite_database_path: None,
28
19
            sqlite_cache_size: 256 * 1024 * 1024,
29
19
            keystore_path: None,
30
19
            json_rpc_listen: None,
31
19
        },
32
19
        relay_chain: None,
33
19
        libp2p_key: Box::new([0; 32]),
34
19
        listen_addresses: Vec::new(),
35
703
        tasks_executor: Arc::new(|task| smol::spawn(task).detach()),
36
38
        log_callback: Arc::new(move |_, _| {}),
37
19
        jaeger_agent: None,
38
19
    })
39
95
    .await
40
19
    .unwrap()
41
19
}
42
43
#[test]
44
1
fn chain_spec_v1_chain_name() {
45
1
    smol::block_on(async move {
46
5
        let 
client1
=
start_client()1
.await;
47
48
1
        client.send_json_rpc_request(
49
1
            r#"{"jsonrpc":"2.0","id":1,"method":"chainSpec_v1_chainName","params":[]}"#.to_owned(),
50
1
        );
51
52
1
        let response_raw = client.next_json_rpc_response().
await0
;
53
1
        let (_, result_json) = json_rpc::parse::parse_response(&response_raw)
54
1
            .unwrap()
55
1
            .into_success()
56
1
            .unwrap();
57
1
        assert_eq!(
58
1
            serde_json::from_str::<String>(result_json).unwrap(),
59
1
            "Local Testnet"
60
1
        );
61
1
    });
62
1
}
63
64
#[test]
65
1
fn chain_spec_v1_genesis_hash() {
66
1
    smol::block_on(async move {
67
5
        let 
client1
=
start_client()1
.await;
68
69
1
        client.send_json_rpc_request(
70
1
            r#"{"jsonrpc":"2.0","id":1,"method":"chainSpec_v1_genesisHash","params":[]}"#
71
1
                .to_owned(),
72
1
        );
73
74
1
        let response_raw = client.next_json_rpc_response().await;
75
1
        let (_, result_json) = json_rpc::parse::parse_response(&response_raw)
76
1
            .unwrap()
77
1
            .into_success()
78
1
            .unwrap();
79
1
        assert_eq!(
80
1
            serde_json::from_str::<String>(result_json).unwrap(),
81
1
            "0x6bf30d04495c16ef053de4ac74eac35dfd6473e4907810f450bea1b976ac518f"
82
1
        );
83
1
    });
84
1
}
85
86
#[test]
87
1
fn chain_spec_v1_properties() {
88
1
    smol::block_on(async move {
89
5
        let 
client1
=
start_client()1
.await;
90
91
1
        client.send_json_rpc_request(
92
1
            r#"{"jsonrpc":"2.0","id":1,"method":"chainSpec_v1_properties","params":[]}"#.to_owned(),
93
1
        );
94
95
1
        let response_raw = client.next_json_rpc_response().
await0
;
96
1
        let (_, result_json) = json_rpc::parse::parse_response(&response_raw)
97
1
            .unwrap()
98
1
            .into_success()
99
1
            .unwrap();
100
1
        assert_eq!(result_json, r#"{"tokenDecimals": 15}"#);
101
1
    });
102
1
}
103
104
#[test]
105
1
fn chain_get_block_hash() {
106
1
    smol::block_on(async move {
107
5
        let 
client1
=
start_client()1
.await;
108
109
1
        client.send_json_rpc_request(
110
1
            r#"{"jsonrpc":"2.0","id":1,"method":"chain_getBlockHash","params":[0]}"#.to_owned(),
111
1
        );
112
1
        let response_raw = client.next_json_rpc_response().
await0
;
113
1
        let (_, result_json) = json_rpc::parse::parse_response(&response_raw)
114
1
            .unwrap()
115
1
            .into_success()
116
1
            .unwrap();
117
1
        assert_eq!(
118
1
            serde_json::from_str::<String>(result_json).unwrap(),
119
1
            "0x6bf30d04495c16ef053de4ac74eac35dfd6473e4907810f450bea1b976ac518f"
120
1
        );
121
122
1
        client.send_json_rpc_request(
123
1
            r#"{"jsonrpc":"2.0","id":1,"method":"chain_getBlockHash","params":[10000]}"#.to_owned(),
124
1
        );
125
1
        let response_raw = client.next_json_rpc_response().await;
126
1
        let (_, result_json) = json_rpc::parse::parse_response(&response_raw)
127
1
            .unwrap()
128
1
            .into_success()
129
1
            .unwrap();
130
1
        assert_eq!(result_json, "null");
131
132
        // TODO: test for a non-zero block?
133
1
    });
134
1
}
135
136
#[test]
137
1
fn chain_get_header() {
138
1
    smol::block_on(async move {
139
5
        let 
client1
=
start_client()1
.await;
140
141
        // Test the current best block.
142
1
        client.send_json_rpc_request(
143
1
            r#"{"jsonrpc":"2.0","id":1,"method":"chain_getHeader","params":[]}"#.to_owned(),
144
1
        );
145
1
        let response_raw = client.next_json_rpc_response().await;
146
1
        let (_, result_json) = json_rpc::parse::parse_response(&response_raw)
147
1
            .unwrap()
148
1
            .into_success()
149
1
            .unwrap();
150
1
        let decoded_header =
151
1
            serde_json::from_str::<json_rpc::methods::Header>(result_json).unwrap();
152
1
        assert_eq!(
153
1
            decoded_header.parent_hash.0,
154
1
            [
155
1
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
156
1
                0, 0, 0, 0
157
1
            ]
158
1
        );
159
1
        assert_eq!(decoded_header.number, 0);
160
1
        assert_eq!(
161
1
            decoded_header.state_root.0,
162
1
            [
163
1
                40, 162, 219, 5, 170, 164, 232, 78, 136, 198, 190, 40, 202, 73, 212, 91, 4, 51,
164
1
                248, 171, 238, 66, 27, 9, 45, 250, 15, 77, 216, 87, 135, 166
165
1
            ]
166
1
        );
167
1
        assert!(decoded_header.digest.logs.is_empty());
168
169
        // Test passing an explicit block hash.
170
1
        client.send_json_rpc_request(
171
1
            r#"{"jsonrpc":"2.0","id":1,"method":"chain_getHeader","params":["0x6bf30d04495c16ef053de4ac74eac35dfd6473e4907810f450bea1b976ac518f"]}"#.to_owned(),
172
1
        );
173
1
        let response_raw = client.next_json_rpc_response().
await0
;
174
1
        let (_, result_json) = json_rpc::parse::parse_response(&response_raw)
175
1
            .unwrap()
176
1
            .into_success()
177
1
            .unwrap();
178
1
        let decoded_header =
179
1
            serde_json::from_str::<json_rpc::methods::Header>(result_json).unwrap();
180
1
        assert_eq!(
181
1
            decoded_header.parent_hash.0,
182
1
            [
183
1
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
184
1
                0, 0, 0, 0
185
1
            ]
186
1
        );
187
1
        assert_eq!(decoded_header.number, 0);
188
1
        assert_eq!(
189
1
            decoded_header.state_root.0,
190
1
            [
191
1
                40, 162, 219, 5, 170, 164, 232, 78, 136, 198, 190, 40, 202, 73, 212, 91, 4, 51,
192
1
                248, 171, 238, 66, 27, 9, 45, 250, 15, 77, 216, 87, 135, 166
193
1
            ]
194
1
        );
195
1
        assert!(decoded_header.digest.logs.is_empty());
196
197
        // Test for unknown block.
198
1
        client.send_json_rpc_request(
199
1
            r#"{"jsonrpc":"2.0","id":1,"method":"chain_getHeader","params":["0xdeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddead"]}"#.to_owned(),
200
1
        );
201
1
        let response_raw = client.next_json_rpc_response().
await0
;
202
1
        let (_, result_json) = json_rpc::parse::parse_response(&response_raw)
203
1
            .unwrap()
204
1
            .into_success()
205
1
            .unwrap();
206
1
        assert_eq!(result_json, "null");
207
1
    });
208
1
}
209
210
#[test]
211
1
fn state_get_metadata() {
212
1
    smol::block_on(async move {
213
5
        let 
client1
=
start_client()1
.await;
214
215
        // Query the metadata of the genesis.
216
1
        client.send_json_rpc_request(
217
1
            r#"{"jsonrpc":"2.0","id":1,"method":"state_getMetadata","params":["0x6bf30d04495c16ef053de4ac74eac35dfd6473e4907810f450bea1b976ac518f"]}"#.to_owned(),
218
1
        );
219
1
        let response_raw = client.next_json_rpc_response().await;
220
1
        let (_, result_json) = json_rpc::parse::parse_response(&response_raw)
221
1
            .unwrap()
222
1
            .into_success()
223
1
            .unwrap();
224
1
        assert_eq!(
225
1
            serde_json::from_str::<String>(result_json).unwrap(),
226
1
            include_str!("./substrate-node-template-metadata.hex").trim()
227
1
        );
228
229
        // TOOD: there are no tests for the corner cases of state_getMetadata because it's unclear how the function is supposed to behave at all
230
1
    });
231
1
}
232
233
#[test]
234
1
fn state_get_runtime_version() {
235
1
    smol::block_on(async move {
236
5
        let 
client1
=
start_client()1
.await;
237
238
        // Query the runtime of the genesis.
239
1
        client.send_json_rpc_request(
240
1
            r#"{"jsonrpc":"2.0","id":1,"method":"state_getRuntimeVersion","params":["0x6bf30d04495c16ef053de4ac74eac35dfd6473e4907810f450bea1b976ac518f"]}"#.to_owned(),
241
1
        );
242
1
        let response_raw = client.next_json_rpc_response().await;
243
1
        let (_, result_json) = json_rpc::parse::parse_response(&response_raw)
244
1
            .unwrap()
245
1
            .into_success()
246
1
            .unwrap();
247
1
        let decoded =
248
1
            serde_json::from_str::<json_rpc::methods::RuntimeVersion>(result_json).unwrap();
249
1
        assert_eq!(decoded.impl_name, "node-template");
250
1
        assert_eq!(decoded.spec_version, 100);
251
1
        assert_eq!(decoded.apis.len(), 10);
252
253
        // TOOD: there are no tests for the corner cases of state_getRuntimeVersion because it's unclear how the function is supposed to behave at all
254
1
    });
255
1
}
256
257
#[test]
258
1
fn state_get_keys_paged_basic() {
259
1
    smol::block_on(async move {
260
5
        let 
client1
=
start_client()1
.await;
261
262
1
        client.send_json_rpc_request(
263
1
            r#"{"jsonrpc":"2.0","id":1,"method":"state_getKeysPaged","params":["0x", 10]}"#
264
1
                .to_owned(),
265
1
        );
266
1
        let response_raw = client.next_json_rpc_response().
await0
;
267
1
        let (_, result_json) = json_rpc::parse::parse_response(&response_raw)
268
1
            .unwrap()
269
1
            .into_success()
270
1
            .unwrap();
271
1
        let decoded = serde_json::from_str::<Vec<json_rpc::methods::HexString>>(result_json)
272
1
            .unwrap()
273
1
            .into_iter()
274
10
            .map(|v| v.0)
275
1
            .collect::<Vec<_>>();
276
1
        assert_eq!(
277
1
            decoded,
278
1
            &[
279
1
                &[
280
1
                    23, 126, 104, 87, 251, 29, 14, 64, 147, 118, 18, 47, 238, 58, 212, 248, 78,
281
1
                    123, 144, 18, 9, 107, 65, 196, 235, 58, 175, 148, 127, 110, 164, 41
282
1
                ][..],
283
1
                &[
284
1
                    38, 170, 57, 78, 234, 86, 48, 224, 124, 72, 174, 12, 149, 88, 206, 247, 78,
285
1
                    123, 144, 18, 9, 107, 65, 196, 235, 58, 175, 148, 127, 110, 164, 41
286
1
                ],
287
1
                &[
288
1
                    38, 170, 57, 78, 234, 86, 48, 224, 124, 72, 174, 12, 149, 88, 206, 247, 86,
289
1
                    132, 160, 34, 163, 77, 216, 191, 162, 186, 175, 68, 241, 114, 183, 16
290
1
                ],
291
1
                &[
292
1
                    38, 170, 57, 78, 234, 86, 48, 224, 124, 72, 174, 12, 149, 88, 206, 247, 138,
293
1
                    66, 243, 51, 35, 203, 92, 237, 59, 68, 221, 130, 95, 218, 159, 204
294
1
                ],
295
1
                &[
296
1
                    38, 170, 57, 78, 234, 86, 48, 224, 124, 72, 174, 12, 149, 88, 206, 247, 164,
297
1
                    71, 4, 181, 104, 210, 22, 103, 53, 106, 90, 5, 12, 17, 135, 70, 180, 222, 242,
298
1
                    92, 253, 166, 239, 58, 0, 0, 0, 0
299
1
                ],
300
1
                &[
301
1
                    38, 170, 57, 78, 234, 86, 48, 224, 124, 72, 174, 12, 149, 88, 206, 247, 167,
302
1
                    253, 108, 40, 131, 107, 154, 40, 82, 45, 201, 36, 17, 12, 244, 57
303
1
                ],
304
1
                &[
305
1
                    38, 170, 57, 78, 234, 86, 48, 224, 124, 72, 174, 12, 149, 88, 206, 247, 185,
306
1
                    157, 136, 14, 198, 129, 121, 156, 12, 243, 14, 136, 134, 55, 29, 169, 0, 124,
307
1
                    188, 18, 112, 181, 176, 145, 117, 143, 156, 66, 245, 145, 91, 62, 138, 197,
308
1
                    158, 17, 150, 58, 241, 145, 116, 208, 185, 77, 93, 120, 4, 28, 35, 63, 85, 210,
309
1
                    225, 147, 36, 102, 91, 175, 223, 182, 41, 37, 175, 45
310
1
                ],
311
1
                &[
312
1
                    38, 170, 57, 78, 234, 86, 48, 224, 124, 72, 174, 12, 149, 88, 206, 247, 185,
313
1
                    157, 136, 14, 198, 129, 121, 156, 12, 243, 14, 136, 134, 55, 29, 169, 35, 160,
314
1
                    92, 171, 246, 211, 189, 231, 202, 62, 240, 209, 21, 150, 181, 97, 28, 189, 45,
315
1
                    67, 83, 10, 68, 112, 90, 208, 136, 175, 49, 62, 24, 248, 11, 83, 239, 22, 179,
316
1
                    97, 119, 205, 75, 119, 184, 70, 242, 165, 240, 124
317
1
                ],
318
1
                &[
319
1
                    38, 170, 57, 78, 234, 86, 48, 224, 124, 72, 174, 12, 149, 88, 206, 247, 185,
320
1
                    157, 136, 14, 198, 129, 121, 156, 12, 243, 14, 136, 134, 55, 29, 169, 50, 165,
321
1
                    147, 95, 110, 220, 97, 122, 225, 120, 254, 249, 235, 30, 33, 31, 190, 93, 219,
322
1
                    21, 121, 183, 46, 132, 82, 79, 194, 158, 120, 96, 158, 60, 175, 66, 232, 90,
323
1
                    161, 24, 235, 254, 11, 10, 212, 4, 181, 189, 210, 95
324
1
                ],
325
1
                &[
326
1
                    38, 170, 57, 78, 234, 86, 48, 224, 124, 72, 174, 12, 149, 88, 206, 247, 185,
327
1
                    157, 136, 14, 198, 129, 121, 156, 12, 243, 14, 136, 134, 55, 29, 169, 79, 154,
328
1
                    234, 26, 250, 121, 18, 101, 250, 227, 89, 39, 43, 173, 193, 207, 142, 175, 4,
329
1
                    21, 22, 135, 115, 99, 38, 201, 254, 161, 126, 37, 252, 82, 135, 97, 54, 147,
330
1
                    201, 18, 144, 156, 178, 38, 170, 71, 148, 242, 106, 72
331
1
                ]
332
1
            ]
333
1
        );
334
1
    });
335
1
}
336
337
#[test]
338
1
fn state_get_keys_paged_prefix_works() {
339
1
    smol::block_on(async move {
340
5
        let 
client1
=
start_client()1
.await;
341
342
1
        client.send_json_rpc_request(
343
1
            r#"{"jsonrpc":"2.0","id":1,"method":"state_getKeysPaged","params":["0x26aa394e", 2]}"#
344
1
                .to_owned(),
345
1
        );
346
1
        let response_raw = client.next_json_rpc_response().await;
347
1
        let (_, result_json) = json_rpc::parse::parse_response(&response_raw)
348
1
            .unwrap()
349
1
            .into_success()
350
1
            .unwrap();
351
1
        let decoded = serde_json::from_str::<Vec<json_rpc::methods::HexString>>(result_json)
352
1
            .unwrap()
353
1
            .into_iter()
354
2
            .map(|v| v.0)
355
1
            .collect::<Vec<_>>();
356
1
        assert_eq!(
357
1
            decoded,
358
1
            &[
359
1
                &[
360
1
                    38, 170, 57, 78, 234, 86, 48, 224, 124, 72, 174, 12, 149, 88, 206, 247, 78,
361
1
                    123, 144, 18, 9, 107, 65, 196, 235, 58, 175, 148, 127, 110, 164, 41
362
1
                ][..],
363
1
                &[
364
1
                    38, 170, 57, 78, 234, 86, 48, 224, 124, 72, 174, 12, 149, 88, 206, 247, 86,
365
1
                    132, 160, 34, 163, 77, 216, 191, 162, 186, 175, 68, 241, 114, 183, 16
366
1
                ]
367
1
            ]
368
1
        );
369
1
    });
370
1
}
371
372
#[test]
373
1
fn state_get_keys_paged_start_key_exact_match() {
374
1
    smol::block_on(async move {
375
5
        let 
client1
=
start_client()1
.await;
376
377
        // This test checks whether the start key is included in the results on an exact match.
378
        // `0x26aa394eea5630e07c48ae0c9558cef7` is equal to `[38, 170, 57, 78, 234, 86, 48, 224, 124, 72, 174, 12, 149, 88, 206, 247]`.
379
380
1
        client.send_json_rpc_request(
381
1
            r#"{"jsonrpc":"2.0","id":1,"method":"state_getKeysPaged","params":["0x", 2, "0x26aa394eea5630e07c48ae0c9558cef7"]}"#
382
1
                .to_owned(),
383
1
        );
384
1
        let response_raw = client.next_json_rpc_response().
await0
;
385
1
        let (_, result_json) = json_rpc::parse::parse_response(&response_raw)
386
1
            .unwrap()
387
1
            .into_success()
388
1
            .unwrap();
389
1
        let decoded = serde_json::from_str::<Vec<json_rpc::methods::HexString>>(result_json)
390
1
            .unwrap()
391
1
            .into_iter()
392
2
            .map(|v| v.0)
393
1
            .collect::<Vec<_>>();
394
1
        assert_eq!(
395
1
            decoded,
396
1
            &[
397
1
                &[
398
1
                    38, 170, 57, 78, 234, 86, 48, 224, 124, 72, 174, 12, 149, 88, 206, 247, 78,
399
1
                    123, 144, 18, 9, 107, 65, 196, 235, 58, 175, 148, 127, 110, 164, 41
400
1
                ][..],
401
1
                &[
402
1
                    38, 170, 57, 78, 234, 86, 48, 224, 124, 72, 174, 12, 149, 88, 206, 247, 86,
403
1
                    132, 160, 34, 163, 77, 216, 191, 162, 186, 175, 68, 241, 114, 183, 16
404
1
                ]
405
1
            ]
406
1
        );
407
1
    });
408
1
}
409
410
#[test]
411
1
fn state_get_keys_paged_count_overflow() {
412
1
    smol::block_on(async move {
413
5
        let 
client1
=
start_client()1
.await;
414
415
1
        client.send_json_rpc_request(
416
1
            r#"{"jsonrpc":"2.0","id":1,"method":"state_getKeysPaged","params":["0x", 1000]}"#
417
1
                .to_owned(),
418
1
        );
419
1
        let response_raw = client.next_json_rpc_response().
await0
;
420
1
        assert!(
matches!0
(
421
1
            json_rpc::parse::parse_response(&response_raw).unwrap(),
422
            json_rpc::parse::Response::Success { .. }
423
        ));
424
425
1
        client.send_json_rpc_request(
426
1
            r#"{"jsonrpc":"2.0","id":2,"method":"state_getKeysPaged","params":["0x", 1001]}"#
427
1
                .to_owned(),
428
1
        );
429
1
        let response_raw = client.next_json_rpc_response().
await0
;
430
1
        assert!(
matches!0
(
431
1
            json_rpc::parse::parse_response(&response_raw).unwrap(),
432
            json_rpc::parse::Response::Error {
433
                error_code: -32602, // Invalid parameter error code.
434
                ..
435
            }
436
        ));
437
1
    });
438
1
}
439
440
#[test]
441
1
fn state_get_keys_paged_unknown_block() {
442
1
    smol::block_on(async move {
443
5
        let 
client1
=
start_client()1
.await;
444
445
1
        client.send_json_rpc_request(
446
1
            r#"{"jsonrpc":"2.0","id":1,"method":"state_getKeysPaged","params":["0x", 10, "0x", "0x0000000000000000000000000000000000000000000000000000000000000000"]}"#
447
1
                .to_owned(),
448
1
        );
449
1
        let response_raw = client.next_json_rpc_response().await;
450
1
        assert!(
matches!0
(
451
1
            json_rpc::parse::parse_response(&response_raw).unwrap(),
452
            json_rpc::parse::Response::Error {
453
                error_code: -32602, // Invalid parameter error code.
454
                ..
455
            }
456
        ));
457
1
    });
458
1
}
459
460
#[test]
461
1
fn system_chain() {
462
1
    smol::block_on(async move {
463
5
        let 
client1
=
start_client()1
.await;
464
465
1
        client.send_json_rpc_request(
466
1
            r#"{"jsonrpc":"2.0","id":1,"method":"system_chain","params":[]}"#.to_owned(),
467
1
        );
468
469
1
        let response_raw = client.next_json_rpc_response().await;
470
1
        let (_, result_json) = json_rpc::parse::parse_response(&response_raw)
471
1
            .unwrap()
472
1
            .into_success()
473
1
            .unwrap();
474
1
        assert_eq!(
475
1
            serde_json::from_str::<String>(result_json).unwrap(),
476
1
            "Local Testnet"
477
1
        );
478
1
    });
479
1
}
480
481
#[test]
482
1
fn system_chain_type() {
483
1
    smol::block_on(async move {
484
5
        let 
client1
=
start_client()1
.await;
485
486
1
        client.send_json_rpc_request(
487
1
            r#"{"jsonrpc":"2.0","id":1,"method":"system_chainType","params":[]}"#.to_owned(),
488
1
        );
489
490
1
        let response_raw = client.next_json_rpc_response().await;
491
1
        let (_, result_json) = json_rpc::parse::parse_response(&response_raw)
492
1
            .unwrap()
493
1
            .into_success()
494
1
            .unwrap();
495
1
        assert_eq!(
496
1
            serde_json::from_str::<String>(result_json).unwrap(),
497
1
            "Local"
498
1
        );
499
1
    });
500
1
}
501
502
#[test]
503
1
fn system_health() {
504
1
    smol::block_on(async move {
505
5
        let 
client1
=
start_client()1
.await;
506
507
        // Query the runtime of the genesis.
508
1
        client.send_json_rpc_request(
509
1
            r#"{"jsonrpc":"2.0","id":1,"method":"system_health","params":[]}"#.to_owned(),
510
1
        );
511
1
        let response_raw = client.next_json_rpc_response().
await0
;
512
1
        let (_, result_json) = json_rpc::parse::parse_response(&response_raw)
513
1
            .unwrap()
514
1
            .into_success()
515
1
            .unwrap();
516
1
        let decoded = serde_json::from_str::<json_rpc::methods::SystemHealth>(result_json).unwrap();
517
1
        assert_eq!(decoded.peers, 0);
518
1
        assert_eq!(decoded.should_have_peers, true);
519
1
    });
520
1
}
521
522
#[test]
523
1
fn system_local_peer_id() {
524
1
    smol::block_on(async move {
525
5
        let 
client1
=
start_client()1
.await;
526
527
1
        client.send_json_rpc_request(
528
1
            r#"{"jsonrpc":"2.0","id":1,"method":"system_localPeerId","params":[]}"#.to_owned(),
529
1
        );
530
531
1
        let response_raw = client.next_json_rpc_response().await;
532
1
        let (_, result_json) = json_rpc::parse::parse_response(&response_raw)
533
1
            .unwrap()
534
1
            .into_success()
535
1
            .unwrap();
536
1
        assert_eq!(
537
1
            serde_json::from_str::<String>(result_json).unwrap(),
538
1
            "12D3KooWDpJ7As7BWAwRMfu1VU2WCqNjvq387JEYKDBj4kx6nXTN"
539
1
        );
540
1
    });
541
1
}
542
543
#[test]
544
1
fn system_name() {
545
1
    smol::block_on(async move {
546
5
        let 
client1
=
start_client()1
.await;
547
548
1
        client.send_json_rpc_request(
549
1
            r#"{"jsonrpc":"2.0","id":1,"method":"system_name","params":[]}"#.to_owned(),
550
1
        );
551
552
1
        let response_raw = client.next_json_rpc_response().await;
553
1
        let (_, result_json) = json_rpc::parse::parse_response(&response_raw)
554
1
            .unwrap()
555
1
            .into_success()
556
1
            .unwrap();
557
1
        assert_eq!(
558
1
            serde_json::from_str::<String>(result_json).unwrap(),
559
1
            "smoldot-full-node"
560
1
        );
561
1
    });
562
1
}
563
564
#[test]
565
1
fn system_properties() {
566
1
    smol::block_on(async move {
567
5
        let 
client1
=
start_client()1
.await;
568
569
1
        client.send_json_rpc_request(
570
1
            r#"{"jsonrpc":"2.0","id":1,"method":"system_properties","params":[]}"#.to_owned(),
571
1
        );
572
573
1
        let response_raw = client.next_json_rpc_response().await;
574
1
        let (_, result_json) = json_rpc::parse::parse_response(&response_raw)
575
1
            .unwrap()
576
1
            .into_success()
577
1
            .unwrap();
578
1
        assert_eq!(result_json, r#"{"tokenDecimals": 15}"#);
579
1
    });
580
1
}
581
582
#[test]
583
1
fn system_version() {
584
1
    smol::block_on(async move {
585
5
        let 
client1
=
start_client()1
.await;
586
587
1
        client.send_json_rpc_request(
588
1
            r#"{"jsonrpc":"2.0","id":1,"method":"system_version","params":[]}"#.to_owned(),
589
1
        );
590
591
1
        let response_raw = client.next_json_rpc_response().await;
592
        // Note: we don't check the actual result, as the version changes pretty often.
593
1
        json_rpc::parse::parse_response(&response_raw)
594
1
            .unwrap()
595
1
            .into_success()
596
1
            .unwrap();
597
1
    });
598
1
}
599
600
// TODO: add tests for `chain_subscribeAllHeads`
601
// TODO: add tests for `chain_subscribeFinalizedHeads`
602
// TODO: add tests for `chain_subscribeNewHeads`
603
// TODO: add tests for `state_queryStorageAt`