Skip to content

Commit

Permalink
upgrade packages and slow test
Browse files Browse the repository at this point in the history
  • Loading branch information
LiranCohen committed Feb 2, 2024
1 parent 54e7d0d commit 6531593
Show file tree
Hide file tree
Showing 10 changed files with 683 additions and 67 deletions.
633 changes: 615 additions & 18 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"devDependencies": {
"@npmcli/package-json": "5.0.0",
"@typescript-eslint/eslint-plugin": "6.4.0",
"@web5/dwn-server": "0.1.9",
"@web5/dwn-server": "0.1.10",
"eslint-plugin-mocha": "10.1.0"
}
}
4 changes: 2 additions & 2 deletions packages/agent/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@web5/agent",
"version": "0.2.6",
"version": "0.2.7",
"type": "module",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
Expand Down Expand Up @@ -68,7 +68,7 @@
"node": ">=18.0.0"
},
"dependencies": {
"@tbd54566975/dwn-sdk-js": "0.2.10",
"@tbd54566975/dwn-sdk-js": "0.2.16",
"@web5/common": "0.2.3",
"@web5/crypto": "0.2.2",
"@web5/dids": "0.2.4",
Expand Down
4 changes: 2 additions & 2 deletions packages/agent/src/dwn-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export class DwnManager {

let reply: UnionMessageReply;
if (request.store !== false) {
reply = await this._dwn.processMessage(request.target, message, dataStream);
reply = await this._dwn.processMessage(request.target, message, { dataStream });
} else {
reply = { status: { code: 202, detail: 'Accepted' }};
}
Expand Down Expand Up @@ -435,6 +435,6 @@ export class DwnManager {
}): Promise<UnionMessageReply> {
const { dataStream, message, targetDid } = options;

return await this._dwn.processMessage(targetDid, message, dataStream);
return await this._dwn.processMessage(targetDid, message, { dataStream });
}
}
5 changes: 4 additions & 1 deletion packages/agent/tests/dwn-manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,10 @@ describe('DwnManager', () => {
});

