Skip to content

Commit

Permalink
Allow coin selection of 0 value coins
Browse files Browse the repository at this point in the history
  • Loading branch information
Quexington committed Jan 21, 2025
1 parent 55028d3 commit 96d7817
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 18 additions & 0 deletions chia/_tests/wallet/test_coin_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,24 @@ async def test_coin_selection_randomly(self, a_hash: bytes32) -> None:
assert sum(coin.amount for coin in result) >= target_amount
assert len(result) <= 500

@pytest.mark.anyio
async def test_coin_selection_zero_coins(self, a_hash: bytes32) -> None:
coin_list: list[WalletCoinRecord] = [
WalletCoinRecord(Coin(a_hash, a_hash, uint64(0)), uint32(1), uint32(1), False, True, WalletType(0), 1)
for _ in range(0, 100)
]

result: set[Coin] = await select_coins(
uint128(0),
DEFAULT_COIN_SELECTION_CONFIG,
coin_list,
{},
logging.getLogger("test"),
uint128(0),
)

assert len(result) > 0

@pytest.mark.anyio
async def test_coin_selection_with_dust(self, a_hash: bytes32) -> None:
spendable_amount = uint128(5000000000000 + 10000)
Expand Down
2 changes: 1 addition & 1 deletion chia/wallet/coin_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ async def select_coins(
f"Transaction for {amount} is greater than max spendable balance in a block of {sum_spendable_coins}. "
"There may be other transactions pending or our minimum coin amount is too high."
)
if amount == 0 and sum_spendable_coins == 0:
if amount == 0 and len(spendable_coins) == 0:
raise ValueError(
"No coins available to spend, you can not create a coin with an amount of 0,"
" without already having coins."
Expand Down

0 comments on commit 96d7817

Please sign in to comment.