Преглед изворни кода

darkfid/tests: use diff p2p ports on nodes of each test so they communicate with the ones expected when running concurently

skoupidi пре 2 година
родитељ
комит
90b024f5fc

+ 4 - 2
bin/darkfid/src/tests/harness.rs

@@ -47,6 +47,8 @@ pub struct HarnessConfig {
     pub pow_target: u32,
     pub pow_fixed_difficulty: Option<BigUint>,
     pub finalization_threshold: usize,
+    pub alice_url: String,
+    pub bob_url: String,
 }
 
 pub struct Harness {
@@ -89,12 +91,12 @@ impl Harness {
             Settings { localnet: true, inbound_connections: 3, ..Default::default() };
 
         // Alice
-        let alice_url = Url::parse("tcp+tls://127.0.0.1:18340")?;
+        let alice_url = Url::parse(&config.alice_url)?;
         settings.inbound_addrs = vec![alice_url.clone()];
         let alice = generate_node(&vks, &validator_config, &settings, ex, true, true, None).await?;
 
         // Bob
-        let bob_url = Url::parse("tcp+tls://127.0.0.1:18341")?;
+        let bob_url = Url::parse(&config.bob_url)?;
         settings.inbound_addrs = vec![bob_url];
         settings.peers = vec![alice_url];
         let bob = generate_node(&vks, &validator_config, &settings, ex, true, false, None).await?;

+ 2 - 0
bin/darkfid/src/tests/mod.rs

@@ -44,6 +44,8 @@ async fn sync_blocks_real(ex: Arc<Executor<'static>>) -> Result<()> {
         pow_target,
         pow_fixed_difficulty: pow_fixed_difficulty.clone(),
         finalization_threshold: 3,
+        alice_url: "tcp+tls://127.0.0.1:18340".to_string(),
+        bob_url: "tcp+tls://127.0.0.1:18341".to_string(),
     };
     let th = Harness::new(config, true, &ex).await?;
 

+ 3 - 1
bin/darkfid/src/tests/sync_forks.rs

@@ -37,6 +37,8 @@ async fn sync_forks_real(ex: Arc<Executor<'static>>) -> Result<()> {
         pow_target,
         pow_fixed_difficulty: pow_fixed_difficulty.clone(),
         finalization_threshold: 6,
+        alice_url: "tcp+tls://127.0.0.1:18440".to_string(),
+        bob_url: "tcp+tls://127.0.0.1:18441".to_string(),
     };
     let th = Harness::new(config, true, &ex).await?;
 
@@ -63,7 +65,7 @@ async fn sync_forks_real(ex: Arc<Executor<'static>>) -> Result<()> {
     // We are going to create a third node and try to sync from Bob
     let mut settings = Settings { localnet: true, inbound_connections: 3, ..Default::default() };
 
-    let charlie_url = Url::parse("tcp+tls://127.0.0.1:18342")?;
+    let charlie_url = Url::parse("tcp+tls://127.0.0.1:18442")?;
     settings.inbound_addrs = vec![charlie_url];
     let bob_url = th.bob.p2p.settings().inbound_addrs[0].clone();
     settings.peers = vec![bob_url];

+ 24 - 4
bin/darkfid/src/tests/unproposed_txs.rs

@@ -41,7 +41,12 @@ use smol::Executor;
 
 /// Simulates the processing of a specified number of unproposed transactions, returning
 /// the total number of unproposed transactions and gas used.
-async fn simulate_unproposed_txs(num_txs: u64, ex: Arc<Executor<'static>>) -> Result<(u64, u64)> {
+async fn simulate_unproposed_txs(
+    num_txs: u64,
+    alice_url: String,
+    bob_url: String,
+    ex: Arc<Executor<'static>>,
+) -> Result<(u64, u64)> {
     init_logger();
 
     // Set current block height used to create and retrieve unproposed transactions
@@ -54,6 +59,8 @@ async fn simulate_unproposed_txs(num_txs: u64, ex: Arc<Executor<'static>>) -> Re
         pow_target,
         pow_fixed_difficulty: pow_fixed_difficulty.clone(),
         finalization_threshold: 6,
+        alice_url,
+        bob_url,
     };
 
     // Create chain test harness using created configuration
@@ -113,7 +120,14 @@ fn test_unproposed_txs_within_gas_limit() -> Result<()> {
         || {
             smol::block_on(async {
                 // Receive number of unproposed txs within gas limit
-                let (num_unproposed_txs, _) = simulate_unproposed_txs(5, ex.clone()).await.unwrap();
+                let (num_unproposed_txs, _) = simulate_unproposed_txs(
+                    5,
+                    "tcp+tls://127.0.0.1:18540".to_string(),
+                    "tcp+tls://127.0.0.1:18541".to_string(),
+                    ex.clone(),
+                )
+                .await
+                .unwrap();
 
                 // Shutdown spawned nodes
                 signal.send(()).await.unwrap();
@@ -142,8 +156,14 @@ fn test_unproposed_txs_exceeding_gas_limit() -> Result<()> {
         || {
             smol::block_on(async {
                 // Receive total gas used by simulating a number of transactions that will exceed gas limit
-                let (num_unproposed_txs, total_gas_used) =
-                    simulate_unproposed_txs(135, ex.clone()).await.unwrap();
+                let (num_unproposed_txs, total_gas_used) = simulate_unproposed_txs(
+                    135,
+                    "tcp+tls://127.0.0.1:18640".to_string(),
+                    "tcp+tls://127.0.0.1:18641".to_string(),
+                    ex.clone(),
+                )
+                .await
+                .unwrap();
 
                 // Shutdown spawned nodes
                 signal.send(()).await.unwrap();