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
use diem_crypto::{
traits::Uniform,
x25519::{PrivateKey, PublicKey},
};
use diem_types::network_address as address;
use network::protocols::wire::{handshake, messaging};
use rand::{rngs::StdRng, SeedableRng};
use serde_reflection::{Registry, Result, Samples, Tracer, TracerConfig};
use std::str::FromStr;
pub fn output_file() -> Option<&'static str> {
Some("tests/staged/network.yaml")
}
fn trace_crypto_values(tracer: &mut Tracer, samples: &mut Samples) -> Result<()> {
let mut rng: StdRng = SeedableRng::from_seed([0; 32]);
let private_key = PrivateKey::generate(&mut rng);
let public_key: PublicKey = (&private_key).into();
tracer.trace_value(samples, &public_key)?;
Ok(())
}
pub fn get_registry() -> Result<Registry> {
let mut tracer =
Tracer::new(TracerConfig::default().is_human_readable(bcs::is_human_readable()));
let mut samples = Samples::new();
trace_crypto_values(&mut tracer, &mut samples)?;
tracer.trace_value(
&mut samples,
&address::DnsName::from_str("example.com").unwrap(),
)?;
tracer.trace_value(&mut samples, &address::NetworkAddress::mock())?;
tracer.trace_type::<messaging::v1::NetworkMessage>(&samples)?;
tracer.trace_type::<handshake::v1::HandshakeMsg>(&samples)?;
tracer.trace_type::<address::NetworkAddress>(&samples)?;
tracer.trace_type::<address::encrypted::EncNetworkAddress>(&samples)?;
tracer.trace_type::<messaging::v1::ErrorCode>(&samples)?;
tracer.trace_type::<messaging::v1::ParsingErrorType>(&samples)?;
tracer.trace_type::<messaging::v1::NotSupportedType>(&samples)?;
tracer.trace_type::<handshake::v1::ProtocolId>(&samples)?;
tracer.trace_type::<address::Protocol>(&samples)?;
tracer.trace_type::<diem_config::network_id::NetworkId>(&samples)?;
tracer.registry()
}