Coverage Report

Created: 2024-05-16 12:16

/__w/smoldot/smoldot/repo/full-node/tests/author.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
#[test]
22
#[ignore] // TODO: restore after https://github.com/smol-dot/smoldot/issues/1109
23
0
fn basic_block_generated() {
24
0
    smol::block_on(async move {
25
0
        let client = smoldot_full_node::start(smoldot_full_node::Config {
26
0
            chain: smoldot_full_node::ChainConfig {
27
0
                chain_spec: (&include_bytes!("./substrate-node-template.json")[..]).into(),
28
0
                additional_bootnodes: Vec::new(),
29
0
                keystore_memory: vec![smoldot::identity::seed_phrase::decode_sr25519_private_key(
30
0
                    "//Alice",
31
0
                )
32
0
                .unwrap()],
33
0
                sqlite_database_path: None,
34
0
                sqlite_cache_size: 256 * 1024 * 1024,
35
0
                keystore_path: None,
36
0
                json_rpc_listen: None,
37
0
            },
38
0
            relay_chain: None,
39
0
            libp2p_key: Box::new([0; 32]),
40
0
            listen_addresses: Vec::new(),
41
0
            tasks_executor: Arc::new(|task| smol::spawn(task).detach()),
42
0
            log_callback: Arc::new(move |_, _| {}),
43
0
            jaeger_agent: None,
44
0
        })
45
0
        .await
46
0
        .unwrap();
47
48
0
        loop {
49
0
            client.send_json_rpc_request(
50
0
                r#"{"jsonrpc":"2.0","id":1,"method":"chainHead_v1_follow","params":[false]}"#
51
0
                    .to_owned(),
52
0
            );
53
0
54
0
            let _ = json_rpc::parse::parse_response(&client.next_json_rpc_response().await)
55
0
                .unwrap()
56
0
                .into_success()
57
0
                .unwrap();
58
59
            loop {
60
0
                match json_rpc::methods::parse_notification(&client.next_json_rpc_response().await)
61
0
                    .unwrap()
62
                {
63
                    json_rpc::methods::ServerToClient::chainHead_v1_followEvent {
64
                        result: json_rpc::methods::FollowEvent::NewBlock { .. },
65
                        ..
66
0
                    } => return, // Test success
67
                    json_rpc::methods::ServerToClient::chainHead_v1_followEvent {
68
                        result: json_rpc::methods::FollowEvent::Stop { .. },
69
                        ..
70
0
                    } => break,
71
0
                    _ => {}
72
                }
73
            }
74
        }
75
0
    });
76
0
}