@xyo-network/crypto-nft-collection-witness-plugin 4.2.0 → 5.0.1

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,24 @@
1
+ import '@xylabs/vitest-extended'
2
+
3
+ import { readFile } from 'node:fs/promises'
4
+ import Path from 'node:path'
5
+
6
+ import type { NftInfo } from '@xyo-network/crypto-nft-payload-plugin'
7
+ import {
8
+ describe, expect,
9
+ test,
10
+ } from 'vitest'
11
+
12
+ import { getNftCollectionMetrics } from '../getNftCollectionMetrics.ts'
13
+
14
+ describe('getNftCollectionMetrics', () => {
15
+ test('gets NFTs collection metrics', async () => {
16
+ const filePath = Path.join(__dirname, '..', 'lib', 'spec', 'testData.json')
17
+ const fileContents = await readFile(filePath, 'utf8')
18
+ const nfts = JSON.parse(fileContents) as NftInfo[]
19
+ const result = getNftCollectionMetrics(nfts)
20
+ expect(result).toBeObject()
21
+ expect(result?.metadata).toBeObject()
22
+ expect(result?.metadata?.attributes).toBeObject()
23
+ })
24
+ })
@@ -0,0 +1,26 @@
1
+ import '@xylabs/vitest-extended'
2
+
3
+ import type { EthAddress } from '@xylabs/hex'
4
+ import { getProviderFromEnv } from '@xyo-network/witness-blockchain-abstract'
5
+ import {
6
+ describe, expect, it,
7
+ } from 'vitest'
8
+
9
+ import { getNftCollectionNfts } from '../getNftCollectionNfts.ts'
10
+
11
+ describe.skipIf(!process.env.INFURA_PROJECT_ID)('getNftCollectionNfts', () => {
12
+ const cases: [address: EthAddress, chainId: number][] = [
13
+ // ['0xb47e3cd837dDF8e4c57F05d70Ab865de6e193BBB', 1], //CryptoPunks - Need special handling
14
+ ['0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D' as EthAddress, 1],
15
+ ['0x60E4d786628Fea6478F785A6d7e704777c86a7c6' as EthAddress, 1],
16
+ ['0xED5AF388653567Af2F388E6224dC7C4b3241C544' as EthAddress, 1],
17
+ ['0x059EDD72Cd353dF5106D2B9cC5ab83a52287aC3a' as EthAddress, 1],
18
+ ]
19
+
20
+ it.each(cases)('gets NFTs owned by the address', async (address, chainId) => {
21
+ const provider = getProviderFromEnv(chainId)
22
+ const result = await getNftCollectionNfts(address, provider, undefined, 5)
23
+ expect(result).toBeArray()
24
+ expect(result.at(0)).toBeObject()
25
+ })
26
+ })
@@ -0,0 +1,26 @@
1
+ import '@xylabs/vitest-extended'
2
+
3
+ import { getProviderFromEnv } from '@xyo-network/witness-blockchain-abstract'
4
+ import {
5
+ describe, expect,
6
+ it,
7
+ } from 'vitest'
8
+
9
+ import { isErc721, isErc1155 } from '../tokenTypes.ts'
10
+
11
+ describe.skipIf(!process.env.INFURA_PROJECT_ID)('getNftCollectionMetadata', () => {
12
+ it('Check ERC721', async () => {
13
+ const provider = getProviderFromEnv(0x01)
14
+ const address = '0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D'
15
+ const result721 = await isErc721(provider, address)
16
+ const result1155 = await isErc1155(provider, address)
17
+ expect(result721).toBeTrue()
18
+ expect(result1155).toBeFalse()
19
+ })
20
+ it('Check ERC1155', async () => {
21
+ const provider = getProviderFromEnv(0x01)
22
+ const address = '0x495f947276749ce646f68ac8c248420045cb7b5e'
23
+ const result1155 = await isErc1155(provider, address)
24
+ expect(result1155).toBeTrue()
25
+ })
26
+ })
@@ -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 { CryptoNftCollectionWitnessPlugin } from '../Plugin.ts'
10
+
11
+ describe('CryptoNftCollectionWitnessPlugin', () => {
12
+ test('Add to Resolver', async () => {
13
+ const plugin = CryptoNftCollectionWitnessPlugin()
14
+ const resolver = await new PayloadSetPluginResolver().register(plugin)
15
+ expect(resolver.resolve(plugin.set)).toBeDefined()
16
+ })
17
+ })
@@ -0,0 +1,101 @@
1
+ import '@xylabs/vitest-extended'
2
+
3
+ import { writeFile } from 'node:fs/promises'
4
+
5
+ import { Account } from '@xyo-network/account'
6
+ import type { AccountInstance } from '@xyo-network/account-model'
7
+ import type { NftCollectionWitnessQuery } from '@xyo-network/crypto-nft-collection-payload-plugin'
8
+ import {
9
+ isNftCollectionInfoWithSources,
10
+ NftCollectionWitnessConfigSchema,
11
+ NftCollectionWitnessQuerySchema,
12
+ } from '@xyo-network/crypto-nft-collection-payload-plugin'
13
+ import type { Payload } from '@xyo-network/payload-model'
14
+ import { getProvidersFromEnv } from '@xyo-network/witness-blockchain-abstract'
15
+ import {
16
+ beforeAll, describe, expect,
17
+ it,
18
+ } from 'vitest'
19
+
20
+ import { CryptoNftCollectionWitness } from '../Witness.ts'
21
+
22
+ const validateObservation = (observation: Payload[]) => {
23
+ const results = observation.filter(isNftCollectionInfoWithSources)
24
+ expect(results.length).toBeGreaterThan(0)
25
+ const collectionInfo = results[0]
26
+ expect(collectionInfo.address).toBeString()
27
+ expect(collectionInfo.chainId).toBeNumber()
28
+ expect(collectionInfo.name).toBeString()
29
+ expect(collectionInfo.type).toBeOneOf(['ERC721', 'ERC1155', null])
30
+ expect(collectionInfo.$sources).toBeArray()
31
+ expect(collectionInfo.$sources?.length).toBeGreaterThan(0)
32
+ }
33
+
34
+ /**
35
+ * @group slow
36
+ */
37
+
38
+ describe.skipIf(!process.env.INFURA_PROJECT_ID)('CryptoNftCollectionWitness', () => {
39
+ let account: AccountInstance
40
+ beforeAll(async () => {
41
+ account = await Account.random()
42
+ })
43
+ describe('observe', () => {
44
+ const address = '0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D'
45
+ const chainId = 1
46
+ describe('with no address or chainId in query', () => {
47
+ it('uses values from config', async () => {
48
+ const witness = await CryptoNftCollectionWitness.create({
49
+ account,
50
+ config: {
51
+ address, chainId, schema: NftCollectionWitnessConfigSchema,
52
+ },
53
+ providers: () => getProvidersFromEnv(1, chainId),
54
+ })
55
+ const query: NftCollectionWitnessQuery = { maxNfts: 10, schema: NftCollectionWitnessQuerySchema }
56
+ const observation = await witness.observe([query])
57
+ validateObservation(observation)
58
+ })
59
+ })
60
+ describe('with address and chainId in query', () => {
61
+ it('uses values from query', async () => {
62
+ const witness = await CryptoNftCollectionWitness.create({
63
+ account,
64
+ config: { schema: NftCollectionWitnessConfigSchema },
65
+ providers: () => getProvidersFromEnv(1, chainId),
66
+ })
67
+ const query: NftCollectionWitnessQuery = {
68
+ address, chainId, maxNfts: 10, schema: NftCollectionWitnessQuerySchema,
69
+ }
70
+ const observation = await witness.observe([query])
71
+ validateObservation(observation)
72
+ })
73
+ })
74
+ })
75
+ describe.skip('with common NFT collections', () => {
76
+ const cases: [address: string, chainId: number][] = [
77
+ ['0xb47e3cd837dDF8e4c57F05d70Ab865de6e193BBB', 1],
78
+ ['0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D', 1],
79
+ ['0x60E4d786628Fea6478F785A6d7e704777c86a7c6', 1],
80
+ ['0xED5AF388653567Af2F388E6224dC7C4b3241C544', 1],
81
+ ['0x059EDD72Cd353dF5106D2B9cC5ab83a52287aC3a', 1],
82
+ ]
83
+ it.each(cases)(
84
+ 'witness the collection',
85
+ async (address, chainId) => {
86
+ const witness = await CryptoNftCollectionWitness.create({
87
+ account,
88
+ config: { schema: NftCollectionWitnessConfigSchema },
89
+ providers: () => getProvidersFromEnv(1, chainId),
90
+ })
91
+ const query: NftCollectionWitnessQuery = {
92
+ address, chainId, maxNfts: 20_000, schema: NftCollectionWitnessQuerySchema,
93
+ }
94
+ const observation = await witness.observe([query])
95
+ validateObservation(observation)
96
+ await writeFile(`./nftData/witness/${address}-witness.json`, JSON.stringify(observation, null, 2))
97
+ },
98
+ 120_000,
99
+ )
100
+ })
101
+ })
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
- }