]> Untitled Git - bdk/commitdiff
Use mixed order insertions
authorTobin Harding <me@tobin.cc>
Wed, 24 Feb 2021 02:39:36 +0000 (13:39 +1100)
committerTobin Harding <me@tobin.cc>
Wed, 24 Feb 2021 02:39:36 +0000 (13:39 +1100)
Currently we have a unit test to test that signers are sorted by
ordering. We call `add_external` to add them but currently we add them
in the same order we expect them to be in. This means if the
implementation happens to insert them simply in the order they are
added (i.e. insert to end of list) then this test will still pass.

Insert in a mixed order, including one lower followed by one higher -
this ensures we are not inserting at the front or at the back but are
actually sorting based on the `SignerOrdering`.

src/wallet/signer.rs

index a573c6e1986e92eeda65d3807e88f0727f42e2f2..eebafa586fd36673eb54d5ea8ba55ef9238e6665 100644 (file)
@@ -602,8 +602,9 @@ mod signers_container_tests {
         let signer2 = Arc::new(DummySigner { number: 2 });
         let signer3 = Arc::new(DummySigner { number: 3 });
 
-        signers.add_external(SignerId::Dummy(1), SignerOrdering(1), signer1.clone());
+        // Mixed order insertions verifies we are not inserting at head or tail.
         signers.add_external(SignerId::Dummy(2), SignerOrdering(2), signer2.clone());
+        signers.add_external(SignerId::Dummy(1), SignerOrdering(1), signer1.clone());
         signers.add_external(SignerId::Dummy(3), SignerOrdering(3), signer3.clone());
 
         // Check that signers are sorted from lowest to highest ordering