Repository: Chia-Network/chia-blockchain
File: chia/_tests/core/test_full_node_rpc.py (Python)

Code before:
        assert len(await client.get_coin_records_by_puzzle_hash(ph_receiver)) == 0
        blocks = bt.get_consecutive_blocks(
            2,
            block_list_input=blocks,
            guarantee_transaction_block=True,
            farmer_reward_puzzle_hash=ph,
            pool_reward_puzzle_hash=ph,
        )
        for block in blocks[-2:]:
            await full_node_api_1.full_node.add_block(block)
        assert len(await client.get_coin_records_by_puzzle_hash(ph)) == 2
        assert len(await client.get_coin_records_by_puzzle_hash(ph_receiver)) == 0

        # NOTE: indexing and hard coded values below depend on the ordering
        included_reward_coins = sorted(blocks[-1].get_included_reward_coins(), key=lambda c: c.amount)

        coin_to_spend = included_reward_coins[0]

        spend_bundle = wallet.generate_signed_transaction(coin_to_spend.amount, ph_receiver, coin_to_spend)

        assert len(await client.get_all_mempool_items()) == 0
        assert len(await client.get_all_mempool_tx_ids()) == 0
        with pytest.raises(ValueError, match="not in the mempool"):
            await client.get_mempool_item_by_tx_id(spend_bundle.name())
            await client.get_mempool_item_by_tx_id(spend_bundle.name(), False)

        await client.push_tx(spend_bundle)
        coin = spend_bundle.additions()[0]

        assert len(await client.get_all_mempool_items()) == 1
        assert len(await client.get_all_mempool_tx_ids()) == 1
        assert (
            WalletSpendBundle.from_json_dict(
                next(iter((await client.get_all_mempool_items()).values()))["spend_bundle"]
            )
            == spend_bundle
        )
        assert (await client.get_all_mempool_tx_ids())[0] == spend_bundle.name()
        mempool_item = await client.get_mempool_item_by_tx_id(spend_bundle.name())
        assert mempool_item is not None
        assert WalletSpendBundle.from_json_dict(mempool_item["spend_bundle"]) == spend_bundle
        with pytest.raises(ValueError, match="not found"):
            await client.get_coin_record_by_name(coin.name())

        # Verify that the include_pending arg to get_mempool_item_by_tx_id works
        coin_to_spend_pending = included_reward_coins[1]
        ahr = ConditionOpcode.ASSERT_HEIGHT_RELATIVE  # to force pending/potential
        condition_dic = {ahr: [ConditionWithArgs(ahr, [int_to_bytes(100)])]}
        spend_bundle_pending = wallet.generate_signed_transaction(
            coin_to_spend_pending.amount,
            ph_receiver,

Review comment (suggestion):
I'm pretty sure this line won't be executed. I think it would need its own `with pytest.raises(...):`  context

Code after:
        assert len(await client.get_coin_records_by_puzzle_hash(ph_receiver)) == 0
        blocks = bt.get_consecutive_blocks(
            2,
            block_list_input=blocks,
            guarantee_transaction_block=True,
            farmer_reward_puzzle_hash=ph,
            pool_reward_puzzle_hash=ph,
        )
        for block in blocks[-2:]:
            await full_node_api_1.full_node.add_block(block)
        assert len(await client.get_coin_records_by_puzzle_hash(ph)) == 2
        assert len(await client.get_coin_records_by_puzzle_hash(ph_receiver)) == 0

        # NOTE: indexing and hard coded values below depend on the ordering
        included_reward_coins = sorted(blocks[-1].get_included_reward_coins(), key=lambda c: c.amount)

        coin_to_spend = included_reward_coins[0]

        spend_bundle = wallet.generate_signed_transaction(coin_to_spend.amount, ph_receiver, coin_to_spend)

        assert len(await client.get_all_mempool_items()) == 0
        assert len(await client.get_all_mempool_tx_ids()) == 0
        with pytest.raises(ValueError, match="not in the mempool"):
            await client.get_mempool_item_by_tx_id(spend_bundle.name())
        with pytest.raises(ValueError, match="not in the mempool"):
            await client.get_mempool_item_by_tx_id(spend_bundle.name(), False)

        await client.push_tx(spend_bundle)
        coin = spend_bundle.additions()[0]

        assert len(await client.get_all_mempool_items()) == 1
        assert len(await client.get_all_mempool_tx_ids()) == 1
        assert (
            WalletSpendBundle.from_json_dict(
                next(iter((await client.get_all_mempool_items()).values()))["spend_bundle"]
            )
            == spend_bundle
        )
        assert (await client.get_all_mempool_tx_ids())[0] == spend_bundle.name()
        mempool_item = await client.get_mempool_item_by_tx_id(spend_bundle.name())
        assert mempool_item is not None
        assert WalletSpendBundle.from_json_dict(mempool_item["spend_bundle"]) == spend_bundle
        with pytest.raises(ValueError, match="not found"):
            await client.get_coin_record_by_name(coin.name())

        # Verify that the include_pending arg to get_mempool_item_by_tx_id works
        coin_to_spend_pending = included_reward_coins[1]
        ahr = ConditionOpcode.ASSERT_HEIGHT_RELATIVE  # to force pending/potential
        condition_dic = {ahr: [ConditionWithArgs(ahr, [int_to_bytes(100)])]}
        spend_bundle_pending = wallet.generate_signed_transaction(
            coin_to_spend_pending.amount,