mirror of
https://gitlab.com/veilid/veilid.git
synced 2024-11-22 08:56:58 -06:00
python and api fixes
This commit is contained in:
parent
9551ecd9a3
commit
422a645708
@ -347,8 +347,9 @@ impl StorageManager {
|
|||||||
if last_signed_value_data.value_data().data() == &data
|
if last_signed_value_data.value_data().data() == &data
|
||||||
&& last_signed_value_data.value_data().writer() == &writer.key
|
&& last_signed_value_data.value_data().writer() == &writer.key
|
||||||
{
|
{
|
||||||
// Data and writer is the name, nothing is changing, just return the same ValueData
|
// Data and writer is the same, nothing is changing,
|
||||||
return Ok(Some(last_signed_value_data.into_value_data()));
|
// just return that we set it, but no network activity needs to happen
|
||||||
|
return Ok(None);
|
||||||
}
|
}
|
||||||
let seq = last_signed_value_data.value_data().seq();
|
let seq = last_signed_value_data.value_data().seq();
|
||||||
ValueData::new_with_seq(seq + 1, data, writer.key)
|
ValueData::new_with_seq(seq + 1, data, writer.key)
|
||||||
|
@ -7,7 +7,9 @@ import json
|
|||||||
from . import *
|
from . import *
|
||||||
|
|
||||||
##################################################################
|
##################################################################
|
||||||
BOGUS_KEY = veilid.TypedKey.from_value(veilid.CryptoKind.CRYPTO_KIND_VLD0, veilid.PublicKey.from_bytes(b' '))
|
BOGUS_KEY = veilid.TypedKey.from_value(
|
||||||
|
veilid.CryptoKind.CRYPTO_KIND_VLD0, veilid.PublicKey.from_bytes(b' '))
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_get_dht_value_unopened(api_connection: veilid.VeilidAPI):
|
async def test_get_dht_value_unopened(api_connection: veilid.VeilidAPI):
|
||||||
@ -24,6 +26,7 @@ async def test_open_dht_record_nonexistent_no_writer(api_connection: veilid.Veil
|
|||||||
with pytest.raises(veilid.VeilidAPIError):
|
with pytest.raises(veilid.VeilidAPIError):
|
||||||
out = await rc.open_dht_record(BOGUS_KEY, None)
|
out = await rc.open_dht_record(BOGUS_KEY, None)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_close_dht_record_nonexistent(api_connection: veilid.VeilidAPI):
|
async def test_close_dht_record_nonexistent(api_connection: veilid.VeilidAPI):
|
||||||
rc = await api_connection.new_routing_context()
|
rc = await api_connection.new_routing_context()
|
||||||
@ -31,6 +34,7 @@ async def test_close_dht_record_nonexistent(api_connection: veilid.VeilidAPI):
|
|||||||
with pytest.raises(veilid.VeilidAPIError):
|
with pytest.raises(veilid.VeilidAPIError):
|
||||||
await rc.close_dht_record(BOGUS_KEY)
|
await rc.close_dht_record(BOGUS_KEY)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_delete_dht_record_nonexistent(api_connection: veilid.VeilidAPI):
|
async def test_delete_dht_record_nonexistent(api_connection: veilid.VeilidAPI):
|
||||||
rc = await api_connection.new_routing_context()
|
rc = await api_connection.new_routing_context()
|
||||||
@ -38,6 +42,7 @@ async def test_delete_dht_record_nonexistent(api_connection: veilid.VeilidAPI):
|
|||||||
with pytest.raises(veilid.VeilidAPIError):
|
with pytest.raises(veilid.VeilidAPIError):
|
||||||
await rc.delete_dht_record(BOGUS_KEY)
|
await rc.delete_dht_record(BOGUS_KEY)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_create_delete_dht_record_simple(api_connection: veilid.VeilidAPI):
|
async def test_create_delete_dht_record_simple(api_connection: veilid.VeilidAPI):
|
||||||
rc = await api_connection.new_routing_context()
|
rc = await api_connection.new_routing_context()
|
||||||
@ -46,6 +51,7 @@ async def test_create_delete_dht_record_simple(api_connection: veilid.VeilidAPI)
|
|||||||
await rc.close_dht_record(rec.key)
|
await rc.close_dht_record(rec.key)
|
||||||
await rc.delete_dht_record(rec.key)
|
await rc.delete_dht_record(rec.key)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_get_dht_value_nonexistent(api_connection: veilid.VeilidAPI):
|
async def test_get_dht_value_nonexistent(api_connection: veilid.VeilidAPI):
|
||||||
rc = await api_connection.new_routing_context()
|
rc = await api_connection.new_routing_context()
|
||||||
@ -55,6 +61,7 @@ async def test_get_dht_value_nonexistent(api_connection: veilid.VeilidAPI):
|
|||||||
await rc.close_dht_record(rec.key)
|
await rc.close_dht_record(rec.key)
|
||||||
await rc.delete_dht_record(rec.key)
|
await rc.delete_dht_record(rec.key)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_set_get_dht_value(api_connection: veilid.VeilidAPI):
|
async def test_set_get_dht_value(api_connection: veilid.VeilidAPI):
|
||||||
rc = await api_connection.new_routing_context()
|
rc = await api_connection.new_routing_context()
|
||||||
@ -62,7 +69,7 @@ async def test_set_get_dht_value(api_connection: veilid.VeilidAPI):
|
|||||||
rec = await rc.create_dht_record(veilid.DHTSchema.dflt(2))
|
rec = await rc.create_dht_record(veilid.DHTSchema.dflt(2))
|
||||||
|
|
||||||
vd = await rc.set_dht_value(rec.key, 0, b"BLAH BLAH BLAH")
|
vd = await rc.set_dht_value(rec.key, 0, b"BLAH BLAH BLAH")
|
||||||
assert vd != None
|
assert vd == None
|
||||||
|
|
||||||
vd2 = await rc.get_dht_value(rec.key, 0, False)
|
vd2 = await rc.get_dht_value(rec.key, 0, False)
|
||||||
assert vd2 != None
|
assert vd2 != None
|
||||||
@ -73,16 +80,15 @@ async def test_set_get_dht_value(api_connection: veilid.VeilidAPI):
|
|||||||
vd4 = await rc.get_dht_value(rec.key, 1, False)
|
vd4 = await rc.get_dht_value(rec.key, 1, False)
|
||||||
assert vd4 == None
|
assert vd4 == None
|
||||||
|
|
||||||
print("vd: {}", vd.__dict__)
|
|
||||||
print("vd2: {}", vd2.__dict__)
|
print("vd2: {}", vd2.__dict__)
|
||||||
print("vd3: {}", vd3.__dict__)
|
print("vd3: {}", vd3.__dict__)
|
||||||
|
|
||||||
assert vd == vd2
|
|
||||||
assert vd2 == vd3
|
assert vd2 == vd3
|
||||||
|
|
||||||
await rc.close_dht_record(rec.key)
|
await rc.close_dht_record(rec.key)
|
||||||
await rc.delete_dht_record(rec.key)
|
await rc.delete_dht_record(rec.key)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_open_writer_dht_value(api_connection: veilid.VeilidAPI):
|
async def test_open_writer_dht_value(api_connection: veilid.VeilidAPI):
|
||||||
rc = await api_connection.new_routing_context()
|
rc = await api_connection.new_routing_context()
|
||||||
@ -104,10 +110,7 @@ async def test_open_writer_dht_value(api_connection: veilid.VeilidAPI):
|
|||||||
|
|
||||||
# Test subkey writes
|
# Test subkey writes
|
||||||
vdtemp = await rc.set_dht_value(key, 1, va)
|
vdtemp = await rc.set_dht_value(key, 1, va)
|
||||||
assert vdtemp != None
|
assert vdtemp == None
|
||||||
assert vdtemp.data == va
|
|
||||||
assert vdtemp.seq == 0
|
|
||||||
assert vdtemp.writer == owner
|
|
||||||
|
|
||||||
vdtemp = await rc.get_dht_value(key, 1, False)
|
vdtemp = await rc.get_dht_value(key, 1, False)
|
||||||
assert vdtemp.data == va
|
assert vdtemp.data == va
|
||||||
@ -118,8 +121,7 @@ async def test_open_writer_dht_value(api_connection: veilid.VeilidAPI):
|
|||||||
assert vdtemp == None
|
assert vdtemp == None
|
||||||
|
|
||||||
vdtemp = await rc.set_dht_value(key, 0, vb)
|
vdtemp = await rc.set_dht_value(key, 0, vb)
|
||||||
assert vdtemp.data == vb
|
assert vdtemp == None
|
||||||
assert vdtemp.seq == 0
|
|
||||||
|
|
||||||
vdtemp = await rc.get_dht_value(key, 0, True)
|
vdtemp = await rc.get_dht_value(key, 0, True)
|
||||||
assert vdtemp.data == vb
|
assert vdtemp.data == vb
|
||||||
@ -129,17 +131,11 @@ async def test_open_writer_dht_value(api_connection: veilid.VeilidAPI):
|
|||||||
|
|
||||||
# Equal value should not trigger sequence number update
|
# Equal value should not trigger sequence number update
|
||||||
vdtemp = await rc.set_dht_value(key, 1, va)
|
vdtemp = await rc.set_dht_value(key, 1, va)
|
||||||
assert vdtemp != None
|
assert vdtemp == None
|
||||||
assert vdtemp.data == va
|
|
||||||
assert vdtemp.seq == 0
|
|
||||||
assert vdtemp.writer == owner
|
|
||||||
|
|
||||||
# Different value should trigger sequence number update
|
# Different value should trigger sequence number update
|
||||||
vdtemp = await rc.set_dht_value(key, 1, vb)
|
vdtemp = await rc.set_dht_value(key, 1, vb)
|
||||||
assert vdtemp != None
|
assert vdtemp == None
|
||||||
assert vdtemp.data == vb
|
|
||||||
assert vdtemp.seq == 1
|
|
||||||
assert vdtemp.writer == owner
|
|
||||||
|
|
||||||
# Now that we initialized some subkeys
|
# Now that we initialized some subkeys
|
||||||
# and verified they stored correctly
|
# and verified they stored correctly
|
||||||
@ -166,10 +162,7 @@ async def test_open_writer_dht_value(api_connection: veilid.VeilidAPI):
|
|||||||
|
|
||||||
# Verify subkey 1 can be set a second time and it updates because seq is newer
|
# Verify subkey 1 can be set a second time and it updates because seq is newer
|
||||||
vdtemp = await rc.set_dht_value(key, 1, vc)
|
vdtemp = await rc.set_dht_value(key, 1, vc)
|
||||||
assert vdtemp != None
|
assert vdtemp == None
|
||||||
assert vdtemp.data == vc
|
|
||||||
assert vdtemp.seq == 2
|
|
||||||
assert vdtemp.writer == owner
|
|
||||||
|
|
||||||
# Verify the network got the subkey update with a refresh check
|
# Verify the network got the subkey update with a refresh check
|
||||||
vdtemp = await rc.get_dht_value(key, 1, True)
|
vdtemp = await rc.get_dht_value(key, 1, True)
|
||||||
@ -203,4 +196,3 @@ async def test_open_writer_dht_value(api_connection: veilid.VeilidAPI):
|
|||||||
# Clean up
|
# Clean up
|
||||||
await rc.close_dht_record(key)
|
await rc.close_dht_record(key)
|
||||||
await rc.delete_dht_record(key)
|
await rc.delete_dht_record(key)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user