From f8c8bd1697c36221a4c71242f6bff6c1104432a6 Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Fri, 15 Mar 2024 07:43:49 -0400 Subject: [PATCH 01/28] chore: enable anchoring on recon mode --- .../core/src/state-management/repository.ts | 5 -- ...erministic-model-instance-document.test.ts | 22 ++--- .../__tests__/model-instance-document.test.ts | 28 ++---- .../stream-tests/src/__tests__/model.test.ts | 88 ++++--------------- .../src/__tests__/pg-model-indexing.test.ts | 65 +++----------- 5 files changed, 46 insertions(+), 162 deletions(-) diff --git a/packages/core/src/state-management/repository.ts b/packages/core/src/state-management/repository.ts index 877e6a88dc..bd1bc930a5 100644 --- a/packages/core/src/state-management/repository.ts +++ b/packages/core/src/state-management/repository.ts @@ -647,11 +647,6 @@ export class Repository { return } - if (process.env.CERAMIC_RECON_MODE) { - // TODO(WS1-1471): Enable anchoring when in Recon (Prime) mode. - return - } - const carFile = await this.#deps.anchorRequestCarBuilder.build(state$.id, state$.tip) const anchorEvent = await this.anchorService.requestAnchor(carFile) // Don't wait on handling the anchor event, let that happen in the background. diff --git a/packages/stream-tests/src/__tests__/deterministic-model-instance-document.test.ts b/packages/stream-tests/src/__tests__/deterministic-model-instance-document.test.ts index 26d0dea065..83471e3faf 100644 --- a/packages/stream-tests/src/__tests__/deterministic-model-instance-document.test.ts +++ b/packages/stream-tests/src/__tests__/deterministic-model-instance-document.test.ts @@ -125,10 +125,7 @@ describe('ModelInstanceDocument API http-client tests', () => { expect(doc.state.log.length).toEqual(2) expect(doc.state.log[0].type).toEqual(EventType.INIT) expect(doc.state.log[1].type).toEqual(EventType.DATA) - if (!process.env.CERAMIC_RECON_MODE) { - // TODO (WS1-1471): Re-enable this check even in Recon mode - expect(doc.state.anchorStatus).toEqual(AnchorStatus.PENDING) - } + expect(doc.state.anchorStatus).toEqual(AnchorStatus.PENDING) }) test(`Can create deterministic doc with create method`, async () => { @@ -141,10 +138,7 @@ describe('ModelInstanceDocument API http-client tests', () => { expect(doc.state.log.length).toEqual(2) expect(doc.state.log[0].type).toEqual(EventType.INIT) expect(doc.state.log[1].type).toEqual(EventType.DATA) - if (!process.env.CERAMIC_RECON_MODE) { - // TODO (WS1-1471): Re-enable this check even in Recon mode - expect(doc.state.anchorStatus).toEqual(AnchorStatus.PENDING) - } + expect(doc.state.anchorStatus).toEqual(AnchorStatus.PENDING) }) test(`Creating doc with SINGLE accountRelation non-deterministically should fail `, async () => { @@ -260,10 +254,8 @@ describe('ModelInstanceDocument API multi-node tests', () => { const docState = doc.state const loadedState = loaded.state - // TODO(WS1-1471): Enable anchoring when in Recon (Prime) mode. - expect(docState.anchorStatus).toEqual( - process.env.CERAMIC_RECON_MODE ? AnchorStatus.NOT_REQUESTED : AnchorStatus.PENDING - ) + + expect(docState.anchorStatus).toEqual(AnchorStatus.PENDING) expect(loadedState.anchorStatus).toEqual(AnchorStatus.NOT_REQUESTED) delete docState.anchorStatus delete loadedState.anchorStatus @@ -281,10 +273,8 @@ describe('ModelInstanceDocument API multi-node tests', () => { const docState = doc.state const loadedState = loaded.state - // TODO(WS1-1471): Enable anchoring when in Recon (Prime) mode. - expect(docState.anchorStatus).toEqual( - process.env.CERAMIC_RECON_MODE ? AnchorStatus.NOT_REQUESTED : AnchorStatus.PENDING - ) + + expect(docState.anchorStatus).toEqual(AnchorStatus.PENDING) expect(loadedState.anchorStatus).toEqual(AnchorStatus.NOT_REQUESTED) delete docState.anchorStatus delete loadedState.anchorStatus diff --git a/packages/stream-tests/src/__tests__/model-instance-document.test.ts b/packages/stream-tests/src/__tests__/model-instance-document.test.ts index c7dfad9523..c9c7c9bcd4 100644 --- a/packages/stream-tests/src/__tests__/model-instance-document.test.ts +++ b/packages/stream-tests/src/__tests__/model-instance-document.test.ts @@ -81,9 +81,6 @@ const MODEL_WITH_RELATION_DEFINITION: ModelDefinition = { }, } -// TODO(WS1-1471): These tests should be enabled once anchoring works in Recon mode -const testIfV3ShouldPassWithAnchoring = process.env.CERAMIC_RECON_MODE ? test.skip : test - describe('ModelInstanceDocument API http-client tests', () => { jest.setTimeout(1000 * 30) @@ -166,10 +163,8 @@ describe('ModelInstanceDocument API http-client tests', () => { expect(doc.metadata.unique).toBeInstanceOf(Uint8Array) expect(doc.state.log.length).toEqual(1) expect(doc.state.log[0].type).toEqual(EventType.INIT) - if (!process.env.CERAMIC_RECON_MODE) { - // TODO (WS1-1471): Re-enable this check even in Recon mode - expect(doc.state.anchorStatus).toEqual(AnchorStatus.PENDING) - } + expect(doc.state.anchorStatus).toEqual(AnchorStatus.PENDING) + expect(doc.metadata.model.toString()).toEqual(model.id.toString()) await expect(TestUtils.isPinned(ceramic.admin, doc.id)).resolves.toBeTruthy() await expect(TestUtils.isPinned(ceramic.admin, doc.metadata.model)).resolves.toBeTruthy() @@ -187,10 +182,8 @@ describe('ModelInstanceDocument API http-client tests', () => { expect(docWithRelation.metadata.unique).toBeInstanceOf(Uint8Array) expect(docWithRelation.state.log.length).toEqual(1) expect(docWithRelation.state.log[0].type).toEqual(EventType.INIT) - if (!process.env.CERAMIC_RECON_MODE) { - // TODO (WS1-1471): Re-enable this check even in Recon mode - expect(docWithRelation.state.anchorStatus).toEqual(AnchorStatus.PENDING) - } + expect(docWithRelation.state.anchorStatus).toEqual(AnchorStatus.PENDING) + expect(docWithRelation.metadata.model.toString()).toEqual(modelWithRelation.id.toString()) await expect(TestUtils.isPinned(ceramic.admin, docWithRelation.id)).resolves.toBeTruthy() await expect( @@ -272,7 +265,7 @@ describe('ModelInstanceDocument API http-client tests', () => { expect(docWithRelation.content.optionalLinkedDoc).toBe(docID) }) - testIfV3ShouldPassWithAnchoring('Anchor genesis', async () => { + test('Anchor genesis', async () => { const doc = await ModelInstanceDocument.create(ceramic, CONTENT0, midMetadata) expect(doc.state.anchorStatus).toEqual(AnchorStatus.PENDING) @@ -286,7 +279,7 @@ describe('ModelInstanceDocument API http-client tests', () => { expect(doc.content).toEqual(CONTENT0) }) - testIfV3ShouldPassWithAnchoring('Anchor after updating', async () => { + test('Anchor after updating', async () => { const doc = await ModelInstanceDocument.create(ceramic, CONTENT0, midMetadata) expect(doc.state.anchorStatus).toEqual(AnchorStatus.PENDING) await doc.replace(CONTENT1) @@ -303,7 +296,7 @@ describe('ModelInstanceDocument API http-client tests', () => { expect(doc.content).toEqual(CONTENT1) }) - testIfV3ShouldPassWithAnchoring('multiple updates', async () => { + test('multiple updates', async () => { const doc = await ModelInstanceDocument.create(ceramic, CONTENT0, midMetadata) await doc.replace(CONTENT1) @@ -350,7 +343,7 @@ describe('ModelInstanceDocument API http-client tests', () => { ).rejects.toThrow(/Attempting to create a ModelInstanceDocument with an invalid DID string/) }) - testIfV3ShouldPassWithAnchoring('Can load a stream', async () => { + test('Can load a stream', async () => { const doc = await ModelInstanceDocument.create(ceramic, CONTENT0, midMetadata) await doc.replace(CONTENT1) await CoreUtils.anchorUpdate(core, doc) @@ -428,10 +421,7 @@ describe('ModelInstanceDocument API http-client tests', () => { }) }) -// should pass on v4 as soon as recon is integrated and cross-node syncing works. -const describeIfV3ShouldPass = process.env.CERAMIC_RECON_MODE ? describe.skip : describe - -describeIfV3ShouldPass('ModelInstanceDocument API multi-node tests', () => { +describe('ModelInstanceDocument API multi-node tests', () => { jest.setTimeout(1000 * 30) let ipfs0: IpfsApi diff --git a/packages/stream-tests/src/__tests__/model.test.ts b/packages/stream-tests/src/__tests__/model.test.ts index d79faaae03..407343b57b 100644 --- a/packages/stream-tests/src/__tests__/model.test.ts +++ b/packages/stream-tests/src/__tests__/model.test.ts @@ -76,9 +76,6 @@ const MODEL_DEFINITION_WITH_RELATION: ModelDefinition = { relations: { linkedDoc: { type: 'document', model: MODEL_STREAM_ID } }, } -// TODO(WS1-1471): These tests should be enabled once anchoring works in Recon mode -const testIfV3ShouldPassWithAnchoring = process.env.CERAMIC_RECON_MODE ? test.skip : test - describe('Model API http-client tests', () => { jest.setTimeout(1000 * 30) @@ -133,11 +130,7 @@ describe('Model API http-client tests', () => { expect(model.metadata).toEqual({ controller: ceramic.did.id.toString(), model: Model.MODEL }) expect(model.state.log.length).toEqual(1) expect(model.state.log[0].type).toEqual(EventType.INIT) - - if (!process.env.CERAMIC_RECON_MODE) { - // TODO (WS1-1471): Re-enable this check even in Recon mode - expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) - } + expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) expect(model.id.toString()).toEqual(MODEL_STREAM_ID) }) @@ -150,10 +143,7 @@ describe('Model API http-client tests', () => { expect(model.metadata).toEqual({ controller: ceramic.did.id.toString(), model: Model.MODEL }) expect(model.state.log.length).toEqual(1) expect(model.state.log[0].type).toEqual(EventType.INIT) - if (!process.env.CERAMIC_RECON_MODE) { - // TODO (WS1-1471): Re-enable this check even in Recon mode - expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) - } + expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) await expect(ceramic.admin.pin.add(model.id)).resolves.not.toThrow() @@ -174,10 +164,7 @@ describe('Model API http-client tests', () => { expect(model.metadata).toEqual({ controller: ceramic.did.id.toString(), model: Model.MODEL }) expect(model.state.log.length).toEqual(1) expect(model.state.log[0].type).toEqual(EventType.INIT) - if (!process.env.CERAMIC_RECON_MODE) { - // TODO (WS1-1471): Re-enable this check even in Recon mode - expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) - } + expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) await expect(ceramic.admin.pin.add(model.id)).resolves.not.toThrow() @@ -200,10 +187,7 @@ describe('Model API http-client tests', () => { expect(model.metadata).toEqual({ controller: ceramic.did.id.toString(), model: Model.MODEL }) expect(model.state.log.length).toEqual(1) expect(model.state.log[0].type).toEqual(EventType.INIT) - if (!process.env.CERAMIC_RECON_MODE) { - // TODO (WS1-1471): Re-enable this check even in Recon mode - expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) - } + expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) await expect(ceramic.admin.pin.add(model.id)).resolves.not.toThrow() @@ -229,10 +213,7 @@ describe('Model API http-client tests', () => { expect(model.metadata).toEqual({ controller: ceramic.did.id.toString(), model: Model.MODEL }) expect(model.state.log.length).toEqual(1) expect(model.state.log[0].type).toEqual(EventType.INIT) - if (!process.env.CERAMIC_RECON_MODE) { - // TODO (WS1-1471): Re-enable this check even in Recon mode - expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) - } + expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) await expect( ceramic.admin.startIndexingModelData([ @@ -256,10 +237,7 @@ describe('Model API http-client tests', () => { expect(model.metadata).toEqual({ controller: ceramic.did.id.toString(), model: Model.MODEL }) expect(model.state.log.length).toEqual(1) expect(model.state.log[0].type).toEqual(EventType.INIT) - if (!process.env.CERAMIC_RECON_MODE) { - // TODO (WS1-1471): Re-enable this check even in Recon mode - expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) - } + expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) await expect(ceramic.admin.pin.add(model.id)).resolves.not.toThrow() @@ -287,10 +265,7 @@ describe('Model API http-client tests', () => { expect(model.metadata).toEqual({ controller: ceramic.did.id.toString(), model: Model.MODEL }) expect(model.state.log.length).toEqual(1) expect(model.state.log[0].type).toEqual(EventType.INIT) - if (!process.env.CERAMIC_RECON_MODE) { - // TODO (WS1-1471): Re-enable this check even in Recon mode - expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) - } + expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) await expect(ceramic.admin.pin.add(model.id)).resolves.not.toThrow() @@ -326,10 +301,7 @@ describe('Model API http-client tests', () => { expect(model.metadata).toEqual({ controller: ceramic.did.id.toString(), model: Model.MODEL }) expect(model.state.log.length).toEqual(1) expect(model.state.log[0].type).toEqual(EventType.INIT) - if (!process.env.CERAMIC_RECON_MODE) { - // TODO (WS1-1471): Re-enable this check even in Recon mode - expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) - } + expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) await expect(ceramic.admin.pin.add(model.id)).resolves.not.toThrow() @@ -365,10 +337,7 @@ describe('Model API http-client tests', () => { expect(model.metadata).toEqual({ controller: ceramic.did.id.toString(), model: Model.MODEL }) expect(model.state.log.length).toEqual(1) expect(model.state.log[0].type).toEqual(EventType.INIT) - if (!process.env.CERAMIC_RECON_MODE) { - // TODO (WS1-1471): Re-enable this check even in Recon mode - expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) - } + expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) await expect(ceramic.admin.pin.add(model.id)).resolves.not.toThrow() @@ -412,10 +381,7 @@ describe('Model API http-client tests', () => { expect(model.metadata).toEqual({ controller: ceramic.did.id.toString(), model: Model.MODEL }) expect(model.state.log.length).toEqual(1) expect(model.state.log[0].type).toEqual(EventType.INIT) - if (!process.env.CERAMIC_RECON_MODE) { - // TODO (WS1-1471): Re-enable this check even in Recon mode - expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) - } + expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) await expect(ceramic.admin.pin.add(model.id)).resolves.not.toThrow() @@ -462,10 +428,7 @@ describe('Model API http-client tests', () => { expect(model.metadata).toEqual({ controller: ceramic.did.id.toString(), model: Model.MODEL }) expect(model.state.log.length).toEqual(1) expect(model.state.log[0].type).toEqual(EventType.INIT) - if (!process.env.CERAMIC_RECON_MODE) { - // TODO (WS1-1471): Re-enable this check even in Recon mode - expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) - } + expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) await expect(ceramic.admin.pin.add(model.id)).resolves.not.toThrow() @@ -506,10 +469,7 @@ describe('Model API http-client tests', () => { expect(model.metadata).toEqual({ controller: ceramic.did.id.toString(), model: Model.MODEL }) expect(model.state.log.length).toEqual(1) expect(model.state.log[0].type).toEqual(EventType.INIT) - if (!process.env.CERAMIC_RECON_MODE) { - // TODO (WS1-1471): Re-enable this check even in Recon mode - expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) - } + expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) await expect(ceramic.admin.pin.add(model.id)).resolves.not.toThrow() @@ -530,10 +490,7 @@ describe('Model API http-client tests', () => { expect(model.metadata).toEqual({ controller: ceramic.did.id.toString(), model: Model.MODEL }) expect(model.state.log.length).toEqual(1) expect(model.state.log[0].type).toEqual(EventType.INIT) - if (!process.env.CERAMIC_RECON_MODE) { - // TODO (WS1-1471): Re-enable this check even in Recon mode - expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) - } + expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) await expect(ceramic.admin.pin.add(model.id)).resolves.not.toThrow() @@ -559,10 +516,7 @@ describe('Model API http-client tests', () => { expect(model.metadata).toEqual({ controller: ceramic.did.id.toString(), model: Model.MODEL }) expect(model.state.log.length).toEqual(1) expect(model.state.log[0].type).toEqual(EventType.INIT) - if (!process.env.CERAMIC_RECON_MODE) { - // TODO (WS1-1471): Re-enable this check even in Recon mode - expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) - } + expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) await expect(ceramic.admin.pin.add(model.id)).resolves.not.toThrow() @@ -594,13 +548,10 @@ describe('Model API http-client tests', () => { expect(model.metadata).toEqual({ controller: ceramic.did.id.toString(), model: Model.MODEL }) expect(model.state.log.length).toEqual(1) expect(model.state.log[0].type).toEqual(EventType.INIT) - if (!process.env.CERAMIC_RECON_MODE) { - // TODO (WS1-1471): Re-enable this check even in Recon mode - expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) - } + expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) }) - testIfV3ShouldPassWithAnchoring('Anchor genesis', async () => { + test('Anchor genesis', async () => { const model = await Model.create(ceramic, MODEL_DEFINITION) expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) @@ -683,7 +634,7 @@ describe('Model API http-client tests', () => { ) }) - testIfV3ShouldPassWithAnchoring('Can load a complete stream', async () => { + test('Can load a complete stream', async () => { const model = await Model.create(ceramic, MODEL_DEFINITION) await CoreUtils.anchorUpdate(core, model) await model.sync() @@ -776,10 +727,7 @@ describe('Model API http-client tests', () => { }) }) -// should pass on v4 as soon as recon is integrated and cross-node syncing works. -const describeIfV3ShouldPass = process.env.CERAMIC_RECON_MODE ? describe.skip : describe - -describeIfV3ShouldPass('Model API multi-node tests', () => { +describe('Model API multi-node tests', () => { jest.setTimeout(1000 * 30) let ipfs0: IpfsApi diff --git a/packages/stream-tests/src/__tests__/pg-model-indexing.test.ts b/packages/stream-tests/src/__tests__/pg-model-indexing.test.ts index b75f12028d..bccdc6f43d 100644 --- a/packages/stream-tests/src/__tests__/pg-model-indexing.test.ts +++ b/packages/stream-tests/src/__tests__/pg-model-indexing.test.ts @@ -92,10 +92,7 @@ describe('Postgres Model indexing tests', () => { expect(model.metadata).toEqual({ controller: ceramic.did.id.toString(), model: Model.MODEL }) expect(model.state.log.length).toEqual(1) expect(model.state.log[0].type).toEqual(EventType.INIT) - if (!process.env.CERAMIC_RECON_MODE) { - // TODO (WS1-1471): Re-enable this check even in Recon mode - expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) - } + expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) await expect(ceramic.admin.pin.add(model.id)).resolves.not.toThrow() @@ -116,10 +113,7 @@ describe('Postgres Model indexing tests', () => { expect(model.metadata).toEqual({ controller: ceramic.did.id.toString(), model: Model.MODEL }) expect(model.state.log.length).toEqual(1) expect(model.state.log[0].type).toEqual(EventType.INIT) - if (!process.env.CERAMIC_RECON_MODE) { - // TODO (WS1-1471): Re-enable this check even in Recon mode - expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) - } + expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) await expect(ceramic.admin.pin.add(model.id)).resolves.not.toThrow() @@ -142,10 +136,7 @@ describe('Postgres Model indexing tests', () => { expect(model.metadata).toEqual({ controller: ceramic.did.id.toString(), model: Model.MODEL }) expect(model.state.log.length).toEqual(1) expect(model.state.log[0].type).toEqual(EventType.INIT) - if (!process.env.CERAMIC_RECON_MODE) { - // TODO (WS1-1471): Re-enable this check even in Recon mode - expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) - } + expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) await expect(ceramic.admin.pin.add(model.id)).resolves.not.toThrow() @@ -171,10 +162,7 @@ describe('Postgres Model indexing tests', () => { expect(model.metadata).toEqual({ controller: ceramic.did.id.toString(), model: Model.MODEL }) expect(model.state.log.length).toEqual(1) expect(model.state.log[0].type).toEqual(EventType.INIT) - if (!process.env.CERAMIC_RECON_MODE) { - // TODO (WS1-1471): Re-enable this check even in Recon mode - expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) - } + expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) await expect( ceramic.admin.startIndexingModelData([ @@ -198,10 +186,7 @@ describe('Postgres Model indexing tests', () => { expect(model.metadata).toEqual({ controller: ceramic.did.id.toString(), model: Model.MODEL }) expect(model.state.log.length).toEqual(1) expect(model.state.log[0].type).toEqual(EventType.INIT) - if (!process.env.CERAMIC_RECON_MODE) { - // TODO (WS1-1471): Re-enable this check even in Recon mode - expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) - } + expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) await expect(ceramic.admin.pin.add(model.id)).resolves.not.toThrow() @@ -229,10 +214,7 @@ describe('Postgres Model indexing tests', () => { expect(model.metadata).toEqual({ controller: ceramic.did.id.toString(), model: Model.MODEL }) expect(model.state.log.length).toEqual(1) expect(model.state.log[0].type).toEqual(EventType.INIT) - if (!process.env.CERAMIC_RECON_MODE) { - // TODO (WS1-1471): Re-enable this check even in Recon mode - expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) - } + expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) await expect(ceramic.admin.pin.add(model.id)).resolves.not.toThrow() @@ -268,10 +250,7 @@ describe('Postgres Model indexing tests', () => { expect(model.metadata).toEqual({ controller: ceramic.did.id.toString(), model: Model.MODEL }) expect(model.state.log.length).toEqual(1) expect(model.state.log[0].type).toEqual(EventType.INIT) - if (!process.env.CERAMIC_RECON_MODE) { - // TODO (WS1-1471): Re-enable this check even in Recon mode - expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) - } + expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) await expect(ceramic.admin.pin.add(model.id)).resolves.not.toThrow() @@ -307,10 +286,7 @@ describe('Postgres Model indexing tests', () => { expect(model.metadata).toEqual({ controller: ceramic.did.id.toString(), model: Model.MODEL }) expect(model.state.log.length).toEqual(1) expect(model.state.log[0].type).toEqual(EventType.INIT) - if (!process.env.CERAMIC_RECON_MODE) { - // TODO (WS1-1471): Re-enable this check even in Recon mode - expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) - } + expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) await expect(ceramic.admin.pin.add(model.id)).resolves.not.toThrow() @@ -355,10 +331,7 @@ describe('Postgres Model indexing tests', () => { expect(model.metadata).toEqual({ controller: ceramic.did.id.toString(), model: Model.MODEL }) expect(model.state.log.length).toEqual(1) expect(model.state.log[0].type).toEqual(EventType.INIT) - if (!process.env.CERAMIC_RECON_MODE) { - // TODO (WS1-1471): Re-enable this check even in Recon mode - expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) - } + expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) await expect(ceramic.admin.pin.add(model.id)).resolves.not.toThrow() @@ -405,10 +378,7 @@ describe('Postgres Model indexing tests', () => { expect(model.metadata).toEqual({ controller: ceramic.did.id.toString(), model: Model.MODEL }) expect(model.state.log.length).toEqual(1) expect(model.state.log[0].type).toEqual(EventType.INIT) - if (!process.env.CERAMIC_RECON_MODE) { - // TODO (WS1-1471): Re-enable this check even in Recon mode - expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) - } + expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) await expect(ceramic.admin.pin.add(model.id)).resolves.not.toThrow() @@ -449,10 +419,7 @@ describe('Postgres Model indexing tests', () => { expect(model.metadata).toEqual({ controller: ceramic.did.id.toString(), model: Model.MODEL }) expect(model.state.log.length).toEqual(1) expect(model.state.log[0].type).toEqual(EventType.INIT) - if (!process.env.CERAMIC_RECON_MODE) { - // TODO (WS1-1471): Re-enable this check even in Recon mode - expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) - } + expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) await expect(ceramic.admin.pin.add(model.id)).resolves.not.toThrow() @@ -473,10 +440,7 @@ describe('Postgres Model indexing tests', () => { expect(model.metadata).toEqual({ controller: ceramic.did.id.toString(), model: Model.MODEL }) expect(model.state.log.length).toEqual(1) expect(model.state.log[0].type).toEqual(EventType.INIT) - if (!process.env.CERAMIC_RECON_MODE) { - // TODO (WS1-1471): Re-enable this check even in Recon mode - expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) - } + expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) await expect(ceramic.admin.pin.add(model.id)).resolves.not.toThrow() @@ -502,10 +466,7 @@ describe('Postgres Model indexing tests', () => { expect(model.metadata).toEqual({ controller: ceramic.did.id.toString(), model: Model.MODEL }) expect(model.state.log.length).toEqual(1) expect(model.state.log[0].type).toEqual(EventType.INIT) - if (!process.env.CERAMIC_RECON_MODE) { - // TODO (WS1-1471): Re-enable this check even in Recon mode - expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) - } + expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING) await expect(ceramic.admin.pin.add(model.id)).resolves.not.toThrow() From 3b6a0684c8dd38291a78332e83283a2fd290481e Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Sun, 17 Mar 2024 01:57:56 -0400 Subject: [PATCH 02/28] chore: make tests support enabled recon --- .../cli/src/__tests__/ceramic-daemon.test.ts | 40 ++++++------- packages/core/src/recon.ts | 2 +- .../__tests__/model-instance-document.test.ts | 58 +++++++++++++++++-- 3 files changed, 71 insertions(+), 29 deletions(-) diff --git a/packages/cli/src/__tests__/ceramic-daemon.test.ts b/packages/cli/src/__tests__/ceramic-daemon.test.ts index d5758742f0..2641d65555 100644 --- a/packages/cli/src/__tests__/ceramic-daemon.test.ts +++ b/packages/cli/src/__tests__/ceramic-daemon.test.ts @@ -31,10 +31,6 @@ import { decode } from 'codeco' const seed = 'SEED' -// Should pass on v4 if updated from TileDocument -const describeIfV3 = process.env.CERAMIC_RECON_MODE ? describe.skip : describe -const testIfV3 = process.env.CERAMIC_RECON_MODE ? test.skip : test - describe('Ceramic interop: core <> http-client', () => { jest.setTimeout(30000) let ipfs: IpfsApi @@ -122,18 +118,18 @@ describe('Ceramic interop: core <> http-client', () => { isOnlineSpy.mockReset() }) - testIfV3('can store commit if the size is lesser than the maximum size ~256KB', async () => { + test('can store commit if the size is lesser than the maximum size ~256KB', async () => { const streamtype = await TileDocument.create(client, { test: randomString(200000) }) expect(streamtype).not.toBeNull() }) - testIfV3('cannot store commit if the size is greater than the maximum size ~256KB', async () => { + test('cannot store commit if the size is greater than the maximum size ~256KB', async () => { await expect(TileDocument.create(client, { test: randomString(300000) })).rejects.toThrow( /exceeds the maximum block size of/ ) }) - testIfV3('properly creates document', async () => { + test('properly creates document', async () => { const doc1 = await TileDocument.create(core, { test: 123 }, null, { anchor: false, publish: false, @@ -159,7 +155,7 @@ describe('Ceramic interop: core <> http-client', () => { expect(state1).toEqual(state2) }) - testIfV3('gets anchor commit updates', async () => { + test('gets anchor commit updates', async () => { const doc1 = await TileDocument.create(core, { test: 123 }) await anchorDoc(doc1) expect(doc1.state.log.length).toEqual(2) @@ -170,7 +166,7 @@ describe('Ceramic interop: core <> http-client', () => { expect(doc2.state.anchorStatus).toEqual(AnchorStatus.ANCHORED) }) - testIfV3('loads documents correctly', async () => { + test('loads documents correctly', async () => { const doc1 = await TileDocument.create(core, { test: 123 }) await anchorDoc(doc1) const doc2 = await client.loadStream(doc1.id) @@ -184,7 +180,7 @@ describe('Ceramic interop: core <> http-client', () => { expect(StreamUtils.serializeState(doc3.state)).toEqual(StreamUtils.serializeState(doc4.state)) }) - testIfV3('loads document commits correctly', async () => { + test('loads document commits correctly', async () => { const doc1 = await TileDocument.create(core, { test: 123 }) await anchorDoc(doc1) const doc2 = await TileDocument.load(client, doc1.id) @@ -207,7 +203,7 @@ describe('Ceramic interop: core <> http-client', () => { expect(serializeCommits(commits1)).toEqual(serializeCommits(commits2)) }) - testIfV3('makes and gets updates correctly with subscription', async () => { + test('makes and gets updates correctly with subscription', async () => { const initialContent = { a: 'initial' } const middleContent = { ...initialContent, b: 'middle' } const finalContent = { ...middleContent, c: 'final' } @@ -244,7 +240,7 @@ describe('Ceramic interop: core <> http-client', () => { subscription2.unsubscribe() }) - testIfV3('makes and gets updates correctly with manual sync', async () => { + test('makes and gets updates correctly with manual sync', async () => { const initialContent = { a: 'initial' } const middleContent = { ...initialContent, b: 'middle' } const finalContent = { ...middleContent, c: 'final' } @@ -271,7 +267,7 @@ describe('Ceramic interop: core <> http-client', () => { expect(StreamUtils.serializeState(doc1.state)).toEqual(StreamUtils.serializeState(doc2.state)) }) - testIfV3('Throw on rejected update', async () => { + test('Throw on rejected update', async () => { const contentOg = { test: 123 } const contentRejected = { test: 'rejected' } @@ -294,7 +290,7 @@ describe('Ceramic interop: core <> http-client', () => { expect(streamOg.state.log.length).toEqual(2) }) - testIfV3('loads commits correctly', async () => { + test('loads commits correctly', async () => { // Create multiple commits of the same document const content1 = { test: 123 } const content2 = { test: 456 } @@ -388,7 +384,7 @@ describe('Ceramic interop: core <> http-client', () => { expect(docV5Client.state.log.length).toEqual(6) }) - testIfV3('can get stream contents from /streams/contents', async () => { + test('can get stream contents from /streams/contents', async () => { const content1 = { test: 123 } const content2 = { test: 456, test2: 'abc' } const content3 = { test2: 'def' } @@ -402,7 +398,7 @@ describe('Ceramic interop: core <> http-client', () => { expect(json).toEqual(content3) }) - testIfV3('Aborts fetch if it is taking too long', async () => { + test('Aborts fetch if it is taking too long', async () => { const content1 = { test: 123 } const doc = await TileDocument.create(core, content1, null, { anchor: false }) @@ -425,7 +421,7 @@ describe('Ceramic interop: core <> http-client', () => { clearTimeout(id) }) - testIfV3('Aborts fetch through passed in AbortSignal', async () => { + test('Aborts fetch through passed in AbortSignal', async () => { const content1 = { test: 123 } const doc = await TileDocument.create(core, content1, null, { anchor: false }) @@ -451,7 +447,7 @@ describe('Ceramic interop: core <> http-client', () => { clearTimeout(id) }) - testIfV3( + test( 'Aborts fetch if taking too long even if given an AbortSignal that did not get aborted', async () => { const content1 = { test: 123 } @@ -480,7 +476,7 @@ describe('Ceramic interop: core <> http-client', () => { } ) - testIfV3('Aborts fetch if the AbortSignal given has already been aborted', async () => { + test('Aborts fetch if the AbortSignal given has already been aborted', async () => { const content1 = { test: 123 } const doc = await TileDocument.create(core, content1, null, { anchor: false }) @@ -494,7 +490,7 @@ describe('Ceramic interop: core <> http-client', () => { ).rejects.toThrow(/aborted/) }) - testIfV3('requestAnchor works via http api', async () => { + test('requestAnchor works via http api', async () => { const content1 = { test: 123 } const doc = await TileDocument.create(client, content1, null, { anchor: false }) @@ -531,7 +527,7 @@ describe('Ceramic interop: core <> http-client', () => { expect(messageEvent.metadata.model instanceof StreamID).toBeTruthy() }, 30000) - describeIfV3('multiqueries', () => { + describe('multiqueries', () => { let docA, docB, docC, docD beforeEach(async () => { docD = await TileDocument.create(core, { test: '321d' }) @@ -639,7 +635,7 @@ describe('Ceramic interop: core <> http-client', () => { }) }) - describeIfV3('pin api', () => { + describe('pin api', () => { let docA, docB let adminClient: CeramicClient diff --git a/packages/core/src/recon.ts b/packages/core/src/recon.ts index 8da904fc93..c81b7e9de5 100644 --- a/packages/core/src/recon.ts +++ b/packages/core/src/recon.ts @@ -195,7 +195,7 @@ export class ReconApi extends Observable implements IRec return of({ events: [], cursor: initialCursor, first: true }).pipe( // projects the starting event to an Observable that emits the next events. Then it recursively projects each event to an Observable that emits the next event expand((prev) => { - // creates an observable that emits the next event after a ceratin delay (pollInterval) unless this is the first event + // creates an observable that emits the next event after a certain delay (pollInterval) unless this is the first event return timer(prev.first ? 0 : this.#pollInterval).pipe( // concat map is used to ensure that the next event is only emitted after the previous event has been processed concatMap(() => diff --git a/packages/stream-tests/src/__tests__/model-instance-document.test.ts b/packages/stream-tests/src/__tests__/model-instance-document.test.ts index c9c7c9bcd4..aa40d721f3 100644 --- a/packages/stream-tests/src/__tests__/model-instance-document.test.ts +++ b/packages/stream-tests/src/__tests__/model-instance-document.test.ts @@ -1,7 +1,7 @@ import { jest, test, expect, describe, beforeAll, afterAll } from '@jest/globals' import getPort from 'get-port' -import { AnchorStatus, EventType, IpfsApi } from '@ceramicnetwork/common' -import { Utils as CoreUtils } from '@ceramicnetwork/core' +import { AnchorStatus, EventType, IpfsApi, LoggerProvider } from '@ceramicnetwork/common' +import { Utils as CoreUtils, ReconApi } from '@ceramicnetwork/core' import { createIPFS, swarmConnect } from '@ceramicnetwork/ipfs-daemon' import { ModelInstanceDocument, @@ -13,6 +13,7 @@ import { CeramicDaemon, DaemonConfig } from '@ceramicnetwork/cli' import { CeramicClient } from '@ceramicnetwork/http-client' import { Model, ModelDefinition } from '@ceramicnetwork/stream-model' import { CommonTestUtils as TestUtils } from '@ceramicnetwork/common-test-utils' +import HttpRequestMock from 'http-request-mock' const CONTENT0 = { myData: 0 } const CONTENT1 = { myData: 1 } @@ -81,6 +82,10 @@ const MODEL_WITH_RELATION_DEFINITION: ModelDefinition = { }, } +const RECON_URL = 'http://example.com' +const LOGGER = new LoggerProvider().getDiagnosticsLogger() +const mocker = HttpRequestMock.setupForUnitTest('fetch') + describe('ModelInstanceDocument API http-client tests', () => { jest.setTimeout(1000 * 30) @@ -430,27 +435,68 @@ describe('ModelInstanceDocument API multi-node tests', () => { let ceramic1: Ceramic let model: Model let midMetadata: ModelInstanceDocumentMetadataArgs + /*let reconApi0: ReconApi + let reconApi1: ReconApi*/ + beforeAll(async () => { ipfs0 = await createIPFS() ipfs1 = await createIPFS() + await swarmConnect(ipfs0, ipfs1) + if (process.env.CERAMIC_RECON_MODE) { + const regexPattern = new RegExp(`${RECON_URL}.*`) +/* + reconApi0 = new ReconApi( + { + enabled: true, + url: RECON_URL, + feedEnabled: false, + }, + LOGGER, + fetch + ) + + reconApi1 = new ReconApi( + { + enabled: true, + url: RECON_URL, + feedEnabled: false, + }, + LOGGER, + fetch + ) - ceramic0 = await createCeramic(ipfs0) - ceramic1 = await createCeramic(ipfs1) + await reconApi0.init() + await reconApi1.init() +*/ + + mocker.mock({ + url: regexPattern, + body: JSON.stringify({events: [], resumeToken: 'test'}), + status: 200, + }) + + ipfs0.config.set('Addresses.API', RECON_URL) + ipfs1.config.set('Addresses.API', RECON_URL) + } + + ceramic0 = await createCeramic(ipfs0) + ceramic1 = await createCeramic(ipfs1) model = await Model.create(ceramic0, MODEL_DEFINITION) midMetadata = { model: model.id } - }, 12000) + }, 22000) afterAll(async () => { await ceramic0.close() await ceramic1.close() await ipfs0.stop() await ipfs1.stop() + mocker.reset() }) - test('load basic doc', async () => { + test.only('load basic doc', async () => { const doc = await ModelInstanceDocument.create(ceramic0, CONTENT0, midMetadata) const loaded = await ModelInstanceDocument.load(ceramic1, doc.id) From e21f329d85b69288a1545f3c2dc939f9488b6b4e Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Mon, 18 Mar 2024 11:55:39 -0400 Subject: [PATCH 03/28] chore: expose recon in package index --- packages/core/src/index.ts | 1 + .../__tests__/model-instance-document.test.ts | 26 +++++++++++-------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index ca8e66c2a1..6c36f6144e 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -4,5 +4,6 @@ export * from './store/ikv-store.js' export * from './ceramic.js' export * from './pubsub/pubsub-message.js' export * from './utils.js' +export * from './recon.js' export { ProvidersCache } from './providers-cache.js' diff --git a/packages/stream-tests/src/__tests__/model-instance-document.test.ts b/packages/stream-tests/src/__tests__/model-instance-document.test.ts index aa40d721f3..b9b432bbdf 100644 --- a/packages/stream-tests/src/__tests__/model-instance-document.test.ts +++ b/packages/stream-tests/src/__tests__/model-instance-document.test.ts @@ -435,9 +435,8 @@ describe('ModelInstanceDocument API multi-node tests', () => { let ceramic1: Ceramic let model: Model let midMetadata: ModelInstanceDocumentMetadataArgs - /*let reconApi0: ReconApi - let reconApi1: ReconApi*/ - + let reconApi0: ReconApi + let reconApi1: ReconApi beforeAll(async () => { ipfs0 = await createIPFS() @@ -446,10 +445,10 @@ describe('ModelInstanceDocument API multi-node tests', () => { await swarmConnect(ipfs0, ipfs1) if (process.env.CERAMIC_RECON_MODE) { const regexPattern = new RegExp(`${RECON_URL}.*`) -/* + reconApi0 = new ReconApi( { - enabled: true, + enabled: false, url: RECON_URL, feedEnabled: false, }, @@ -459,7 +458,7 @@ describe('ModelInstanceDocument API multi-node tests', () => { reconApi1 = new ReconApi( { - enabled: true, + enabled: false, url: RECON_URL, feedEnabled: false, }, @@ -469,24 +468,29 @@ describe('ModelInstanceDocument API multi-node tests', () => { await reconApi0.init() await reconApi1.init() -*/ mocker.mock({ url: regexPattern, - body: JSON.stringify({events: [], resumeToken: 'test'}), + body: JSON.stringify({ events: [], resumeToken: 'test' }), status: 200, }) + // Simulates --ipfs-api ipfs0.config.set('Addresses.API', RECON_URL) ipfs1.config.set('Addresses.API', RECON_URL) } + ceramic0 = await createCeramic(ipfs0) + ceramic1 = await createCeramic(ipfs1) - ceramic0 = await createCeramic(ipfs0) - ceramic1 = await createCeramic(ipfs1) + reconApi0.stop() + reconApi1.stop() model = await Model.create(ceramic0, MODEL_DEFINITION) + reconApi0.stop() + reconApi1.stop() + midMetadata = { model: model.id } - }, 22000) + }, 80000) afterAll(async () => { await ceramic0.close() From 8a74337105a929d084827d1943df2779ccef52e0 Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Wed, 20 Mar 2024 17:28:14 -0400 Subject: [PATCH 04/28] fix: update tests --- .../cli/src/__tests__/ceramic-daemon.test.ts | 45 ++++++------ packages/common-test-utils/src/index.ts | 3 - .../__tests__/model-instance-document.test.ts | 68 ++++++++----------- 3 files changed, 50 insertions(+), 66 deletions(-) diff --git a/packages/cli/src/__tests__/ceramic-daemon.test.ts b/packages/cli/src/__tests__/ceramic-daemon.test.ts index 2641d65555..105d27d9c7 100644 --- a/packages/cli/src/__tests__/ceramic-daemon.test.ts +++ b/packages/cli/src/__tests__/ceramic-daemon.test.ts @@ -447,34 +447,31 @@ describe('Ceramic interop: core <> http-client', () => { clearTimeout(id) }) - test( - 'Aborts fetch if taking too long even if given an AbortSignal that did not get aborted', - async () => { - const content1 = { test: 123 } - const doc = await TileDocument.create(core, content1, null, { anchor: false }) - - const loadStreamMock = jest.spyOn(core, 'loadStream') - let id = null - loadStreamMock.mockImplementation(() => { - return new Promise((resolve) => { - id = setTimeout(() => { - resolve(doc) - }, 4000) - }) + test('Aborts fetch if taking too long even if given an AbortSignal that did not get aborted', async () => { + const content1 = { test: 123 } + const doc = await TileDocument.create(core, content1, null, { anchor: false }) + + const loadStreamMock = jest.spyOn(core, 'loadStream') + let id = null + loadStreamMock.mockImplementation(() => { + return new Promise((resolve) => { + id = setTimeout(() => { + resolve(doc) + }, 4000) }) + }) - const controller = new AbortController() + const controller = new AbortController() - await expect( - fetchJson(`http://localhost:${daemon.port}/api/v0/streams/${doc.id}/content`, { - signal: controller.signal, - timeout: 1000, - }) - ).rejects.toThrow(/aborted/) + await expect( + fetchJson(`http://localhost:${daemon.port}/api/v0/streams/${doc.id}/content`, { + signal: controller.signal, + timeout: 1000, + }) + ).rejects.toThrow(/aborted/) - clearTimeout(id) - } - ) + clearTimeout(id) + }) test('Aborts fetch if the AbortSignal given has already been aborted', async () => { const content1 = { test: 123 } diff --git a/packages/common-test-utils/src/index.ts b/packages/common-test-utils/src/index.ts index 665d236341..8d6364b8c7 100644 --- a/packages/common-test-utils/src/index.ts +++ b/packages/common-test-utils/src/index.ts @@ -13,9 +13,6 @@ import { import first from 'it-first' import { BaseTestUtils } from '@ceramicnetwork/base-test-utils' -export const testIfV3 = process.env['CERAMIC_RECON_MODE'] ? test.skip : test -export const describeIfV3 = process.env['CERAMIC_RECON_MODE'] ? describe.skip : describe - class FakeRunningState extends BehaviorSubject implements RunningStateLike { readonly id: StreamID readonly state: StreamState diff --git a/packages/stream-tests/src/__tests__/model-instance-document.test.ts b/packages/stream-tests/src/__tests__/model-instance-document.test.ts index b9b432bbdf..e853e4c266 100644 --- a/packages/stream-tests/src/__tests__/model-instance-document.test.ts +++ b/packages/stream-tests/src/__tests__/model-instance-document.test.ts @@ -1,6 +1,6 @@ import { jest, test, expect, describe, beforeAll, afterAll } from '@jest/globals' import getPort from 'get-port' -import { AnchorStatus, EventType, IpfsApi, LoggerProvider } from '@ceramicnetwork/common' +import { AnchorStatus, EventType, IpfsApi, LoggerProvider, Networks } from '@ceramicnetwork/common' import { Utils as CoreUtils, ReconApi } from '@ceramicnetwork/core' import { createIPFS, swarmConnect } from '@ceramicnetwork/ipfs-daemon' import { @@ -439,56 +439,43 @@ describe('ModelInstanceDocument API multi-node tests', () => { let reconApi1: ReconApi beforeAll(async () => { - ipfs0 = await createIPFS() - ipfs1 = await createIPFS() - - await swarmConnect(ipfs0, ipfs1) if (process.env.CERAMIC_RECON_MODE) { - const regexPattern = new RegExp(`${RECON_URL}.*`) - - reconApi0 = new ReconApi( - { - enabled: false, - url: RECON_URL, - feedEnabled: false, - }, - LOGGER, - fetch - ) - - reconApi1 = new ReconApi( - { - enabled: false, - url: RECON_URL, - feedEnabled: false, - }, - LOGGER, - fetch - ) - - await reconApi0.init() - await reconApi1.init() + /* const regexPattern = new RegExp(`${RECON_URL}.*`) mocker.mock({ url: regexPattern, body: JSON.stringify({ events: [], resumeToken: 'test' }), status: 200, + })*/ + ipfs0 = await createIPFS({ + rust: { + type: 'binary', + network: Networks.INMEMORY, + }, }) - - // Simulates --ipfs-api - ipfs0.config.set('Addresses.API', RECON_URL) - ipfs1.config.set('Addresses.API', RECON_URL) + ipfs1 = await createIPFS({ + rust: { + type: 'binary', + network: Networks.INMEMORY, + }, + }) + } else { + ipfs0 = await createIPFS() + ipfs1 = await createIPFS() } + + await swarmConnect(ipfs0, ipfs1) + console.log("1") ceramic0 = await createCeramic(ipfs0) + console.log("1") ceramic1 = await createCeramic(ipfs1) - - reconApi0.stop() - reconApi1.stop() - + console.log("1") model = await Model.create(ceramic0, MODEL_DEFINITION) - reconApi0.stop() - reconApi1.stop() + console.log("1") + if (process.env.CERAMIC_RECON_MODE) + await TestUtils.waitForEvent(ceramic0.repository.recon, model.tip) + console.log("1") midMetadata = { model: model.id } }, 80000) @@ -503,6 +490,9 @@ describe('ModelInstanceDocument API multi-node tests', () => { test.only('load basic doc', async () => { const doc = await ModelInstanceDocument.create(ceramic0, CONTENT0, midMetadata) + if (process.env.CERAMIC_RECON_MODE) + await TestUtils.waitForEvent(ceramic1.repository.recon, doc.tip) + const loaded = await ModelInstanceDocument.load(ceramic1, doc.id) const docState = doc.state From 674d69d2fd176e14082be616e84894492a7f14fc Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Thu, 21 Mar 2024 08:16:18 -0400 Subject: [PATCH 05/28] chore: skip tests using tile docs --- .../cli/src/__tests__/ceramic-daemon.test.ts | 83 ++++++++++--------- 1 file changed, 45 insertions(+), 38 deletions(-) diff --git a/packages/cli/src/__tests__/ceramic-daemon.test.ts b/packages/cli/src/__tests__/ceramic-daemon.test.ts index 105d27d9c7..d5758742f0 100644 --- a/packages/cli/src/__tests__/ceramic-daemon.test.ts +++ b/packages/cli/src/__tests__/ceramic-daemon.test.ts @@ -31,6 +31,10 @@ import { decode } from 'codeco' const seed = 'SEED' +// Should pass on v4 if updated from TileDocument +const describeIfV3 = process.env.CERAMIC_RECON_MODE ? describe.skip : describe +const testIfV3 = process.env.CERAMIC_RECON_MODE ? test.skip : test + describe('Ceramic interop: core <> http-client', () => { jest.setTimeout(30000) let ipfs: IpfsApi @@ -118,18 +122,18 @@ describe('Ceramic interop: core <> http-client', () => { isOnlineSpy.mockReset() }) - test('can store commit if the size is lesser than the maximum size ~256KB', async () => { + testIfV3('can store commit if the size is lesser than the maximum size ~256KB', async () => { const streamtype = await TileDocument.create(client, { test: randomString(200000) }) expect(streamtype).not.toBeNull() }) - test('cannot store commit if the size is greater than the maximum size ~256KB', async () => { + testIfV3('cannot store commit if the size is greater than the maximum size ~256KB', async () => { await expect(TileDocument.create(client, { test: randomString(300000) })).rejects.toThrow( /exceeds the maximum block size of/ ) }) - test('properly creates document', async () => { + testIfV3('properly creates document', async () => { const doc1 = await TileDocument.create(core, { test: 123 }, null, { anchor: false, publish: false, @@ -155,7 +159,7 @@ describe('Ceramic interop: core <> http-client', () => { expect(state1).toEqual(state2) }) - test('gets anchor commit updates', async () => { + testIfV3('gets anchor commit updates', async () => { const doc1 = await TileDocument.create(core, { test: 123 }) await anchorDoc(doc1) expect(doc1.state.log.length).toEqual(2) @@ -166,7 +170,7 @@ describe('Ceramic interop: core <> http-client', () => { expect(doc2.state.anchorStatus).toEqual(AnchorStatus.ANCHORED) }) - test('loads documents correctly', async () => { + testIfV3('loads documents correctly', async () => { const doc1 = await TileDocument.create(core, { test: 123 }) await anchorDoc(doc1) const doc2 = await client.loadStream(doc1.id) @@ -180,7 +184,7 @@ describe('Ceramic interop: core <> http-client', () => { expect(StreamUtils.serializeState(doc3.state)).toEqual(StreamUtils.serializeState(doc4.state)) }) - test('loads document commits correctly', async () => { + testIfV3('loads document commits correctly', async () => { const doc1 = await TileDocument.create(core, { test: 123 }) await anchorDoc(doc1) const doc2 = await TileDocument.load(client, doc1.id) @@ -203,7 +207,7 @@ describe('Ceramic interop: core <> http-client', () => { expect(serializeCommits(commits1)).toEqual(serializeCommits(commits2)) }) - test('makes and gets updates correctly with subscription', async () => { + testIfV3('makes and gets updates correctly with subscription', async () => { const initialContent = { a: 'initial' } const middleContent = { ...initialContent, b: 'middle' } const finalContent = { ...middleContent, c: 'final' } @@ -240,7 +244,7 @@ describe('Ceramic interop: core <> http-client', () => { subscription2.unsubscribe() }) - test('makes and gets updates correctly with manual sync', async () => { + testIfV3('makes and gets updates correctly with manual sync', async () => { const initialContent = { a: 'initial' } const middleContent = { ...initialContent, b: 'middle' } const finalContent = { ...middleContent, c: 'final' } @@ -267,7 +271,7 @@ describe('Ceramic interop: core <> http-client', () => { expect(StreamUtils.serializeState(doc1.state)).toEqual(StreamUtils.serializeState(doc2.state)) }) - test('Throw on rejected update', async () => { + testIfV3('Throw on rejected update', async () => { const contentOg = { test: 123 } const contentRejected = { test: 'rejected' } @@ -290,7 +294,7 @@ describe('Ceramic interop: core <> http-client', () => { expect(streamOg.state.log.length).toEqual(2) }) - test('loads commits correctly', async () => { + testIfV3('loads commits correctly', async () => { // Create multiple commits of the same document const content1 = { test: 123 } const content2 = { test: 456 } @@ -384,7 +388,7 @@ describe('Ceramic interop: core <> http-client', () => { expect(docV5Client.state.log.length).toEqual(6) }) - test('can get stream contents from /streams/contents', async () => { + testIfV3('can get stream contents from /streams/contents', async () => { const content1 = { test: 123 } const content2 = { test: 456, test2: 'abc' } const content3 = { test2: 'def' } @@ -398,7 +402,7 @@ describe('Ceramic interop: core <> http-client', () => { expect(json).toEqual(content3) }) - test('Aborts fetch if it is taking too long', async () => { + testIfV3('Aborts fetch if it is taking too long', async () => { const content1 = { test: 123 } const doc = await TileDocument.create(core, content1, null, { anchor: false }) @@ -421,7 +425,7 @@ describe('Ceramic interop: core <> http-client', () => { clearTimeout(id) }) - test('Aborts fetch through passed in AbortSignal', async () => { + testIfV3('Aborts fetch through passed in AbortSignal', async () => { const content1 = { test: 123 } const doc = await TileDocument.create(core, content1, null, { anchor: false }) @@ -447,33 +451,36 @@ describe('Ceramic interop: core <> http-client', () => { clearTimeout(id) }) - test('Aborts fetch if taking too long even if given an AbortSignal that did not get aborted', async () => { - const content1 = { test: 123 } - const doc = await TileDocument.create(core, content1, null, { anchor: false }) - - const loadStreamMock = jest.spyOn(core, 'loadStream') - let id = null - loadStreamMock.mockImplementation(() => { - return new Promise((resolve) => { - id = setTimeout(() => { - resolve(doc) - }, 4000) + testIfV3( + 'Aborts fetch if taking too long even if given an AbortSignal that did not get aborted', + async () => { + const content1 = { test: 123 } + const doc = await TileDocument.create(core, content1, null, { anchor: false }) + + const loadStreamMock = jest.spyOn(core, 'loadStream') + let id = null + loadStreamMock.mockImplementation(() => { + return new Promise((resolve) => { + id = setTimeout(() => { + resolve(doc) + }, 4000) + }) }) - }) - const controller = new AbortController() + const controller = new AbortController() - await expect( - fetchJson(`http://localhost:${daemon.port}/api/v0/streams/${doc.id}/content`, { - signal: controller.signal, - timeout: 1000, - }) - ).rejects.toThrow(/aborted/) + await expect( + fetchJson(`http://localhost:${daemon.port}/api/v0/streams/${doc.id}/content`, { + signal: controller.signal, + timeout: 1000, + }) + ).rejects.toThrow(/aborted/) - clearTimeout(id) - }) + clearTimeout(id) + } + ) - test('Aborts fetch if the AbortSignal given has already been aborted', async () => { + testIfV3('Aborts fetch if the AbortSignal given has already been aborted', async () => { const content1 = { test: 123 } const doc = await TileDocument.create(core, content1, null, { anchor: false }) @@ -487,7 +494,7 @@ describe('Ceramic interop: core <> http-client', () => { ).rejects.toThrow(/aborted/) }) - test('requestAnchor works via http api', async () => { + testIfV3('requestAnchor works via http api', async () => { const content1 = { test: 123 } const doc = await TileDocument.create(client, content1, null, { anchor: false }) @@ -524,7 +531,7 @@ describe('Ceramic interop: core <> http-client', () => { expect(messageEvent.metadata.model instanceof StreamID).toBeTruthy() }, 30000) - describe('multiqueries', () => { + describeIfV3('multiqueries', () => { let docA, docB, docC, docD beforeEach(async () => { docD = await TileDocument.create(core, { test: '321d' }) @@ -632,7 +639,7 @@ describe('Ceramic interop: core <> http-client', () => { }) }) - describe('pin api', () => { + describeIfV3('pin api', () => { let docA, docB let adminClient: CeramicClient From b65ad46de08754e1ba2222c0d145b7bf1f0093cd Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Thu, 21 Mar 2024 08:19:01 -0400 Subject: [PATCH 06/28] chore: remove console log --- .../src/__tests__/model-instance-document.test.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/stream-tests/src/__tests__/model-instance-document.test.ts b/packages/stream-tests/src/__tests__/model-instance-document.test.ts index e853e4c266..1718b767d8 100644 --- a/packages/stream-tests/src/__tests__/model-instance-document.test.ts +++ b/packages/stream-tests/src/__tests__/model-instance-document.test.ts @@ -465,17 +465,16 @@ describe('ModelInstanceDocument API multi-node tests', () => { } await swarmConnect(ipfs0, ipfs1) - console.log("1") + ceramic0 = await createCeramic(ipfs0) - console.log("1") ceramic1 = await createCeramic(ipfs1) - console.log("1") + model = await Model.create(ceramic0, MODEL_DEFINITION) - console.log("1") + if (process.env.CERAMIC_RECON_MODE) await TestUtils.waitForEvent(ceramic0.repository.recon, model.tip) - console.log("1") + console.log('1') midMetadata = { model: model.id } }, 80000) From 692c73018bb0c8fe49faeafbfba4425751ded9ad Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Thu, 21 Mar 2024 08:35:37 -0400 Subject: [PATCH 07/28] chore: restore skip describe --- packages/common-test-utils/src/index.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/common-test-utils/src/index.ts b/packages/common-test-utils/src/index.ts index 8d6364b8c7..665d236341 100644 --- a/packages/common-test-utils/src/index.ts +++ b/packages/common-test-utils/src/index.ts @@ -13,6 +13,9 @@ import { import first from 'it-first' import { BaseTestUtils } from '@ceramicnetwork/base-test-utils' +export const testIfV3 = process.env['CERAMIC_RECON_MODE'] ? test.skip : test +export const describeIfV3 = process.env['CERAMIC_RECON_MODE'] ? describe.skip : describe + class FakeRunningState extends BehaviorSubject implements RunningStateLike { readonly id: StreamID readonly state: StreamState From e6e3069e38549567306cf4c4edbbd9105a5649c6 Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Thu, 21 Mar 2024 09:35:10 -0400 Subject: [PATCH 08/28] chore: remove unused library --- packages/core/src/recon.ts | 2 +- .../__tests__/model-instance-document.test.ts | 35 ++++--------------- 2 files changed, 8 insertions(+), 29 deletions(-) diff --git a/packages/core/src/recon.ts b/packages/core/src/recon.ts index c81b7e9de5..0fd525b673 100644 --- a/packages/core/src/recon.ts +++ b/packages/core/src/recon.ts @@ -124,7 +124,7 @@ export class ReconApi extends Observable implements IRec if (!this.enabled) { throw new Error(`Recon: disabled, not registering interest in model ${model.toString()}`) } - + console.log("URL INSIDE RECON", this.#url) try { await this.#sendRequest(this.#url + `/ceramic/interests/model/${model.toString()}`, { method: 'POST', diff --git a/packages/stream-tests/src/__tests__/model-instance-document.test.ts b/packages/stream-tests/src/__tests__/model-instance-document.test.ts index 1718b767d8..689342b15a 100644 --- a/packages/stream-tests/src/__tests__/model-instance-document.test.ts +++ b/packages/stream-tests/src/__tests__/model-instance-document.test.ts @@ -1,7 +1,7 @@ import { jest, test, expect, describe, beforeAll, afterAll } from '@jest/globals' import getPort from 'get-port' -import { AnchorStatus, EventType, IpfsApi, LoggerProvider, Networks } from '@ceramicnetwork/common' -import { Utils as CoreUtils, ReconApi } from '@ceramicnetwork/core' +import { AnchorStatus, EventType, IpfsApi, Networks } from '@ceramicnetwork/common' +import { Utils as CoreUtils } from '@ceramicnetwork/core' import { createIPFS, swarmConnect } from '@ceramicnetwork/ipfs-daemon' import { ModelInstanceDocument, @@ -13,7 +13,6 @@ import { CeramicDaemon, DaemonConfig } from '@ceramicnetwork/cli' import { CeramicClient } from '@ceramicnetwork/http-client' import { Model, ModelDefinition } from '@ceramicnetwork/stream-model' import { CommonTestUtils as TestUtils } from '@ceramicnetwork/common-test-utils' -import HttpRequestMock from 'http-request-mock' const CONTENT0 = { myData: 0 } const CONTENT1 = { myData: 1 } @@ -82,10 +81,6 @@ const MODEL_WITH_RELATION_DEFINITION: ModelDefinition = { }, } -const RECON_URL = 'http://example.com' -const LOGGER = new LoggerProvider().getDiagnosticsLogger() -const mocker = HttpRequestMock.setupForUnitTest('fetch') - describe('ModelInstanceDocument API http-client tests', () => { jest.setTimeout(1000 * 30) @@ -435,28 +430,20 @@ describe('ModelInstanceDocument API multi-node tests', () => { let ceramic1: Ceramic let model: Model let midMetadata: ModelInstanceDocumentMetadataArgs - let reconApi0: ReconApi - let reconApi1: ReconApi beforeAll(async () => { if (process.env.CERAMIC_RECON_MODE) { - /* const regexPattern = new RegExp(`${RECON_URL}.*`) - - mocker.mock({ - url: regexPattern, - body: JSON.stringify({ events: [], resumeToken: 'test' }), - status: 200, - })*/ + const host = '127.0.0.1' ipfs0 = await createIPFS({ rust: { - type: 'binary', - network: Networks.INMEMORY, + type: 'remote', + host, }, }) ipfs1 = await createIPFS({ rust: { - type: 'binary', - network: Networks.INMEMORY, + type: 'remote', + host, }, }) } else { @@ -471,10 +458,6 @@ describe('ModelInstanceDocument API multi-node tests', () => { model = await Model.create(ceramic0, MODEL_DEFINITION) - if (process.env.CERAMIC_RECON_MODE) - await TestUtils.waitForEvent(ceramic0.repository.recon, model.tip) - - console.log('1') midMetadata = { model: model.id } }, 80000) @@ -483,15 +466,11 @@ describe('ModelInstanceDocument API multi-node tests', () => { await ceramic1.close() await ipfs0.stop() await ipfs1.stop() - mocker.reset() }) test.only('load basic doc', async () => { const doc = await ModelInstanceDocument.create(ceramic0, CONTENT0, midMetadata) - if (process.env.CERAMIC_RECON_MODE) - await TestUtils.waitForEvent(ceramic1.repository.recon, doc.tip) - const loaded = await ModelInstanceDocument.load(ceramic1, doc.id) const docState = doc.state From 517ac32f792bae46fe1e85ea618628c816adcf2b Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Thu, 21 Mar 2024 13:58:02 -0400 Subject: [PATCH 09/28] refactor: model instance document test --- .../__tests__/model-instance-document.test.ts | 30 +++++-------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/packages/stream-tests/src/__tests__/model-instance-document.test.ts b/packages/stream-tests/src/__tests__/model-instance-document.test.ts index 689342b15a..dbc50ed966 100644 --- a/packages/stream-tests/src/__tests__/model-instance-document.test.ts +++ b/packages/stream-tests/src/__tests__/model-instance-document.test.ts @@ -430,34 +430,18 @@ describe('ModelInstanceDocument API multi-node tests', () => { let ceramic1: Ceramic let model: Model let midMetadata: ModelInstanceDocumentMetadataArgs + let disablePeerDataSync: boolean beforeAll(async () => { - if (process.env.CERAMIC_RECON_MODE) { - const host = '127.0.0.1' - ipfs0 = await createIPFS({ - rust: { - type: 'remote', - host, - }, - }) - ipfs1 = await createIPFS({ - rust: { - type: 'remote', - host, - }, - }) - } else { - ipfs0 = await createIPFS() - ipfs1 = await createIPFS() - } - + disablePeerDataSync = process.env.CERAMIC_RECON_MODE ? true : false + ipfs0 = await createIPFS() + ipfs1 = await createIPFS() await swarmConnect(ipfs0, ipfs1) - ceramic0 = await createCeramic(ipfs0) - ceramic1 = await createCeramic(ipfs1) + ceramic0 = await createCeramic(ipfs0, { disablePeerDataSync, reconFeedEnabled: false }) + ceramic1 = await createCeramic(ipfs1, { disablePeerDataSync, reconFeedEnabled: false }) model = await Model.create(ceramic0, MODEL_DEFINITION) - midMetadata = { model: model.id } }, 80000) @@ -468,7 +452,7 @@ describe('ModelInstanceDocument API multi-node tests', () => { await ipfs1.stop() }) - test.only('load basic doc', async () => { + test('load basic doc', async () => { const doc = await ModelInstanceDocument.create(ceramic0, CONTENT0, midMetadata) const loaded = await ModelInstanceDocument.load(ceramic1, doc.id) From bc68b0a0a28aae1bd673b478ccf92fde4f4d41fe Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Thu, 21 Mar 2024 15:00:43 -0400 Subject: [PATCH 10/28] chore: refactor beforeAll hook --- packages/core/src/recon.ts | 1 - .../__tests__/model-instance-document.test.ts | 20 +++++++++++++------ .../stream-tests/src/__tests__/model.test.ts | 16 ++++++++++++--- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/packages/core/src/recon.ts b/packages/core/src/recon.ts index 0fd525b673..e7e8a8116c 100644 --- a/packages/core/src/recon.ts +++ b/packages/core/src/recon.ts @@ -124,7 +124,6 @@ export class ReconApi extends Observable implements IRec if (!this.enabled) { throw new Error(`Recon: disabled, not registering interest in model ${model.toString()}`) } - console.log("URL INSIDE RECON", this.#url) try { await this.#sendRequest(this.#url + `/ceramic/interests/model/${model.toString()}`, { method: 'POST', diff --git a/packages/stream-tests/src/__tests__/model-instance-document.test.ts b/packages/stream-tests/src/__tests__/model-instance-document.test.ts index dbc50ed966..e0ea70d417 100644 --- a/packages/stream-tests/src/__tests__/model-instance-document.test.ts +++ b/packages/stream-tests/src/__tests__/model-instance-document.test.ts @@ -430,16 +430,24 @@ describe('ModelInstanceDocument API multi-node tests', () => { let ceramic1: Ceramic let model: Model let midMetadata: ModelInstanceDocumentMetadataArgs - let disablePeerDataSync: boolean beforeAll(async () => { - disablePeerDataSync = process.env.CERAMIC_RECON_MODE ? true : false - ipfs0 = await createIPFS() - ipfs1 = await createIPFS() + ipfs0 = await createIPFS({ + rust: { + type: 'binary', + network: Networks.INMEMORY, + }, + }) + ipfs1 = await createIPFS({ + rust: { + type: 'binary', + network: Networks.INMEMORY, + }, + }) await swarmConnect(ipfs0, ipfs1) - ceramic0 = await createCeramic(ipfs0, { disablePeerDataSync, reconFeedEnabled: false }) - ceramic1 = await createCeramic(ipfs1, { disablePeerDataSync, reconFeedEnabled: false }) + ceramic0 = await createCeramic(ipfs0) + ceramic1 = await createCeramic(ipfs1) model = await Model.create(ceramic0, MODEL_DEFINITION) midMetadata = { model: model.id } diff --git a/packages/stream-tests/src/__tests__/model.test.ts b/packages/stream-tests/src/__tests__/model.test.ts index 407343b57b..5e2389a007 100644 --- a/packages/stream-tests/src/__tests__/model.test.ts +++ b/packages/stream-tests/src/__tests__/model.test.ts @@ -1,6 +1,6 @@ import { jest } from '@jest/globals' import getPort from 'get-port' -import { AnchorStatus, EventType, IpfsApi } from '@ceramicnetwork/common' +import { AnchorStatus, EventType, IpfsApi, Networks } from '@ceramicnetwork/common' import { Utils as CoreUtils } from '@ceramicnetwork/core' import { createIPFS, swarmConnect } from '@ceramicnetwork/ipfs-daemon' import { Model, ModelDefinition, parseModelVersion } from '@ceramicnetwork/stream-model' @@ -736,8 +736,18 @@ describe('Model API multi-node tests', () => { let ceramic1: Ceramic beforeAll(async () => { - ipfs0 = await createIPFS() - ipfs1 = await createIPFS() + ipfs0 = await createIPFS({ + rust: { + type: 'binary', + network: Networks.INMEMORY, + }, + }) + ipfs1 = await createIPFS({ + rust: { + type: 'binary', + network: Networks.INMEMORY, + }, + }) await swarmConnect(ipfs0, ipfs1) }, 12000) From aa7e94a31c52df7cc6ae963d16f3b283bbe3031f Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Fri, 22 Mar 2024 08:45:35 -0400 Subject: [PATCH 11/28] fix: test delay --- .../core/src/anchor/__tests__/anchor-processing-loop.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/anchor/__tests__/anchor-processing-loop.test.ts b/packages/core/src/anchor/__tests__/anchor-processing-loop.test.ts index 8e2b3486b5..176da5448c 100644 --- a/packages/core/src/anchor/__tests__/anchor-processing-loop.test.ts +++ b/packages/core/src/anchor/__tests__/anchor-processing-loop.test.ts @@ -152,7 +152,7 @@ test('Dont process the same entry multiple times concurrently', async () => { async function* overEntries(): AsyncGenerator { do { // Need this sleep or else the Node runtime might never switch back to the "process" function. - await CommonTestUtils.delay(1) + await CommonTestUtils.delay(5) for (const e of entries) yield e } while (true) } From b9a4fdb8b37ac43420acebf830cd93e63ad4665e Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Mon, 25 Mar 2024 14:12:15 -0400 Subject: [PATCH 12/28] chore: update tests --- .../stream-tests/src/__tests__/model.test.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/stream-tests/src/__tests__/model.test.ts b/packages/stream-tests/src/__tests__/model.test.ts index 5e2389a007..0a6086a4e4 100644 --- a/packages/stream-tests/src/__tests__/model.test.ts +++ b/packages/stream-tests/src/__tests__/model.test.ts @@ -8,6 +8,7 @@ import { createCeramic } from '../create-ceramic.js' import { Ceramic } from '@ceramicnetwork/core' import { CeramicDaemon, DaemonConfig } from '@ceramicnetwork/cli' import { CeramicClient } from '@ceramicnetwork/http-client' +import { CommonTestUtils as TestUtils } from '@ceramicnetwork/common-test-utils' const MODEL_DEFINITION: ModelDefinition = { name: 'myModel', @@ -752,8 +753,8 @@ describe('Model API multi-node tests', () => { }, 12000) beforeEach(async () => { - ceramic0 = await createCeramic(ipfs0) - ceramic1 = await createCeramic(ipfs1) + ceramic0 = await createCeramic(ipfs0, { networkName: Networks.INMEMORY }) + ceramic1 = await createCeramic(ipfs1, { networkName: Networks.INMEMORY }) }, 12000) afterEach(async () => { @@ -769,6 +770,12 @@ describe('Model API multi-node tests', () => { test('load basic model', async () => { const model = await Model.create(ceramic0, MODEL_DEFINITION) + if (process.env.CERAMIC_RECON_MODE) + await TestUtils.waitForEvent(ceramic1.repository.recon, model.tip) + + await ceramic0.admin.startIndexingModelData([{ streamID: model.id }]) + await ceramic1.admin.startIndexingModelData([{ streamID: model.id }]) + const loaded = await Model.load(ceramic1, model.id) const modelState = model.state @@ -783,6 +790,12 @@ describe('Model API multi-node tests', () => { test('load anchored model', async () => { const model = await Model.create(ceramic0, MODEL_DEFINITION) + + if (process.env.CERAMIC_RECON_MODE) + await TestUtils.waitForEvent(ceramic1.repository.recon, model.tip) + + await ceramic0.admin.startIndexingModelData([{ streamID: model.id }]) + await ceramic1.admin.startIndexingModelData([{ streamID: model.id }]) await CoreUtils.anchorUpdate(ceramic0, model) const loaded = await Model.load(ceramic1, model.id) From 6ea0c7fc4746b3265cf7dd4720d1d1a945018005 Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Mon, 25 Mar 2024 14:24:42 -0400 Subject: [PATCH 13/28] chore: run lint --- packages/core/src/providers-cache.ts | 8 +++++++- packages/stream-tests/src/__tests__/model.test.ts | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/core/src/providers-cache.ts b/packages/core/src/providers-cache.ts index 52ba2575c5..83aabaf2c5 100644 --- a/packages/core/src/providers-cache.ts +++ b/packages/core/src/providers-cache.ts @@ -29,7 +29,13 @@ const ETH_CHAIN_ID_MAPPINGS: Record = { type: 'Test', endpoint: 'https://rpc.ankr.com/gnosis', }, - 'eip155:11155111': { network: 'sepolia', chain: 'ETH', chainId: 11155111, networkId: 11155111, type: 'Test' }, + 'eip155:11155111': { + network: 'sepolia', + chain: 'ETH', + chainId: 11155111, + networkId: 11155111, + type: 'Test', + }, } const BASE_CHAIN_ID = 'eip155' diff --git a/packages/stream-tests/src/__tests__/model.test.ts b/packages/stream-tests/src/__tests__/model.test.ts index 0a6086a4e4..9a1b13bf69 100644 --- a/packages/stream-tests/src/__tests__/model.test.ts +++ b/packages/stream-tests/src/__tests__/model.test.ts @@ -792,7 +792,7 @@ describe('Model API multi-node tests', () => { const model = await Model.create(ceramic0, MODEL_DEFINITION) if (process.env.CERAMIC_RECON_MODE) - await TestUtils.waitForEvent(ceramic1.repository.recon, model.tip) + await TestUtils.waitForEvent(ceramic1.repository.recon, model.tip) await ceramic0.admin.startIndexingModelData([{ streamID: model.id }]) await ceramic1.admin.startIndexingModelData([{ streamID: model.id }]) From 0d28018cb1d047ee0b54915c7473ca26d901027e Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Mon, 25 Mar 2024 14:52:52 -0400 Subject: [PATCH 14/28] chore: update tests --- .../__tests__/model-instance-document.test.ts | 29 +++++++++++++++++-- .../stream-tests/src/__tests__/model.test.ts | 2 +- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/packages/stream-tests/src/__tests__/model-instance-document.test.ts b/packages/stream-tests/src/__tests__/model-instance-document.test.ts index f2698288dd..1ede5c7109 100644 --- a/packages/stream-tests/src/__tests__/model-instance-document.test.ts +++ b/packages/stream-tests/src/__tests__/model-instance-document.test.ts @@ -518,11 +518,17 @@ describe('ModelInstanceDocument API multi-node tests', () => { }) await swarmConnect(ipfs0, ipfs1) - ceramic0 = await createCeramic(ipfs0) - ceramic1 = await createCeramic(ipfs1) + ceramic0 = await createCeramic(ipfs0, { networkName: Networks.INMEMORY }) + ceramic1 = await createCeramic(ipfs1, { networkName: Networks.INMEMORY }) model = await Model.create(ceramic0, MODEL_DEFINITION) midMetadata = { model: model.id } + + if (process.env.CERAMIC_RECON_MODE) + await TestUtils.waitForEvent(ceramic1.repository.recon, model.tip) + + await ceramic0.admin.startIndexingModelData([{ streamID: model.id }]) + await ceramic1.admin.startIndexingModelData([{ streamID: model.id }]) }, 80000) afterAll(async () => { @@ -535,6 +541,12 @@ describe('ModelInstanceDocument API multi-node tests', () => { test('load basic doc', async () => { const doc = await ModelInstanceDocument.create(ceramic0, CONTENT0, midMetadata) + if (process.env.CERAMIC_RECON_MODE) + await TestUtils.waitForEvent(ceramic1.repository.recon, doc.tip) + + await ceramic0.admin.startIndexingModelData([{ streamID: doc.id }]) + await ceramic1.admin.startIndexingModelData([{ streamID: doc.id }]) + const loaded = await ModelInstanceDocument.load(ceramic1, doc.id) const docState = doc.state @@ -549,6 +561,13 @@ describe('ModelInstanceDocument API multi-node tests', () => { test('load updated doc', async () => { const doc = await ModelInstanceDocument.create(ceramic0, CONTENT0, midMetadata) + + if (process.env.CERAMIC_RECON_MODE) + await TestUtils.waitForEvent(ceramic1.repository.recon, doc.tip) + + await ceramic0.admin.startIndexingModelData([{ streamID: doc.id }]) + await ceramic1.admin.startIndexingModelData([{ streamID: doc.id }]) + await doc.replace(CONTENT1) const loaded = await ModelInstanceDocument.load(ceramic1, doc.id) @@ -566,6 +585,12 @@ describe('ModelInstanceDocument API multi-node tests', () => { test('load updated and anchored doc', async () => { const doc = await ModelInstanceDocument.create(ceramic0, CONTENT0, midMetadata) + if (process.env.CERAMIC_RECON_MODE) + await TestUtils.waitForEvent(ceramic1.repository.recon, doc.tip) + + await ceramic0.admin.startIndexingModelData([{ streamID: doc.id }]) + await ceramic1.admin.startIndexingModelData([{ streamID: doc.id }]) + await doc.replace(CONTENT1) await CoreUtils.anchorUpdate(ceramic0, doc) diff --git a/packages/stream-tests/src/__tests__/model.test.ts b/packages/stream-tests/src/__tests__/model.test.ts index 9a1b13bf69..7a24b10f09 100644 --- a/packages/stream-tests/src/__tests__/model.test.ts +++ b/packages/stream-tests/src/__tests__/model.test.ts @@ -803,5 +803,5 @@ describe('Model API multi-node tests', () => { expect(loaded.state.anchorStatus).toEqual(AnchorStatus.ANCHORED) expect(loaded.state.log.length).toEqual(2) expect(JSON.stringify(loaded.state)).toEqual(JSON.stringify(model.state)) - }) + }, 50000) }) From c525ff95bb1ee332bce1d40d9999321d43a073d5 Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Mon, 25 Mar 2024 15:46:54 -0400 Subject: [PATCH 15/28] chore: update tests --- .../src/__tests__/model-instance-document.test.ts | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/packages/stream-tests/src/__tests__/model-instance-document.test.ts b/packages/stream-tests/src/__tests__/model-instance-document.test.ts index 1ede5c7109..c95a41f3ae 100644 --- a/packages/stream-tests/src/__tests__/model-instance-document.test.ts +++ b/packages/stream-tests/src/__tests__/model-instance-document.test.ts @@ -538,15 +538,12 @@ describe('ModelInstanceDocument API multi-node tests', () => { await ipfs1.stop() }) - test('load basic doc', async () => { + test.only('load basic doc', async () => { const doc = await ModelInstanceDocument.create(ceramic0, CONTENT0, midMetadata) if (process.env.CERAMIC_RECON_MODE) await TestUtils.waitForEvent(ceramic1.repository.recon, doc.tip) - await ceramic0.admin.startIndexingModelData([{ streamID: doc.id }]) - await ceramic1.admin.startIndexingModelData([{ streamID: doc.id }]) - const loaded = await ModelInstanceDocument.load(ceramic1, doc.id) const docState = doc.state @@ -565,9 +562,6 @@ describe('ModelInstanceDocument API multi-node tests', () => { if (process.env.CERAMIC_RECON_MODE) await TestUtils.waitForEvent(ceramic1.repository.recon, doc.tip) - await ceramic0.admin.startIndexingModelData([{ streamID: doc.id }]) - await ceramic1.admin.startIndexingModelData([{ streamID: doc.id }]) - await doc.replace(CONTENT1) const loaded = await ModelInstanceDocument.load(ceramic1, doc.id) @@ -588,9 +582,6 @@ describe('ModelInstanceDocument API multi-node tests', () => { if (process.env.CERAMIC_RECON_MODE) await TestUtils.waitForEvent(ceramic1.repository.recon, doc.tip) - await ceramic0.admin.startIndexingModelData([{ streamID: doc.id }]) - await ceramic1.admin.startIndexingModelData([{ streamID: doc.id }]) - await doc.replace(CONTENT1) await CoreUtils.anchorUpdate(ceramic0, doc) From 31eba9ef022218fd30bcd2198769ae7c5e72306b Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Mon, 25 Mar 2024 16:02:39 -0400 Subject: [PATCH 16/28] chore: remove .only --- .../src/__tests__/model-instance-document.test.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/stream-tests/src/__tests__/model-instance-document.test.ts b/packages/stream-tests/src/__tests__/model-instance-document.test.ts index c95a41f3ae..4a1d8a6532 100644 --- a/packages/stream-tests/src/__tests__/model-instance-document.test.ts +++ b/packages/stream-tests/src/__tests__/model-instance-document.test.ts @@ -538,13 +538,15 @@ describe('ModelInstanceDocument API multi-node tests', () => { await ipfs1.stop() }) - test.only('load basic doc', async () => { + test('load basic doc', async () => { const doc = await ModelInstanceDocument.create(ceramic0, CONTENT0, midMetadata) if (process.env.CERAMIC_RECON_MODE) await TestUtils.waitForEvent(ceramic1.repository.recon, doc.tip) const loaded = await ModelInstanceDocument.load(ceramic1, doc.id) + const hasBothUpdates = (state: StreamState) => state.log.length === 2 + await TestUtils.waitFor(loaded, hasBothUpdates) const docState = doc.state const loadedState = loaded.state From c058d424212880be6df51a1ef8f3571d447b8a3d Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Tue, 26 Mar 2024 09:40:12 -0400 Subject: [PATCH 17/28] feat: add test delay --- packages/stream-tests/src/__tests__/model.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/stream-tests/src/__tests__/model.test.ts b/packages/stream-tests/src/__tests__/model.test.ts index 7a24b10f09..3ec549577d 100644 --- a/packages/stream-tests/src/__tests__/model.test.ts +++ b/packages/stream-tests/src/__tests__/model.test.ts @@ -798,6 +798,7 @@ describe('Model API multi-node tests', () => { await ceramic1.admin.startIndexingModelData([{ streamID: model.id }]) await CoreUtils.anchorUpdate(ceramic0, model) + await TestUtils.delay(1000) const loaded = await Model.load(ceramic1, model.id) expect(loaded.state.anchorStatus).toEqual(AnchorStatus.ANCHORED) From df324011d0211dace74dc5b402e5198774f8e132 Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Tue, 26 Mar 2024 10:15:23 -0400 Subject: [PATCH 18/28] fix: post merge fix --- .../src/__tests__/model-instance-document.test.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/stream-tests/src/__tests__/model-instance-document.test.ts b/packages/stream-tests/src/__tests__/model-instance-document.test.ts index 4a1d8a6532..05fa385104 100644 --- a/packages/stream-tests/src/__tests__/model-instance-document.test.ts +++ b/packages/stream-tests/src/__tests__/model-instance-document.test.ts @@ -545,8 +545,6 @@ describe('ModelInstanceDocument API multi-node tests', () => { await TestUtils.waitForEvent(ceramic1.repository.recon, doc.tip) const loaded = await ModelInstanceDocument.load(ceramic1, doc.id) - const hasBothUpdates = (state: StreamState) => state.log.length === 2 - await TestUtils.waitFor(loaded, hasBothUpdates) const docState = doc.state const loadedState = loaded.state @@ -565,7 +563,7 @@ describe('ModelInstanceDocument API multi-node tests', () => { await TestUtils.waitForEvent(ceramic1.repository.recon, doc.tip) await doc.replace(CONTENT1) - + await TestUtils.delay(1000) const loaded = await ModelInstanceDocument.load(ceramic1, doc.id) const docState = doc.state From 82f3c32c350c920f3ceeac7ac5682f6682e88192 Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Tue, 26 Mar 2024 10:21:17 -0400 Subject: [PATCH 19/28] fix: add delay to test --- .../stream-tests/src/__tests__/model-instance-document.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/stream-tests/src/__tests__/model-instance-document.test.ts b/packages/stream-tests/src/__tests__/model-instance-document.test.ts index 05fa385104..43ed3f7a35 100644 --- a/packages/stream-tests/src/__tests__/model-instance-document.test.ts +++ b/packages/stream-tests/src/__tests__/model-instance-document.test.ts @@ -584,7 +584,7 @@ describe('ModelInstanceDocument API multi-node tests', () => { await doc.replace(CONTENT1) await CoreUtils.anchorUpdate(ceramic0, doc) - + await TestUtils.delay(1000) const loaded = await ModelInstanceDocument.load(ceramic1, doc.id) expect(loaded.state.anchorStatus).toEqual(AnchorStatus.ANCHORED) From e9872aeb28dcf4128aaa8c12b79c3a2ec004a90f Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Tue, 26 Mar 2024 12:01:04 -0400 Subject: [PATCH 20/28] fix: update tests --- .../src/__tests__/model-instance-document.test.ts | 4 ++-- packages/stream-tests/src/__tests__/model.test.ts | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/stream-tests/src/__tests__/model-instance-document.test.ts b/packages/stream-tests/src/__tests__/model-instance-document.test.ts index 43ed3f7a35..8c79a072eb 100644 --- a/packages/stream-tests/src/__tests__/model-instance-document.test.ts +++ b/packages/stream-tests/src/__tests__/model-instance-document.test.ts @@ -563,7 +563,7 @@ describe('ModelInstanceDocument API multi-node tests', () => { await TestUtils.waitForEvent(ceramic1.repository.recon, doc.tip) await doc.replace(CONTENT1) - await TestUtils.delay(1000) + await TestUtils.delay(2000) const loaded = await ModelInstanceDocument.load(ceramic1, doc.id) const docState = doc.state @@ -584,7 +584,7 @@ describe('ModelInstanceDocument API multi-node tests', () => { await doc.replace(CONTENT1) await CoreUtils.anchorUpdate(ceramic0, doc) - await TestUtils.delay(1000) + await TestUtils.delay(2000) const loaded = await ModelInstanceDocument.load(ceramic1, doc.id) expect(loaded.state.anchorStatus).toEqual(AnchorStatus.ANCHORED) diff --git a/packages/stream-tests/src/__tests__/model.test.ts b/packages/stream-tests/src/__tests__/model.test.ts index 3ec549577d..68c22e7065 100644 --- a/packages/stream-tests/src/__tests__/model.test.ts +++ b/packages/stream-tests/src/__tests__/model.test.ts @@ -791,6 +791,7 @@ describe('Model API multi-node tests', () => { test('load anchored model', async () => { const model = await Model.create(ceramic0, MODEL_DEFINITION) + await TestUtils.delay(2000) if (process.env.CERAMIC_RECON_MODE) await TestUtils.waitForEvent(ceramic1.repository.recon, model.tip) From cdd99b123bc09e3a5bccdb9fdfdce87aaf4a4f53 Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Thu, 28 Mar 2024 15:44:32 -0400 Subject: [PATCH 21/28] fix: add needed delay time --- packages/stream-tests/src/__tests__/model.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/stream-tests/src/__tests__/model.test.ts b/packages/stream-tests/src/__tests__/model.test.ts index 68c22e7065..b8d0ea0fc5 100644 --- a/packages/stream-tests/src/__tests__/model.test.ts +++ b/packages/stream-tests/src/__tests__/model.test.ts @@ -788,22 +788,22 @@ describe('Model API multi-node tests', () => { expect(JSON.stringify(loadedState)).toEqual(JSON.stringify(modelState)) }) + test('load anchored model', async () => { const model = await Model.create(ceramic0, MODEL_DEFINITION) - await TestUtils.delay(2000) if (process.env.CERAMIC_RECON_MODE) - await TestUtils.waitForEvent(ceramic1.repository.recon, model.tip) + await TestUtils.waitForEvent(ceramic1.repository.recon, model.tip, 70000) await ceramic0.admin.startIndexingModelData([{ streamID: model.id }]) await ceramic1.admin.startIndexingModelData([{ streamID: model.id }]) await CoreUtils.anchorUpdate(ceramic0, model) - await TestUtils.delay(1000) + await TestUtils.delay(2000) const loaded = await Model.load(ceramic1, model.id) expect(loaded.state.anchorStatus).toEqual(AnchorStatus.ANCHORED) expect(loaded.state.log.length).toEqual(2) expect(JSON.stringify(loaded.state)).toEqual(JSON.stringify(model.state)) - }, 50000) + }, 120000) }) From 4561c7ff31ff453f87c583b279913e7942248884 Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Thu, 28 Mar 2024 15:48:26 -0400 Subject: [PATCH 22/28] chore: run lint --- packages/stream-tests/src/__tests__/model.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/stream-tests/src/__tests__/model.test.ts b/packages/stream-tests/src/__tests__/model.test.ts index b8d0ea0fc5..b43a482dd3 100644 --- a/packages/stream-tests/src/__tests__/model.test.ts +++ b/packages/stream-tests/src/__tests__/model.test.ts @@ -788,7 +788,6 @@ describe('Model API multi-node tests', () => { expect(JSON.stringify(loadedState)).toEqual(JSON.stringify(modelState)) }) - test('load anchored model', async () => { const model = await Model.create(ceramic0, MODEL_DEFINITION) From c07bc3a79ecea8555e5cfab434066344c6c9742c Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Fri, 29 Mar 2024 10:08:14 -0400 Subject: [PATCH 23/28] feat: update default creation values --- packages/ipfs-daemon/src/create-ipfs.ts | 4 ++-- .../__tests__/model-instance-document.test.ts | 18 ++++-------------- .../stream-tests/src/__tests__/model.test.ts | 18 ++++-------------- packages/stream-tests/src/create-ceramic.ts | 4 ++-- 4 files changed, 12 insertions(+), 32 deletions(-) diff --git a/packages/ipfs-daemon/src/create-ipfs.ts b/packages/ipfs-daemon/src/create-ipfs.ts index 9328d1dad8..2a31d569dc 100644 --- a/packages/ipfs-daemon/src/create-ipfs.ts +++ b/packages/ipfs-daemon/src/create-ipfs.ts @@ -7,7 +7,7 @@ import type { IpfsApi } from '@ceramicnetwork/common' import tmp from 'tmp-promise' import { RustIpfsOptions, RustIpfs } from './rust-ipfs.js' import { IPFSOptions as GoIpfsOptions } from 'ipfsd-ctl' -import { DiagnosticsLogger } from '@ceramicnetwork/common' +import { DiagnosticsLogger, Networks } from '@ceramicnetwork/common' const mergeOptions = mergeOpts.bind({ ignoreUndefined: true }) @@ -150,7 +150,7 @@ export async function createIPFS( await createIPFSFlavor( { name: 'rust', - options: options.rust || { type: 'binary' }, + options: options.rust || { type: 'binary', network: Networks.INMEMORY }, } as RustIpfsFlavor, disposable ) diff --git a/packages/stream-tests/src/__tests__/model-instance-document.test.ts b/packages/stream-tests/src/__tests__/model-instance-document.test.ts index 8c79a072eb..de8452e0eb 100644 --- a/packages/stream-tests/src/__tests__/model-instance-document.test.ts +++ b/packages/stream-tests/src/__tests__/model-instance-document.test.ts @@ -504,22 +504,12 @@ describe('ModelInstanceDocument API multi-node tests', () => { let midMetadata: ModelInstanceDocumentMetadataArgs beforeAll(async () => { - ipfs0 = await createIPFS({ - rust: { - type: 'binary', - network: Networks.INMEMORY, - }, - }) - ipfs1 = await createIPFS({ - rust: { - type: 'binary', - network: Networks.INMEMORY, - }, - }) + ipfs0 = await createIPFS() + ipfs1 = await createIPFS() await swarmConnect(ipfs0, ipfs1) - ceramic0 = await createCeramic(ipfs0, { networkName: Networks.INMEMORY }) - ceramic1 = await createCeramic(ipfs1, { networkName: Networks.INMEMORY }) + ceramic0 = await createCeramic(ipfs0) + ceramic1 = await createCeramic(ipfs1) model = await Model.create(ceramic0, MODEL_DEFINITION) midMetadata = { model: model.id } diff --git a/packages/stream-tests/src/__tests__/model.test.ts b/packages/stream-tests/src/__tests__/model.test.ts index b43a482dd3..67d8a3d2f1 100644 --- a/packages/stream-tests/src/__tests__/model.test.ts +++ b/packages/stream-tests/src/__tests__/model.test.ts @@ -737,24 +737,14 @@ describe('Model API multi-node tests', () => { let ceramic1: Ceramic beforeAll(async () => { - ipfs0 = await createIPFS({ - rust: { - type: 'binary', - network: Networks.INMEMORY, - }, - }) - ipfs1 = await createIPFS({ - rust: { - type: 'binary', - network: Networks.INMEMORY, - }, - }) + ipfs0 = await createIPFS() + ipfs1 = await createIPFS() await swarmConnect(ipfs0, ipfs1) }, 12000) beforeEach(async () => { - ceramic0 = await createCeramic(ipfs0, { networkName: Networks.INMEMORY }) - ceramic1 = await createCeramic(ipfs1, { networkName: Networks.INMEMORY }) + ceramic0 = await createCeramic(ipfs0) + ceramic1 = await createCeramic(ipfs1) }, 12000) afterEach(async () => { diff --git a/packages/stream-tests/src/create-ceramic.ts b/packages/stream-tests/src/create-ceramic.ts index 9aa8dd77ea..057187ade4 100644 --- a/packages/stream-tests/src/create-ceramic.ts +++ b/packages/stream-tests/src/create-ceramic.ts @@ -1,13 +1,13 @@ import mergeOpts from 'merge-options' import { CeramicConfig, Ceramic } from '@ceramicnetwork/core' -import { IpfsApi } from '@ceramicnetwork/common' +import { IpfsApi, Networks } from '@ceramicnetwork/common' import tmp from 'tmp-promise' import { createDid } from './create_did.js' import type { ProvidersCache } from '@ceramicnetwork/core' export async function createCeramic( ipfs: IpfsApi, - config: CeramicConfig & { seed?: string } = {}, + config: CeramicConfig & { seed?: string } = { networkName: Networks.INMEMORY }, providersCache?: ProvidersCache ): Promise { const stateStoreDirectory = await tmp.tmpName() From 73108bb391f296e9abb410b17a75b80ab94f6250 Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Fri, 29 Mar 2024 14:06:06 -0400 Subject: [PATCH 24/28] refactor: replace delays for waitFor --- packages/cli/src/ceramic-daemon.ts | 32 +++++++++---------- .../__tests__/model-instance-document.test.ts | 9 ++++-- .../stream-tests/src/__tests__/model.test.ts | 5 +-- 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/packages/cli/src/ceramic-daemon.ts b/packages/cli/src/ceramic-daemon.ts index 81392d751f..c18e3ff3d4 100644 --- a/packages/cli/src/ceramic-daemon.ts +++ b/packages/cli/src/ceramic-daemon.ts @@ -9,7 +9,7 @@ import { DEFAULT_PUBLISH_INTERVAL_MS, ModelMetrics, Counter, - Observable + Observable, } from '@ceramicnetwork/model-metrics' import { IpfsConnectionFactory } from './ipfs-connection-factory.js' import { @@ -120,7 +120,7 @@ export function makeCeramicConfig(opts: DaemonConfig): CeramicConfig { syncOverride: SYNC_OPTIONS_MAP[opts.node.syncOverride], streamCacheLimit: opts.node.streamCacheLimit, indexing: opts.indexing, - disablePeerDataSync: opts.ipfs.disablePeerDataSync + disablePeerDataSync: opts.ipfs.disablePeerDataSync, } if (opts.stateStore?.mode == StateStoreMode.FS) { ceramicConfig.stateStoreDirectory = opts.stateStore.localDirectory @@ -345,20 +345,20 @@ export class CeramicDaemon { // Now that ceramic node is set up we can start publishing metrics if (opts.metrics?.metricsPublisherEnabled) { - - const ipfsVersion = await ipfs.version(); - ModelMetrics.start({ ceramic: ceramic, - network: params.networkOptions.name, - ceramicVersion: version, - ipfsVersion: ipfsVersion.version, - intervalMS: opts.metrics?.metricsPublishIntervalMS || DEFAULT_PUBLISH_INTERVAL_MS, - nodeId: ipfsId.publicKey, // what makes the best ID for the node? - nodeName: '', // daemon.hostname is not useful - nodeAuthDID: did.id, - nodeIPAddr: '', // daemon.hostname is not the external name - nodePeerId: ipfsId.publicKey, - logger: diagnosticsLogger - }) + const ipfsVersion = await ipfs.version() + ModelMetrics.start({ + ceramic: ceramic, + network: params.networkOptions.name, + ceramicVersion: version, + ipfsVersion: ipfsVersion.version, + intervalMS: opts.metrics?.metricsPublishIntervalMS || DEFAULT_PUBLISH_INTERVAL_MS, + nodeId: ipfsId.publicKey, // what makes the best ID for the node? + nodeName: '', // daemon.hostname is not useful + nodeAuthDID: did.id, + nodeIPAddr: '', // daemon.hostname is not the external name + nodePeerId: ipfsId.publicKey, + logger: diagnosticsLogger, + }) } return daemon diff --git a/packages/stream-tests/src/__tests__/model-instance-document.test.ts b/packages/stream-tests/src/__tests__/model-instance-document.test.ts index de8452e0eb..c975ff56fb 100644 --- a/packages/stream-tests/src/__tests__/model-instance-document.test.ts +++ b/packages/stream-tests/src/__tests__/model-instance-document.test.ts @@ -1,6 +1,6 @@ import { jest, test, expect, describe, beforeAll, afterAll } from '@jest/globals' import getPort from 'get-port' -import { AnchorStatus, EventType, IpfsApi, Networks } from '@ceramicnetwork/common' +import { AnchorStatus, EventType, IpfsApi, StreamState } from '@ceramicnetwork/common' import { Utils as CoreUtils } from '@ceramicnetwork/core' import { createIPFS, swarmConnect } from '@ceramicnetwork/ipfs-daemon' import { @@ -553,7 +553,8 @@ describe('ModelInstanceDocument API multi-node tests', () => { await TestUtils.waitForEvent(ceramic1.repository.recon, doc.tip) await doc.replace(CONTENT1) - await TestUtils.delay(2000) + const hasUpdate = (state: StreamState) => state.log.length === 2 + await TestUtils.waitFor(doc, hasUpdate) const loaded = await ModelInstanceDocument.load(ceramic1, doc.id) const docState = doc.state @@ -574,7 +575,9 @@ describe('ModelInstanceDocument API multi-node tests', () => { await doc.replace(CONTENT1) await CoreUtils.anchorUpdate(ceramic0, doc) - await TestUtils.delay(2000) + const hasBothUpdates = (state: StreamState) => state.log.length === 3 + await TestUtils.waitFor(doc, hasBothUpdates) + const loaded = await ModelInstanceDocument.load(ceramic1, doc.id) expect(loaded.state.anchorStatus).toEqual(AnchorStatus.ANCHORED) diff --git a/packages/stream-tests/src/__tests__/model.test.ts b/packages/stream-tests/src/__tests__/model.test.ts index 67d8a3d2f1..5cbec8ce29 100644 --- a/packages/stream-tests/src/__tests__/model.test.ts +++ b/packages/stream-tests/src/__tests__/model.test.ts @@ -1,6 +1,6 @@ import { jest } from '@jest/globals' import getPort from 'get-port' -import { AnchorStatus, EventType, IpfsApi, Networks } from '@ceramicnetwork/common' +import { AnchorStatus, EventType, IpfsApi, StreamState } from '@ceramicnetwork/common' import { Utils as CoreUtils } from '@ceramicnetwork/core' import { createIPFS, swarmConnect } from '@ceramicnetwork/ipfs-daemon' import { Model, ModelDefinition, parseModelVersion } from '@ceramicnetwork/stream-model' @@ -788,7 +788,8 @@ describe('Model API multi-node tests', () => { await ceramic1.admin.startIndexingModelData([{ streamID: model.id }]) await CoreUtils.anchorUpdate(ceramic0, model) - await TestUtils.delay(2000) + const hasAnchorUpdate = (state: StreamState) => state.log.length === 2 + await TestUtils.waitFor(model, hasAnchorUpdate) const loaded = await Model.load(ceramic1, model.id) expect(loaded.state.anchorStatus).toEqual(AnchorStatus.ANCHORED) From 43cca09ae20aa2bbeca809f965080971c30e3cee Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Fri, 29 Mar 2024 15:38:31 -0400 Subject: [PATCH 25/28] refactor: change test --- .../src/__tests__/model-instance-document.test.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/stream-tests/src/__tests__/model-instance-document.test.ts b/packages/stream-tests/src/__tests__/model-instance-document.test.ts index c975ff56fb..ae8e5fb226 100644 --- a/packages/stream-tests/src/__tests__/model-instance-document.test.ts +++ b/packages/stream-tests/src/__tests__/model-instance-document.test.ts @@ -553,9 +553,11 @@ describe('ModelInstanceDocument API multi-node tests', () => { await TestUtils.waitForEvent(ceramic1.repository.recon, doc.tip) await doc.replace(CONTENT1) - const hasUpdate = (state: StreamState) => state.log.length === 2 - await TestUtils.waitFor(doc, hasUpdate) + const loaded = await ModelInstanceDocument.load(ceramic1, doc.id) + const hasDataUpdate = (state: StreamState) => + state.log.some((entry) => entry.type === EventType.DATA) + await TestUtils.waitFor(loaded, hasDataUpdate) const docState = doc.state const loadedState = loaded.state @@ -575,10 +577,11 @@ describe('ModelInstanceDocument API multi-node tests', () => { await doc.replace(CONTENT1) await CoreUtils.anchorUpdate(ceramic0, doc) - const hasBothUpdates = (state: StreamState) => state.log.length === 3 - await TestUtils.waitFor(doc, hasBothUpdates) const loaded = await ModelInstanceDocument.load(ceramic1, doc.id) + const hasAnchorUpdate = (state: StreamState) => + state.log.some((entry) => entry.type === EventType.TIME) + await TestUtils.waitFor(loaded, hasAnchorUpdate) expect(loaded.state.anchorStatus).toEqual(AnchorStatus.ANCHORED) expect(loaded.state.log.length).toEqual(3) From b2502504bdf95e34effa66f0a7670ddd56f3941c Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Fri, 29 Mar 2024 16:56:18 -0400 Subject: [PATCH 26/28] fix: update test --- packages/stream-tests/src/__tests__/model.test.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/stream-tests/src/__tests__/model.test.ts b/packages/stream-tests/src/__tests__/model.test.ts index 5cbec8ce29..eeabd03f51 100644 --- a/packages/stream-tests/src/__tests__/model.test.ts +++ b/packages/stream-tests/src/__tests__/model.test.ts @@ -782,15 +782,16 @@ describe('Model API multi-node tests', () => { const model = await Model.create(ceramic0, MODEL_DEFINITION) if (process.env.CERAMIC_RECON_MODE) - await TestUtils.waitForEvent(ceramic1.repository.recon, model.tip, 70000) + await TestUtils.waitForEvent(ceramic1.repository.recon, model.tip) await ceramic0.admin.startIndexingModelData([{ streamID: model.id }]) await ceramic1.admin.startIndexingModelData([{ streamID: model.id }]) await CoreUtils.anchorUpdate(ceramic0, model) - const hasAnchorUpdate = (state: StreamState) => state.log.length === 2 - await TestUtils.waitFor(model, hasAnchorUpdate) const loaded = await Model.load(ceramic1, model.id) + const hasAnchorUpdate = (state: StreamState) => + state.log.some((entry) => entry.type === EventType.TIME) + await TestUtils.waitFor(loaded, hasAnchorUpdate) expect(loaded.state.anchorStatus).toEqual(AnchorStatus.ANCHORED) expect(loaded.state.log.length).toEqual(2) From 14d58fd0e69c477db84810338d311c7c7c010da3 Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Fri, 29 Mar 2024 18:55:01 -0400 Subject: [PATCH 27/28] refactor: test hooks --- packages/stream-tests/src/__tests__/model.test.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/packages/stream-tests/src/__tests__/model.test.ts b/packages/stream-tests/src/__tests__/model.test.ts index eeabd03f51..364c408a1a 100644 --- a/packages/stream-tests/src/__tests__/model.test.ts +++ b/packages/stream-tests/src/__tests__/model.test.ts @@ -736,13 +736,11 @@ describe('Model API multi-node tests', () => { let ceramic0: Ceramic let ceramic1: Ceramic - beforeAll(async () => { + beforeEach(async () => { ipfs0 = await createIPFS() ipfs1 = await createIPFS() await swarmConnect(ipfs0, ipfs1) - }, 12000) - beforeEach(async () => { ceramic0 = await createCeramic(ipfs0) ceramic1 = await createCeramic(ipfs1) }, 12000) @@ -750,9 +748,6 @@ describe('Model API multi-node tests', () => { afterEach(async () => { await ceramic0.close() await ceramic1.close() - }) - - afterAll(async () => { await ipfs0.stop() await ipfs1.stop() }) From 5f2918763593a70278e4b1d6321d6e1c13634be5 Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Mon, 1 Apr 2024 15:12:35 -0400 Subject: [PATCH 28/28] fix: undo anchor added delay --- .../core/src/anchor/__tests__/anchor-processing-loop.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/anchor/__tests__/anchor-processing-loop.test.ts b/packages/core/src/anchor/__tests__/anchor-processing-loop.test.ts index a4cefda90c..a7d95712b7 100644 --- a/packages/core/src/anchor/__tests__/anchor-processing-loop.test.ts +++ b/packages/core/src/anchor/__tests__/anchor-processing-loop.test.ts @@ -152,7 +152,7 @@ test('Dont process the same entry multiple times concurrently', async () => { async function* overEntries(): AsyncGenerator { do { // Need this sleep or else the Node runtime might never switch back to the "process" function. - await CommonTestUtils.delay(5) + await CommonTestUtils.delay(1) for (const e of entries) yield e } while (!isDone.isResolved) }