add inspect test to wasm

This commit is contained in:
Christien Rioux 2024-03-15 12:11:44 -04:00
parent ee54358c27
commit d586748333
5 changed files with 61 additions and 6 deletions

View File

@ -879,7 +879,15 @@ impl RoutingTable {
// does it have some dial info we need?
let filter = |n: &NodeInfo| {
let mut keep = false;
// Bootstraps must have -only- inbound capable network class
if !matches!(n.network_class(), NetworkClass::InboundCapable) {
return false;
}
for did in n.dial_info_detail_list() {
// Bootstraps must have -only- direct dial info
if !matches!(did.class, DialInfoClass::Direct) {
return false;
}
if matches!(did.dial_info.address_type(), AddressType::IPV4) {
for (n, protocol_type) in protocol_types.iter().enumerate() {
if nodes_proto_v4[n] < max_per_type

View File

@ -286,8 +286,7 @@ impl RoutingTable {
{
Ok(NodeContactMethod::Direct(v)) => v,
Ok(v) => {
log_rtab!(warn "invalid contact method for bootstrap, restarting network: {:?}", v);
routing_table.network_manager().restart_network();
log_rtab!(warn "invalid contact method for bootstrap, ignoring peer: {:?}", v);
return;
}
Err(e) => {

View File

@ -407,10 +407,12 @@ impl VeilidRoutingContext {
pub async fn inspectDhtRecord(
&self,
key: String,
subkeys: ValueSubkeyRangeSet,
scope: DHTReportScope,
subkeys: Option<ValueSubkeyRangeSet>,
scope: Option<DHTReportScope>,
) -> APIResult<DHTRecordReport> {
let key = TypedKey::from_str(&key)?;
let subkeys = subkeys.unwrap_or_default();
let scope = scope.unwrap_or_default();
let routing_context = self.getRoutingContext()?;
let res = routing_context

View File

@ -240,6 +240,54 @@ describe('VeilidRoutingContext', () => {
expect(cancelValueRes).toEqual(false);
});
it('should set a value and inspect it', async () => {
const setValueRes = await routingContext.setDhtValue(
dhtRecord.key,
0,
textEncoder.encode(data)
);
expect(setValueRes).toBeUndefined();
// Inspect locally
const inspectRes = await routingContext.inspectDhtRecord(
dhtRecord.key,
[[0, 0]],
"Local",
);
expect(inspectRes).toBeDefined();
expect(inspectRes.subkeys).toEqual([[0, 0]]);
expect(inspectRes.local_seqs).toEqual([0]);
expect(inspectRes.network_seqs).toEqual([]);
// Inspect network
const inspectRes2 = await routingContext.inspectDhtRecord(
dhtRecord.key,
[[0, 0]],
"SyncGet",
);
expect(inspectRes2).toBeDefined();
expect(inspectRes2.subkeys).toEqual([[0, 0]]);
expect(inspectRes2.local_seqs).toEqual([0]);
expect(inspectRes2.network_seqs).toEqual([0]);
});
it('should set a value and inspect it with defaults', async () => {
const setValueRes = await routingContext.setDhtValue(
dhtRecord.key,
0,
textEncoder.encode(data)
);
expect(setValueRes).toBeUndefined();
// Inspect locally
const inspectRes = await routingContext.inspectDhtRecord(
dhtRecord.key,
);
expect(inspectRes).toBeDefined();
expect(inspectRes.subkeys).toEqual([[0, 0]]);
expect(inspectRes.local_seqs).toEqual([0]);
expect(inspectRes.network_seqs).toEqual([]);
});
});
});
});

View File

@ -21,7 +21,5 @@ export const veilidCoreInitConfig: VeilidWASMConfig = {
export var veilidCoreStartupConfig = (() => {
var defaultConfig = JSON.parse(veilidClient.defaultConfig());
defaultConfig.program_name = 'veilid-wasm-test';
defaultConfig.network.routing_table.bootstrap = ['ws://bootstrap.dev.veilid.net:5150/ws'];
defaultConfig.network.network_key_password = 'dev';
return defaultConfig;
})();