-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1153 from XYOracleNetwork/feature/sentinel-tests
Image Thumbnail Sentinel Tests
- Loading branch information
Showing
3 changed files
with
72 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...ns/packages/payloadset/packages/image-thumbnail/src/Witness/spec/Witness.sentinel.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { HDWallet } from '@xyo-network/account' | ||
import { isImageThumbnail } from '@xyo-network/image-thumbnail-payload-plugin' | ||
import { MemoryNode } from '@xyo-network/node-memory' | ||
import { PayloadBuilder } from '@xyo-network/payload-builder' | ||
import { MemorySentinel } from '@xyo-network/sentinel' | ||
import { UrlSchema } from '@xyo-network/url-payload-plugin' | ||
import { isTimestamp, TimestampWitness } from '@xyo-network/witness-timestamp' | ||
import { mock, MockProxy } from 'jest-mock-extended' | ||
|
||
import { ImageThumbnailWitness } from '../Witness' | ||
|
||
describe('Witness', () => { | ||
describe('when behind sentinel', () => { | ||
let thumbnailWitness: ImageThumbnailWitness | ||
let timestampWitness: TimestampWitness | ||
let sentinel: MemorySentinel | ||
let node: MemoryNode | ||
const logger = mock<Console>() | ||
|
||
beforeAll(async () => { | ||
thumbnailWitness = await ImageThumbnailWitness.create({ | ||
config: { schema: ImageThumbnailWitness.configSchema }, | ||
logger, | ||
wallet: await HDWallet.random(), | ||
}) | ||
timestampWitness = await TimestampWitness.create({ | ||
config: { schema: TimestampWitness.configSchema }, | ||
logger, | ||
wallet: await HDWallet.random(), | ||
}) | ||
sentinel = await MemorySentinel.create({ | ||
config: { schema: MemorySentinel.configSchema }, | ||
logger, | ||
wallet: await HDWallet.random(), | ||
}) | ||
const modules = [timestampWitness, thumbnailWitness, sentinel] | ||
node = await MemoryNode.create({ | ||
config: { schema: MemoryNode.configSchema }, | ||
logger, | ||
wallet: await HDWallet.random(), | ||
}) | ||
await node.start() | ||
await Promise.all( | ||
modules.map(async (mod) => { | ||
await node.register(mod) | ||
await node.attach(mod.address, true) | ||
}), | ||
) | ||
}) | ||
it('witnesses thumbnail for url', async () => { | ||
// TODO: Replace with data url for speed | ||
// const url = | ||
// "data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100' viewBox='0 0 100 100'><circle cx='50' cy='50' r='48' fill='yellow' stroke='black' stroke-width='2'/><circle cx='35' cy='35' r='5' fill='black'/><circle cx='65' cy='35' r='5' fill='black'/><path d='M 35 70 Q 50 85, 65 70' fill='none' stroke='black' stroke-width='2'/></svg>" | ||
const url = 'https://placekitten.com/200/300' | ||
const query = new PayloadBuilder({ schema: UrlSchema }).fields({ url }).build() | ||
const values = await sentinel.report([query]) | ||
const timestamps = values.filter(isTimestamp) | ||
expect(timestamps.length).toBe(1) | ||
const thumbnails = values.filter(isImageThumbnail) | ||
expect(thumbnails.length).toBe(1) | ||
const thumbnail = thumbnails[0] | ||
expect(thumbnail.sourceUrl).toBe(url) | ||
}) | ||
}) | ||
}) |