@xyo-network/diviner-payload-pointer-memory 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 +36 -32
- package/src/spec/Diviner.payloadPointer.address.spec.ts +94 -0
- package/src/spec/Diviner.payloadPointer.schema.spec.ts +133 -0
- package/src/spec/Diviner.payloadPointer.sequence.spec.ts +79 -0
- package/src/spec/Diviner.spec.ts +32 -0
- package/src/spec/combineRules.spec.ts +86 -0
- package/xy.config.ts +0 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyo-network/diviner-payload-pointer-memory",
|
|
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,41 +28,45 @@
|
|
|
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/exists": "^
|
|
34
|
-
"@xyo-network/boundwitness-wrapper": "^
|
|
35
|
-
"@xyo-network/diviner-abstract": "^
|
|
36
|
-
"@xyo-network/diviner-boundwitness-model": "^
|
|
37
|
-
"@xyo-network/diviner-model": "^
|
|
38
|
-
"@xyo-network/diviner-payload-model": "^
|
|
39
|
-
"@xyo-network/diviner-payload-pointer-model": "^
|
|
40
|
-
"@xyo-network/payload-model": "^
|
|
41
|
-
"@xyo-network/payload-wrapper": "^
|
|
36
|
+
"@xylabs/assert": "^5.0.0",
|
|
37
|
+
"@xylabs/exists": "^5.0.0",
|
|
38
|
+
"@xyo-network/boundwitness-wrapper": "^5.0.0",
|
|
39
|
+
"@xyo-network/diviner-abstract": "^5.0.0",
|
|
40
|
+
"@xyo-network/diviner-boundwitness-model": "^5.0.0",
|
|
41
|
+
"@xyo-network/diviner-model": "^5.0.0",
|
|
42
|
+
"@xyo-network/diviner-payload-model": "^5.0.0",
|
|
43
|
+
"@xyo-network/diviner-payload-pointer-model": "^5.0.0",
|
|
44
|
+
"@xyo-network/payload-model": "^5.0.0",
|
|
45
|
+
"@xyo-network/payload-wrapper": "^5.0.0"
|
|
42
46
|
},
|
|
43
47
|
"devDependencies": {
|
|
44
48
|
"@types/uuid": "^10.0.0",
|
|
45
|
-
"@xylabs/delay": "^
|
|
46
|
-
"@xylabs/hex": "^
|
|
47
|
-
"@xylabs/ts-scripts-yarn3": "^7.0.
|
|
48
|
-
"@xylabs/tsconfig": "^7.0.
|
|
49
|
-
"@xylabs/vitest-extended": "^
|
|
50
|
-
"@xyo-network/account": "^
|
|
51
|
-
"@xyo-network/account-model": "^
|
|
52
|
-
"@xyo-network/archivist-memory": "^
|
|
53
|
-
"@xyo-network/archivist-model": "^
|
|
54
|
-
"@xyo-network/boundwitness-builder": "^
|
|
55
|
-
"@xyo-network/boundwitness-model": "^
|
|
56
|
-
"@xyo-network/diviner-boundwitness-abstract": "^
|
|
57
|
-
"@xyo-network/diviner-boundwitness-memory": "^
|
|
58
|
-
"@xyo-network/diviner-payload-abstract": "^
|
|
59
|
-
"@xyo-network/diviner-payload-generic": "^
|
|
60
|
-
"@xyo-network/diviner-payload-memory": "^
|
|
61
|
-
"@xyo-network/node-memory": "^
|
|
62
|
-
"@xyo-network/node-model": "^
|
|
63
|
-
"@xyo-network/payload-builder": "^
|
|
64
|
-
"@xyo-network/wallet": "^
|
|
65
|
-
"@xyo-network/wallet-model": "^
|
|
49
|
+
"@xylabs/delay": "^5.0.0",
|
|
50
|
+
"@xylabs/hex": "^5.0.0",
|
|
51
|
+
"@xylabs/ts-scripts-yarn3": "^7.0.2",
|
|
52
|
+
"@xylabs/tsconfig": "^7.0.2",
|
|
53
|
+
"@xylabs/vitest-extended": "^5.0.0",
|
|
54
|
+
"@xyo-network/account": "^5.0.0",
|
|
55
|
+
"@xyo-network/account-model": "^5.0.0",
|
|
56
|
+
"@xyo-network/archivist-memory": "^5.0.0",
|
|
57
|
+
"@xyo-network/archivist-model": "^5.0.0",
|
|
58
|
+
"@xyo-network/boundwitness-builder": "^5.0.0",
|
|
59
|
+
"@xyo-network/boundwitness-model": "^5.0.0",
|
|
60
|
+
"@xyo-network/diviner-boundwitness-abstract": "^5.0.0",
|
|
61
|
+
"@xyo-network/diviner-boundwitness-memory": "^5.0.0",
|
|
62
|
+
"@xyo-network/diviner-payload-abstract": "^5.0.0",
|
|
63
|
+
"@xyo-network/diviner-payload-generic": "^5.0.0",
|
|
64
|
+
"@xyo-network/diviner-payload-memory": "^5.0.0",
|
|
65
|
+
"@xyo-network/node-memory": "^5.0.0",
|
|
66
|
+
"@xyo-network/node-model": "^5.0.0",
|
|
67
|
+
"@xyo-network/payload-builder": "^5.0.0",
|
|
68
|
+
"@xyo-network/wallet": "^5.0.0",
|
|
69
|
+
"@xyo-network/wallet-model": "^5.0.0",
|
|
66
70
|
"typescript": "^5.8.3",
|
|
67
71
|
"uuid": "^11.1.0",
|
|
68
72
|
"vitest": "^3.2.4"
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import '@xylabs/vitest-extended'
|
|
2
|
+
|
|
3
|
+
import { delay } from '@xylabs/delay'
|
|
4
|
+
import { Account } from '@xyo-network/account'
|
|
5
|
+
import type { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
6
|
+
import type { NodeInstance } from '@xyo-network/node-model'
|
|
7
|
+
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
8
|
+
import type { Payload } from '@xyo-network/payload-model'
|
|
9
|
+
import {
|
|
10
|
+
beforeAll,
|
|
11
|
+
describe, expect, it,
|
|
12
|
+
} from 'vitest'
|
|
13
|
+
|
|
14
|
+
import type { PayloadPointerDiviner } from '../Diviner.ts'
|
|
15
|
+
import {
|
|
16
|
+
createPointer,
|
|
17
|
+
getArchivist,
|
|
18
|
+
getNewBoundWitness,
|
|
19
|
+
getPayloadPointerDiviner,
|
|
20
|
+
getTestNode,
|
|
21
|
+
insertBlock,
|
|
22
|
+
insertPayload,
|
|
23
|
+
} from './testUtil/index.ts'
|
|
24
|
+
|
|
25
|
+
describe('PayloadPointerDiviner', () => {
|
|
26
|
+
describe('with rules for [address]', () => {
|
|
27
|
+
const accountA = Account.random()
|
|
28
|
+
const accountB = Account.random()
|
|
29
|
+
const accountC = Account.random()
|
|
30
|
+
const accountD = Account.random()
|
|
31
|
+
const payloads: Payload[] = []
|
|
32
|
+
let node: NodeInstance
|
|
33
|
+
let archivist: ArchivistInstance
|
|
34
|
+
let sut: PayloadPointerDiviner
|
|
35
|
+
beforeAll(async () => {
|
|
36
|
+
node = await getTestNode()
|
|
37
|
+
archivist = await getArchivist(node)
|
|
38
|
+
sut = await getPayloadPointerDiviner(node)
|
|
39
|
+
const [bwA, payloadsA] = await getNewBoundWitness([await accountA])
|
|
40
|
+
const [bwB, payloadsB] = await getNewBoundWitness([await accountB])
|
|
41
|
+
const [bwC, payloadsC] = await getNewBoundWitness([await accountC])
|
|
42
|
+
const [bwD, payloadsD] = await getNewBoundWitness([await accountD])
|
|
43
|
+
const [bwE, payloadsE] = await getNewBoundWitness([await accountC, await accountD])
|
|
44
|
+
const [bwF, payloadsF] = await getNewBoundWitness([await accountC])
|
|
45
|
+
const [bwG, payloadsG] = await getNewBoundWitness([await accountD])
|
|
46
|
+
payloads.push(...payloadsA, ...payloadsB, ...payloadsC, ...payloadsD, ...payloadsE, ...payloadsF, ...payloadsG)
|
|
47
|
+
const boundWitnesses = [bwA, bwB, bwC, bwD, bwE, bwF, bwG]
|
|
48
|
+
for (const bw of boundWitnesses) {
|
|
49
|
+
await delay(2)
|
|
50
|
+
const payloadResponse = await insertBlock(archivist, bw)
|
|
51
|
+
expect(payloadResponse.length).toBe(1)
|
|
52
|
+
}
|
|
53
|
+
for (const payload of payloads) {
|
|
54
|
+
await delay(2)
|
|
55
|
+
const payloadResponse = await insertPayload(archivist, payload)
|
|
56
|
+
expect(payloadResponse.length).toBe(1)
|
|
57
|
+
}
|
|
58
|
+
})
|
|
59
|
+
describe('single address', () => {
|
|
60
|
+
it.each([
|
|
61
|
+
[accountA, () => payloads[0]],
|
|
62
|
+
[accountB, () => payloads[1]],
|
|
63
|
+
])('returns Payload signed by address', async (account, getData) => {
|
|
64
|
+
const expected = getData()
|
|
65
|
+
const pointer = createPointer([[(await account).address]], [[expected.schema]])
|
|
66
|
+
const result = await sut.divine([pointer])
|
|
67
|
+
expect(PayloadBuilder.omitStorageMeta(result)).toEqual([expected])
|
|
68
|
+
})
|
|
69
|
+
})
|
|
70
|
+
describe('multiple address rules', () => {
|
|
71
|
+
describe('combined serially', () => {
|
|
72
|
+
it('returns Payload signed by both addresses', async () => {
|
|
73
|
+
const expected = payloads[4]
|
|
74
|
+
const pointer = createPointer([[(await accountC).address], [(await accountD).address]], [[expected.schema]])
|
|
75
|
+
const result = await sut.divine([pointer])
|
|
76
|
+
expect(PayloadBuilder.omitStorageMeta(result)).toEqual([expected])
|
|
77
|
+
})
|
|
78
|
+
})
|
|
79
|
+
describe('combined in parallel', () => {
|
|
80
|
+
it('returns Payload signed by both address', async () => {
|
|
81
|
+
const expected = payloads[4]
|
|
82
|
+
const pointer = createPointer([[(await accountC).address, (await accountD).address]], [[expected.schema]])
|
|
83
|
+
const result = await sut.divine([pointer])
|
|
84
|
+
expect(PayloadBuilder.omitStorageMeta(result)).toEqual([expected])
|
|
85
|
+
})
|
|
86
|
+
})
|
|
87
|
+
})
|
|
88
|
+
it('no matching address', async () => {
|
|
89
|
+
const pointer = createPointer([[(await Account.random()).address]], [[payloads[0].schema]])
|
|
90
|
+
const result = await sut.divine([pointer])
|
|
91
|
+
expect(result).toEqual([])
|
|
92
|
+
})
|
|
93
|
+
})
|
|
94
|
+
})
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import '@xylabs/vitest-extended'
|
|
2
|
+
|
|
3
|
+
import { delay } from '@xylabs/delay'
|
|
4
|
+
import { Account } from '@xyo-network/account'
|
|
5
|
+
import type { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
6
|
+
import { BoundWitnessBuilder } from '@xyo-network/boundwitness-builder'
|
|
7
|
+
import type { NodeInstance } from '@xyo-network/node-model'
|
|
8
|
+
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
9
|
+
import type { Payload } from '@xyo-network/payload-model'
|
|
10
|
+
import {
|
|
11
|
+
beforeAll, describe, expect, it,
|
|
12
|
+
} from 'vitest'
|
|
13
|
+
|
|
14
|
+
import type { PayloadPointerDiviner } from '../Diviner.ts'
|
|
15
|
+
import {
|
|
16
|
+
createPointer,
|
|
17
|
+
getArchivist,
|
|
18
|
+
getNewPayload,
|
|
19
|
+
getPayloadPointerDiviner,
|
|
20
|
+
getTestNode,
|
|
21
|
+
getTestSchemaName,
|
|
22
|
+
insertPayload,
|
|
23
|
+
} from './testUtil/index.ts'
|
|
24
|
+
|
|
25
|
+
describe('PayloadPointerDiviner', () => {
|
|
26
|
+
describe('with rules for [schema]', () => {
|
|
27
|
+
const account = Account.random()
|
|
28
|
+
const schemaA = getTestSchemaName()
|
|
29
|
+
const schemaB = getTestSchemaName()
|
|
30
|
+
|
|
31
|
+
const payloadA = {
|
|
32
|
+
...getNewPayload(), schema: schemaA, salt: 1,
|
|
33
|
+
}
|
|
34
|
+
const payloadB = {
|
|
35
|
+
...getNewPayload(), schema: schemaB, salt: 2,
|
|
36
|
+
}
|
|
37
|
+
const schemas = [schemaA, schemaB]
|
|
38
|
+
let node: NodeInstance
|
|
39
|
+
let archivist: ArchivistInstance
|
|
40
|
+
let sut: PayloadPointerDiviner
|
|
41
|
+
beforeAll(async () => {
|
|
42
|
+
node = await getTestNode()
|
|
43
|
+
archivist = await getArchivist(node)
|
|
44
|
+
sut = await getPayloadPointerDiviner(node)
|
|
45
|
+
const [bw] = await new BoundWitnessBuilder()
|
|
46
|
+
.payloads([payloadA, payloadB])
|
|
47
|
+
.signer(await account)
|
|
48
|
+
.build()
|
|
49
|
+
const payloads: Payload[] = [bw, payloadA, payloadB]
|
|
50
|
+
for (const payload of payloads) {
|
|
51
|
+
await delay(2)
|
|
52
|
+
const payloadResponse = await insertPayload(archivist, payload)
|
|
53
|
+
expect(payloadResponse.length).toBe(1)
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
describe('single schema', () => {
|
|
57
|
+
it.each([
|
|
58
|
+
[schemaA, payloadA],
|
|
59
|
+
[schemaB, payloadB],
|
|
60
|
+
])('returns Payload of schema type', async (schema, expected) => {
|
|
61
|
+
const pointer = createPointer([[]], [[schema]])
|
|
62
|
+
const result = await sut.divine([pointer])
|
|
63
|
+
expect(result).toBeArrayOfSize(1)
|
|
64
|
+
const [actual] = result
|
|
65
|
+
expect(PayloadBuilder.omitMeta(actual)).toEqual(expected)
|
|
66
|
+
})
|
|
67
|
+
})
|
|
68
|
+
describe('single schema [w/address]', () => {
|
|
69
|
+
it.each([
|
|
70
|
+
[schemaA, payloadA],
|
|
71
|
+
[schemaB, payloadB],
|
|
72
|
+
])('returns Payload of schema type', async (schema, expected) => {
|
|
73
|
+
const pointer = createPointer([[(await account).address]], [[schema]])
|
|
74
|
+
const result = await sut.divine([pointer])
|
|
75
|
+
expect(result).toBeArrayOfSize(1)
|
|
76
|
+
const [actual] = result
|
|
77
|
+
expect(PayloadBuilder.omitMeta(actual)).toEqual(expected)
|
|
78
|
+
})
|
|
79
|
+
})
|
|
80
|
+
describe('multiple schema rules', () => {
|
|
81
|
+
describe('combined serially', () => {
|
|
82
|
+
it('returns Payload of either schema', async () => {
|
|
83
|
+
const pointer = createPointer([[]], [[payloadA.schema, payloadB.schema]])
|
|
84
|
+
const results = await sut.divine([pointer])
|
|
85
|
+
expect(results).toBeDefined()
|
|
86
|
+
expect(results).toBeArrayOfSize(1)
|
|
87
|
+
const [result] = results
|
|
88
|
+
expect(result).toBeDefined()
|
|
89
|
+
expect(schemas).toContain(result.schema)
|
|
90
|
+
})
|
|
91
|
+
})
|
|
92
|
+
describe('combined serially [w/address]', () => {
|
|
93
|
+
it('returns Payload of either schema', async () => {
|
|
94
|
+
const pointer = createPointer([[(await account).address]], [[payloadA.schema, payloadB.schema]])
|
|
95
|
+
const results = await sut.divine([pointer])
|
|
96
|
+
expect(results).toBeDefined()
|
|
97
|
+
expect(results).toBeArrayOfSize(1)
|
|
98
|
+
const [result] = results
|
|
99
|
+
expect(result).toBeDefined()
|
|
100
|
+
expect(schemas).toContain(result.schema)
|
|
101
|
+
})
|
|
102
|
+
})
|
|
103
|
+
describe('combined in parallel', () => {
|
|
104
|
+
it('returns Payload of either schema', async () => {
|
|
105
|
+
const pointer = createPointer([[]], [[payloadA.schema], [payloadB.schema]])
|
|
106
|
+
const results = await sut.divine([pointer])
|
|
107
|
+
expect(results).toBeDefined()
|
|
108
|
+
expect(results).toBeArrayOfSize(1)
|
|
109
|
+
const [result] = results
|
|
110
|
+
expect(result).toBeDefined()
|
|
111
|
+
expect(schemas).toContain(result.schema)
|
|
112
|
+
})
|
|
113
|
+
})
|
|
114
|
+
describe('combined in parallel [w/address]', () => {
|
|
115
|
+
it('returns Payload of either schema', async () => {
|
|
116
|
+
const pointer = createPointer([[(await account).address]], [[payloadA.schema], [payloadB.schema]])
|
|
117
|
+
const results = await sut.divine([pointer])
|
|
118
|
+
expect(results).toBeDefined()
|
|
119
|
+
expect(results).toBeArrayOfSize(1)
|
|
120
|
+
const [result] = results
|
|
121
|
+
expect(result).toBeDefined()
|
|
122
|
+
expect(schemas).toContain(result.schema)
|
|
123
|
+
})
|
|
124
|
+
})
|
|
125
|
+
})
|
|
126
|
+
it('no matching schema', async () => {
|
|
127
|
+
const pointer = createPointer([[(await account).address]], [['network.xyo.test']])
|
|
128
|
+
const results = await sut.divine([pointer])
|
|
129
|
+
expect(results).toBeDefined()
|
|
130
|
+
expect(results).toBeEmpty()
|
|
131
|
+
})
|
|
132
|
+
})
|
|
133
|
+
})
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import '@xylabs/vitest-extended'
|
|
2
|
+
|
|
3
|
+
import { assertEx } from '@xylabs/assert'
|
|
4
|
+
import { delay } from '@xylabs/delay'
|
|
5
|
+
import { Account } from '@xyo-network/account'
|
|
6
|
+
import type { AccountInstance } from '@xyo-network/account-model'
|
|
7
|
+
import type { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
8
|
+
import type { NodeInstance } from '@xyo-network/node-model'
|
|
9
|
+
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
10
|
+
import type { Payload } from '@xyo-network/payload-model'
|
|
11
|
+
import { SequenceConstants } from '@xyo-network/payload-model'
|
|
12
|
+
import {
|
|
13
|
+
beforeAll,
|
|
14
|
+
describe, expect, it,
|
|
15
|
+
} from 'vitest'
|
|
16
|
+
|
|
17
|
+
import type { PayloadPointerDiviner } from '../Diviner.ts'
|
|
18
|
+
import {
|
|
19
|
+
createPointer,
|
|
20
|
+
getArchivist,
|
|
21
|
+
getNewBoundWitness,
|
|
22
|
+
getPayloadPointerDiviner,
|
|
23
|
+
getTestNode,
|
|
24
|
+
insertBlock,
|
|
25
|
+
insertPayload,
|
|
26
|
+
} from './testUtil/index.ts'
|
|
27
|
+
|
|
28
|
+
describe('PayloadPointerDiviner', () => {
|
|
29
|
+
describe('with rules for [sequence]', () => {
|
|
30
|
+
let account: AccountInstance
|
|
31
|
+
let payloads: Payload[]
|
|
32
|
+
let expectedSchema: string
|
|
33
|
+
let node: NodeInstance
|
|
34
|
+
let archivist: ArchivistInstance
|
|
35
|
+
let sut: PayloadPointerDiviner
|
|
36
|
+
beforeAll(async () => {
|
|
37
|
+
node = await getTestNode()
|
|
38
|
+
archivist = await getArchivist(node)
|
|
39
|
+
sut = await getPayloadPointerDiviner(node)
|
|
40
|
+
account = await Account.random()
|
|
41
|
+
const [bwA, payloadsA] = await getNewBoundWitness([account])
|
|
42
|
+
await delay(2)
|
|
43
|
+
const [bwB, payloadsB] = await getNewBoundWitness([account])
|
|
44
|
+
await delay(2)
|
|
45
|
+
const [bwC, payloadsC] = await getNewBoundWitness([account])
|
|
46
|
+
await delay(2)
|
|
47
|
+
payloads = [...payloadsA, ...payloadsB, ...payloadsC]
|
|
48
|
+
const boundWitnesses = [bwA, bwB, bwC]
|
|
49
|
+
expectedSchema = payloadsA[0].schema
|
|
50
|
+
for (const bw of boundWitnesses) {
|
|
51
|
+
await delay(2)
|
|
52
|
+
const blockResponse = await insertBlock(archivist, bw)
|
|
53
|
+
expect(blockResponse.length).toBe(1)
|
|
54
|
+
}
|
|
55
|
+
for (const payload of payloads) {
|
|
56
|
+
await delay(2)
|
|
57
|
+
const payloadResponse = await insertPayload(archivist, payload)
|
|
58
|
+
expect(payloadResponse.length).toBe(1)
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
it('ascending', async () => {
|
|
62
|
+
const expected = assertEx(payloads.at(0))
|
|
63
|
+
const pointer = createPointer([[account.address]], [[expectedSchema]], 'asc')
|
|
64
|
+
const result = await sut.divine([pointer])
|
|
65
|
+
expect(PayloadBuilder.omitStorageMeta(result)).toEqual([expected])
|
|
66
|
+
})
|
|
67
|
+
it('descending', async () => {
|
|
68
|
+
const expected = assertEx(payloads.at(-1))
|
|
69
|
+
const pointer = createPointer([[account.address]], [[expectedSchema]], 'desc')
|
|
70
|
+
const result = await sut.divine([pointer])
|
|
71
|
+
expect(PayloadBuilder.omitStorageMeta(result)).toEqual([expected])
|
|
72
|
+
})
|
|
73
|
+
it('no matching sequence', async () => {
|
|
74
|
+
const pointer = createPointer([[account.address]], [[expectedSchema]], 'asc', SequenceConstants.maxLocalSequence)
|
|
75
|
+
const result = await sut.divine([pointer])
|
|
76
|
+
expect(result).toEqual([])
|
|
77
|
+
})
|
|
78
|
+
})
|
|
79
|
+
})
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import '@xylabs/vitest-extended'
|
|
2
|
+
|
|
3
|
+
import { PayloadPointerDivinerConfigSchema } from '@xyo-network/diviner-payload-pointer-model'
|
|
4
|
+
import { HDWallet } from '@xyo-network/wallet'
|
|
5
|
+
import type { WalletInstance } from '@xyo-network/wallet-model'
|
|
6
|
+
import {
|
|
7
|
+
beforeAll, describe, expect, it,
|
|
8
|
+
} from 'vitest'
|
|
9
|
+
|
|
10
|
+
import { PayloadPointerDiviner } from '../Diviner.ts'
|
|
11
|
+
|
|
12
|
+
describe('PayloadPointerDiviner', () => {
|
|
13
|
+
let account: WalletInstance
|
|
14
|
+
let sut: PayloadPointerDiviner
|
|
15
|
+
beforeAll(async () => {
|
|
16
|
+
account = await HDWallet.random()
|
|
17
|
+
sut = await PayloadPointerDiviner.create({
|
|
18
|
+
account,
|
|
19
|
+
config: {
|
|
20
|
+
archivist: 'archivist',
|
|
21
|
+
boundWitnessDiviner: 'boundWitnessDiviner',
|
|
22
|
+
payloadDiviner: 'payloadDiviner',
|
|
23
|
+
schema: PayloadPointerDivinerConfigSchema,
|
|
24
|
+
},
|
|
25
|
+
})
|
|
26
|
+
})
|
|
27
|
+
describe('with no input', () => {
|
|
28
|
+
it('returns empty array', async () => {
|
|
29
|
+
expect(await sut.divine()).toEqual([])
|
|
30
|
+
})
|
|
31
|
+
})
|
|
32
|
+
})
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import '@xylabs/vitest-extended'
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
PayloadAddressRule, PayloadRule, PayloadSchemaRule, PayloadSequenceOrderRule,
|
|
5
|
+
} from '@xyo-network/diviner-payload-pointer-model'
|
|
6
|
+
import { SequenceConstants } from '@xyo-network/payload-model'
|
|
7
|
+
import {
|
|
8
|
+
describe, expect, it,
|
|
9
|
+
} from 'vitest'
|
|
10
|
+
|
|
11
|
+
import { combineRules } from '../combineRules.ts'
|
|
12
|
+
|
|
13
|
+
const validRules = (): PayloadRule[][] => {
|
|
14
|
+
return [
|
|
15
|
+
[{ schema: 'network.xyo.debug' }],
|
|
16
|
+
[{ order: 'desc', sequence: SequenceConstants.maxLocalSequence }],
|
|
17
|
+
]
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
describe('combineRules', () => {
|
|
21
|
+
describe('with no rules', () => {
|
|
22
|
+
it('should throw', () => {
|
|
23
|
+
expect(() => {
|
|
24
|
+
combineRules([])
|
|
25
|
+
}).toThrow()
|
|
26
|
+
})
|
|
27
|
+
it('for addresses defaults to an empty array', () => {
|
|
28
|
+
const rules = validRules()
|
|
29
|
+
const actual = combineRules(rules)
|
|
30
|
+
expect(actual.addresses.length).toBe(0)
|
|
31
|
+
})
|
|
32
|
+
it('for schema should throw', () => {
|
|
33
|
+
expect(() => {
|
|
34
|
+
const rules = validRules().filter(rule => !(rule?.[0] as PayloadSchemaRule)?.schema)
|
|
35
|
+
combineRules(rules)
|
|
36
|
+
}).toThrow()
|
|
37
|
+
})
|
|
38
|
+
describe('for sequence defaults to', () => {
|
|
39
|
+
it('sequence set to current time', () => {
|
|
40
|
+
const rules = validRules().filter(rule => !(rule?.[0] as PayloadSequenceOrderRule)?.sequence)
|
|
41
|
+
const actual = combineRules(rules)
|
|
42
|
+
expect(actual.cursor).toBe(undefined)
|
|
43
|
+
})
|
|
44
|
+
it('direction defaults to desc', () => {
|
|
45
|
+
const rules = validRules().filter(rule => !(rule?.[0] as PayloadSequenceOrderRule)?.sequence)
|
|
46
|
+
const actual = combineRules(rules)
|
|
47
|
+
expect(actual.order).toBe('desc')
|
|
48
|
+
})
|
|
49
|
+
})
|
|
50
|
+
})
|
|
51
|
+
describe('with PayloadAddressRule rules', () => {
|
|
52
|
+
it('combines multiple rules', () => {
|
|
53
|
+
const rules = validRules()
|
|
54
|
+
const addressRules: PayloadAddressRule[] = [{ address: 'foo' }, { address: 'bar' }]
|
|
55
|
+
rules.push(addressRules)
|
|
56
|
+
const actual = combineRules(rules)
|
|
57
|
+
// eslint-disable-next-line sonarjs/no-alphabetical-sort
|
|
58
|
+
expect(actual.addresses.toSorted()).toEqual(['bar', 'foo'])
|
|
59
|
+
})
|
|
60
|
+
})
|
|
61
|
+
describe('with PayloadSchemaRule rules', () => {
|
|
62
|
+
it('combines multiple rules', () => {
|
|
63
|
+
const rules: PayloadRule[][] = [
|
|
64
|
+
[{ order: 'desc', sequence: SequenceConstants.maxLocalSequence }],
|
|
65
|
+
[{ schema: 'network.xyo.test' }, { schema: 'network.xyo.debug' }],
|
|
66
|
+
]
|
|
67
|
+
const actual = combineRules(rules)
|
|
68
|
+
// eslint-disable-next-line sonarjs/no-alphabetical-sort
|
|
69
|
+
expect(actual.schemas.toSorted()).toEqual(['network.xyo.debug', 'network.xyo.test'])
|
|
70
|
+
})
|
|
71
|
+
})
|
|
72
|
+
describe('with multiple PayloadSequenceDirectionRule rules', () => {
|
|
73
|
+
it('should only allow one rule', () => {
|
|
74
|
+
const rules: PayloadRule[][] = [
|
|
75
|
+
[{ schema: 'network.xyo.debug' }],
|
|
76
|
+
[
|
|
77
|
+
{ order: 'desc', sequence: SequenceConstants.maxLocalSequence },
|
|
78
|
+
{ order: 'asc', sequence: SequenceConstants.minLocalSequence },
|
|
79
|
+
],
|
|
80
|
+
]
|
|
81
|
+
expect(() => {
|
|
82
|
+
combineRules(rules)
|
|
83
|
+
}).toThrow()
|
|
84
|
+
})
|
|
85
|
+
})
|
|
86
|
+
})
|