use crate::network::PersistentNetworkActorState;
use crate::schema::PUBLIC_KEY_NETWORK_ACTOR_STATE_PREFIX;
use super::{deterministic_pubkey, StoreSample};
impl StoreSample for PersistentNetworkActorState {
const STORE_PREFIX: u8 = PUBLIC_KEY_NETWORK_ACTOR_STATE_PREFIX;
const TYPE_NAME: &'static str = "PersistentNetworkActorState";
fn samples(seed: u64) -> Vec<Self> {
vec![sample_minimal(), sample_full(seed)]
}
}
fn sample_minimal() -> PersistentNetworkActorState {
PersistentNetworkActorState::new()
}
fn sample_full(seed: u64) -> PersistentNetworkActorState {
let pubkey1 = deterministic_pubkey(seed, 0);
let json = serde_json::json!({
"saved_peer_addresses": {
(hex::encode(pubkey1.serialize())): ["/ip4/127.0.0.1/tcp/8000", "/ip4/10.0.0.1/tcp/7000"],
},
});
serde_json::from_value(json).expect("PersistentNetworkActorState JSON deserialization")
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_persistent_network_actor_state_samples_roundtrip() {
PersistentNetworkActorState::verify_samples_roundtrip(42);
}
#[test]
fn test_persistent_network_actor_state_samples_deterministic() {
let bytes_a = PersistentNetworkActorState::sample_bytes(42);
let bytes_b = PersistentNetworkActorState::sample_bytes(42);
assert_eq!(bytes_a, bytes_b, "Same seed must produce identical bytes");
}
#[test]
fn test_persistent_network_actor_state_different_seeds() {
let bytes_42 = PersistentNetworkActorState::sample_bytes(42);
let bytes_99 = PersistentNetworkActorState::sample_bytes(99);
assert_ne!(
bytes_42, bytes_99,
"Different seeds should produce different bytes"
);
}
#[test]
fn test_persistent_network_actor_state_sample_count() {
let samples = PersistentNetworkActorState::samples(42);
assert_eq!(samples.len(), 2, "Should produce 2 sample variants");
}
}