]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Make several tests more robust against harmless transaction changes
authorMatt Corallo <git@bluematt.me>
Sat, 7 Sep 2024 12:57:39 +0000 (12:57 +0000)
committerMatt Corallo <git@bluematt.me>
Wed, 18 Sep 2024 16:48:42 +0000 (16:48 +0000)
In the next commit we'll be changing the order some transactions
get spent in packages, causing some tests to spuriously fail. Here
we update a few tests to avoid that by checking sets of inputs
rather than specific ordering.

lightning/src/ln/monitor_tests.rs

index 200e5ed84f46dc5652414944760a14761c95c428..f0a63f8b9fa0b36487ee81de5c0fc7e3be3bf886 100644 (file)
@@ -1637,15 +1637,15 @@ fn do_test_revoked_counterparty_htlc_tx_balances(anchors: bool) {
                        assert_eq!(as_commitment_claim_txn[0].input[0].previous_output.vout, 4); // Separate to_remote claim
                        check_spends!(as_commitment_claim_txn[0], revoked_local_txn[0]);
                        assert_eq!(as_commitment_claim_txn[1].input.len(), 2);
-                       assert_eq!(as_commitment_claim_txn[1].input[0].previous_output.vout, 2);
-                       assert_eq!(as_commitment_claim_txn[1].input[1].previous_output.vout, 3);
+                       assert!(as_commitment_claim_txn[1].input.iter().any(|inp| inp.previous_output.vout == 2));
+                       assert!(as_commitment_claim_txn[1].input.iter().any(|inp| inp.previous_output.vout == 3));
                        check_spends!(as_commitment_claim_txn[1], revoked_local_txn[0]);
                        Some(as_commitment_claim_txn.remove(0))
                } else {
                        assert_eq!(as_commitment_claim_txn[0].input.len(), 3);
-                       assert_eq!(as_commitment_claim_txn[0].input[0].previous_output.vout, 2);
-                       assert_eq!(as_commitment_claim_txn[0].input[1].previous_output.vout, 0);
-                       assert_eq!(as_commitment_claim_txn[0].input[2].previous_output.vout, 1);
+                       assert!(as_commitment_claim_txn[0].input.iter().any(|inp| inp.previous_output.vout == 2));
+                       assert!(as_commitment_claim_txn[0].input.iter().any(|inp| inp.previous_output.vout == 0));
+                       assert!(as_commitment_claim_txn[0].input.iter().any(|inp| inp.previous_output.vout == 1));
                        check_spends!(as_commitment_claim_txn[0], revoked_local_txn[0]);
                        None
                }
@@ -1953,9 +1953,9 @@ fn do_test_revoked_counterparty_aggregated_claims(anchors: bool) {
                Some(claim_txn.remove(0))
        } else {
                assert_eq!(claim_txn[0].input.len(), 3);
-               assert_eq!(claim_txn[0].input[0].previous_output.vout, 3);
-               assert_eq!(claim_txn[0].input[1].previous_output.vout, 0);
-               assert_eq!(claim_txn[0].input[2].previous_output.vout, 1);
+               assert!(claim_txn[0].input.iter().any(|inp| inp.previous_output.vout == 3));
+               assert!(claim_txn[0].input.iter().any(|inp| inp.previous_output.vout == 0));
+               assert!(claim_txn[0].input.iter().any(|inp| inp.previous_output.vout == 1));
                check_spends!(claim_txn[0], as_revoked_txn[0]);
                None
        };