Skip to content

Commit

Permalink
tzero ready to go (in theory)
Browse files Browse the repository at this point in the history
  • Loading branch information
arietrouw committed May 24, 2024
1 parent 89e7998 commit c2b9d09
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 4 deletions.
2 changes: 2 additions & 0 deletions packages/payloadset/packages/api/src/Payload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,6 @@ export type ApiCallResult<TJson extends JsonArray | JsonObject = JsonArray | Jso
| ApiCallErrorResult

export const isApiCallResult = isPayloadOfSchemaType<ApiCallResult>(ApiCallResultSchema)
export const isApiCallErrorResult = (value: unknown): value is ApiCallErrorResult =>
!!isPayloadOfSchemaType<ApiCallResult>(ApiCallResultSchema) && ((value as ApiCallErrorResult).http?.status ?? 200) >= 400
export const asApiCallResult = AsObjectFactory.create(isApiCallResult)
3 changes: 2 additions & 1 deletion packages/payloadset/packages/api/src/spec/Witness.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ApiCallWitnessConfigSchema } from '../Config'
import { ApiCallResultSchema, ApiCallSchema } from '../Payload'
import { ApiCallResultSchema, ApiCallSchema, isApiCallErrorResult } from '../Payload'
import { ApiCallWitness } from '../Witness'

describe('CryptoWalletNftWitness', () => {
Expand All @@ -12,6 +12,7 @@ describe('CryptoWalletNftWitness', () => {
})
const observation = await witness.observe([{ schema: ApiCallSchema, uri }])
expect(observation[0].schema).toBe(ApiCallResultSchema)
expect(isApiCallErrorResult(observation[0].schema)).toBe(false)
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { isPayloadOfSchemaType } from '@xyo-network/payload-model'
import { asSentinelInstance } from '@xyo-network/sentinel-model'
import { asWitnessInstance } from '@xyo-network/witness-model'

import { ApiCallJsonResult, ApiCallResultSchema, ApiCallSchema, ApiUriTemplateCall } from '../Payload'
import { ApiCallJsonResult, ApiCallResultSchema, ApiCallSchema, ApiUriTemplateCall, isApiCallErrorResult } from '../Payload'
import { ApiCallWitness } from '../Witness'
import tzeroMarketdataManifest from './tzero-marketdata-price-history.json'

Expand Down Expand Up @@ -55,6 +55,7 @@ describe('tZero', () => {
const apiCallResult = report?.find(isPayloadOfSchemaType<ApiCallJsonResult<TZeroMarketdataSandboxResponse>>(ApiCallResultSchema))
expect(apiCallResult).toBeDefined()
console.log(`Result: ${toJsonString(apiCallResult, 10)}`)
expect(isApiCallErrorResult(apiCallResult)).toBe(false)
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { isPayloadOfSchemaType } from '@xyo-network/payload-model'
import { asSentinelInstance } from '@xyo-network/sentinel-model'
import { asWitnessInstance } from '@xyo-network/witness-model'

import { ApiCallJsonResult, ApiCallResultSchema, ApiCallSchema, ApiUriTemplateCall } from '../Payload'
import { ApiCallJsonResult, ApiCallResultSchema, ApiCallSchema, ApiUriTemplateCall, isApiCallErrorResult } from '../Payload'
import { ApiCallWitness } from '../Witness'
import tzeroMarketdataManifest from './tzero-marketdata-snapshots-symbol.json'

Expand Down Expand Up @@ -55,6 +55,7 @@ describe('tZero', () => {
const apiCallResult = report?.find(isPayloadOfSchemaType<ApiCallJsonResult<TZeroMarketdataSandboxResponse>>(ApiCallResultSchema))
expect(apiCallResult).toBeDefined()
console.log(`Result: ${toJsonString(apiCallResult, 10)}`)
expect(isApiCallErrorResult(apiCallResult)).toBe(false)
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { isPayloadOfSchemaType } from '@xyo-network/payload-model'
import { asSentinelInstance } from '@xyo-network/sentinel-model'
import { asWitnessInstance } from '@xyo-network/witness-model'

import { ApiCallJsonResult, ApiCallResultSchema, ApiCallSchema, ApiUriTemplateCall } from '../Payload'
import { ApiCallJsonResult, ApiCallResultSchema, ApiCallSchema, ApiUriTemplateCall, isApiCallErrorResult } from '../Payload'
import { ApiCallWitness } from '../Witness'
import tzeroMarketdataManifest from './tzero-marketdata-snapshots.json'

Expand Down Expand Up @@ -53,6 +53,7 @@ describe('tZero', () => {
const apiCallResult = report?.find(isPayloadOfSchemaType<ApiCallJsonResult<TZeroMarketdataSandboxResponse>>(ApiCallResultSchema))
expect(apiCallResult).toBeDefined()
console.log(`Result: ${toJsonString(apiCallResult, 10)}`)
expect(isApiCallErrorResult(apiCallResult)).toBe(false)
})
})
})

0 comments on commit c2b9d09

Please sign in to comment.