Skip to content

Commit

Permalink
Reduce number of tests that create new did:dht DIDs (#860)
Browse files Browse the repository at this point in the history
In several of the tests we were creating fresh `did:dht` identities before each test run.

In this PR most of the `createIdentity()` methods were moved into `before` instead of `beforeEach` and generating a new protocol URI on each run to differentiate counts, specifically on a remote.

Additionally some tests do not need a remote DWN at all, so a `did:jwk` was used.
  • Loading branch information
LiranCohen committed Aug 31, 2024
1 parent 9f08161 commit d643160
Show file tree
Hide file tree
Showing 8 changed files with 572 additions and 445 deletions.
7 changes: 2 additions & 5 deletions packages/agent/tests/cached-permissions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ import { PlatformAgentTestHarness } from '../src/test-harness.js';
import { TestAgent } from './utils/test-agent.js';
import { BearerDid } from '@web5/dids';

import { testDwnUrl } from './utils/test-config.js';
import { DwnInterfaceName, DwnMethodName, Time } from '@tbd54566975/dwn-sdk-js';
import { CachedPermissions, DwnInterface } from '../src/index.js';
import { Convert } from '@web5/common';

let testDwnUrls: string[] = [testDwnUrl];

describe('CachedPermissions', () => {
let permissions: AgentPermissionsApi;
let testHarness: PlatformAgentTestHarness;
Expand All @@ -37,11 +34,11 @@ describe('CachedPermissions', () => {
await testHarness.createAgentDid();

// Create an "alice" Identity to author the DWN messages.
const alice = await testHarness.createIdentity({ name: 'Alice', testDwnUrls });
const alice = await testHarness.agent.identity.create({ didMethod: 'jwk', metadata: { name: 'Alice' } });
await testHarness.agent.identity.manage({ portableIdentity: await alice.export() });
aliceDid = alice.did;

const bob = await testHarness.createIdentity({ name: 'Bob', testDwnUrls });
const bob = await testHarness.agent.identity.create({ didMethod: 'jwk', metadata: { name: 'Bob' } });
await testHarness.agent.identity.manage({ portableIdentity: await bob.export() });
bobDid = bob.did;

Expand Down
4 changes: 1 addition & 3 deletions packages/agent/tests/permissions-api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ import { PlatformAgentTestHarness } from '../src/test-harness.js';
import { TestAgent } from './utils/test-agent.js';
import { BearerDid } from '@web5/dids';

import { testDwnUrl } from './utils/test-config.js';
import { DwnInterfaceName, DwnMethodName, Time } from '@tbd54566975/dwn-sdk-js';
import { DwnInterface, DwnPermissionGrant, DwnPermissionScope, Web5PlatformAgent } from '../src/index.js';

let testDwnUrls: string[] = [testDwnUrl];

describe('AgentPermissionsApi', () => {
let testHarness: PlatformAgentTestHarness;
Expand All @@ -34,7 +32,7 @@ describe('AgentPermissionsApi', () => {
await testHarness.createAgentDid();

// Create an "alice" Identity to author the DWN messages.
const alice = await testHarness.createIdentity({ name: 'Alice', testDwnUrls });
const alice = await testHarness.agent.identity.create({ didMethod: 'jwk', metadata: { name: 'Alice' } });
await testHarness.agent.identity.manage({ portableIdentity: await alice.export() });
aliceDid = alice.did;
});
Expand Down
Loading

0 comments on commit d643160

Please sign in to comment.