@xyo-network/evm-call-witness 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.
- package/dist/neutral/index.d.ts +6 -99
- package/dist/neutral/index.mjs +2 -2
- package/dist/neutral/index.mjs.map +1 -1
- package/package.json +43 -40
- package/src/Witness.ts +2 -2
- package/src/spec/Sentinel.collection.spec.ts +127 -0
- package/src/spec/Sentinel.token.enumerate.spec.ts +138 -0
- package/src/spec/Sentinel.token.spec.ts +131 -0
- package/src/spec/Witness.spec.ts +43 -0
- package/src/spec/imported/AddressToContract/AddressToContractIndex/Contract.Sentinel.Node.spec.ts +183 -0
- package/src/spec/imported/AddressToContract/CollectionInfo/Sentinel.collection.spec.ts +143 -0
- package/src/spec/imported/AddressToContract/ManualTokenIteration/Sentinel.token.spec.ts +187 -0
- package/src/spec/imported/AddressToTotalSupplyIndex/Erc721.TotalSupply.Index.spec.ts +101 -0
- package/src/spec/imported/NftIndexToNftIdIndex/Erc721.NftId.Index.spec.ts +118 -0
- package/src/spec/imported/TotalSupplyToNftIndexIndex/Erc721.NftIndex.Index.spec.ts +124 -0
- package/typedoc.json +0 -5
- package/xy.config.ts +0 -10
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/* eslint-disable max-statements */
|
|
2
|
+
|
|
3
|
+
import '@xylabs/vitest-extended'
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
createProfiler, profile, profileReport,
|
|
7
|
+
} from '@xylabs/profile'
|
|
8
|
+
import { asDivinerInstance } from '@xyo-network/diviner-model'
|
|
9
|
+
import type { PackageManifestPayload } from '@xyo-network/manifest'
|
|
10
|
+
import { ManifestWrapper } from '@xyo-network/manifest'
|
|
11
|
+
import { ModuleFactoryLocator } from '@xyo-network/module-factory-locator'
|
|
12
|
+
import { ModuleFactory } from '@xyo-network/module-model'
|
|
13
|
+
import {
|
|
14
|
+
ERC721__factory, ERC721Enumerable__factory, ERC721URIStorage__factory, ERC1155__factory,
|
|
15
|
+
} from '@xyo-network/open-zeppelin-typechain'
|
|
16
|
+
import { isPayloadOfSchemaType } from '@xyo-network/payload-model'
|
|
17
|
+
import { asSentinelInstance } from '@xyo-network/sentinel-model'
|
|
18
|
+
import { HDWallet } from '@xyo-network/wallet'
|
|
19
|
+
import { getProvidersFromEnv } from '@xyo-network/witness-evm-abstract'
|
|
20
|
+
import { asWitnessInstance } from '@xyo-network/witness-model'
|
|
21
|
+
import {
|
|
22
|
+
afterAll,
|
|
23
|
+
describe, expect, it,
|
|
24
|
+
} from 'vitest'
|
|
25
|
+
|
|
26
|
+
import type { EvmCallResults } from '../Diviner.ts'
|
|
27
|
+
import { EvmCallDiviner, EvmCallResultsSchema } from '../Diviner.ts'
|
|
28
|
+
import type { EvmCallWitnessParams } from '../model.ts'
|
|
29
|
+
import type { EvmCall } from '../Payload.ts'
|
|
30
|
+
import { EvmCallSchema } from '../Payload.ts'
|
|
31
|
+
import { EvmCallWitness } from '../Witness.ts'
|
|
32
|
+
import erc721TokenSentinelManifest from './Erc721TokenSentinel.json' with { type: 'json' }
|
|
33
|
+
|
|
34
|
+
const profiler = createProfiler()
|
|
35
|
+
|
|
36
|
+
const tokenCount = 0
|
|
37
|
+
const maxProviders = 2
|
|
38
|
+
|
|
39
|
+
describe('Erc721Sentinel - Token', () => {
|
|
40
|
+
// const address = '0x562fC2927c77cB975680088566ADa1dC6cB8b5Ea' //Random ERC721
|
|
41
|
+
const address = '0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D' // Bored Apes
|
|
42
|
+
// const address = '0x495f947276749Ce646f68AC8c248420045cb7b5e' //OpenSea Storefront
|
|
43
|
+
// const address = '0x6802df79bcbbf019fe5cb366ff25720d1365cfd3' //Upgradeable
|
|
44
|
+
|
|
45
|
+
const tokenId = 1
|
|
46
|
+
|
|
47
|
+
const providers = getProvidersFromEnv(maxProviders)
|
|
48
|
+
|
|
49
|
+
describe.skipIf(providers.length === 0)('report', () => {
|
|
50
|
+
it('specifying address', async () => {
|
|
51
|
+
profile(profiler, 'setup')
|
|
52
|
+
const wallet = await HDWallet.random()
|
|
53
|
+
const locator = new ModuleFactoryLocator()
|
|
54
|
+
locator.register(EvmCallDiviner.factory())
|
|
55
|
+
|
|
56
|
+
locator.register(
|
|
57
|
+
new ModuleFactory(EvmCallWitness, {
|
|
58
|
+
config: { abi: ERC721__factory.abi },
|
|
59
|
+
providers: () => getProvidersFromEnv(maxProviders),
|
|
60
|
+
} as EvmCallWitnessParams),
|
|
61
|
+
{ 'network.xyo.evm.interface': 'Erc721' },
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
locator.register(
|
|
65
|
+
new ModuleFactory(EvmCallWitness, {
|
|
66
|
+
config: { abi: ERC721Enumerable__factory.abi },
|
|
67
|
+
providers: () => getProvidersFromEnv(maxProviders),
|
|
68
|
+
} as EvmCallWitnessParams),
|
|
69
|
+
{ 'network.xyo.evm.interface': 'Erc721Enumerable' },
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
locator.register(
|
|
73
|
+
new ModuleFactory(EvmCallWitness, {
|
|
74
|
+
config: { abi: ERC721URIStorage__factory.abi },
|
|
75
|
+
providers: () => getProvidersFromEnv(maxProviders),
|
|
76
|
+
} as EvmCallWitnessParams),
|
|
77
|
+
{ 'network.xyo.evm.interface': 'ERC721URIStorage' },
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
locator.register(
|
|
81
|
+
new ModuleFactory(EvmCallWitness, {
|
|
82
|
+
config: { abi: ERC1155__factory.abi },
|
|
83
|
+
providers: () => getProvidersFromEnv(maxProviders),
|
|
84
|
+
} as EvmCallWitnessParams),
|
|
85
|
+
{ 'network.xyo.evm.interface': 'Erc1155' },
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
profile(profiler, 'setup')
|
|
89
|
+
profile(profiler, 'manifest')
|
|
90
|
+
const manifest = new ManifestWrapper(erc721TokenSentinelManifest as PackageManifestPayload, wallet, locator)
|
|
91
|
+
profile(profiler, 'manifest-load')
|
|
92
|
+
const node = await manifest.loadNodeFromIndex(0)
|
|
93
|
+
profile(profiler, 'manifest-load')
|
|
94
|
+
profile(profiler, 'manifest-resolve')
|
|
95
|
+
const mods = await node.resolve('*')
|
|
96
|
+
profile(profiler, 'manifest-resolve')
|
|
97
|
+
profile(profiler, 'manifest')
|
|
98
|
+
expect(mods.length).toBe(6)
|
|
99
|
+
|
|
100
|
+
const tokenSentinel = asSentinelInstance(await node.resolve('NftTokenInfoSentinel'))
|
|
101
|
+
expect(tokenSentinel).toBeDefined()
|
|
102
|
+
|
|
103
|
+
const tokenUriWitness = asWitnessInstance(await node.resolve('Erc721TokenURIWitness'))
|
|
104
|
+
expect(tokenUriWitness).toBeDefined()
|
|
105
|
+
|
|
106
|
+
const ownerOfWitness = asWitnessInstance(await node.resolve('Erc721OwnerOfWitness'))
|
|
107
|
+
expect(ownerOfWitness).toBeDefined()
|
|
108
|
+
|
|
109
|
+
const uriWitness = asWitnessInstance(await node.resolve('Erc1155UriWitness'))
|
|
110
|
+
expect(uriWitness).toBeDefined()
|
|
111
|
+
|
|
112
|
+
const diviner = asDivinerInstance(await node.resolve('TokenInfoDiviner'))
|
|
113
|
+
expect(diviner).toBeDefined()
|
|
114
|
+
|
|
115
|
+
const tokenCallPayload: EvmCall = {
|
|
116
|
+
address, args: [tokenId], schema: EvmCallSchema,
|
|
117
|
+
}
|
|
118
|
+
profile(profiler, 'tokenReport')
|
|
119
|
+
const report = await tokenSentinel?.report([tokenCallPayload])
|
|
120
|
+
const info = report?.find(isPayloadOfSchemaType<EvmCallResults>(EvmCallResultsSchema))
|
|
121
|
+
console.log(`info: ${JSON.stringify(info, null, 2)}`)
|
|
122
|
+
expect(info?.results?.['ownerOf']?.result).toBeString()
|
|
123
|
+
expect(info?.results?.['tokenURI']?.result).toBeString()
|
|
124
|
+
})
|
|
125
|
+
afterAll(() => {
|
|
126
|
+
const profileData = profileReport(profiler)
|
|
127
|
+
if (profileData['tokenReport']) console.log(`Timer: ${profileData['tokenReport'] / tokenCount}ms`)
|
|
128
|
+
console.log(`Profile: ${JSON.stringify(profileData, null, 2)}`)
|
|
129
|
+
})
|
|
130
|
+
})
|
|
131
|
+
})
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import '@xylabs/vitest-extended'
|
|
2
|
+
|
|
3
|
+
import { ERC20__factory } from '@xyo-network/open-zeppelin-typechain'
|
|
4
|
+
import type { Payload } from '@xyo-network/payload-model'
|
|
5
|
+
import { isPayloadOfSchemaType } from '@xyo-network/payload-model'
|
|
6
|
+
import { getProvidersFromEnv } from '@xyo-network/witness-evm-abstract'
|
|
7
|
+
import {
|
|
8
|
+
describe, expect,
|
|
9
|
+
it,
|
|
10
|
+
} from 'vitest'
|
|
11
|
+
|
|
12
|
+
import { EvmCallWitnessConfigSchema } from '../model.ts'
|
|
13
|
+
import type { EvmCall, EvmCallResult } from '../Payload.ts'
|
|
14
|
+
import { EvmCallResultSchema, EvmCallSchema } from '../Payload.ts'
|
|
15
|
+
import { EvmCallWitness } from '../Witness.ts'
|
|
16
|
+
|
|
17
|
+
const validateObservation = (observation: Payload[]) => {
|
|
18
|
+
const results = observation.filter(isPayloadOfSchemaType<EvmCallResult>(EvmCallResultSchema))
|
|
19
|
+
expect(results.length).toBeGreaterThan(0)
|
|
20
|
+
expect(observation.length).toEqual(results.length)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
describe.skipIf(!process.env.INFURA_PROJECT_ID)('CryptoWalletNftWitness', () => {
|
|
24
|
+
const address = '0x55296f69f40ea6d20e478533c15a6b08b654e758' // XYO ERC20
|
|
25
|
+
const functionName = 'balanceOf'
|
|
26
|
+
const args = ['0xaDe7DFBC532A01dB67BFEA3b728D4eA22869f381'] // Random Holder
|
|
27
|
+
describe('observe', () => {
|
|
28
|
+
describe('with no address or chainId in query', () => {
|
|
29
|
+
it('uses values from config', async () => {
|
|
30
|
+
const witness = await EvmCallWitness.create({
|
|
31
|
+
account: 'random',
|
|
32
|
+
config: { abi: ERC20__factory.abi, schema: EvmCallWitnessConfigSchema },
|
|
33
|
+
providers: getProvidersFromEnv,
|
|
34
|
+
})
|
|
35
|
+
const call: EvmCall = {
|
|
36
|
+
address, args, functionName, schema: EvmCallSchema,
|
|
37
|
+
}
|
|
38
|
+
const observation = await witness.observe([call])
|
|
39
|
+
validateObservation(observation)
|
|
40
|
+
})
|
|
41
|
+
})
|
|
42
|
+
})
|
|
43
|
+
})
|
package/src/spec/imported/AddressToContract/AddressToContractIndex/Contract.Sentinel.Node.spec.ts
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/* eslint-disable max-statements */
|
|
2
|
+
import '@xylabs/vitest-extended'
|
|
3
|
+
|
|
4
|
+
import type { Address } from '@xylabs/hex'
|
|
5
|
+
import { MemoryArchivist } from '@xyo-network/archivist-memory'
|
|
6
|
+
import { isErc721ContractInfo, isErc1155ContractInfo } from '@xyo-network/crypto-contract-function-read-payload-plugin'
|
|
7
|
+
import { MemoryBoundWitnessDiviner } from '@xyo-network/diviner-boundwitness-memory'
|
|
8
|
+
import { JsonPatchDiviner } from '@xyo-network/diviner-jsonpatch'
|
|
9
|
+
import { JsonPathAggregateDiviner } from '@xyo-network/diviner-jsonpath-aggregate-memory'
|
|
10
|
+
import { asDivinerInstance } from '@xyo-network/diviner-model'
|
|
11
|
+
import { GenericPayloadDiviner } from '@xyo-network/diviner-payload-generic'
|
|
12
|
+
import type { PayloadDivinerQueryPayload } from '@xyo-network/diviner-payload-model'
|
|
13
|
+
import { PayloadDivinerQuerySchema } from '@xyo-network/diviner-payload-model'
|
|
14
|
+
import {
|
|
15
|
+
TemporalIndexingDiviner,
|
|
16
|
+
TemporalIndexingDivinerDivinerQueryToIndexQueryDiviner,
|
|
17
|
+
TemporalIndexingDivinerIndexCandidateToIndexDiviner,
|
|
18
|
+
TemporalIndexingDivinerIndexQueryResponseToDivinerQueryResponseDiviner,
|
|
19
|
+
TemporalIndexingDivinerStateToIndexCandidateDiviner,
|
|
20
|
+
} from '@xyo-network/diviner-temporal-indexing'
|
|
21
|
+
import type { Erc1822WitnessParams } from '@xyo-network/erc1822-witness'
|
|
22
|
+
import { Erc1822Witness } from '@xyo-network/erc1822-witness'
|
|
23
|
+
import type { Erc1967WitnessParams } from '@xyo-network/erc1967-witness'
|
|
24
|
+
import { Erc1967Witness } from '@xyo-network/erc1967-witness'
|
|
25
|
+
import type { PackageManifestPayload } from '@xyo-network/manifest'
|
|
26
|
+
import { ManifestWrapper } from '@xyo-network/manifest'
|
|
27
|
+
import { ModuleFactoryLocator } from '@xyo-network/module-factory-locator'
|
|
28
|
+
import {
|
|
29
|
+
ModuleFactory, resolveLocalNameToAddress, resolveLocalNameToInstance, resolvePathToAddress,
|
|
30
|
+
} from '@xyo-network/module-model'
|
|
31
|
+
import type { MemoryNode } from '@xyo-network/node-memory'
|
|
32
|
+
import {
|
|
33
|
+
ERC721__factory, ERC721Enumerable__factory, ERC1155__factory,
|
|
34
|
+
} from '@xyo-network/open-zeppelin-typechain'
|
|
35
|
+
import { asSentinelInstance } from '@xyo-network/sentinel-model'
|
|
36
|
+
import { HDWallet } from '@xyo-network/wallet'
|
|
37
|
+
import type { WalletInstance } from '@xyo-network/wallet-model'
|
|
38
|
+
import { getProvidersFromEnv } from '@xyo-network/witness-evm-abstract'
|
|
39
|
+
import { TimestampWitness } from '@xyo-network/witness-timestamp'
|
|
40
|
+
import {
|
|
41
|
+
beforeAll,
|
|
42
|
+
describe, expect, it,
|
|
43
|
+
} from 'vitest'
|
|
44
|
+
|
|
45
|
+
import { EvmCallDiviner } from '../../../../Diviner.ts'
|
|
46
|
+
import type { EvmCallWitnessParams } from '../../../../model.ts'
|
|
47
|
+
import type { EvmCall } from '../../../../Payload.ts'
|
|
48
|
+
import { EvmCallSchema } from '../../../../Payload.ts'
|
|
49
|
+
import { EvmCallWitness } from '../../../../Witness.ts'
|
|
50
|
+
import erc721IndexNodeManifest from './Contract.Sentinel.Erc721.Index.json' with { type: 'json' }
|
|
51
|
+
import erc1155IndexNodeManifest from './Contract.Sentinel.Erc1155.Index.json' with { type: 'json' }
|
|
52
|
+
import sentinelNodeManifest from './Contract.Sentinel.Node.json' with { type: 'json' }
|
|
53
|
+
|
|
54
|
+
describe.skip('Contract Node', () => {
|
|
55
|
+
type TokenType = 'ERC721' | 'ERC1155'
|
|
56
|
+
const cases: [TokenType, string][] = [
|
|
57
|
+
['ERC721', '0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D'.toLowerCase()],
|
|
58
|
+
// ['ERC1155', '0xEdB61f74B0d09B2558F1eeb79B247c1F363Ae452'.toLowerCase()],
|
|
59
|
+
// ['ERC1155', '0x2A6d6a082C410a195157EC4caf67CB9fD718f087'.toLowerCase()],
|
|
60
|
+
// ['ERC1155', '0x33FD426905F149f8376e227d0C9D3340AaD17aF1'.toLowerCase()],
|
|
61
|
+
// ['ERC1155', '0x7DaEC605E9e2a1717326eeDFd660601e2753A057'.toLowerCase()],
|
|
62
|
+
// // ['ERC1155', '0xCaf94eB06D4dE233c45B353723C387D3E440f3d6'.toLowerCase()],
|
|
63
|
+
// ['ERC1155', '0xbF42C1972877F39e102807E5E80ed2ff5D16aa5f'.toLowerCase()],
|
|
64
|
+
]
|
|
65
|
+
let wallet: WalletInstance
|
|
66
|
+
let wallet721: WalletInstance
|
|
67
|
+
let wallet1155: WalletInstance
|
|
68
|
+
let node: MemoryNode
|
|
69
|
+
beforeAll(async () => {
|
|
70
|
+
const mnemonic = 'later puppy sound rebuild rebuild noise ozone amazing hope broccoli crystal grief'
|
|
71
|
+
wallet = await HDWallet.fromPhrase(mnemonic)
|
|
72
|
+
wallet721 = await HDWallet.random()
|
|
73
|
+
wallet1155 = await HDWallet.random()
|
|
74
|
+
const locator = new ModuleFactoryLocator()
|
|
75
|
+
locator.register(MemoryArchivist.factory())
|
|
76
|
+
locator.register(MemoryBoundWitnessDiviner.factory())
|
|
77
|
+
locator.register(GenericPayloadDiviner.factory())
|
|
78
|
+
locator.register(TimestampWitness.factory())
|
|
79
|
+
locator.register(EvmCallDiviner.factory())
|
|
80
|
+
locator.register(TemporalIndexingDivinerDivinerQueryToIndexQueryDiviner.factory(), EvmCallDiviner.labels)
|
|
81
|
+
locator.register(TemporalIndexingDivinerIndexCandidateToIndexDiviner.factory(), EvmCallDiviner.labels)
|
|
82
|
+
locator.register(TemporalIndexingDivinerIndexQueryResponseToDivinerQueryResponseDiviner.factory(), EvmCallDiviner.labels)
|
|
83
|
+
locator.register(TemporalIndexingDivinerStateToIndexCandidateDiviner.factory(), EvmCallDiviner.labels)
|
|
84
|
+
locator.register(TemporalIndexingDiviner.factory(), EvmCallDiviner.labels)
|
|
85
|
+
locator.register(JsonPathAggregateDiviner.factory())
|
|
86
|
+
locator.register(
|
|
87
|
+
new ModuleFactory(EvmCallWitness, {
|
|
88
|
+
config: { abi: ERC721__factory.abi },
|
|
89
|
+
providers: getProvidersFromEnv,
|
|
90
|
+
} as EvmCallWitnessParams),
|
|
91
|
+
{ 'network.xyo.evm.interface': 'Erc721' },
|
|
92
|
+
)
|
|
93
|
+
locator.register(
|
|
94
|
+
new ModuleFactory(EvmCallWitness, {
|
|
95
|
+
config: { abi: ERC721Enumerable__factory.abi },
|
|
96
|
+
providers: getProvidersFromEnv,
|
|
97
|
+
} as EvmCallWitnessParams),
|
|
98
|
+
{ 'network.xyo.evm.interface': 'Erc721Enumerable' },
|
|
99
|
+
)
|
|
100
|
+
locator.register(
|
|
101
|
+
new ModuleFactory(EvmCallWitness, {
|
|
102
|
+
config: { abi: ERC1155__factory.abi },
|
|
103
|
+
providers: getProvidersFromEnv,
|
|
104
|
+
} as EvmCallWitnessParams),
|
|
105
|
+
{ 'network.xyo.evm.interface': 'Erc1155' },
|
|
106
|
+
)
|
|
107
|
+
locator.register(JsonPatchDiviner.factory())
|
|
108
|
+
locator.register(TemporalIndexingDiviner.factory())
|
|
109
|
+
locator.register(
|
|
110
|
+
new ModuleFactory(Erc1822Witness, { providers: getProvidersFromEnv } as Erc1822WitnessParams),
|
|
111
|
+
)
|
|
112
|
+
locator.register(
|
|
113
|
+
new ModuleFactory(Erc1967Witness, { providers: getProvidersFromEnv } as Erc1967WitnessParams),
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
const manifest = new ManifestWrapper(sentinelNodeManifest as PackageManifestPayload, wallet, locator)
|
|
117
|
+
node = await manifest.loadNodeFromIndex(0)
|
|
118
|
+
|
|
119
|
+
const manifest721 = new ManifestWrapper(erc721IndexNodeManifest as PackageManifestPayload, wallet721, locator)
|
|
120
|
+
const node721 = await manifest721.loadNodeFromIndex(0)
|
|
121
|
+
|
|
122
|
+
await node.register(node721)
|
|
123
|
+
await node.attach(node721.address, true)
|
|
124
|
+
|
|
125
|
+
const manifest1155 = new ManifestWrapper(erc1155IndexNodeManifest as PackageManifestPayload, wallet1155, locator)
|
|
126
|
+
const node1155 = await manifest1155.loadNodeFromIndex(0)
|
|
127
|
+
|
|
128
|
+
await node.register(node1155)
|
|
129
|
+
await node.attach(node1155.address, true)
|
|
130
|
+
})
|
|
131
|
+
describe('Sentinel', () => {
|
|
132
|
+
it.each(cases)('With %s (%s)', async (_, address) => {
|
|
133
|
+
const collectionSentinel = asSentinelInstance(await node.resolve('NftInfoSentinel'))
|
|
134
|
+
expect(collectionSentinel).toBeDefined()
|
|
135
|
+
const collectionCallPayload: EvmCall = { address: address.toLowerCase(), schema: EvmCallSchema }
|
|
136
|
+
const report = await collectionSentinel?.report([collectionCallPayload])
|
|
137
|
+
let foundAny = false
|
|
138
|
+
const erc721 = report?.find(isErc721ContractInfo)
|
|
139
|
+
if (erc721) {
|
|
140
|
+
foundAny = true
|
|
141
|
+
expect(erc721?.results?.name).toBe('BoredApeYachtClub')
|
|
142
|
+
expect(erc721?.results?.symbol).toBe('BAYC')
|
|
143
|
+
}
|
|
144
|
+
const erc1155 = report?.find(isErc1155ContractInfo)
|
|
145
|
+
if (erc1155) {
|
|
146
|
+
foundAny = true
|
|
147
|
+
expect(erc1155?.results?.uri).toBeDefined()
|
|
148
|
+
}
|
|
149
|
+
expect(foundAny).toBe(true)
|
|
150
|
+
})
|
|
151
|
+
})
|
|
152
|
+
describe('ERC721 Index', () => {
|
|
153
|
+
const erc721Cases = cases.filter(([type]) => type === 'ERC721')
|
|
154
|
+
it.each(erc721Cases)('With %s (%s)', async (_, address) => {
|
|
155
|
+
const diviner = asDivinerInstance(await node.resolve('NftInfo:Erc721IndexDiviner'))
|
|
156
|
+
expect(diviner).toBeDefined()
|
|
157
|
+
const query: PayloadDivinerQueryPayload = { address: address.toLowerCase() as Address, schema: PayloadDivinerQuerySchema }
|
|
158
|
+
const result = await diviner?.divine([query])
|
|
159
|
+
expect(result).toBeDefined()
|
|
160
|
+
expect(result).toBeArrayOfSize(1)
|
|
161
|
+
})
|
|
162
|
+
})
|
|
163
|
+
describe('ERC1155 Index', () => {
|
|
164
|
+
const erc1155 = cases.filter(([type]) => type === 'ERC1155')
|
|
165
|
+
it.each(erc1155)('With %s (%s)', async (_, address) => {
|
|
166
|
+
const erc1155Node = await resolveLocalNameToInstance(node, 'ERC1155Node')
|
|
167
|
+
expect(erc1155Node).toBeDefined()
|
|
168
|
+
if (erc1155Node) {
|
|
169
|
+
expect(await resolveLocalNameToAddress(erc1155Node, 'Erc1155IndexDiviner')).toBeDefined()
|
|
170
|
+
const modAddress = await resolvePathToAddress(node, 'ERC1155Node:Erc1155IndexDiviner')
|
|
171
|
+
expect(modAddress).toBeDefined()
|
|
172
|
+
if (modAddress) {
|
|
173
|
+
const diviner = asDivinerInstance(await node.resolve(modAddress))
|
|
174
|
+
expect(diviner).toBeDefined()
|
|
175
|
+
const query: PayloadDivinerQueryPayload = { address: address.toLowerCase() as Address, schema: PayloadDivinerQuerySchema }
|
|
176
|
+
const result = await diviner?.divine([query])
|
|
177
|
+
expect(result).toBeDefined()
|
|
178
|
+
expect(result).toBeArrayOfSize(1)
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
})
|
|
182
|
+
})
|
|
183
|
+
})
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/* eslint-disable max-statements */
|
|
2
|
+
|
|
3
|
+
import '@xylabs/vitest-extended'
|
|
4
|
+
|
|
5
|
+
import { asDivinerInstance } from '@xyo-network/diviner-model'
|
|
6
|
+
import type { PackageManifestPayload } from '@xyo-network/manifest'
|
|
7
|
+
import { ManifestWrapper } from '@xyo-network/manifest'
|
|
8
|
+
import { ModuleFactoryLocator } from '@xyo-network/module-factory-locator'
|
|
9
|
+
import { ModuleFactory } from '@xyo-network/module-model'
|
|
10
|
+
import {
|
|
11
|
+
ERC721__factory, ERC721Enumerable__factory, ERC1155__factory,
|
|
12
|
+
} from '@xyo-network/open-zeppelin-typechain'
|
|
13
|
+
import { isPayloadOfSchemaType } from '@xyo-network/payload-model'
|
|
14
|
+
import { asSentinelInstance } from '@xyo-network/sentinel-model'
|
|
15
|
+
import { HDWallet } from '@xyo-network/wallet'
|
|
16
|
+
import { getProvidersFromEnv } from '@xyo-network/witness-evm-abstract'
|
|
17
|
+
import { asWitnessInstance } from '@xyo-network/witness-model'
|
|
18
|
+
import {
|
|
19
|
+
afterAll,
|
|
20
|
+
describe, expect, it,
|
|
21
|
+
} from 'vitest'
|
|
22
|
+
|
|
23
|
+
import type { EvmCallResults } from '../../../../Diviner.ts'
|
|
24
|
+
import { EvmCallDiviner, EvmCallResultsSchema } from '../../../../Diviner.ts'
|
|
25
|
+
import type { EvmCallWitnessParams } from '../../../../model.ts'
|
|
26
|
+
import type { EvmCall } from '../../../../Payload.ts'
|
|
27
|
+
import { EvmCallSchema } from '../../../../Payload.ts'
|
|
28
|
+
import { EvmCallWitness } from '../../../../Witness.ts'
|
|
29
|
+
import erc721SentinelManifest from '../Erc721Sentinel.json' with { type: 'json' }
|
|
30
|
+
|
|
31
|
+
const profileData: Record<string, number[]> = {}
|
|
32
|
+
|
|
33
|
+
const profile = (name: string) => {
|
|
34
|
+
const timeData = profileData[name] ?? []
|
|
35
|
+
timeData.push(Date.now())
|
|
36
|
+
profileData[name] = timeData
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const profileReport = () => {
|
|
40
|
+
let lowest = Date.now()
|
|
41
|
+
let highest = 0
|
|
42
|
+
// eslint-disable-next-line unicorn/no-array-reduce
|
|
43
|
+
const results = Object.entries(profileData).reduce<Record<string, number>>((prev, [name, readings]) => {
|
|
44
|
+
const start = readings.at(0)
|
|
45
|
+
if (start) {
|
|
46
|
+
if (start < lowest) {
|
|
47
|
+
lowest = start
|
|
48
|
+
}
|
|
49
|
+
const end = readings.at(-1) ?? Date.now()
|
|
50
|
+
if (end > highest) {
|
|
51
|
+
highest = end
|
|
52
|
+
}
|
|
53
|
+
prev[name] = end - start
|
|
54
|
+
}
|
|
55
|
+
return prev
|
|
56
|
+
}, {})
|
|
57
|
+
if (highest) {
|
|
58
|
+
results['-all-'] = highest - lowest
|
|
59
|
+
}
|
|
60
|
+
return results
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const tokenCount = 0
|
|
64
|
+
|
|
65
|
+
describe.skip('Erc721Sentinel', () => {
|
|
66
|
+
// const address = '0x562fC2927c77cB975680088566ADa1dC6cB8b5Ea' //Random ERC721
|
|
67
|
+
const address = '0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D' // Bored Apes
|
|
68
|
+
|
|
69
|
+
describe('report', () => {
|
|
70
|
+
it('specifying address', async () => {
|
|
71
|
+
profile('setup')
|
|
72
|
+
const mnemonic = 'later puppy sound rebuild rebuild noise ozone amazing hope broccoli crystal grief'
|
|
73
|
+
const wallet = await HDWallet.fromPhrase(mnemonic)
|
|
74
|
+
const locator = new ModuleFactoryLocator()
|
|
75
|
+
locator.register(EvmCallDiviner.factory())
|
|
76
|
+
|
|
77
|
+
locator.register(
|
|
78
|
+
new ModuleFactory(EvmCallWitness, {
|
|
79
|
+
config: { abi: ERC721__factory.abi },
|
|
80
|
+
providers: getProvidersFromEnv,
|
|
81
|
+
} as EvmCallWitnessParams),
|
|
82
|
+
{ 'network.xyo.evm.interface': 'Erc721' },
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
locator.register(
|
|
86
|
+
new ModuleFactory(EvmCallWitness, {
|
|
87
|
+
config: { abi: ERC721Enumerable__factory.abi },
|
|
88
|
+
providers: getProvidersFromEnv,
|
|
89
|
+
} as EvmCallWitnessParams),
|
|
90
|
+
{ 'network.xyo.evm.interface': 'Erc721Enumerable' },
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
locator.register(
|
|
94
|
+
new ModuleFactory(EvmCallWitness, {
|
|
95
|
+
config: { abi: ERC1155__factory.abi },
|
|
96
|
+
providers: getProvidersFromEnv,
|
|
97
|
+
} as EvmCallWitnessParams),
|
|
98
|
+
{ 'network.xyo.evm.interface': 'Erc1155' },
|
|
99
|
+
)
|
|
100
|
+
profile('setup')
|
|
101
|
+
profile('manifest')
|
|
102
|
+
const manifest = new ManifestWrapper(erc721SentinelManifest as PackageManifestPayload, wallet, locator)
|
|
103
|
+
profile('manifest-load')
|
|
104
|
+
const node = await manifest.loadNodeFromIndex(0)
|
|
105
|
+
profile('manifest-load')
|
|
106
|
+
profile('manifest-resolve')
|
|
107
|
+
const mods = await node.resolve('*')
|
|
108
|
+
profile('manifest-resolve')
|
|
109
|
+
profile('manifest')
|
|
110
|
+
expect(mods.length).toBeGreaterThan(5)
|
|
111
|
+
|
|
112
|
+
const collectionSentinel = asSentinelInstance(await node.resolve('NftInfoSentinel'))
|
|
113
|
+
expect(collectionSentinel).toBeDefined()
|
|
114
|
+
|
|
115
|
+
const tokenSentinel = asSentinelInstance(await node.resolve('NftTokenInfoSentinel'))
|
|
116
|
+
expect(tokenSentinel).toBeDefined()
|
|
117
|
+
|
|
118
|
+
const nameWitness = asWitnessInstance(await node.resolve('Erc721NameWitness'))
|
|
119
|
+
expect(nameWitness).toBeDefined()
|
|
120
|
+
|
|
121
|
+
const symbolWitness = asWitnessInstance(await node.resolve('Erc721SymbolWitness'))
|
|
122
|
+
expect(symbolWitness).toBeDefined()
|
|
123
|
+
|
|
124
|
+
const diviner = asDivinerInstance(await node.resolve('Erc721ContractInfoDiviner'))
|
|
125
|
+
expect(diviner).toBeDefined()
|
|
126
|
+
|
|
127
|
+
const collectionCallPayload: EvmCall = { address, schema: EvmCallSchema }
|
|
128
|
+
profile('collectionReport')
|
|
129
|
+
const report = await collectionSentinel?.report([collectionCallPayload])
|
|
130
|
+
profile('collectionReport')
|
|
131
|
+
profile('tokenCallSetup')
|
|
132
|
+
const info = report?.find(isPayloadOfSchemaType<EvmCallResults>(EvmCallResultsSchema))
|
|
133
|
+
|
|
134
|
+
expect(info?.results?.name?.result).toBe('BoredApeYachtClub')
|
|
135
|
+
expect(info?.results?.symbol?.result).toBe('BAYC')
|
|
136
|
+
})
|
|
137
|
+
afterAll(() => {
|
|
138
|
+
const profileData = profileReport()
|
|
139
|
+
if (profileData['tokenReport']) console.log(`Timer: ${profileData['tokenReport'] / tokenCount}ms`)
|
|
140
|
+
console.log(`Profile: ${JSON.stringify(profileData, null, 2)}`)
|
|
141
|
+
})
|
|
142
|
+
})
|
|
143
|
+
})
|