@xyo-network/crypto-nft-collection-diviner-score-plugin 4.1.1 → 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.
@@ -0,0 +1,79 @@
1
+ import '@xylabs/vitest-extended'
2
+
3
+ import { readFile, writeFile } from 'node:fs/promises'
4
+
5
+ import { Account } from '@xyo-network/account'
6
+ import type {
7
+ NftCollectionInfo,
8
+ NftCollectionScore,
9
+ } from '@xyo-network/crypto-nft-collection-payload-plugin'
10
+ import {
11
+ isNftCollectionScore,
12
+ NftCollectionSchema,
13
+ } from '@xyo-network/crypto-nft-collection-payload-plugin'
14
+ import { PayloadWrapper } from '@xyo-network/payload-wrapper'
15
+ import {
16
+ beforeAll,
17
+ describe, expect, it, test,
18
+ } from 'vitest'
19
+
20
+ import { NftCollectionScoreDiviner } from '../Diviner.ts'
21
+
22
+ describe('NftCollectionScoreDiviner', () => {
23
+ const data: NftCollectionInfo[] = [
24
+ {
25
+ address: '0x0000000000',
26
+ chainId: 1,
27
+ metrics: { metadata: { attributes: {} } },
28
+ name: 'test',
29
+ schema: NftCollectionSchema,
30
+ symbol: 'TEST',
31
+ total: 20_000,
32
+ type: 'ERC721',
33
+ },
34
+ ]
35
+ let diviner: NftCollectionScoreDiviner
36
+ beforeAll(async () => {
37
+ const account = await Account.random()
38
+ diviner = await NftCollectionScoreDiviner.create({ account })
39
+ })
40
+ const cases: [address: string, chainId: number][] = [
41
+ ['0xb47e3cd837dDF8e4c57F05d70Ab865de6e193BBB', 1],
42
+ ['0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D', 1],
43
+ ['0x60E4d786628Fea6478F785A6d7e704777c86a7c6', 1],
44
+ ['0xED5AF388653567Af2F388E6224dC7C4b3241C544', 1],
45
+ ['0x059EDD72Cd353dF5106D2B9cC5ab83a52287aC3a', 1],
46
+ ]
47
+ it.skip.each(cases)('diviner calibration', async (address) => {
48
+ const json = await readFile(`./nftData/witness/${address}-witness.json`)
49
+ const data: NftCollectionInfo[] = JSON.parse(json.toString())
50
+ const results = await diviner.divine(data)
51
+ const scores = results.filter(isNftCollectionScore) as NftCollectionScore[]
52
+ for (const score of scores) {
53
+ const address = score.address
54
+ // eslint-disable-next-line unicorn/no-array-reduce
55
+ const total = Object.values(score.scores).reduce(
56
+ ([accValue, accTotal], [value, total]) => {
57
+ return [accValue + value, accTotal + total]
58
+ },
59
+ [0, 0],
60
+ )
61
+ const rating = total[0] / total[1]
62
+ console.log(`Address: ${address} Rating: ${rating}`)
63
+ await writeFile(`./nftData/diviner/${address}-diviner.json`, JSON.stringify(score, null, 2))
64
+ }
65
+ })
66
+ test('divine', async () => {
67
+ const scores = (await diviner.divine(data)).filter(isNftCollectionScore) as NftCollectionScore[]
68
+ expect(scores).toBeArrayOfSize(data.length)
69
+ for (const [i, score] of scores.entries()) {
70
+ const wrapped = PayloadWrapper.wrap<NftCollectionScore>(score)
71
+ expect(await wrapped.getValid()).toBe(true)
72
+ const payload = wrapped.payload
73
+ expect(payload?.sources).toBeArrayOfSize(1)
74
+ expect(payload?.sources?.[0]).toBeString()
75
+ const sourceHash = await PayloadWrapper.wrap(data[i]).dataHash()
76
+ expect(payload?.sources?.[0]).toBe(sourceHash)
77
+ }
78
+ })
79
+ })
@@ -0,0 +1,17 @@
1
+ import '@xylabs/vitest-extended'
2
+
3
+ import { PayloadSetPluginResolver } from '@xyo-network/payloadset-plugin'
4
+ import {
5
+ describe, expect,
6
+ test,
7
+ } from 'vitest'
8
+
9
+ import { NftCollectionScoreDivinerPlugin } from '../Plugin.ts'
10
+
11
+ describe('NftCollectionScoreDivinerPlugin', () => {
12
+ test('Add to Resolver', async () => {
13
+ const plugin = NftCollectionScoreDivinerPlugin()
14
+ const resolver = await new PayloadSetPluginResolver().register(plugin)
15
+ expect(resolver.resolve(plugin.set)).toBeDefined()
16
+ })
17
+ })
package/typedoc.json DELETED
@@ -1,5 +0,0 @@
1
- {
2
- "$schema": "https://typedoc.org/schema.json",
3
- "entryPoints": ["./src/index.ts"],
4
- "tsconfig": "./tsconfig.typedoc.json"
5
- }