mirror of
https://gitlab.com/veilid/veilid.git
synced 2025-08-09 07:02:41 -04:00
update api surface for create_dht_record with owner
This commit is contained in:
parent
bebdbee41b
commit
69378ca9b0
20 changed files with 206 additions and 88 deletions
|
@ -52,7 +52,7 @@ async def test_create_delete_dht_record_simple(api_connection: veilid.VeilidAPI)
|
|||
rc = await api_connection.new_routing_context()
|
||||
async with rc:
|
||||
rec = await rc.create_dht_record(
|
||||
veilid.DHTSchema.dflt(1), veilid.CryptoKind.CRYPTO_KIND_VLD0
|
||||
veilid.DHTSchema.dflt(1), kind=veilid.CryptoKind.CRYPTO_KIND_VLD0
|
||||
)
|
||||
await rc.close_dht_record(rec.key)
|
||||
await rc.delete_dht_record(rec.key)
|
||||
|
@ -95,6 +95,38 @@ async def test_set_get_dht_value(api_connection: veilid.VeilidAPI):
|
|||
await rc.delete_dht_record(rec.key)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_set_get_dht_value_with_owner(api_connection: veilid.VeilidAPI):
|
||||
rc = await api_connection.new_routing_context()
|
||||
async with rc:
|
||||
|
||||
cs = await api_connection.best_crypto_system()
|
||||
async with cs:
|
||||
owner = await cs.generate_key_pair()
|
||||
|
||||
rec = await rc.create_dht_record(veilid.DHTSchema.dflt(2), owner=owner)
|
||||
|
||||
vd = await rc.set_dht_value(rec.key, ValueSubkey(0), b"BLAH BLAH BLAH")
|
||||
assert vd is None
|
||||
|
||||
vd2 = await rc.get_dht_value(rec.key, ValueSubkey(0), False)
|
||||
assert vd2 is not None
|
||||
|
||||
vd3 = await rc.get_dht_value(rec.key, ValueSubkey(0), True)
|
||||
assert vd3 is not None
|
||||
|
||||
vd4 = await rc.get_dht_value(rec.key, ValueSubkey(1), False)
|
||||
assert vd4 is None
|
||||
|
||||
print("vd2: {}", vd2.__dict__)
|
||||
print("vd3: {}", vd3.__dict__)
|
||||
|
||||
assert vd2 == vd3
|
||||
|
||||
await rc.close_dht_record(rec.key)
|
||||
await rc.delete_dht_record(rec.key)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_open_writer_dht_value(api_connection: veilid.VeilidAPI):
|
||||
rc = await api_connection.new_routing_context()
|
||||
|
|
|
@ -49,7 +49,7 @@ class RoutingContext(ABC):
|
|||
|
||||
@abstractmethod
|
||||
async def create_dht_record(
|
||||
self, schema: types.DHTSchema, kind: Optional[types.CryptoKind] = None
|
||||
self, schema: types.DHTSchema, owner: Optional[types.KeyPair] = None, kind: Optional[types.CryptoKind] = None
|
||||
) -> types.DHTRecordDescriptor:
|
||||
pass
|
||||
|
||||
|
|
|
@ -578,7 +578,7 @@ class _JsonRoutingContext(RoutingContext):
|
|||
)
|
||||
|
||||
async def create_dht_record(
|
||||
self, schema: DHTSchema, kind: Optional[CryptoKind] = None
|
||||
self, schema: DHTSchema, owner: Optional[KeyPair] = None, kind: Optional[CryptoKind] = None
|
||||
) -> DHTRecordDescriptor:
|
||||
return DHTRecordDescriptor.from_json(
|
||||
raise_api_result(
|
||||
|
@ -588,6 +588,7 @@ class _JsonRoutingContext(RoutingContext):
|
|||
rc_id=self.rc_id,
|
||||
rc_op=RoutingContextOperation.CREATE_DHT_RECORD,
|
||||
kind=kind,
|
||||
owner=owner,
|
||||
schema=schema,
|
||||
)
|
||||
)
|
||||
|
|
|
@ -327,6 +327,12 @@
|
|||
"null"
|
||||
]
|
||||
},
|
||||
"owner": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"rc_op": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue