Skip to content

Commit

Permalink
feat: Disable anchoring when CERAMIC_RECON_MODE env var is set (#3154)
Browse files Browse the repository at this point in the history
  • Loading branch information
stbrody authored Feb 10, 2024
1 parent 265bcff commit 0baa9dc
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 38 deletions.
5 changes: 5 additions & 0 deletions packages/core/src/state-management/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,11 @@ 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ 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)
expect(doc.state.anchorStatus).toEqual(AnchorStatus.PENDING)
if (!process.env.CERAMIC_RECON_MODE) {
// TODO (WS1-1471): Re-enable this check even in Recon mode
expect(doc.state.anchorStatus).toEqual(AnchorStatus.PENDING)
}
})

test(`Can create deterministic doc with create method`, async () => {
Expand All @@ -138,7 +141,10 @@ 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)
expect(doc.state.anchorStatus).toEqual(AnchorStatus.PENDING)
if (!process.env.CERAMIC_RECON_MODE) {
// TODO (WS1-1471): Re-enable this check even in Recon mode
expect(doc.state.anchorStatus).toEqual(AnchorStatus.PENDING)
}
})

test(`Creating doc with SINGLE accountRelation non-deterministically should fail `, async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ 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)

Expand Down Expand Up @@ -162,7 +165,10 @@ 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)
expect(doc.state.anchorStatus).toEqual(AnchorStatus.PENDING)
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.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()
Expand All @@ -180,7 +186,10 @@ 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)
expect(docWithRelation.state.anchorStatus).toEqual(AnchorStatus.PENDING)
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.metadata.model.toString()).toEqual(modelWithRelation.id.toString())
await expect(TestUtils.isPinned(ceramic.admin, docWithRelation.id)).resolves.toBeTruthy()
await expect(
Expand Down Expand Up @@ -262,7 +271,7 @@ describe('ModelInstanceDocument API http-client tests', () => {
expect(docWithRelation.content.optionalLinkedDoc).toBe(docID)
})

test('Anchor genesis', async () => {
testIfV3ShouldPassWithAnchoring('Anchor genesis', async () => {
const doc = await ModelInstanceDocument.create(ceramic, CONTENT0, midMetadata)
expect(doc.state.anchorStatus).toEqual(AnchorStatus.PENDING)

Expand All @@ -276,7 +285,7 @@ describe('ModelInstanceDocument API http-client tests', () => {
expect(doc.content).toEqual(CONTENT0)
})

test('Anchor after updating', async () => {
testIfV3ShouldPassWithAnchoring('Anchor after updating', async () => {
const doc = await ModelInstanceDocument.create(ceramic, CONTENT0, midMetadata)
expect(doc.state.anchorStatus).toEqual(AnchorStatus.PENDING)
await doc.replace(CONTENT1)
Expand All @@ -293,7 +302,7 @@ describe('ModelInstanceDocument API http-client tests', () => {
expect(doc.content).toEqual(CONTENT1)
})

test('multiple updates', async () => {
testIfV3ShouldPassWithAnchoring('multiple updates', async () => {
const doc = await ModelInstanceDocument.create(ceramic, CONTENT0, midMetadata)
await doc.replace(CONTENT1)

Expand Down Expand Up @@ -340,7 +349,7 @@ describe('ModelInstanceDocument API http-client tests', () => {
).rejects.toThrow(/Attempting to create a ModelInstanceDocument with an invalid DID string/)
})

test('Can load a stream', async () => {
testIfV3ShouldPassWithAnchoring('Can load a stream', async () => {
const doc = await ModelInstanceDocument.create(ceramic, CONTENT0, midMetadata)
await doc.replace(CONTENT1)
await CoreUtils.anchorUpdate(core, doc)
Expand Down
83 changes: 66 additions & 17 deletions packages/stream-tests/src/__tests__/model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ 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)

Expand Down Expand Up @@ -130,7 +133,11 @@ 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)
expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING)

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.id.toString()).toEqual(MODEL_STREAM_ID)
})

Expand All @@ -143,7 +150,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)
expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING)
if (!process.env.CERAMIC_RECON_MODE) {
// TODO (WS1-1471): Re-enable this check even in Recon mode
expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING)
}

await expect(ceramic.admin.pin.add(model.id)).resolves.not.toThrow()

Expand All @@ -164,7 +174,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)
expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING)
if (!process.env.CERAMIC_RECON_MODE) {
// TODO (WS1-1471): Re-enable this check even in Recon mode
expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING)
}

await expect(ceramic.admin.pin.add(model.id)).resolves.not.toThrow()

Expand All @@ -187,7 +200,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)
expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING)
if (!process.env.CERAMIC_RECON_MODE) {
// TODO (WS1-1471): Re-enable this check even in Recon mode
expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING)
}

await expect(ceramic.admin.pin.add(model.id)).resolves.not.toThrow()

Expand All @@ -213,7 +229,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)
expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING)
if (!process.env.CERAMIC_RECON_MODE) {
// TODO (WS1-1471): Re-enable this check even in Recon mode
expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING)
}

