Skip to content

Commit

Permalink
WIP - #305 fixing up tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tegefaulkes committed Feb 18, 2022
1 parent ff4d516 commit fe12502
Show file tree
Hide file tree
Showing 14 changed files with 987 additions and 676 deletions.
1 change: 0 additions & 1 deletion src/PolykeyAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,6 @@ class PolykeyAgent {
vaultsPath,
keyManager,
nodeConnectionManager,
nodeManager,
notificationsManager,
gestaltGraph,
acl,
Expand Down
2 changes: 1 addition & 1 deletion src/agent/service/vaultsScan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type * as grpc from '@grpc/grpc-js';
import type { GestaltGraph } from '../../gestalts';
import type { VaultManager } from '../../vaults';
import type * as nodesPB from '../../proto/js/polykey/v1/nodes/nodes_pb';
import * as validationUtils from '@/validation/utils';
import * as validationUtils from '../../validation/utils';
import * as vaultsPB from '../../proto/js/polykey/v1/vaults/vaults_pb';
import { utils as vaultsUtils, errors as vaultsErrors } from '../../vaults';
import { utils as grpcUtils } from '../../grpc';
Expand Down
1 change: 0 additions & 1 deletion src/bootstrap/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ async function bootstrapState({
keyManager,
nodeConnectionManager,
vaultsPath,
nodeManager,
notificationsManager,
logger: logger.getChild(VaultManager.name),
fresh,
Expand Down
2 changes: 1 addition & 1 deletion src/client/service/vaultsShare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { VaultId, VaultName } from '../../vaults/types';
import type * as vaultsPB from '../../proto/js/polykey/v1/vaults/vaults_pb';
import * as grpc from '@grpc/grpc-js';
import { utils as idUtils } from '@matrixai/id';
import * as validationUtils from '@/validation/utils';
import * as validationUtils from '../../validation/utils';
import { errors as vaultsErrors } from '../../vaults';
import { utils as grpcUtils } from '../../grpc';
import * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb';
Expand Down
2 changes: 1 addition & 1 deletion src/sigchain/Sigchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ class Sigchain {

@ready(new sigchainErrors.ErrorSigchainNotRunning())
public async clearDB() {
this.sigchainDb.clear();
await this.sigchainDb.clear();

await this._transaction(async () => {
await this.db.put(
Expand Down
31 changes: 12 additions & 19 deletions src/vaults/VaultManager.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { MutexInterface } from 'async-mutex';
import type { DB, DBDomain, DBLevel } from '@matrixai/db';
import type { VaultId, VaultName, VaultActions, VaultIdEncoded } from './types';
import type { VaultId, VaultName, VaultActions } from './types';
import type { Vault } from './Vault';

import type { FileSystem } from '../types';
import type { PolykeyWorkerManagerInterface } from '../workers/types';
import type { NodeId } from '../nodes/types';

import type { KeyManager } from '../keys';
import type { NodeConnectionManager, NodeManager } from '../nodes';
import type { NodeConnectionManager } from '../nodes';
import type { GestaltGraph } from '../gestalts';
import type { ACL } from '../acl';
import type { NotificationsManager } from '../notifications';
Expand Down Expand Up @@ -72,7 +72,6 @@ class VaultManager {
acl,
keyManager,
nodeConnectionManager,
nodeManager,
gestaltGraph,
notificationsManager,
keyBits = 256,
Expand All @@ -85,7 +84,6 @@ class VaultManager {
acl: ACL;
keyManager: KeyManager;
nodeConnectionManager: NodeConnectionManager;
nodeManager: NodeManager;
gestaltGraph: GestaltGraph;
notificationsManager: NotificationsManager;
keyBits?: 128 | 192 | 256;
Expand All @@ -101,7 +99,6 @@ class VaultManager {
acl,
keyManager,
nodeConnectionManager,
nodeManager,
gestaltGraph,
notificationsManager,
keyBits,
Expand All @@ -123,7 +120,6 @@ class VaultManager {
protected acl: ACL;
protected keyManager: KeyManager;
protected nodeConnectionManager: NodeConnectionManager;
protected nodeManager: NodeManager;
protected gestaltGraph: GestaltGraph;
protected notificationsManager: NotificationsManager;
protected vaultsDbDomain: DBDomain = [this.constructor.name];
Expand All @@ -142,7 +138,6 @@ class VaultManager {
acl,
keyManager,
nodeConnectionManager,
nodeManager,
gestaltGraph,
notificationsManager,
keyBits,
Expand All @@ -154,7 +149,6 @@ class VaultManager {
acl: ACL;
keyManager: KeyManager;
nodeConnectionManager: NodeConnectionManager;
nodeManager: NodeManager;
gestaltGraph: GestaltGraph;
notificationsManager: NotificationsManager;
keyBits: 128 | 192 | 256;
Expand All @@ -168,7 +162,6 @@ class VaultManager {
this.acl = acl;
this.keyManager = keyManager;
this.nodeConnectionManager = nodeConnectionManager;
this.nodeManager = nodeManager;
this.gestaltGraph = gestaltGraph;
this.notificationsManager = notificationsManager;
this.keyBits = keyBits;
Expand Down Expand Up @@ -247,7 +240,7 @@ class VaultManager {
// it will be clearer!!
// await vaultAndLock.vault?.stop();

await vaultAndLock.vault?.destroy();
await vaultAndLock.vault?.stop();
}, [vaultId]);
}

Expand Down Expand Up @@ -347,7 +340,6 @@ class VaultManager {
this.vaultMap.set(vaultId, { lock });
return await this.transact(async () => {
// Adding vault to name map
console.log(vaultId.toBuffer());
await this.db.put(
this.vaultsNamesDbDomain,
vaultName,
Expand Down Expand Up @@ -450,13 +442,15 @@ class VaultManager {
public async listVaults(): Promise<VaultList> {
const vaults: VaultList = new Map();
// Stream of vaultName VaultId key value pairs
for await (const o of this.vaultsNamesDb.createReadStream()) {
const obj = o as any;
console.log(obj.key.toString());
console.log(obj.value as Buffer);
const vaultId = IdInternal.fromBuffer<VaultId>(obj.value as Buffer);
console.log(vaultId);
vaults.set(obj.key.toString() as VaultName, vaultId);
for await (const vaultNameBuffer of this.vaultsNamesDb.createKeyStream()) {
const vaultName = vaultNameBuffer.toString() as VaultName;
const vaultIdBuffer = await this.db.get(
this.vaultsNamesDbDomain,
vaultNameBuffer,
true,
);
const vaultId = IdInternal.fromBuffer<VaultId>(vaultIdBuffer!);
vaults.set(vaultName, vaultId);
}
return vaults;
}
Expand Down Expand Up @@ -545,7 +539,6 @@ class VaultManager {
@ready(new vaultsErrors.ErrorVaultManagerNotRunning())
public async shareVault(vaultId: VaultId, nodeId: NodeId): Promise<void> {
const vaultMeta = await this.getVaultMeta(vaultId);
console.log(vaultId, vaultMeta);
if (!vaultMeta) throw new vaultsErrors.ErrorVaultsVaultUndefined();
await this.transact(async () => {
await this.gestaltGraph._transaction(async () => {
Expand Down
5 changes: 0 additions & 5 deletions src/vaults/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,12 @@ import type {
CommitId,
VaultName,
} from './types';
import type { FileSystem, POJO } from '../types';
import type { GRPCClientAgent } from '../agent';
import type { NodeId } from '../nodes/types';

import path from 'path';
import { IdInternal, IdRandom, utils as idUtils } from '@matrixai/id';
import * as grpc from '@grpc/grpc-js';
import { tagLast, refs, vaultActions } from './types';
import * as nodesUtils from '../nodes/utils';
import * as vaultsPB from '../proto/js/polykey/v1/vaults/vaults_pb';
import * as nodesPB from '../proto/js/polykey/v1/nodes/nodes_pb';

/**
* Vault history is designed for linear-history
Expand Down
1 change: 0 additions & 1 deletion tests/acl/ACL.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import path from 'path';
import fs from 'fs';
import Logger, { LogLevel, StreamHandler } from '@matrixai/logger';
import { DB } from '@matrixai/db';
import { utils as idUtils } from '@matrixai/id';
import { ACL, errors as aclErrors } from '@/acl';
import { utils as keysUtils } from '@/keys';
import { utils as vaultsUtils } from '@/vaults';
Expand Down
1 change: 0 additions & 1 deletion tests/agent/GRPCClientAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ describe(GRPCClientAgent.name, () => {
keyManager: keyManager,
vaultsPath: vaultsPath,
nodeConnectionManager: nodeConnectionManager,
nodeManager: nodeManager,
db: db,
acl: acl,
gestaltGraph: gestaltGraph,
Expand Down
1 change: 0 additions & 1 deletion tests/bin/notifications/notifications.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import os from 'os';
import path from 'path';
import fs from 'fs';
import Logger, { LogLevel, StreamHandler } from '@matrixai/logger';
import { utils as idUtils } from '@matrixai/id';
import PolykeyAgent from '@/PolykeyAgent';
import * as vaultsUtils from '@/vaults/utils';
import { utils as nodesUtils } from '@/nodes';
Expand Down
1 change: 0 additions & 1 deletion tests/nodes/NodeConnection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ describe(`${NodeConnection.name} test`, () => {
keyManager: serverKeyManager,
vaultsPath: serverVaultsPath,
nodeConnectionManager: dummyNodeConnectionManager,
nodeManager: serverNodeManager,
notificationsManager: serverNotificationsManager,
db: serverDb,
acl: serverACL,
Expand Down
1 change: 0 additions & 1 deletion tests/notifications/NotificationsManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ describe('NotificationsManager', () => {
keyManager: receiverKeyManager,
vaultsPath: receiverVaultsPath,
nodeConnectionManager: receiverNodeConnectionManager,
nodeManager: receiverNodeManager,
notificationsManager: receiverNotificationsManager,
db: receiverDb,
acl: receiverACL,
Expand Down
1 change: 0 additions & 1 deletion tests/notifications/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { Notification, NotificationData } from '@/notifications/types';
import type { VaultActions, VaultName } from '@/vaults/types';
import { createPublicKey } from 'crypto';
import { EmbeddedJWK, jwtVerify, exportJWK } from 'jose';
import { utils as idUtils } from '@matrixai/id';

import * as keysUtils from '@/keys/utils';
import * as notificationsUtils from '@/notifications/utils';
Expand Down
Loading

0 comments on commit fe12502

Please sign in to comment.