Address comments.

This commit is contained in:
Florin Chirica 2022-08-01 14:53:22 +02:00
parent e162a578b6
commit bf1e5d0595
No known key found for this signature in database
GPG Key ID: 1805593F7B529698
3 changed files with 12 additions and 7 deletions

View File

@ -741,8 +741,11 @@ 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):
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(

View File

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

View File

@ -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