@@ -3130,7 +3130,7 @@ def make_coin(idx: int) -> Coin:
31303130
31313131def test_dedup_by_fee () -> None :
31323132 """
3133- We pick the solution to use for dedup based on the spend with the highest
3133+ We pick the solution to use for dedup based on the spendbundle with the highest
31343134 fee per cost, not based on which one would give the overall best fee per cost
31353135 """
31363136 mempool = construct_mempool ()
@@ -3141,26 +3141,31 @@ def add_spend_bundles(spend_bundles: list[SpendBundle]) -> None:
31413141 mempool .add_to_pool (mi )
31423142 invariant_check_mempool (mempool )
31433143
3144+ DEDUP_COIN = make_coin (0 )
3145+ COIN_A1 = make_coin (1 )
3146+ COIN_A2 = make_coin (2 )
3147+ # all other coins belong to solution B, the dedup alternative to solution A
3148+
31443149 # Create a spend bundle with a high fee, spending sb_A, which supports dedup
3145- sb_A = make_test_spendbundle (make_coin ( 0 ) )
3146- sb_high_rate = make_test_spendbundle (make_coin ( 1 ) , fee = 10 )
3150+ sb_A = make_test_spendbundle (DEDUP_COIN )
3151+ sb_high_rate = make_test_spendbundle (COIN_A1 , fee = 10 )
31473152 add_spend_bundles ([sb_A , sb_high_rate ])
31483153
31493154 # Create a spend bundle, with a low fee, that spends the dedup coin using the same solution A
3150- sb_low_rate = make_test_spendbundle (make_coin ( 2 ) , fee = 10 )
3155+ sb_low_rate = make_test_spendbundle (COIN_A2 , fee = 10 )
31513156 add_spend_bundles ([sb_A , sb_low_rate ])
31523157
31533158 # validate that dedup happens at all for sb_A
31543159 result = mempool .create_bundle_from_mempool_items (test_constants , uint32 (0 ))
31553160 assert result is not None
31563161 agg , _ = result
31573162 # Make sure both items would be processed
3158- assert [c .coin for c in agg .coin_spends ] == [make_coin ( 0 ), make_coin ( 1 ), make_coin ( 2 ) ]
3163+ assert [c .coin for c in agg .coin_spends ] == [DEDUP_COIN , COIN_A1 , COIN_A2 ]
31593164
31603165 # Now we add a bunch of alternative spends for coin 0, with lower fees
31613166 # Even though the total fee would be higher if we deduped on this solution,
31623167 # we won't.
3163- sb_B = make_test_spendbundle (make_coin ( 0 ) , with_higher_cost = True )
3168+ sb_B = make_test_spendbundle (DEDUP_COIN , with_higher_cost = True )
31643169 for i in range (3 , 600 ):
31653170 sb_high_rate = make_test_spendbundle (make_coin (i ), fee = 10 )
31663171 add_spend_bundles ([sb_B , sb_high_rate ])
@@ -3169,8 +3174,9 @@ def add_spend_bundles(spend_bundles: list[SpendBundle]) -> None:
31693174 assert result is not None
31703175 agg , _ = result
31713176 # We ran with solution A and missed bigger savings on solution B
3177+ # we've added 599 spend bundles now. 2 with solution A and 598 with solution B
31723178 assert mempool .size () == 599
3173- assert [c .coin for c in agg .coin_spends ] == [make_coin ( 0 ), make_coin ( 1 ), make_coin ( 2 ) ]
3179+ assert [c .coin for c in agg .coin_spends ] == [DEDUP_COIN , COIN_A1 , COIN_A2 ]
31743180
31753181 # Now, if we add a high fee per-cost-for sb_B, it should be picked
31763182 sb_high_rate = make_test_spendbundle (make_coin (600 ), fee = 1_000_000_000 )
@@ -3181,11 +3187,12 @@ def add_spend_bundles(spend_bundles: list[SpendBundle]) -> None:
31813187 agg , _ = result
31823188 # The 3 items got skipped here
31833189 # We ran with solution B
3190+ # we've added 600 spend bundles now. 2 with solution A and 599 with solution B
31843191 assert mempool .size () == 600
31853192 spends_in_block = {c .coin for c in agg .coin_spends }
3186- assert make_coin ( 0 ) in spends_in_block
3187- assert make_coin ( 1 ) not in spends_in_block
3188- assert make_coin ( 2 ) not in spends_in_block
3193+ assert DEDUP_COIN in spends_in_block
3194+ assert COIN_A1 not in spends_in_block
3195+ assert COIN_A2 not in spends_in_block
31893196
31903197 for i in range (3 , 601 ):
31913198 assert make_coin (i ) in spends_in_block
0 commit comments