Skip to content

Commit 3a9f071

Browse files
committed
syntax: linting
1 parent fc767fe commit 3a9f071

3 files changed

Lines changed: 154 additions & 147 deletions

File tree

tests/nodes/NodeConnectionManager.seednodes.test.ts

Lines changed: 81 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -424,84 +424,88 @@ describe(`${NodeConnectionManager.name} seed nodes test`, () => {
424424
await queue?.stop();
425425
}
426426
});
427-
test('should expand the network when nodes enter', async () => {
428-
// Using a single seed node we need to check that each entering node adds itself to the seed node.
429-
// Also need to check that the new nodes can be seen in the network.
430-
let node1: PolykeyAgent | undefined;
431-
let node2: PolykeyAgent | undefined;
432-
const seedNodes: SeedNodes = {};
433-
seedNodes[nodesUtils.encodeNodeId(remoteNodeId1)] = {
434-
host: remoteNode1.proxy.getProxyHost(),
435-
port: remoteNode1.proxy.getProxyPort(),
436-
};
437-
seedNodes[nodesUtils.encodeNodeId(remoteNodeId2)] = {
438-
host: remoteNode2.proxy.getProxyHost(),
439-
port: remoteNode2.proxy.getProxyPort(),
440-
};
441-
try {
442-
logger.setLevel(LogLevel.WARN);
443-
node1 = await PolykeyAgent.createPolykeyAgent({
444-
nodePath: path.join(dataDir, 'node1'),
445-
password: 'password',
446-
networkConfig: {
447-
proxyHost: localHost,
448-
agentHost: localHost,
449-
clientHost: localHost,
450-
forwardHost: localHost,
451-
},
452-
seedNodes,
453-
logger,
454-
});
455-
node2 = await PolykeyAgent.createPolykeyAgent({
456-
nodePath: path.join(dataDir, 'node2'),
457-
password: 'password',
458-
networkConfig: {
459-
proxyHost: localHost,
460-
agentHost: localHost,
461-
clientHost: localHost,
462-
forwardHost: localHost,
463-
},
464-
seedNodes,
465-
logger,
466-
});
427+
test(
428+
'should expand the network when nodes enter',
429+
async () => {
430+
// Using a single seed node we need to check that each entering node adds itself to the seed node.
431+
// Also need to check that the new nodes can be seen in the network.
432+
let node1: PolykeyAgent | undefined;
433+
let node2: PolykeyAgent | undefined;
434+
const seedNodes: SeedNodes = {};
435+
seedNodes[nodesUtils.encodeNodeId(remoteNodeId1)] = {
436+
host: remoteNode1.proxy.getProxyHost(),
437+
port: remoteNode1.proxy.getProxyPort(),
438+
};
439+
seedNodes[nodesUtils.encodeNodeId(remoteNodeId2)] = {
440+
host: remoteNode2.proxy.getProxyHost(),
441+
port: remoteNode2.proxy.getProxyPort(),
442+
};
443+
try {
444+
logger.setLevel(LogLevel.WARN);
445+
node1 = await PolykeyAgent.createPolykeyAgent({
446+
nodePath: path.join(dataDir, 'node1'),
447+
password: 'password',
448+
networkConfig: {
449+
proxyHost: localHost,
450+
agentHost: localHost,
451+
clientHost: localHost,
452+
forwardHost: localHost,
453+
},
454+
seedNodes,
455+
logger,
456+
});
457+
node2 = await PolykeyAgent.createPolykeyAgent({
458+
nodePath: path.join(dataDir, 'node2'),
459+
password: 'password',
460+
networkConfig: {
461+
proxyHost: localHost,
462+
agentHost: localHost,
463+
clientHost: localHost,
464+
forwardHost: localHost,
465+
},
466+
seedNodes,
467+
logger,
468+
});
467469

468-
await node1.queue.drained();
469-
await node1.nodeManager.refreshBucketQueueDrained();
470-
await node2.queue.drained();
471-
await node2.nodeManager.refreshBucketQueueDrained();
470+
await node1.queue.drained();
471+
await node1.nodeManager.refreshBucketQueueDrained();
472+
await node2.queue.drained();
473+
await node2.nodeManager.refreshBucketQueueDrained();
472474

473-
const getAllNodes = async (node: PolykeyAgent) => {
474-
const nodes: Array<NodeIdEncoded> = [];
475-
for await (const [nodeId] of node.nodeGraph.getNodes()) {
476-
nodes.push(nodesUtils.encodeNodeId(nodeId));
477-
}
478-
return nodes;
479-
};
480-
const rNode1Nodes = await getAllNodes(remoteNode1);
481-
const rNode2Nodes = await getAllNodes(remoteNode2);
482-
const node1Nodes = await getAllNodes(node1);
483-
const node2Nodes = await getAllNodes(node2);
475+
const getAllNodes = async (node: PolykeyAgent) => {
476+
const nodes: Array<NodeIdEncoded> = [];
477+
for await (const [nodeId] of node.nodeGraph.getNodes()) {
478+
nodes.push(nodesUtils.encodeNodeId(nodeId));
479+
}
480+
return nodes;
481+
};
482+
const rNode1Nodes = await getAllNodes(remoteNode1);
483+
const rNode2Nodes = await getAllNodes(remoteNode2);
484+
const node1Nodes = await getAllNodes(node1);
485+
const node2Nodes = await getAllNodes(node2);
484486

485-
const nodeIdR1 = nodesUtils.encodeNodeId(remoteNodeId1);
486-
const nodeIdR2 = nodesUtils.encodeNodeId(remoteNodeId2);
487-
const nodeId1 = nodesUtils.encodeNodeId(node1.keyManager.getNodeId());
488-
const nodeId2 = nodesUtils.encodeNodeId(node2.keyManager.getNodeId());
489-
expect(rNode1Nodes).toContain(nodeId1);
490-
expect(rNode1Nodes).toContain(nodeId2);
491-
expect(rNode2Nodes).toContain(nodeId1);
492-
expect(rNode2Nodes).toContain(nodeId2);
493-
expect(node1Nodes).toContain(nodeIdR1);
494-
expect(node1Nodes).toContain(nodeIdR2);
495-
expect(node1Nodes).toContain(nodeId2);
496-
expect(node2Nodes).toContain(nodeIdR1);
497-
expect(node2Nodes).toContain(nodeIdR2);
498-
expect(node2Nodes).toContain(nodeId1);
499-
} finally {
500-
logger.setLevel(LogLevel.WARN);
501-
await node1?.stop();
502-
await node1?.destroy();
503-
await node2?.stop();
504-
await node2?.destroy();
505-
}
506-
}, global.defaultTimeout * 2);
487+
const nodeIdR1 = nodesUtils.encodeNodeId(remoteNodeId1);
488+
const nodeIdR2 = nodesUtils.encodeNodeId(remoteNodeId2);
489+
const nodeId1 = nodesUtils.encodeNodeId(node1.keyManager.getNodeId());
490+
const nodeId2 = nodesUtils.encodeNodeId(node2.keyManager.getNodeId());
491+
expect(rNode1Nodes).toContain(nodeId1);
492+
expect(rNode1Nodes).toContain(nodeId2);
493+
expect(rNode2Nodes).toContain(nodeId1);
494+
expect(rNode2Nodes).toContain(nodeId2);
495+
expect(node1Nodes).toContain(nodeIdR1);
496+
expect(node1Nodes).toContain(nodeIdR2);
497+
expect(node1Nodes).toContain(nodeId2);
498+
expect(node2Nodes).toContain(nodeIdR1);
499+
expect(node2Nodes).toContain(nodeIdR2);
500+
expect(node2Nodes).toContain(nodeId1);
501+
} finally {
502+
logger.setLevel(LogLevel.WARN);
503+
await node1?.stop();
504+
await node1?.destroy();
505+
await node2?.stop();
506+
await node2?.destroy();
507+
}
508+
},
509+
global.defaultTimeout * 2,
510+
);
507511
});

