mirror of
https://github.com/Chia-Network/chia-blockchain.git
synced 2024-09-21 08:31:52 +03:00
Address comments.
This commit is contained in:
parent
e162a578b6
commit
bf1e5d0595
@ -741,10 +741,13 @@ class DataStore:
|
||||
pairs = await self.get_keys_values(tree_id=tree_id, lock=False)
|
||||
return {node.key: node.value for node in pairs}
|
||||
|
||||
async def get_keys(self, tree_id: bytes32, *, lock: bool = True) -> List[bytes]:
|
||||
async def get_keys(
|
||||
self, tree_id: bytes32, root_hash: Optional[bytes32] = None, *, lock: bool = True
|
||||
) -> List[bytes]:
|
||||
async with self.db_wrapper.locked_transaction(lock=lock):
|
||||
root = await self.get_tree_root(tree_id=tree_id, lock=False)
|
||||
root_hash = root.node_hash
|
||||
if root_hash is None:
|
||||
root = await self.get_tree_root(tree_id=tree_id, lock=False)
|
||||
root_hash = root.node_hash
|
||||
cursor = await self.db.execute(
|
||||
"""
|
||||
WITH RECURSIVE
|
||||
|
@ -99,7 +99,7 @@ class DataLayerRpcApi:
|
||||
return {"value": hex}
|
||||
|
||||
async def get_keys(self, request: Dict[str, Any]) -> EndpointResult:
|
||||
store_id = bytes32(hexstr_to_bytes(request["id"]))
|
||||
store_id = bytes32.from_hexstr(request["id"])
|
||||
if self.service is None:
|
||||
raise Exception("Data layer not created")
|
||||
keys = await self.service.get_keys(store_id)
|
||||
|
@ -315,7 +315,7 @@ async def test_keys_values_ancestors(one_wallet_node_and_rpc: nodes_with_port, b
|
||||
assert dic["0x" + key5.hex()] == "0x" + value5.hex()
|
||||
assert len(keys["keys"]) == len(dic)
|
||||
for key in keys["keys"]:
|
||||
assert "0x" + key.hex() in dic
|
||||
assert key in dic
|
||||
val = await data_rpc_api.get_ancestors({"id": store_id.hex(), "hash": val["keys_values"][4]["hash"]})
|
||||
# todo better assertions for get_ancestors result
|
||||
assert len(val["ancestors"]) == 3
|
||||
@ -340,8 +340,10 @@ async def test_keys_values_ancestors(one_wallet_node_and_rpc: nodes_with_port, b
|
||||
assert res_after["timestamp"] > res_before["timestamp"]
|
||||
pairs_before = await data_rpc_api.get_keys_values({"id": store_id.hex(), "root_hash": res_before["hash"].hex()})
|
||||
pairs_after = await data_rpc_api.get_keys_values({"id": store_id.hex(), "root_hash": res_after["hash"].hex()})
|
||||
assert len(pairs_before["keys_values"]) == 5
|
||||
assert len(pairs_after["keys_values"]) == 7
|
||||
keys_before = await data_rpc_api.get_keys({"id": store_id.hex(), "root_hash": res_before["hash"].hex()})
|
||||
keys_after = data_rpc_api.get_keys_values({"id": store_id.hex(), "root_hash": res_after["hash"].hex()})
|
||||
assert len(pairs_before["keys_values"]) == len(keys_before["keys"]) == 5
|
||||
assert len(pairs_after["keys_values"]) == len(keys_after["keys"]) == 7
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
Loading…
Reference in New Issue
Block a user