await expect(
ceramic.admin.startIndexingModelData([
Expand All @@ -237,7 +256,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)
expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING)
if (!process.env.CERAMIC_RECON_MODE) {
// TODO (WS1-1471): Re-enable this check even in Recon mode
expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING)
}

await expect(ceramic.admin.pin.add(model.id)).resolves.not.toThrow()

Expand Down Expand Up @@ -265,7 +287,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)
expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING)
if (!process.env.CERAMIC_RECON_MODE) {
// TODO (WS1-1471): Re-enable this check even in Recon mode
expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING)
}

await expect(ceramic.admin.pin.add(model.id)).resolves.not.toThrow()

Expand Down Expand Up @@ -301,7 +326,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)
expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING)
if (!process.env.CERAMIC_RECON_MODE) {
// TODO (WS1-1471): Re-enable this check even in Recon mode
expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING)
}

await expect(ceramic.admin.pin.add(model.id)).resolves.not.toThrow()

Expand Down Expand Up @@ -337,7 +365,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)
expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING)
if (!process.env.CERAMIC_RECON_MODE) {
// TODO (WS1-1471): Re-enable this check even in Recon mode
expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING)
}

await expect(ceramic.admin.pin.add(model.id)).resolves.not.toThrow()

Expand Down Expand Up @@ -381,7 +412,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)
expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING)
if (!process.env.CERAMIC_RECON_MODE) {
// TODO (WS1-1471): Re-enable this check even in Recon mode
expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING)
}

await expect(ceramic.admin.pin.add(model.id)).resolves.not.toThrow()

Expand Down Expand Up @@ -428,7 +462,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)
expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING)
if (!process.env.CERAMIC_RECON_MODE) {
// TODO (WS1-1471): Re-enable this check even in Recon mode
expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING)
}

await expect(ceramic.admin.pin.add(model.id)).resolves.not.toThrow()

Expand Down Expand Up @@ -469,7 +506,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)
expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING)
if (!process.env.CERAMIC_RECON_MODE) {
// TODO (WS1-1471): Re-enable this check even in Recon mode
expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING)
}

await expect(ceramic.admin.pin.add(model.id)).resolves.not.toThrow()

Expand All @@ -490,7 +530,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)
expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING)
if (!process.env.CERAMIC_RECON_MODE) {
// TODO (WS1-1471): Re-enable this check even in Recon mode
expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING)
}

await expect(ceramic.admin.pin.add(model.id)).resolves.not.toThrow()

Expand All @@ -516,7 +559,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)
expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING)
if (!process.env.CERAMIC_RECON_MODE) {
// TODO (WS1-1471): Re-enable this check even in Recon mode
expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING)
}

await expect(ceramic.admin.pin.add(model.id)).resolves.not.toThrow()

Expand Down Expand Up @@ -548,10 +594,13 @@ 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)
expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING)
if (!process.env.CERAMIC_RECON_MODE) {
// TODO (WS1-1471): Re-enable this check even in Recon mode
expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING)
}
})

test('Anchor genesis', async () => {
testIfV3ShouldPassWithAnchoring('Anchor genesis', async () => {
const model = await Model.create(ceramic, MODEL_DEFINITION)
expect(model.state.anchorStatus).toEqual(AnchorStatus.PENDING)

Expand Down Expand Up @@ -634,7 +683,7 @@ describe('Model API http-client tests', () => {
)
})

test('Can load a complete stream', async () => {
testIfV3ShouldPassWithAnchoring('Can load a complete stream', async () => {
const model = await Model.create(ceramic, MODEL_DEFINITION)
await CoreUtils.anchorUpdate(core, model)
await model.sync()
Expand Down
Loading

0 comments on commit 0baa9dc

Please sign in to comment.