@xyo-network/diviner-stateful 4.3.0 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +31 -27
- package/src/spec/Diviner.spec.ts +89 -0
- package/xy.config.ts +0 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyo-network/diviner-stateful",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "Primary SDK for using XYO Protocol 2.0",
|
|
5
5
|
"homepage": "https://xyo.network",
|
|
6
6
|
"bugs": {
|
|
@@ -28,35 +28,39 @@
|
|
|
28
28
|
},
|
|
29
29
|
"module": "dist/neutral/index.mjs",
|
|
30
30
|
"types": "dist/neutral/index.d.ts",
|
|
31
|
+
"files": [
|
|
32
|
+
"dist",
|
|
33
|
+
"src"
|
|
34
|
+
],
|
|
31
35
|
"dependencies": {
|
|
32
|
-
"@xylabs/assert": "^
|
|
33
|
-
"@xylabs/object": "^
|
|
34
|
-
"@xyo-network/archivist-model": "^
|
|
35
|
-
"@xyo-network/archivist-wrapper": "^
|
|
36
|
-
"@xyo-network/boundwitness-builder": "^
|
|
37
|
-
"@xyo-network/boundwitness-model": "^
|
|
38
|
-
"@xyo-network/diviner-abstract": "^
|
|
39
|
-
"@xyo-network/diviner-boundwitness-model": "^
|
|
40
|
-
"@xyo-network/diviner-model": "^
|
|
41
|
-
"@xyo-network/diviner-wrapper": "^
|
|
42
|
-
"@xyo-network/module-model": "^
|
|
43
|
-
"@xyo-network/payload-builder": "^
|
|
44
|
-
"@xyo-network/payload-model": "^
|
|
36
|
+
"@xylabs/assert": "^5.0.0",
|
|
37
|
+
"@xylabs/object": "^5.0.0",
|
|
38
|
+
"@xyo-network/archivist-model": "^5.0.0",
|
|
39
|
+
"@xyo-network/archivist-wrapper": "^5.0.0",
|
|
40
|
+
"@xyo-network/boundwitness-builder": "^5.0.0",
|
|
41
|
+
"@xyo-network/boundwitness-model": "^5.0.0",
|
|
42
|
+
"@xyo-network/diviner-abstract": "^5.0.0",
|
|
43
|
+
"@xyo-network/diviner-boundwitness-model": "^5.0.0",
|
|
44
|
+
"@xyo-network/diviner-model": "^5.0.0",
|
|
45
|
+
"@xyo-network/diviner-wrapper": "^5.0.0",
|
|
46
|
+
"@xyo-network/module-model": "^5.0.0",
|
|
47
|
+
"@xyo-network/payload-builder": "^5.0.0",
|
|
48
|
+
"@xyo-network/payload-model": "^5.0.0"
|
|
45
49
|
},
|
|
46
50
|
"devDependencies": {
|
|
47
|
-
"@xylabs/hex": "^
|
|
48
|
-
"@xylabs/ts-scripts-yarn3": "^7.0.
|
|
49
|
-
"@xylabs/tsconfig": "^7.0.
|
|
50
|
-
"@xylabs/vitest-extended": "^
|
|
51
|
-
"@xyo-network/account": "^
|
|
52
|
-
"@xyo-network/archivist-memory": "^
|
|
53
|
-
"@xyo-network/diviner-boundwitness-memory": "^
|
|
54
|
-
"@xyo-network/diviner-payload-generic": "^
|
|
55
|
-
"@xyo-network/diviner-payload-memory": "^
|
|
56
|
-
"@xyo-network/manifest": "^
|
|
57
|
-
"@xyo-network/module-factory-locator": "^
|
|
58
|
-
"@xyo-network/node-memory": "^
|
|
59
|
-
"@xyo-network/wallet": "^
|
|
51
|
+
"@xylabs/hex": "^5.0.0",
|
|
52
|
+
"@xylabs/ts-scripts-yarn3": "^7.0.2",
|
|
53
|
+
"@xylabs/tsconfig": "^7.0.2",
|
|
54
|
+
"@xylabs/vitest-extended": "^5.0.0",
|
|
55
|
+
"@xyo-network/account": "^5.0.0",
|
|
56
|
+
"@xyo-network/archivist-memory": "^5.0.0",
|
|
57
|
+
"@xyo-network/diviner-boundwitness-memory": "^5.0.0",
|
|
58
|
+
"@xyo-network/diviner-payload-generic": "^5.0.0",
|
|
59
|
+
"@xyo-network/diviner-payload-memory": "^5.0.0",
|
|
60
|
+
"@xyo-network/manifest": "^5.0.0",
|
|
61
|
+
"@xyo-network/module-factory-locator": "^5.0.0",
|
|
62
|
+
"@xyo-network/node-memory": "^5.0.0",
|
|
63
|
+
"@xyo-network/wallet": "^5.0.0",
|
|
60
64
|
"typescript": "^5.8.3",
|
|
61
65
|
"vitest": "^3.2.4"
|
|
62
66
|
},
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import '@xylabs/vitest-extended'
|
|
2
|
+
|
|
3
|
+
import { assertEx } from '@xylabs/assert'
|
|
4
|
+
import { MemoryArchivist } from '@xyo-network/archivist-memory'
|
|
5
|
+
import { MemoryBoundWitnessDiviner } from '@xyo-network/diviner-boundwitness-memory'
|
|
6
|
+
import { asDivinerInstance } from '@xyo-network/diviner-model'
|
|
7
|
+
import { GenericPayloadDiviner } from '@xyo-network/diviner-payload-generic'
|
|
8
|
+
import type { PackageManifestPayload } from '@xyo-network/manifest'
|
|
9
|
+
import { ManifestWrapper } from '@xyo-network/manifest'
|
|
10
|
+
import { ModuleFactoryLocator } from '@xyo-network/module-factory-locator'
|
|
11
|
+
import {
|
|
12
|
+
creatableModule, CreatableModuleInstance, type ModuleState,
|
|
13
|
+
} from '@xyo-network/module-model'
|
|
14
|
+
import type { MemoryNode } from '@xyo-network/node-memory'
|
|
15
|
+
import type { Payload } from '@xyo-network/payload-model'
|
|
16
|
+
import { HDWallet } from '@xyo-network/wallet'
|
|
17
|
+
import {
|
|
18
|
+
beforeAll,
|
|
19
|
+
describe, expect, it,
|
|
20
|
+
} from 'vitest'
|
|
21
|
+
|
|
22
|
+
import { StatefulDiviner } from '../Diviner.ts'
|
|
23
|
+
import { StatefulDivinerParams } from '../Params.ts'
|
|
24
|
+
import TestManifest from './TestManifest.json' with { type: 'json' }
|
|
25
|
+
|
|
26
|
+
@creatableModule<CreatableModuleInstance<StatefulDivinerParams>>()
|
|
27
|
+
class TestStatefulDiviner extends StatefulDiviner {
|
|
28
|
+
callCommitState(state: ModuleState) {
|
|
29
|
+
return this.commitState(state)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
callRetrieveState() {
|
|
33
|
+
return this.retrieveState()
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
protected override divineHandler(payloads?: Payload[]): Promise<Payload[]> {
|
|
37
|
+
return Promise.resolve(payloads ?? [])
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @group slow
|
|
43
|
+
*/
|
|
44
|
+
describe('TestStatefulDiviner', () => {
|
|
45
|
+
let sut: TestStatefulDiviner
|
|
46
|
+
let node: MemoryNode
|
|
47
|
+
|
|
48
|
+
beforeAll(async () => {
|
|
49
|
+
const wallet = await HDWallet.random()
|
|
50
|
+
const locator = new ModuleFactoryLocator()
|
|
51
|
+
locator.register(MemoryArchivist.factory())
|
|
52
|
+
locator.register(MemoryBoundWitnessDiviner.factory())
|
|
53
|
+
locator.register(GenericPayloadDiviner.factory())
|
|
54
|
+
locator.register(TestStatefulDiviner.factory())
|
|
55
|
+
const manifest = TestManifest as PackageManifestPayload
|
|
56
|
+
const manifestWrapper = new ManifestWrapper(manifest, wallet, locator)
|
|
57
|
+
node = await manifestWrapper.loadNodeFromIndex(0)
|
|
58
|
+
await node.start()
|
|
59
|
+
|
|
60
|
+
const privateModules = manifest.nodes[0].modules?.private ?? []
|
|
61
|
+
const publicModules = manifest.nodes[0].modules?.public ?? []
|
|
62
|
+
const mods = await node.resolve('*')
|
|
63
|
+
expect(mods.length).toBe(privateModules.length + publicModules.length + 1)
|
|
64
|
+
|
|
65
|
+
sut = assertEx(asDivinerInstance<TestStatefulDiviner>(await node.resolve('Diviner')))
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
describe('divine', () => {
|
|
69
|
+
describe('with no previous state', () => {
|
|
70
|
+
it('returns undefined', async () => {
|
|
71
|
+
const results = await sut.callRetrieveState()
|
|
72
|
+
expect(results).toBeUndefined()
|
|
73
|
+
})
|
|
74
|
+
})
|
|
75
|
+
describe('with previous state', () => {
|
|
76
|
+
const cases: ModuleState[] = [
|
|
77
|
+
{ schema: 'network.xyo.module.state', state: { offset: 0 } },
|
|
78
|
+
{ schema: 'network.xyo.module.state', state: { offset: 1 } },
|
|
79
|
+
{ schema: 'network.xyo.module.state', state: { offset: 1000 } },
|
|
80
|
+
]
|
|
81
|
+
|
|
82
|
+
it.each(cases)('returns state', async (state) => {
|
|
83
|
+
await sut.callCommitState(state)
|
|
84
|
+
const results = await sut.callRetrieveState()
|
|
85
|
+
expect(results).toMatchObject(state)
|
|
86
|
+
})
|
|
87
|
+
})
|
|
88
|
+
})
|
|
89
|
+
})
|