141
141
PushTransactions ,
142
142
PushTX ,
143
143
RoyaltyAsset ,
144
+ SelectCoins ,
144
145
SendTransaction ,
145
146
SetWalletResyncOnStartup ,
146
147
SpendClawbackCoins ,
@@ -645,10 +646,12 @@ async def test_create_signed_transaction(
645
646
646
647
selected_coin = None
647
648
if select_coin :
648
- selected_coin = await wallet_1_rpc .select_coins (
649
- amount = amount_total , wallet_id = wallet_id , coin_selection_config = DEFAULT_COIN_SELECTION_CONFIG
649
+ select_coins_response = await wallet_1_rpc .select_coins (
650
+ SelectCoins .from_coin_selection_config (
651
+ amount = amount_total , wallet_id = uint32 (wallet_id ), coin_selection_config = DEFAULT_COIN_SELECTION_CONFIG
652
+ )
650
653
)
651
- assert len (selected_coin ) == 1
654
+ assert len (select_coins_response . coins ) == 1
652
655
653
656
txs = (
654
657
await wallet_1_rpc .create_signed_transactions (
@@ -784,38 +787,42 @@ async def test_create_signed_transaction_with_excluded_coins(wallet_rpc_environm
784
787
await generate_funds (full_node_api , env .wallet_1 )
785
788
786
789
async def it_does_not_include_the_excluded_coins () -> None :
787
- selected_coins = await wallet_1_rpc .select_coins (
788
- amount = 250000000000 , wallet_id = 1 , coin_selection_config = DEFAULT_COIN_SELECTION_CONFIG
790
+ select_coins_response = await wallet_1_rpc .select_coins (
791
+ SelectCoins .from_coin_selection_config (
792
+ amount = uint64 (250000000000 ), wallet_id = uint32 (1 ), coin_selection_config = DEFAULT_COIN_SELECTION_CONFIG
793
+ )
789
794
)
790
- assert len (selected_coins ) == 1
795
+ assert len (select_coins_response . coins ) == 1
791
796
outputs = await create_tx_outputs (wallet_1 , [(uint64 (250000000000 ), None )])
792
797
793
798
tx = (
794
799
await wallet_1_rpc .create_signed_transactions (
795
800
outputs ,
796
801
DEFAULT_TX_CONFIG .override (
797
- excluded_coin_ids = [c .name () for c in selected_coins ],
802
+ excluded_coin_ids = [c .name () for c in select_coins_response . coins ],
798
803
),
799
804
)
800
805
).signed_tx
801
806
802
807
assert len (tx .removals ) == 1
803
- assert tx .removals [0 ] != selected_coins [0 ]
808
+ assert tx .removals [0 ] != select_coins_response . coins [0 ]
804
809
assert tx .removals [0 ].amount == uint64 (1750000000000 )
805
810
await assert_push_tx_error (full_node_rpc , tx )
806
811
807
812
async def it_throws_an_error_when_all_spendable_coins_are_excluded () -> None :
808
- selected_coins = await wallet_1_rpc .select_coins (
809
- amount = 1750000000000 , wallet_id = 1 , coin_selection_config = DEFAULT_COIN_SELECTION_CONFIG
813
+ select_coins_response = await wallet_1_rpc .select_coins (
814
+ SelectCoins .from_coin_selection_config (
815
+ amount = uint64 (1750000000000 ), wallet_id = uint32 (1 ), coin_selection_config = DEFAULT_COIN_SELECTION_CONFIG
816
+ )
810
817
)
811
- assert len (selected_coins ) == 1
818
+ assert len (select_coins_response . coins ) == 1
812
819
outputs = await create_tx_outputs (wallet_1 , [(uint64 (1750000000000 ), None )])
813
820
814
821
with pytest .raises (ValueError ):
815
822
await wallet_1_rpc .create_signed_transactions (
816
823
outputs ,
817
824
DEFAULT_TX_CONFIG .override (
818
- excluded_coin_ids = [c .name () for c in selected_coins ],
825
+ excluded_coin_ids = [c .name () for c in select_coins_response . coins ],
819
826
),
820
827
)
821
828
@@ -960,8 +967,10 @@ async def test_send_transaction_multi(wallet_rpc_environment: WalletRpcTestEnvir
960
967
961
968
generated_funds = await generate_funds (full_node_api , env .wallet_1 )
962
969
963
- removals = await client .select_coins (
964
- 1750000000000 , wallet_id = 1 , coin_selection_config = DEFAULT_COIN_SELECTION_CONFIG
970
+ select_coins_response = await client .select_coins (
971
+ SelectCoins .from_coin_selection_config (
972
+ amount = uint64 (1750000000000 ), wallet_id = uint32 (1 ), coin_selection_config = DEFAULT_COIN_SELECTION_CONFIG
973
+ )
965
974
) # we want a coin that won't be selected by default
966
975
outputs = await create_tx_outputs (wallet_2 , [(uint64 (1 ), ["memo_1" ]), (uint64 (2 ), ["memo_2" ])])
967
976
amount_outputs = sum (output ["amount" ] for output in outputs )
@@ -972,7 +981,7 @@ async def test_send_transaction_multi(wallet_rpc_environment: WalletRpcTestEnvir
972
981
1 ,
973
982
outputs ,
974
983
DEFAULT_TX_CONFIG ,
975
- coins = removals ,
984
+ coins = select_coins_response . coins ,
976
985
fee = amount_fee ,
977
986
)
978
987
).transaction
@@ -981,7 +990,7 @@ async def test_send_transaction_multi(wallet_rpc_environment: WalletRpcTestEnvir
981
990
assert send_tx_res is not None
982
991
983
992
assert_tx_amounts (send_tx_res , outputs , amount_fee = amount_fee , change_expected = True )
984
- assert send_tx_res .removals == removals
993
+ assert send_tx_res .removals == select_coins_response . coins
985
994
986
995
await farm_transaction (full_node_api , wallet_node , spend_bundle )
987
996
@@ -1355,8 +1364,12 @@ async def test_cat_endpoints(wallet_environments: WalletTestFramework, wallet_ty
1355
1364
await wallet_environments .process_pending_states (cat_spend_changes )
1356
1365
1357
1366
# Test CAT spend with a fee and pre-specified removals / coins
1358
- removals = await env_0 .rpc_client .select_coins (
1359
- amount = uint64 (2 ), wallet_id = cat_0_id , coin_selection_config = wallet_environments .tx_config .coin_selection_config
1367
+ select_coins_response = await env_0 .rpc_client .select_coins (
1368
+ SelectCoins .from_coin_selection_config (
1369
+ amount = uint64 (2 ),
1370
+ wallet_id = cat_0_id ,
1371
+ coin_selection_config = wallet_environments .tx_config .coin_selection_config ,
1372
+ )
1360
1373
)
1361
1374
tx_res = await env_0 .rpc_client .cat_spend (
1362
1375
cat_0_id ,
@@ -1365,12 +1378,12 @@ async def test_cat_endpoints(wallet_environments: WalletTestFramework, wallet_ty
1365
1378
addr_1 ,
1366
1379
uint64 (5_000_000 ),
1367
1380
["the cat memo" ],
1368
- removals = removals ,
1381
+ removals = select_coins_response . coins ,
1369
1382
)
1370
1383
1371
1384
spend_bundle = tx_res .transaction .spend_bundle
1372
1385
assert spend_bundle is not None
1373
- assert removals [0 ] in {removal for tx in tx_res .transactions for removal in tx .removals }
1386
+ assert select_coins_response . coins [0 ] in {removal for tx in tx_res .transactions for removal in tx .removals }
1374
1387
1375
1388
await wallet_environments .process_pending_states (cat_spend_changes )
1376
1389
@@ -1382,10 +1395,14 @@ async def test_cat_endpoints(wallet_environments: WalletTestFramework, wallet_ty
1382
1395
assert len (cats ) == 1
1383
1396
1384
1397
# Test CAT coin selection
1385
- selected_coins = await env_0 .rpc_client .select_coins (
1386
- amount = 1 , wallet_id = cat_0_id , coin_selection_config = wallet_environments .tx_config .coin_selection_config
1398
+ select_coins_response = await env_0 .rpc_client .select_coins (
1399
+ SelectCoins .from_coin_selection_config (
1400
+ amount = uint64 (1 ),
1401
+ wallet_id = cat_0_id ,
1402
+ coin_selection_config = wallet_environments .tx_config .coin_selection_config ,
1403
+ )
1387
1404
)
1388
- assert len (selected_coins ) > 0
1405
+ assert len (select_coins_response . coins ) > 0
1389
1406
1390
1407
# Test get_cat_list
1391
1408
cat_list = (await env_0 .rpc_client .get_cat_list ()).cat_list
@@ -2299,51 +2316,63 @@ async def test_select_coins_rpc(wallet_rpc_environment: WalletRpcTestEnvironment
2299
2316
await time_out_assert (20 , get_confirmed_balance , funds , client , 1 )
2300
2317
2301
2318
# test min coin amount
2302
- min_coins : list [Coin ] = await client_2 .select_coins (
2303
- amount = 1000 ,
2304
- wallet_id = 1 ,
2305
- coin_selection_config = DEFAULT_COIN_SELECTION_CONFIG .override (min_coin_amount = uint64 (1001 )),
2319
+ min_coins_response = await client_2 .select_coins (
2320
+ SelectCoins .from_coin_selection_config (
2321
+ amount = uint64 (1000 ),
2322
+ wallet_id = uint32 (1 ),
2323
+ coin_selection_config = DEFAULT_COIN_SELECTION_CONFIG .override (min_coin_amount = uint64 (1001 )),
2324
+ )
2306
2325
)
2307
- assert len (min_coins ) == 1
2308
- assert min_coins [0 ].amount == uint64 (10_000 )
2326
+ assert len (min_coins_response . coins ) == 1
2327
+ assert min_coins_response . coins [0 ].amount == uint64 (10_000 )
2309
2328
2310
2329
# test max coin amount
2311
- max_coins : list [Coin ] = await client_2 .select_coins (
2312
- amount = 2000 ,
2313
- wallet_id = 1 ,
2314
- coin_selection_config = DEFAULT_COIN_SELECTION_CONFIG .override (
2315
- min_coin_amount = uint64 (999 ), max_coin_amount = uint64 (9999 )
2316
- ),
2330
+ max_coins_reponse = await client_2 .select_coins (
2331
+ SelectCoins .from_coin_selection_config (
2332
+ amount = uint64 (2000 ),
2333
+ wallet_id = uint32 (1 ),
2334
+ coin_selection_config = DEFAULT_COIN_SELECTION_CONFIG .override (
2335
+ min_coin_amount = uint64 (999 ), max_coin_amount = uint64 (9999 )
2336
+ ),
2337
+ )
2317
2338
)
2318
- assert len (max_coins ) == 2
2319
- assert max_coins [0 ].amount == uint64 (1000 )
2339
+ assert len (max_coins_reponse . coins ) == 2
2340
+ assert max_coins_reponse . coins [0 ].amount == uint64 (1000 )
2320
2341
2321
2342
# test excluded coin amounts
2322
2343
non_1000_amt : int = sum (a for a in tx_amounts if a != 1000 )
2323
- excluded_amt_coins : list [Coin ] = await client_2 .select_coins (
2324
- amount = non_1000_amt ,
2325
- wallet_id = 1 ,
2326
- coin_selection_config = DEFAULT_COIN_SELECTION_CONFIG .override (excluded_coin_amounts = [uint64 (1000 )]),
2344
+ excluded_amt_coins_response = await client_2 .select_coins (
2345
+ SelectCoins .from_coin_selection_config (
2346
+ amount = uint64 (non_1000_amt ),
2347
+ wallet_id = uint32 (1 ),
2348
+ coin_selection_config = DEFAULT_COIN_SELECTION_CONFIG .override (excluded_coin_amounts = [uint64 (1000 )]),
2349
+ )
2327
2350
)
2328
- assert len (excluded_amt_coins ) == len ([a for a in tx_amounts if a != 1000 ])
2329
- assert sum (c .amount for c in excluded_amt_coins ) == non_1000_amt
2351
+ assert len (excluded_amt_coins_response . coins ) == len ([a for a in tx_amounts if a != 1000 ])
2352
+ assert sum (c .amount for c in excluded_amt_coins_response . coins ) == non_1000_amt
2330
2353
2331
2354
# test excluded coins
2332
2355
with pytest .raises (ValueError ):
2333
2356
await client_2 .select_coins (
2334
- amount = 5000 ,
2335
- wallet_id = 1 ,
2357
+ SelectCoins .from_coin_selection_config (
2358
+ amount = uint64 (5000 ),
2359
+ wallet_id = uint32 (1 ),
2360
+ coin_selection_config = DEFAULT_COIN_SELECTION_CONFIG .override (
2361
+ excluded_coin_ids = [c .name () for c in min_coins_response .coins ]
2362
+ ),
2363
+ )
2364
+ )
2365
+ excluded_test_response = await client_2 .select_coins (
2366
+ SelectCoins .from_coin_selection_config (
2367
+ amount = uint64 (1300 ),
2368
+ wallet_id = uint32 (1 ),
2336
2369
coin_selection_config = DEFAULT_COIN_SELECTION_CONFIG .override (
2337
- excluded_coin_ids = [c .name () for c in min_coins ]
2370
+ excluded_coin_ids = [c .name () for c in coin_300 ]
2338
2371
),
2339
2372
)
2340
- excluded_test = await client_2 .select_coins (
2341
- amount = 1300 ,
2342
- wallet_id = 1 ,
2343
- coin_selection_config = DEFAULT_COIN_SELECTION_CONFIG .override (excluded_coin_ids = [c .name () for c in coin_300 ]),
2344
2373
)
2345
- assert len (excluded_test ) == 2
2346
- for coin in excluded_test :
2374
+ assert len (excluded_test_response . coins ) == 2
2375
+ for coin in excluded_test_response . coins :
2347
2376
assert coin != coin_300 [0 ]
2348
2377
2349
2378
# test backwards compatibility in the RPC
@@ -2365,10 +2394,10 @@ async def test_select_coins_rpc(wallet_rpc_environment: WalletRpcTestEnvironment
2365
2394
all_coins , _ , _ = await client_2 .get_spendable_coins (
2366
2395
wallet_id = 1 ,
2367
2396
coin_selection_config = DEFAULT_COIN_SELECTION_CONFIG .override (
2368
- excluded_coin_ids = [c .name () for c in excluded_amt_coins ]
2397
+ excluded_coin_ids = [c .name () for c in excluded_amt_coins_response . coins ]
2369
2398
),
2370
2399
)
2371
- assert set (excluded_amt_coins ).intersection ({rec .coin for rec in all_coins }) == set ()
2400
+ assert set (excluded_amt_coins_response . coins ).intersection ({rec .coin for rec in all_coins }) == set ()
2372
2401
all_coins , _ , _ = await client_2 .get_spendable_coins (
2373
2402
wallet_id = 1 ,
2374
2403
coin_selection_config = DEFAULT_COIN_SELECTION_CONFIG .override (excluded_coin_amounts = [uint64 (1000 )]),
0 commit comments