iuna

iuna - experimental devnet protocol
git clone https://iuna.jhx.app/git/iuna.git
Log | Files | Refs | README | LICENSE

test_support.rs (1800B)


      1 use std::{collections::BTreeMap, net::SocketAddr, sync::Arc};
      2 
      3 use crate::{
      4     app::{NodeCore, PeerBook},
      5     domain::{Amount, GenesisBurn, Ledger, Transaction, Wallet},
      6 };
      7 
      8 use super::{GossipNetwork, GossipNetworkInner, InboundConnectionLimiter, P2pMetricsCounters};
      9 
     10 pub(super) fn node(
     11     _network_key: &str,
     12     wallet: Wallet,
     13     allocations: BTreeMap<String, Amount>,
     14 ) -> NodeCore {
     15     let ledger = Ledger::new_with_genesis_burns(
     16         allocations,
     17         vec![GenesisBurn::new(wallet.address(), 1)],
     18         25,
     19     )
     20     .unwrap();
     21     NodeCore::from_ledger(wallet, ledger, 0)
     22 }
     23 
     24 pub(super) fn queue_plaintext_burn(
     25     node: &mut NodeCore,
     26     wallet: &Wallet,
     27     amount: Amount,
     28 ) -> Transaction {
     29     let tx = node.ledger().build_burn(wallet, amount, 0).unwrap();
     30     node.receive_transaction(tx.clone()).unwrap();
     31     tx
     32 }
     33 
     34 pub(super) fn allocations(wallets: &[Wallet], amount: Amount) -> BTreeMap<String, Amount> {
     35     wallets
     36         .iter()
     37         .map(|wallet| (wallet.address().to_string(), amount))
     38         .collect()
     39 }
     40 
     41 pub(super) fn gossip_network(
     42     node: Arc<tokio::sync::Mutex<NodeCore>>,
     43     peers: Arc<tokio::sync::Mutex<PeerBook>>,
     44     listen_addr: SocketAddr,
     45     p2p_announce_addr: Option<SocketAddr>,
     46 ) -> GossipNetwork {
     47     GossipNetwork {
     48         inner: Arc::new(GossipNetworkInner {
     49             node,
     50             peers,
     51             listen_addr,
     52             p2p_announce_addr: tokio::sync::Mutex::new(p2p_announce_addr),
     53             node_id: super::new_node_id(),
     54             accept_task: tokio::sync::Mutex::new(None),
     55             sessions: tokio::sync::Mutex::new(BTreeMap::new()),
     56             inbound_limiter: Arc::new(std::sync::Mutex::new(InboundConnectionLimiter::default())),
     57             metrics: P2pMetricsCounters::default(),
     58         }),
     59     }
     60 }