Repository: Chia-Network/chia-blockchain
File: chia/_tests/wallet/test_wallet.py (Python)

Code before:
                            "pending_coin_removal_count": -1,
                        }
                    },
                ),
                WalletStateTransition(
                    pre_block_balance_updates={},
                    post_block_balance_updates={},
                ),
            ]
        )

        # Check merkle coins
        await time_out_assert(20, wsm.coin_store.count_small_unspent, 1, 1000, CoinType.CLAWBACK)
        await time_out_assert(20, wsm_2.coin_store.count_small_unspent, 1, 1000, CoinType.CLAWBACK)
        txs = await api_0.get_transactions(
            dict(type_filter={"values": [TransactionType.INCOMING_CLAWBACK_SEND], "mode": 1}, wallet_id=1)
        )
        # clawback merkle coin
        [tx] = action_scope.side_effects.transactions
        merkle_coin = tx.additions[0] if tx.additions[0].amount == tx_amount else tx.additions[1]
        interested_coins = await wsm_2.interested_store.get_interested_coin_ids()
        assert merkle_coin.name() in set(interested_coins)
        assert len(txs["transactions"]) == 1
        assert not txs["transactions"][0]["confirmed"]
        assert txs["transactions"][0]["metadata"]["recipient_puzzle_hash"][2:] == normal_puzhash.hex()
        assert txs["transactions"][0]["metadata"]["coin_id"][2:] == merkle_coin.name().hex()
        with pytest.raises(ValueError):
            await api_0.spend_clawback_coins({})

        test_fee = 10
        resp = await api_0.spend_clawback_coins(
            {
                "coin_ids": [normal_puzhash.hex(), merkle_coin.name().hex()],
                "fee": test_fee,
                **wallet_environments.tx_config.to_json_dict(),
            }
        )
        assert resp["success"]
        assert len(resp["transaction_ids"]) == 1

        await wallet_environments.process_pending_states(
            [
                WalletStateTransition(
                    pre_block_balance_updates={
                        1: {
                            "unconfirmed_wallet_balance": tx_amount - test_fee,
                            "<=#spendable_balance": -1,
                            "<=#max_send_amount": -1,
                            ">=#pending_change": 1,
                            "pending_coin_removal_count": 2,  # 1 for fee, one for clawback
                        }

Review comment (suggestion):
maybe?

```suggestion
        assert txs["transactions"][0]["metadata"]["coin_id"] == "0x" + merkle_coin.name().hex()
```

Code after:
                            "pending_coin_removal_count": -1,
                        }
                    },
                ),
                WalletStateTransition(
                    pre_block_balance_updates={},
                    post_block_balance_updates={},
                ),
            ]
        )

        # Check merkle coins
        await time_out_assert(20, wsm.coin_store.count_small_unspent, 1, 1000, CoinType.CLAWBACK)
        await time_out_assert(20, wsm_2.coin_store.count_small_unspent, 1, 1000, CoinType.CLAWBACK)
        txs = await api_0.get_transactions(
            dict(type_filter={"values": [TransactionType.INCOMING_CLAWBACK_SEND], "mode": 1}, wallet_id=1)
        )
        # clawback merkle coin
        [tx] = action_scope.side_effects.transactions
        merkle_coin = tx.additions[0] if tx.additions[0].amount == tx_amount else tx.additions[1]
        interested_coins = await wsm_2.interested_store.get_interested_coin_ids()
        assert merkle_coin.name() in set(interested_coins)
        assert len(txs["transactions"]) == 1
        assert not txs["transactions"][0]["confirmed"]
        assert txs["transactions"][0]["metadata"]["recipient_puzzle_hash"][2:] == normal_puzhash.hex()
        assert txs["transactions"][0]["metadata"]["coin_id"] == "0x" + merkle_coin.name().hex()
        with pytest.raises(ValueError):
            await api_0.spend_clawback_coins({})

        test_fee = 10
        resp = await api_0.spend_clawback_coins(
            {
                "coin_ids": [normal_puzhash.hex(), merkle_coin.name().hex()],
                "fee": test_fee,
                **wallet_environments.tx_config.to_json_dict(),
            }
        )
        assert resp["success"]
        assert len(resp["transaction_ids"]) == 1

        await wallet_environments.process_pending_states(
            [
                WalletStateTransition(
                    pre_block_balance_updates={
                        1: {
                            "unconfirmed_wallet_balance": tx_amount - test_fee,
                            "<=#spendable_balance": -1,
                            "<=#max_send_amount": -1,
                            ">=#pending_change": 1,
                            "pending_coin_removal_count": 2,  # 1 for fee, one for clawback
                        }