Skip to content

Commit

Permalink
Simplify test
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelBCarter committed Dec 18, 2024
1 parent fd06cb1 commit 62e6895
Showing 1 changed file with 16 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ import { BoundWitnessBuilder } from '@xyo-network/boundwitness-builder'
import type { NodeInstance } from '@xyo-network/node-model'
import { PayloadBuilder } from '@xyo-network/payload-builder'
import type { Payload } from '@xyo-network/payload-model'
import { PayloadWrapper } from '@xyo-network/payload-wrapper'
import {
beforeAll,
describe, expect, it,
beforeAll, describe, expect, it,
} from 'vitest'

import type { PayloadPointerDiviner } from '../Diviner.ts'
Expand All @@ -29,18 +27,13 @@ describe('PayloadPointerDiviner', () => {
const account = Account.random()
const schemaA = getTestSchemaName()
const schemaB = getTestSchemaName()
const payloadBaseA = (async () => {
return {
...(await getNewPayload()), schema: schemaA, timestamp: Date.now(),
}
})()
const payloadA: Promise<PayloadWrapper> = (async () => PayloadWrapper.wrap(await payloadBaseA))()
const payloadBaseB = (async () => {
return {
...(await getNewPayload()), schema: schemaB, timestamp: Date.now(),
}
})()
const payloadB: Promise<PayloadWrapper> = (async () => PayloadWrapper.wrap(await payloadBaseB))()

const payloadA = {
...getNewPayload(), schema: schemaA, salt: 1,
}
const payloadB = {
...getNewPayload(), schema: schemaB, salt: 2,
}
const schemas = [schemaA, schemaB]
let node: NodeInstance
let archivist: ArchivistInstance
Expand All @@ -50,10 +43,10 @@ describe('PayloadPointerDiviner', () => {
archivist = await getArchivist(node)
sut = await getPayloadPointerDiviner(node)
const [bw] = await new BoundWitnessBuilder()
.payloads([(await payloadA).payload, (await payloadB).payload])
.payloads([payloadA, payloadB])
.witness(await account)
.build()
const payloads: Payload[] = [bw, (await payloadA).payload, (await payloadB).payload]
const payloads: Payload[] = [bw, payloadA, payloadB]
for (const payload of payloads) {
await delay(2)
const payloadResponse = await insertPayload(archivist, payload)
Expand All @@ -67,7 +60,7 @@ describe('PayloadPointerDiviner', () => {
])('returns Payload of schema type', async (schema, expected) => {
const pointer = createPointer([[]], [[schema]])
const result = await sut.divine([pointer])
expect(result).toEqual([(await expected).payload])
expect(result).toEqual([expected])
})
})
describe('single schema [w/address]', () => {
Expand All @@ -77,13 +70,13 @@ describe('PayloadPointerDiviner', () => {
])('returns Payload of schema type', async (schema, expected) => {
const pointer = createPointer([[(await account).address]], [[schema]])
const result = await sut.divine([pointer])
expect(PayloadBuilder.omitStorageMeta(result)).toEqual([(await expected).payload])
expect(PayloadBuilder.omitStorageMeta(result)).toEqual([expected])
})
})
describe('multiple schema rules', () => {
describe('combined serially', () => {
it('returns Payload of either schema', async () => {
const pointer = createPointer([[]], [[(await payloadA).schema(), (await payloadB).schema()]])
const pointer = createPointer([[]], [[payloadA.schema, payloadB.schema]])
const results = await sut.divine([pointer])
expect(results).toBeDefined()
expect(results).toBeArrayOfSize(1)
Expand All @@ -94,7 +87,7 @@ describe('PayloadPointerDiviner', () => {
})
describe('combined serially [w/address]', () => {
it('returns Payload of either schema', async () => {
const pointer = createPointer([[(await account).address]], [[(await payloadA).schema(), (await payloadB).schema()]])
const pointer = createPointer([[(await account).address]], [[payloadA.schema, payloadB.schema]])
const results = await sut.divine([pointer])
expect(results).toBeDefined()
expect(results).toBeArrayOfSize(1)
Expand All @@ -105,7 +98,7 @@ describe('PayloadPointerDiviner', () => {
})
describe('combined in parallel', () => {
it('returns Payload of either schema', async () => {
const pointer = createPointer([[]], [[(await payloadA).schema()], [(await payloadB).schema()]])
const pointer = createPointer([[]], [[payloadA.schema], [payloadB.schema]])
const results = await sut.divine([pointer])
expect(results).toBeDefined()
expect(results).toBeArrayOfSize(1)
Expand All @@ -116,7 +109,7 @@ describe('PayloadPointerDiviner', () => {
})
describe('combined in parallel [w/address]', () => {
it('returns Payload of either schema', async () => {
const pointer = createPointer([[(await account).address]], [[(await payloadA).schema()], [(await payloadB).schema()]])
const pointer = createPointer([[(await account).address]], [[payloadA.schema], [payloadB.schema]])
const results = await sut.divine([pointer])
expect(results).toBeDefined()
expect(results).toBeArrayOfSize(1)
Expand Down

0 comments on commit 62e6895

Please sign in to comment.