Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CHIA-1219] Allow coin selection of 0 value coins #19162

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading