Skip to content

Commit

Permalink
tests: all nodes tests passing
Browse files Browse the repository at this point in the history
[ci skip]
  • Loading branch information
tegefaulkes committed Dec 4, 2023
1 parent ebe6377 commit b0772be
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 55 deletions.
15 changes: 8 additions & 7 deletions src/nodes/utils.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import type { DBTransaction, KeyPath, LevelPath } from '@matrixai/db';
import type { X509Certificate } from '@peculiar/x509';
import type { QUICClientCrypto, QUICServerCrypto } from '@matrixai/quic';
import type { Key, Certificate, CertificatePEM } from '../keys/types';
import type { Hostname, Port } from '../network/types';
import type {
NodeAddress,
NodeContact,
NodeContactAddress,
NodeContactAddressData,
NodeBucket,
NodeBucketIndex,
NodeId,
SeedNodes,
} from './types';
import type { Key, Certificate, CertificatePEM } from '../keys/types';
import type { NodeContact, NodeContactAddressData } from './types';
import dns from 'dns';
import { utils as dbUtils } from '@matrixai/db';
import { IdInternal } from '@matrixai/id';
Expand Down Expand Up @@ -434,11 +436,10 @@ async function resolveSeednodes(
/\..*/g,
'',
) as ids.NodeIdEncoded;
seednodes[nodeId] = {
host: seednodeRecord.name as Hostname,
port: seednodeRecord.port as Port,
scopes: ['global'],
};
seednodes[nodeId] = [
seednodeRecord.name as Hostname,
seednodeRecord.port as Port,
];
}
} catch (e) {
throw new nodesErrors.ErrorNodeLookupNotFound(
Expand Down
4 changes: 2 additions & 2 deletions tests/nodes/NodeConnectionManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,8 +492,8 @@ describe(`NodeConnectionManager`, () => {
const timeStart = Date.now();
await connectionDestroyProm;
const duration = Date.now() - timeStart;
expect(duration).toBeGreaterThan(900);
expect(duration).toBeLessThan(1500);
expect(duration).toBeGreaterThan(4000);
expect(duration).toBeLessThan(7000);
});
test('non primary connections should timeout with primary in use', async () => {
// Modify the timeout time value
Expand Down
10 changes: 2 additions & 8 deletions tests/nodes/agent/handlers/nodesClaimsGet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ describe('nodesClaimsGet', () => {
new StreamHandler(),
]);
const password = 'password';
const crypto = tlsTestsUtils.createCrypto();
const localHost = '127.0.0.1';

let dataDir: string;
Expand Down Expand Up @@ -86,10 +85,7 @@ describe('nodesClaimsGet', () => {
cert: tlsConfig.certChainPem,
verifyPeer: false,
},
crypto: {
key: keysUtils.generateKey(),
ops: crypto,
},
crypto: nodesUtils.quicServerCrypto,
logger,
});
const handleStream = async (
Expand Down Expand Up @@ -149,9 +145,7 @@ describe('nodesClaimsGet', () => {
logger,
});
quicClient = await QUICClient.createQUICClient({
crypto: {
ops: crypto,
},
crypto: nodesUtils.quicClientCrypto,
config: {
verifyPeer: false,
},
Expand Down
13 changes: 9 additions & 4 deletions tests/nodes/agent/handlers/nodesClosestLocalNode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,15 @@ describe('nodesClosestLocalNode', () => {
const nodes: Array<NodeIdEncoded> = [];
for (let i = 0; i < 10; i++) {
const nodeId = testNodesUtils.generateRandomNodeId();
await nodeGraph.setNode(nodeId, {
host: 'localhost' as Host,
port: 55555 as Port,
});
await nodeGraph.setNodeContactAddressData(
nodeId,
['localhost' as Host, 55555 as Port],
{
mode: 'direct',
connectedTime: Date.now(),
scopes: ['global'],
},
);
nodes.push(nodesUtils.encodeNodeId(nodeId));
}
const nodeIdEncoded = nodesUtils.encodeNodeId(
Expand Down
10 changes: 2 additions & 8 deletions tests/nodes/agent/handlers/nodesConnectionSignalFinal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ describe('nodesHolePunchRequest', () => {
const logger = new Logger('nodesHolePunchRequest test', LogLevel.WARN, [
new StreamHandler(),
]);
const crypto = tlsTestsUtils.createCrypto();
const localHost = '127.0.0.1';

let keyPair: KeyPair;
Expand Down Expand Up @@ -58,10 +57,7 @@ describe('nodesHolePunchRequest', () => {
verifyPeer: true,
verifyCallback: async () => undefined,
},
crypto: {
key: keysUtils.generateKey(),
ops: crypto,
},
crypto: nodesUtils.quicServerCrypto,
logger,
});
const handleStream = async (
Expand Down Expand Up @@ -121,9 +117,7 @@ describe('nodesHolePunchRequest', () => {
logger,
});
quicClient = await QUICClient.createQUICClient({
crypto: {
ops: crypto,
},
crypto: nodesUtils.quicClientCrypto,
config: {
key: tlsConfigClient.keyPrivatePem,
cert: tlsConfigClient.certChainPem,
Expand Down
10 changes: 2 additions & 8 deletions tests/nodes/agent/handlers/nodesConnectionSignalInitial.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ describe('nodesHolePunchSignal', () => {
const logger = new Logger('nodesHolePunchSignal test', LogLevel.WARN, [
new StreamHandler(),
]);
const crypto = tlsTestsUtils.createCrypto();
const localHost = '127.0.0.1';

let keyPair: KeyPair;
Expand Down Expand Up @@ -57,10 +56,7 @@ describe('nodesHolePunchSignal', () => {
verifyPeer: true,
verifyCallback: async () => undefined,
},
crypto: {
key: keysUtils.generateKey(),
ops: crypto,
},
crypto: nodesUtils.quicServerCrypto,
logger,
});
const handleStream = async (
Expand Down Expand Up @@ -120,9 +116,7 @@ describe('nodesHolePunchSignal', () => {
logger,
});
quicClient = await QUICClient.createQUICClient({
crypto: {
ops: crypto,
},
crypto: nodesUtils.quicClientCrypto,
config: {
key: tlsConfigClient.keyPrivatePem,
cert: tlsConfigClient.certChainPem,
Expand Down
10 changes: 2 additions & 8 deletions tests/nodes/agent/handlers/nodesCrossSignClaim.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ describe('nodesCrossSignClaim', () => {
new StreamHandler(),
]);
const password = 'password';
const crypto = tlsTestsUtils.createCrypto();
const localHost = '127.0.0.1';

let dataDir: string;
Expand Down Expand Up @@ -137,10 +136,7 @@ describe('nodesCrossSignClaim', () => {
return undefined;
},
},
crypto: {
key: keysUtils.generateKey(),
ops: crypto,
},
crypto: nodesUtils.quicServerCrypto,
logger,
});
const handleStream = async (
Expand Down Expand Up @@ -203,9 +199,7 @@ describe('nodesCrossSignClaim', () => {
localNodeId = keysUtils.publicKeyToNodeId(clientKeyPair.publicKey);
const tlsConfigClient = await tlsTestsUtils.createTLSConfig(clientKeyPair);
quicClient = await QUICClient.createQUICClient({
crypto: {
ops: crypto,
},
crypto: nodesUtils.quicClientCrypto,
config: {
key: tlsConfigClient.keyPrivatePem,
cert: tlsConfigClient.certChainPem,
Expand Down
17 changes: 7 additions & 10 deletions tests/nodes/agent/handlers/notificationsSend.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { Notification, SignedNotification } from '@/notifications/types';
import type { NodeId } from '@/ids';
import type GestaltGraph from '@/gestalts/GestaltGraph';
import type { Host } from '@/network/types';
import type { AgentServerManifest } from '@/nodes/agent/handlers';
import fs from 'fs';
import path from 'path';
import os from 'os';
Expand Down Expand Up @@ -34,7 +35,6 @@ describe('notificationsSend', () => {
new StreamHandler(),
]);
const password = 'password';
const crypto = tlsTestsUtils.createCrypto();
const localHost = '127.0.0.1' as Host;

let dataDir: string;
Expand Down Expand Up @@ -122,7 +122,6 @@ describe('notificationsSend', () => {
nodeConnectionManager = new NodeConnectionManager({
tlsConfig: tlsConfigClient,
keyRing,
nodeGraph,
connectionConnectTimeoutTime: 2000,
connectionIdleTimeoutTimeMin: 2000,
connectionIdleTimeoutTimeScale: 0,
Expand All @@ -139,7 +138,10 @@ describe('notificationsSend', () => {
logger,
});
await nodeManager.start();
await nodeConnectionManager.start({ host: localHost });
await nodeConnectionManager.start({
host: localHost,
agentService: {} as AgentServerManifest,
});
await taskManager.startProcessing();
notificationsManager =
await NotificationsManager.createNotificationsManager({
Expand Down Expand Up @@ -174,10 +176,7 @@ describe('notificationsSend', () => {
return undefined;
},
},
crypto: {
key: keysUtils.generateKey(),
ops: crypto,
},
crypto: nodesUtils.quicServerCrypto,
logger,
});
const handleStream = async (
Expand Down Expand Up @@ -237,9 +236,7 @@ describe('notificationsSend', () => {
logger,
});
quicClient = await QUICClient.createQUICClient({
crypto: {
ops: crypto,
},
crypto: nodesUtils.quicClientCrypto,
config: {
key: tlsConfigClient.keyPrivatePem,
cert: tlsConfigClient.certChainPem,
Expand Down

0 comments on commit b0772be

Please sign in to comment.