1212import pytest
1313from chia_rs import (
1414 AugSchemeMPL ,
15+ Coin ,
1516 ConsensusConstants ,
1617 Foliage ,
1718 FoliageTransactionBlock ,
111112from chia .wallet .wallet_spend_bundle import WalletSpendBundle
112113
113114
115+ def find_reward_coin (b : FullBlock , puzzle_hash : bytes32 ) -> Coin :
116+ for c in b .get_included_reward_coins ():
117+ if c .puzzle_hash == puzzle_hash :
118+ return c
119+ raise ValueError ("no reward coin with the specified puzzle hash found" )
120+
121+
114122def test_pre_validation_result () -> None :
115123 conds = SpendBundleConditions ([], 0 , 0 , 0 , None , None , [], 0 , 0 , 0 , True , 0 , 0 , 0 , 0 , 0 )
116124 results = PreValidationResult (None , uint64 (1 ), conds , uint32 (0 ))
@@ -812,11 +820,10 @@ async def test_respond_unfinished(
812820 block_list_input = blocks ,
813821 guarantee_transaction_block = True ,
814822 farmer_reward_puzzle_hash = ph ,
815- pool_reward_puzzle_hash = ph ,
816823 )
817824 await full_node_1 .full_node .add_block (blocks [- 2 ])
818825 await full_node_1 .full_node .add_block (blocks [- 1 ])
819- coin_to_spend = blocks [- 1 ]. get_included_reward_coins ()[ 0 ]
826+ coin_to_spend = find_reward_coin ( blocks [- 1 ], ph )
820827
821828 spend_bundle = wallet_a .generate_signed_transaction (coin_to_spend .amount , ph_receiver , coin_to_spend )
822829
@@ -936,7 +943,6 @@ async def test_new_transaction_and_mempool(
936943 3 ,
937944 guarantee_transaction_block = True ,
938945 farmer_reward_puzzle_hash = wallet_ph ,
939- pool_reward_puzzle_hash = wallet_ph ,
940946 )
941947 for block in blocks :
942948 await full_node_1 .full_node .add_block (block )
@@ -1127,7 +1133,6 @@ async def test_request_respond_transaction(
11271133 block_list_input = blocks ,
11281134 guarantee_transaction_block = True ,
11291135 farmer_reward_puzzle_hash = wallet_ph ,
1130- pool_reward_puzzle_hash = wallet_ph ,
11311136 )
11321137
11331138 incoming_queue , _dummy_node_id = await add_dummy_connection (server_1 , self_hostname , 12312 )
@@ -1148,9 +1153,8 @@ async def test_request_respond_transaction(
11481153
11491154 receiver_puzzlehash = wallet_receiver .get_new_puzzlehash ()
11501155
1151- spend_bundle = wallet_a .generate_signed_transaction (
1152- uint64 (100 ), receiver_puzzlehash , blocks [- 1 ].get_included_reward_coins ()[0 ]
1153- )
1156+ coin = find_reward_coin (blocks [- 1 ], wallet_ph )
1157+ spend_bundle = wallet_a .generate_signed_transaction (uint64 (100 ), receiver_puzzlehash , coin )
11541158 assert spend_bundle is not None
11551159 respond_transaction = fnp .RespondTransaction (spend_bundle )
11561160 res = await full_node_1 .respond_transaction (respond_transaction , peer )
@@ -1192,7 +1196,6 @@ async def test_respond_transaction_fail(
11921196 block_list_input = blocks ,
11931197 guarantee_transaction_block = True ,
11941198 farmer_reward_puzzle_hash = cb_ph ,
1195- pool_reward_puzzle_hash = cb_ph ,
11961199 )
11971200 await asyncio .sleep (1 )
11981201 while incoming_queue .qsize () > 0 :
@@ -1204,11 +1207,8 @@ async def test_respond_transaction_fail(
12041207
12051208 await time_out_assert (10 , time_out_messages (incoming_queue , "new_peak" , 3 ))
12061209 # Invalid transaction does not propagate
1207- spend_bundle = wallet_a .generate_signed_transaction (
1208- uint64 (100_000_000_000_000 ),
1209- receiver_puzzlehash ,
1210- blocks_new [- 1 ].get_included_reward_coins ()[0 ],
1211- )
1210+ coin = find_reward_coin (blocks_new [- 1 ], cb_ph )
1211+ spend_bundle = wallet_a .generate_signed_transaction (uint64 (100_000_000_000_000 ), receiver_puzzlehash , coin )
12121212
12131213 assert spend_bundle is not None
12141214 respond_transaction = fnp .RespondTransaction (spend_bundle )
@@ -1228,18 +1228,15 @@ async def test_request_block(
12281228 full_node_1 , _full_node_2 , _server_1 , _server_2 , wallet_a , wallet_receiver , bt = wallet_nodes
12291229 blocks = await full_node_1 .get_all_full_blocks ()
12301230
1231+ wallet_ph = wallet_a .get_new_puzzlehash ()
12311232 blocks = bt .get_consecutive_blocks (
12321233 3 ,
12331234 block_list_input = blocks ,
12341235 guarantee_transaction_block = True ,
1235- farmer_reward_puzzle_hash = wallet_a .get_new_puzzlehash (),
1236- pool_reward_puzzle_hash = wallet_a .get_new_puzzlehash (),
1237- )
1238- spend_bundle = wallet_a .generate_signed_transaction (
1239- uint64 (1123 ),
1240- wallet_receiver .get_new_puzzlehash (),
1241- blocks [- 1 ].get_included_reward_coins ()[0 ],
1236+ farmer_reward_puzzle_hash = wallet_ph ,
12421237 )
1238+ coin = find_reward_coin (blocks [- 1 ], wallet_ph )
1239+ spend_bundle = wallet_a .generate_signed_transaction (uint64 (1123 ), wallet_receiver .get_new_puzzlehash (), coin )
12431240 blocks = bt .get_consecutive_blocks (
12441241 1 , block_list_input = blocks , guarantee_transaction_block = True , transaction_data = spend_bundle
12451242 )
@@ -1280,18 +1277,19 @@ async def test_request_blocks(
12801277 blocks = await full_node_1 .get_all_full_blocks ()
12811278
12821279 # create more blocks than constants.MAX_BLOCK_COUNT_PER_REQUEST (32)
1280+ wallet_ph = wallet_a .get_new_puzzlehash ()
12831281 blocks = bt .get_consecutive_blocks (
12841282 33 ,
12851283 block_list_input = blocks ,
12861284 guarantee_transaction_block = True ,
1287- farmer_reward_puzzle_hash = wallet_a .get_new_puzzlehash (),
1288- pool_reward_puzzle_hash = wallet_a .get_new_puzzlehash (),
1285+ farmer_reward_puzzle_hash = wallet_ph ,
12891286 )
12901287
1288+ coin = find_reward_coin (blocks [- 1 ], wallet_ph )
12911289 spend_bundle = wallet_a .generate_signed_transaction (
12921290 uint64 (1123 ),
12931291 wallet_receiver .get_new_puzzlehash (),
1294- blocks [ - 1 ]. get_included_reward_coins ()[ 0 ] ,
1292+ coin ,
12951293 )
12961294 blocks_t = bt .get_consecutive_blocks (
12971295 1 , block_list_input = blocks , guarantee_transaction_block = True , transaction_data = spend_bundle
@@ -3325,15 +3323,17 @@ async def test_pending_tx_cache_retry_on_new_peak(
33253323 wallet = WalletTool (test_constants )
33263324 ph = wallet .get_new_puzzlehash ()
33273325 blocks = bt .get_consecutive_blocks (
3328- 3 , guarantee_transaction_block = True , farmer_reward_puzzle_hash = ph , pool_reward_puzzle_hash = ph
3326+ 3 ,
3327+ guarantee_transaction_block = True ,
3328+ farmer_reward_puzzle_hash = ph ,
33293329 )
33303330 for block in blocks :
33313331 await full_node_api .full_node .add_block (block )
33323332 peak = full_node_api .full_node .blockchain .get_peak ()
33333333 assert peak is not None
33343334 current_height = peak .height
33353335 # Create a transaction with a height condition that makes it pending
3336- coin = blocks [- 1 ]. get_included_reward_coins ()[ 0 ]
3336+ coin = find_reward_coin ( blocks [- 1 ], ph )
33373337 if condition == ConditionOpcode .ASSERT_HEIGHT_RELATIVE :
33383338 condition_height = 1
33393339 else :
@@ -3406,13 +3406,11 @@ async def test_ban_for_mismatched_tx_cost_fee(
34063406 else :
34073407 node = full_node_2 .full_node
34083408 ws_con = ws_con_2
3409- blocks = bt .get_consecutive_blocks (
3410- 3 , guarantee_transaction_block = True , farmer_reward_puzzle_hash = wallet_ph , pool_reward_puzzle_hash = wallet_ph
3411- )
3409+ blocks = bt .get_consecutive_blocks (3 , guarantee_transaction_block = True , farmer_reward_puzzle_hash = wallet_ph )
34123410 for block in blocks :
34133411 await node .add_block (block )
34143412 # Create a transaction and add it to the relevant full node's mempool
3415- coin = blocks [- 1 ]. get_included_reward_coins ()[ 0 ]
3413+ coin = find_reward_coin ( blocks [- 1 ], wallet_ph )
34163414 sb = wallet .generate_signed_transaction (uint64 (42 ), wallet_ph , coin )
34173415 sb_name = sb .name ()
34183416 await node .add_transaction (sb , sb_name , ws_con )
0 commit comments