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

Code before:
            unf = UnfinishedBlock(
                finished_ss,
                block.reward_chain_block.get_unfinished(),
                block.challenge_chain_sp_proof,
                block.reward_chain_sp_proof,
                block.foliage,
                block.foliage_transaction_block,
                block.transactions_info,
                block.transactions_generator,
                [],
            )
            await full_node_api_1.full_node.add_unfinished_block(unf, None)
            await full_node_api_1.full_node.add_block(block, None)

        assert len(await client.get_unfinished_block_headers()) > 0
        assert len(await client.get_all_block(uint32(0), uint32(2))) == 2
        state = await client.get_blockchain_state()

        peak_block = await client.get_block(state["peak"].header_hash)
        assert peak_block == blocks[-1]
        try:
            await client.get_block(bytes32([1] * 32))
        except ValueError as e:
            assert str(e).endswith("not found")
        else:
            assert False, "Expected ValueError for non-existent block"
        block_record = await client.get_block_record_by_height(2)
        assert block_record is not None
        assert block_record.header_hash == blocks[2].header_hash

        assert len(await client.get_block_records(0, 100)) == num_blocks * 2

        assert (await client.get_block_record_by_height(100)) is None

        # 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)

        ph = included_reward_coins[0].puzzle_hash
        coins = await client.get_coin_records_by_puzzle_hash(ph)
        print(coins)
        assert len(coins) >= 1

        pid = included_reward_coins[0].parent_coin_info
        pid_2 = included_reward_coins[1].parent_coin_info
        coins = await client.get_coin_records_by_parent_ids([pid, pid_2])
        print(coins)
        assert len(coins) == 2

        name = included_reward_coins[0].name()
        name_2 = included_reward_coins[1].name()
        coins = await client.get_coin_records_by_names([name, name_2])

Review comment (suggestion):
```suggestion
        with pytest.raises(ValueError, matches="not found"):
            await client.get_block(bytes32([1] * 32))
```
I think every test in your patch would benefit from this change

Code after:
            unf = UnfinishedBlock(
                finished_ss,
                block.reward_chain_block.get_unfinished(),
                block.challenge_chain_sp_proof,
                block.reward_chain_sp_proof,
                block.foliage,
                block.foliage_transaction_block,
                block.transactions_info,
                block.transactions_generator,
                [],
            )
            await full_node_api_1.full_node.add_unfinished_block(unf, None)
            await full_node_api_1.full_node.add_block(block, None)

        assert len(await client.get_unfinished_block_headers()) > 0
        assert len(await client.get_all_block(uint32(0), uint32(2))) == 2
        state = await client.get_blockchain_state()

        peak_block = await client.get_block(state["peak"].header_hash)
        assert peak_block == blocks[-1]
        with pytest.raises(ValueError, match="not found"):
            await client.get_block(bytes32([1] * 32))
        block_record = await client.get_block_record_by_height(2)
        assert block_record is not None
        assert block_record.header_hash == blocks[2].header_hash

        assert len(await client.get_block_records(0, 100)) == num_blocks * 2

        assert (await client.get_block_record_by_height(100)) is None

        # 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)

        ph = included_reward_coins[0].puzzle_hash
        coins = await client.get_coin_records_by_puzzle_hash(ph)
        print(coins)
        assert len(coins) >= 1

        pid = included_reward_coins[0].parent_coin_info
        pid_2 = included_reward_coins[1].parent_coin_info
        coins = await client.get_coin_records_by_parent_ids([pid, pid_2])
        print(coins)
        assert len(coins) == 2

        name = included_reward_coins[0].name()
        name_2 = included_reward_coins[1].name()
        coins = await client.get_coin_records_by_names([name, name_2])
        print(coins)
        assert len(coins) == 2

        additions, removals = await client.get_additions_and_removals(blocks[-1].header_hash)