tests/utils.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import * as keysUtils from '@/keys/utils';
1414
import * as utilsPB from '@/proto/js/polykey/v1/utils/utils_pb';
1515
import * as grpcErrors from '@/grpc/errors';
1616
import { sleep } from '@/utils';
17-
import * as errors from '@/errors';
1817
import config from '@/config';
1918

2019
/**

tests/vaults/VaultManager.test.ts

Lines changed: 73 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,78 +1113,82 @@ describe('VaultManager', () => {
11131113
},
11141114
global.failedConnectionTimeout,
11151115
);
1116-
test('able to recover metadata after complex operations', async () => {
1117-
const vaultManager = await VaultManager.createVaultManager({
1118-
vaultsPath,
1119-
keyManager: dummyKeyManager,
1120-
gestaltGraph: {} as GestaltGraph,
1121-
nodeConnectionManager,
1122-
acl: {} as ACL,
1123-
notificationsManager: {} as NotificationsManager,
1124-
db,
1125-
logger: logger.getChild(VaultManager.name),
1126-
});
1127-
try {
1128-
const vaultNames = ['Vault1', 'Vault2', 'Vault3', 'Vault4', 'Vault5'];
1129-
const alteredVaultNames = [
1130-
'Vault1',
1131-
'Vault2',
1132-
'Vault3',
1133-
'Vault6',
1134-
'Vault10',
1135-
];
1136-
for (const vaultName of vaultNames) {
1137-
await vaultManager.createVault(vaultName as VaultName);
1138-
}
1139-
const v5 = await vaultManager.getVaultId('Vault5' as VaultName);
1140-
expect(v5).not.toBeUndefined();
1141-
await vaultManager.destroyVault(v5!);
1142-
const v4 = await vaultManager.getVaultId('Vault4' as VaultName);
1143-
expect(v4).toBeTruthy();
1144-
await vaultManager.renameVault(v4!, 'Vault10' as VaultName);
1145-
const v6 = await vaultManager.createVault('Vault6' as VaultName);
1146-
1147-
await vaultManager.withVaults([v6], async (vault6) => {
1148-
await vault6.writeF(async (efs) => {
1149-
await efs.writeFile('reloaded', 'reload');
1150-
});
1116+
test(
1117+
'able to recover metadata after complex operations',
1118+
async () => {
1119+
const vaultManager = await VaultManager.createVaultManager({
1120+
vaultsPath,
1121+
keyManager: dummyKeyManager,
1122+
gestaltGraph: {} as GestaltGraph,
1123+
nodeConnectionManager,
1124+
acl: {} as ACL,
1125+
notificationsManager: {} as NotificationsManager,
1126+
db,
1127+
logger: logger.getChild(VaultManager.name),
11511128
});
1152-
1153-
const vn: Array<string> = [];
1154-
(await vaultManager.listVaults()).forEach((_, vaultName) =>
1155-
vn.push(vaultName),
1156-
);
1157-
expect(vn.sort()).toEqual(alteredVaultNames.sort());
1158-
await vaultManager.stop();
1159-
await vaultManager.start();
1160-
await vaultManager.createVault('Vault7' as VaultName);
1161-
1162-
const v10 = await vaultManager.getVaultId('Vault10' as VaultName);
1163-
expect(v10).not.toBeUndefined();
1164-
alteredVaultNames.push('Vault7');
1165-
expect((await vaultManager.listVaults()).size).toEqual(
1166-
alteredVaultNames.length,
1167-
);
1168-
const vnAltered: Array<string> = [];
1169-
(await vaultManager.listVaults()).forEach((_, vaultName) =>
1170-
vnAltered.push(vaultName),
1171-
);
1172-
expect(vnAltered.sort()).toEqual(alteredVaultNames.sort());
1173-
const file = await vaultManager.withVaults(
1174-
[v6],
1175-
async (reloadedVault) => {
1176-
return await reloadedVault.readF(async (efs) => {
1177-
return await efs.readFile('reloaded', { encoding: 'utf8' });
1129+
try {
1130+
const vaultNames = ['Vault1', 'Vault2', 'Vault3', 'Vault4', 'Vault5'];
1131+
const alteredVaultNames = [
1132+
'Vault1',
1133+
'Vault2',
1134+
'Vault3',
1135+
'Vault6',
1136+
'Vault10',
1137+
];
1138+
for (const vaultName of vaultNames) {
1139+
await vaultManager.createVault(vaultName as VaultName);
1140+
}
1141+
const v5 = await vaultManager.getVaultId('Vault5' as VaultName);
1142+
expect(v5).not.toBeUndefined();
1143+
await vaultManager.destroyVault(v5!);
1144+
const v4 = await vaultManager.getVaultId('Vault4' as VaultName);
1145+
expect(v4).toBeTruthy();
1146+
await vaultManager.renameVault(v4!, 'Vault10' as VaultName);
1147+
const v6 = await vaultManager.createVault('Vault6' as VaultName);
1148+
1149+
await vaultManager.withVaults([v6], async (vault6) => {
1150+
await vault6.writeF(async (efs) => {
1151+
await efs.writeFile('reloaded', 'reload');
11781152
});
1179-
},
1180-
);
1153+
});
11811154

1182-
expect(file).toBe('reload');
1183-
} finally {
1184-
await vaultManager?.stop();
1185-
await vaultManager?.destroy();
1186-
}
1187-
}, global.defaultTimeout * 2);
1155+
const vn: Array<string> = [];
1156+
(await vaultManager.listVaults()).forEach((_, vaultName) =>
1157+
vn.push(vaultName),
1158+
);
1159+
expect(vn.sort()).toEqual(alteredVaultNames.sort());
1160+
await vaultManager.stop();
1161+
await vaultManager.start();
1162+
await vaultManager.createVault('Vault7' as VaultName);
1163+
1164+
const v10 = await vaultManager.getVaultId('Vault10' as VaultName);
1165+
expect(v10).not.toBeUndefined();
1166+
alteredVaultNames.push('Vault7');
1167+
expect((await vaultManager.listVaults()).size).toEqual(
1168+
alteredVaultNames.length,
1169+
);
1170+
const vnAltered: Array<string> = [];
1171+
(await vaultManager.listVaults()).forEach((_, vaultName) =>
1172+
vnAltered.push(vaultName),
1173+
);
1174+
expect(vnAltered.sort()).toEqual(alteredVaultNames.sort());
1175+
const file = await vaultManager.withVaults(
1176+
[v6],
1177+
async (reloadedVault) => {
1178+
return await reloadedVault.readF(async (efs) => {
1179+
return await efs.readFile('reloaded', { encoding: 'utf8' });
1180+
});
1181+
},
1182+
);
1183+
1184+
expect(file).toBe('reload');
1185+
} finally {
1186+
await vaultManager?.stop();
1187+
await vaultManager?.destroy();
1188+
}
1189+
},
1190+
global.defaultTimeout * 2,
1191+
);
11881192
test('throw when trying to commit to a cloned vault', async () => {
11891193
const vaultManager = await VaultManager.createVaultManager({
11901194
vaultsPath,

0 commit comments

Comments
 (0)