it('handles EventsGet', async () => {
const testCursor = 'foo';
const testCursor = {
messageCid : 'foo',
value : 'bar'
};

// Attempt to process the EventsGet.
let eventsGetResponse = await testAgent.agent.dwnManager.processRequest({
Expand Down
85 changes: 50 additions & 35 deletions packages/agent/tests/sync-manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,37 +76,53 @@ describe('SyncManagerLevel', () => {
await testAgent.closeStorage();
});

// NOTE: from `dwn-sdk-js` `v0.2.10` to `v0.2.16` this test saw a significant increase in time. TODO: investigate
it('syncs multiple records in both directions', async () => {
// create 3 local records.
// create 2 local records.
const localRecords: string[] = [];
for (let i = 0; i < 3; i++) {
const writeResponse = await testAgent.agent.dwnManager.processRequest({
author : alice.did,
target : alice.did,
messageType : 'RecordsWrite',
messageOptions : {
dataFormat: 'text/plain'
},
dataStream: new Blob([`Hello, ${i}`])
});

localRecords.push((writeResponse.message as RecordsWriteMessage).recordId);
}
const writeResponse1Promise = testAgent.agent.dwnManager.processRequest({
author : alice.did,
target : alice.did,
messageType : 'RecordsWrite',
messageOptions : {
dataFormat: 'text/plain'
},
dataStream: new Blob(['Hello, 1'])
});
const writeResponse2Promise = testAgent.agent.dwnManager.processRequest({
author : alice.did,
target : alice.did,
messageType : 'RecordsWrite',
messageOptions : {
dataFormat: 'text/plain'
},
dataStream: new Blob(['Hello, 2'])
});
localRecords.push(((await writeResponse1Promise).message as RecordsWriteMessage).recordId);
localRecords.push(((await writeResponse2Promise).message as RecordsWriteMessage).recordId);

// create 3 remote records
// create 2 remote records
const remoteRecords: string[] = [];
for (let i = 0; i < 3; i++) {
let writeResponse = await testAgent.agent.dwnManager.sendRequest({
author : alice.did,
target : alice.did,
messageType : 'RecordsWrite',
messageOptions : {
dataFormat: 'text/plain'
},
dataStream: new Blob([`Hello, ${i}`])
});
remoteRecords.push((writeResponse.message as RecordsWriteMessage).recordId);
}
const writeResponse3Promise = testAgent.agent.dwnManager.sendRequest({
author : alice.did,
target : alice.did,
messageType : 'RecordsWrite',
messageOptions : {
dataFormat: 'text/plain'
},
dataStream: new Blob(['Hello, 3'])
});
const writeResponse4Promise = testAgent.agent.dwnManager.sendRequest({
author : alice.did,
target : alice.did,
messageType : 'RecordsWrite',
messageOptions : {
dataFormat: 'text/plain'
},
dataStream: new Blob(['Hello, 4'])
});
remoteRecords.push(((await writeResponse3Promise).message as RecordsWriteMessage).recordId);
remoteRecords.push(((await writeResponse4Promise).message as RecordsWriteMessage).recordId);

// query local and check for only local records
let localQueryResponse = await testAgent.agent.dwnManager.processRequest({
Expand All @@ -117,7 +133,7 @@ describe('SyncManagerLevel', () => {
});
let localDwnQueryReply = localQueryResponse.reply as RecordsQueryReply;
expect(localDwnQueryReply.status.code).to.equal(200);
expect(localDwnQueryReply.entries).to.have.length(3);
expect(localDwnQueryReply.entries).to.have.length(2);
let localRecordsFromQuery = localDwnQueryReply.entries?.map(entry => entry.recordId);
expect(localRecordsFromQuery).to.have.members(localRecords);

Expand All @@ -130,7 +146,7 @@ describe('SyncManagerLevel', () => {
});
let remoteDwnQueryReply = remoteQueryResponse.reply as RecordsQueryReply;
expect(remoteDwnQueryReply.status.code).to.equal(200);
expect(remoteDwnQueryReply.entries).to.have.length(3);
expect(remoteDwnQueryReply.entries).to.have.length(2);
let remoteRecordsFromQuery = remoteDwnQueryReply.entries?.map(entry => entry.recordId);
expect(remoteRecordsFromQuery).to.have.members(remoteRecords);

Expand All @@ -152,7 +168,7 @@ describe('SyncManagerLevel', () => {
});
localDwnQueryReply = localQueryResponse.reply as RecordsQueryReply;
expect(localDwnQueryReply.status.code).to.equal(200);
expect(localDwnQueryReply.entries).to.have.length(6);
expect(localDwnQueryReply.entries).to.have.length(4);
localRecordsFromQuery = localDwnQueryReply.entries?.map(entry => entry.recordId);
expect(localRecordsFromQuery).to.have.members([...localRecords, ...remoteRecords]);

Expand All @@ -165,11 +181,10 @@ describe('SyncManagerLevel', () => {
});
remoteDwnQueryReply = remoteQueryResponse.reply as RecordsQueryReply;
expect(remoteDwnQueryReply.status.code).to.equal(200);
expect(remoteDwnQueryReply.entries).to.have.length(6);
expect(remoteDwnQueryReply.entries).to.have.length(4);
remoteRecordsFromQuery = remoteDwnQueryReply.entries?.map(entry => entry.recordId);
expect(remoteRecordsFromQuery).to.have.members([...localRecords, ...remoteRecords]);

});
}).timeout(2_500);

describe('pull()', () => {
it('takes no action if no identities are registered', async () => {
Expand Down Expand Up @@ -365,7 +380,7 @@ describe('SyncManagerLevel', () => {
localDwnQueryReply = queryResponse.reply as RecordsQueryReply;
expect(localDwnQueryReply.status.code).to.equal(200); // Query was successfully executed.
expect(localDwnQueryReply.entries).to.have.length(1); // Record does exist on local DWN.
});
}).timeout(2_500);
});

describe('push()', () => {
Expand Down Expand Up @@ -561,7 +576,7 @@ describe('SyncManagerLevel', () => {
remoteDwnQueryReply = queryResponse.reply as RecordsQueryReply;
expect(remoteDwnQueryReply.status.code).to.equal(200); // Query was successfully executed.
expect(remoteDwnQueryReply.entries).to.have.length(1); // Record does exist on remote DWN.
});
}).timeout(2_500);
});

describe('startSync()', () => {
Expand Down
8 changes: 4 additions & 4 deletions packages/api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@web5/api",
"version": "0.8.4",
"version": "0.8.5",
"description": "SDK for accessing the features and capabilities of Web5",
"type": "module",
"main": "./dist/cjs/index.js",
Expand Down Expand Up @@ -76,12 +76,12 @@
"node": ">=18.0.0"
},
"dependencies": {
"@tbd54566975/dwn-sdk-js": "0.2.10",
"@web5/agent": "0.2.6",
"@tbd54566975/dwn-sdk-js": "0.2.16",
"@web5/agent": "0.2.7",
"@web5/common": "0.2.3",
"@web5/crypto": "0.2.2",
"@web5/dids": "0.2.4",
"@web5/user-agent": "0.2.6",
"@web5/user-agent": "0.2.7",
"level": "8.0.0",
"ms": "2.1.3",
"readable-stream": "4.4.2",
Expand Down
3 changes: 2 additions & 1 deletion packages/api/src/dwn-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { DwnResponse, Web5Agent } from '@web5/agent';
import type {
RecordsQueryReply,
RecordsReadOptions,
PaginationCursor,
ProtocolsQueryReply,
RecordsQueryOptions,
RecordsWriteMessage,
Expand Down Expand Up @@ -135,7 +136,7 @@ export type RecordsQueryResponse = ResponseStatus & {
records?: Record[]

/** If there are additional results, the messageCid of the last record will be returned as a pagination cursor. */
cursor?: string;
cursor?: PaginationCursor;
};

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/dev-env/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ version: "3.98"
services:
dwn-server:
container_name: dwn-server
image: ghcr.io/tbd54566975/dwn-server:dwn-sdk-0.2.10
image: ghcr.io/tbd54566975/dwn-server:dwn-sdk-0.2.16
ports:
- "3000:3000"
4 changes: 2 additions & 2 deletions packages/user-agent/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@web5/user-agent",
"version": "0.2.6",
"version": "0.2.7",
"type": "module",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
Expand Down Expand Up @@ -68,7 +68,7 @@
"node": ">=18.0.0"
},
"dependencies": {
"@web5/agent": "0.2.6",
"@web5/agent": "0.2.7",
"@web5/common": "0.2.3",
"@web5/crypto": "0.2.2",
"@web5/dids": "0.2.4"
Expand Down

0 comments on commit 6531593

Please sign in to comment.