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

Code before:
        for _ in range(num_keys):
            use_file = seeded_random.choice([True, False])
            assert tmp_data_store.prefer_db_kv_blob_length > 7
            size = tmp_data_store.prefer_db_kv_blob_length + 1 if use_file else 8
            key = bytes(seeded_random.getrandbits(8) for _ in range(size))
            value = bytes(seeded_random.getrandbits(8) for _ in range(size))
            changelist.append({"action": "insert", "key": key, "value": value})

        await tmp_data_store.insert_batch(store_id, changelist, status=Status.COMMITTED)
        root = await tmp_data_store.get_tree_root(store_id)
        files_path = tmp_path.joinpath("files")
        await write_files_for_root(tmp_data_store, store_id, root, files_path, 1000)
        assert root.node_hash is not None
        filename = get_delta_filename_path(files_path, store_id, root.node_hash, 1)
        assert filename.exists()

    root_hash = bytes32([0] * 31 + [1]) if not success else root.node_hash
    sinfo = ServerInfo("http://127.0.0.1/8003", 0, 0)

    if not success:
        target_filename_path = get_delta_filename_path(files_path, store_id, root_hash, 1)
        shutil.copyfile(filename, target_filename_path)
        assert target_filename_path.exists()

    keys_value_path = data_store.key_value_blobs_path.joinpath(store_id.hex())
    assert sum(1 for _ in keys_value_path.rglob("*") if _.is_file()) == 0

    is_success = await insert_from_delta_file(
        data_store=data_store,
        store_id=store_id,
        existing_generation=0,
        target_generation=1,
        root_hashes=[root_hash],
        server_info=sinfo,
        client_foldername=files_path,
        timeout=aiohttp.ClientTimeout(total=15, sock_connect=5),
        log=log,
        proxy_url="",
        downloader=None,
    )
    assert is_success == success

    async with data_store.db_wrapper.reader() as reader:
        async with reader.execute("SELECT COUNT(*) FROM ids") as cursor:
            row_count = await cursor.fetchone()
            assert row_count is not None
            if success:
                assert row_count[0] > 0
            else:
                assert row_count[0] == 0


Review comment (suggestion):
not sure why ruff or mypy aren't complaining

```suggestion
    assert sum(1 for path in keys_value_path.rglob("*") if path.is_file()) == 0
```

Code after:
        await tmp_data_store.create_tree(store_id, status=Status.COMMITTED)
        changelist: list[dict[str, Any]] = []
        for _ in range(num_keys):
            use_file = seeded_random.choice([True, False])
            assert tmp_data_store.prefer_db_kv_blob_length > 7
            size = tmp_data_store.prefer_db_kv_blob_length + 1 if use_file else 8
            key = seeded_random.randbytes(size)
            value = seeded_random.randbytes(size)
            changelist.append({"action": "insert", "key": key, "value": value})

        await tmp_data_store.insert_batch(store_id, changelist, status=Status.COMMITTED)
        root = await tmp_data_store.get_tree_root(store_id)
        files_path = tmp_path.joinpath("files")
        await write_files_for_root(tmp_data_store, store_id, root, files_path, 1000)
        assert root.node_hash is not None
        filename = get_delta_filename_path(files_path, store_id, root.node_hash, 1)
        assert filename.exists()

    root_hash = bytes32([0] * 31 + [1]) if not success else root.node_hash
    sinfo = ServerInfo("http://127.0.0.1/8003", 0, 0)

    if not success:
        target_filename_path = get_delta_filename_path(files_path, store_id, root_hash, 1)
        shutil.copyfile(filename, target_filename_path)
        assert target_filename_path.exists()

    keys_value_path = data_store.key_value_blobs_path.joinpath(store_id.hex())
    assert sum(1 for path in keys_value_path.rglob("*") if path.is_file()) == 0

    is_success = await insert_from_delta_file(
        data_store=data_store,
        store_id=store_id,
        existing_generation=0,
        target_generation=1,
        root_hashes=[root_hash],
        server_info=sinfo,
        client_foldername=files_path,
        timeout=aiohttp.ClientTimeout(total=15, sock_connect=5),
        log=log,
        proxy_url="",
        downloader=None,
    )
    assert is_success == success

    async with data_store.db_wrapper.reader() as reader:
        async with reader.execute("SELECT COUNT(*) FROM ids") as cursor:
            row_count = await cursor.fetchone()
            assert row_count is not None
            if success:
                assert row_count[0] > 0
            else: