@xyo-network/evm-call-witness 5.1.2 → 5.1.4
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/package.json +44 -41
- package/dist/neutral/spec/Sentinel.collection.spec.d.ts +0 -2
- package/dist/neutral/spec/Sentinel.collection.spec.d.ts.map +0 -1
- package/dist/neutral/spec/Sentinel.token.enumerate.spec.d.ts +0 -2
- package/dist/neutral/spec/Sentinel.token.enumerate.spec.d.ts.map +0 -1
- package/dist/neutral/spec/Sentinel.token.spec.d.ts +0 -2
- package/dist/neutral/spec/Sentinel.token.spec.d.ts.map +0 -1
- package/dist/neutral/spec/Witness.spec.d.ts +0 -2
- package/dist/neutral/spec/Witness.spec.d.ts.map +0 -1
- package/dist/neutral/spec/imported/AddressToContract/AddressToContractIndex/Contract.Sentinel.Node.spec.d.ts +0 -2
- package/dist/neutral/spec/imported/AddressToContract/AddressToContractIndex/Contract.Sentinel.Node.spec.d.ts.map +0 -1
- package/dist/neutral/spec/imported/AddressToContract/CollectionInfo/Sentinel.collection.spec.d.ts +0 -2
- package/dist/neutral/spec/imported/AddressToContract/CollectionInfo/Sentinel.collection.spec.d.ts.map +0 -1
- package/dist/neutral/spec/imported/AddressToContract/ManualTokenIteration/Sentinel.token.spec.d.ts +0 -2
- package/dist/neutral/spec/imported/AddressToContract/ManualTokenIteration/Sentinel.token.spec.d.ts.map +0 -1
- package/dist/neutral/spec/imported/AddressToTotalSupplyIndex/Erc721.TotalSupply.Index.spec.d.ts +0 -2
- package/dist/neutral/spec/imported/AddressToTotalSupplyIndex/Erc721.TotalSupply.Index.spec.d.ts.map +0 -1
- package/dist/neutral/spec/imported/NftIndexToNftIdIndex/Erc721.NftId.Index.spec.d.ts +0 -2
- package/dist/neutral/spec/imported/NftIndexToNftIdIndex/Erc721.NftId.Index.spec.d.ts.map +0 -1
- package/dist/neutral/spec/imported/TotalSupplyToNftIndexIndex/Erc721.NftIndex.Index.spec.d.ts +0 -2
- package/dist/neutral/spec/imported/TotalSupplyToNftIndexIndex/Erc721.NftIndex.Index.spec.d.ts.map +0 -1
- package/src/spec/Sentinel.collection.spec.ts +0 -127
- package/src/spec/Sentinel.token.enumerate.spec.ts +0 -138
- package/src/spec/Sentinel.token.spec.ts +0 -131
- package/src/spec/Witness.spec.ts +0 -43
- package/src/spec/imported/AddressToContract/AddressToContractIndex/Contract.Sentinel.Node.spec.ts +0 -183
- package/src/spec/imported/AddressToContract/CollectionInfo/Sentinel.collection.spec.ts +0 -143
- package/src/spec/imported/AddressToContract/ManualTokenIteration/Sentinel.token.spec.ts +0 -187
- package/src/spec/imported/AddressToTotalSupplyIndex/Erc721.TotalSupply.Index.spec.ts +0 -101
- package/src/spec/imported/NftIndexToNftIdIndex/Erc721.NftId.Index.spec.ts +0 -118
- package/src/spec/imported/TotalSupplyToNftIndexIndex/Erc721.NftIndex.Index.spec.ts +0 -124
package/src/spec/imported/AddressToContract/AddressToContractIndex/Contract.Sentinel.Node.spec.ts
DELETED
|
@@ -1,183 +0,0 @@
|
|
|
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
|
-
})
|
|
@@ -1,143 +0,0 @@
|
|
|
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
|
-
})
|
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
/* eslint-disable max-statements */
|
|
2
|
-
|
|
3
|
-
import '@xylabs/vitest-extended'
|
|
4
|
-
|
|
5
|
-
import { hexFrom } from '@xylabs/hex'
|
|
6
|
-
import { asDivinerInstance } from '@xyo-network/diviner-model'
|
|
7
|
-
import type { PackageManifestPayload } from '@xyo-network/manifest'
|
|
8
|
-
import { ManifestWrapper } from '@xyo-network/manifest'
|
|
9
|
-
import { ModuleFactoryLocator } from '@xyo-network/module-factory-locator'
|
|
10
|
-
import { ModuleFactory } from '@xyo-network/module-model'
|
|
11
|
-
import {
|
|
12
|
-
ERC721__factory, ERC721Enumerable__factory, ERC1155__factory,
|
|
13
|
-
} from '@xyo-network/open-zeppelin-typechain'
|
|
14
|
-
import { isPayloadOfSchemaType } from '@xyo-network/payload-model'
|
|
15
|
-
import { asSentinelInstance } from '@xyo-network/sentinel-model'
|
|
16
|
-
import { HDWallet } from '@xyo-network/wallet'
|
|
17
|
-
import { getProvidersFromEnv } from '@xyo-network/witness-evm-abstract'
|
|
18
|
-
import { asWitnessInstance } from '@xyo-network/witness-model'
|
|
19
|
-
import { Semaphore } from 'async-mutex'
|
|
20
|
-
import {
|
|
21
|
-
afterAll,
|
|
22
|
-
describe, expect,
|
|
23
|
-
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, EvmCallResult } from '../../../../Payload.ts'
|
|
30
|
-
import { EvmCallResultSchema, EvmCallSchema } from '../../../../Payload.ts'
|
|
31
|
-
import { EvmCallWitness } from '../../../../Witness.ts'
|
|
32
|
-
import erc721SentinelManifest from '../Erc721Sentinel.json' with { type: 'json' }
|
|
33
|
-
|
|
34
|
-
const profileData: Record<string, number[]> = {}
|
|
35
|
-
|
|
36
|
-
const profile = (name: string) => {
|
|
37
|
-
const timeData = profileData[name] ?? []
|
|
38
|
-
timeData.push(Date.now())
|
|
39
|
-
profileData[name] = timeData
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const profileReport = () => {
|
|
43
|
-
let lowest = Date.now()
|
|
44
|
-
let highest = 0
|
|
45
|
-
// eslint-disable-next-line unicorn/no-array-reduce
|
|
46
|
-
const results = Object.entries(profileData).reduce<Record<string, number>>((prev, [name, readings]) => {
|
|
47
|
-
const start = readings.at(0)
|
|
48
|
-
if (start) {
|
|
49
|
-
if (start < lowest) {
|
|
50
|
-
lowest = start
|
|
51
|
-
}
|
|
52
|
-
const end = readings.at(-1) ?? Date.now()
|
|
53
|
-
if (end > highest) {
|
|
54
|
-
highest = end
|
|
55
|
-
}
|
|
56
|
-
prev[name] = end - start
|
|
57
|
-
}
|
|
58
|
-
return prev
|
|
59
|
-
}, {})
|
|
60
|
-
if (highest) {
|
|
61
|
-
results['-all-'] = highest - lowest
|
|
62
|
-
}
|
|
63
|
-
return results
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
let tokenCount = 0
|
|
67
|
-
|
|
68
|
-
describe.skip('Erc721Sentinel', () => {
|
|
69
|
-
// const address = '0x562fC2927c77cB975680088566ADa1dC6cB8b5Ea' //Random ERC721
|
|
70
|
-
const address = '0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D' // Bored Apes
|
|
71
|
-
|
|
72
|
-
describe('report', () => {
|
|
73
|
-
it('specifying address', async () => {
|
|
74
|
-
profile('setup')
|
|
75
|
-
const mnemonic = 'later puppy sound rebuild rebuild noise ozone amazing hope broccoli crystal grief'
|
|
76
|
-
const wallet = await HDWallet.fromPhrase(mnemonic)
|
|
77
|
-
const locator = new ModuleFactoryLocator()
|
|
78
|
-
locator.register(EvmCallDiviner.factory())
|
|
79
|
-
|
|
80
|
-
locator.register(
|
|
81
|
-
new ModuleFactory(EvmCallWitness, {
|
|
82
|
-
config: { abi: ERC721__factory.abi },
|
|
83
|
-
providers: getProvidersFromEnv,
|
|
84
|
-
} as EvmCallWitnessParams),
|
|
85
|
-
{ 'network.xyo.evm.interface': 'Erc721' },
|
|
86
|
-
)
|
|
87
|
-
|
|
88
|
-
locator.register(
|
|
89
|
-
new ModuleFactory(EvmCallWitness, {
|
|
90
|
-
config: { abi: ERC721Enumerable__factory.abi },
|
|
91
|
-
providers: getProvidersFromEnv,
|
|
92
|
-
} as EvmCallWitnessParams),
|
|
93
|
-
{ 'network.xyo.evm.interface': 'Erc721Enumerable' },
|
|
94
|
-
)
|
|
95
|
-
|
|
96
|
-
locator.register(
|
|
97
|
-
new ModuleFactory(EvmCallWitness, {
|
|
98
|
-
config: { abi: ERC1155__factory.abi },
|
|
99
|
-
providers: getProvidersFromEnv,
|
|
100
|
-
} as EvmCallWitnessParams),
|
|
101
|
-
{ 'network.xyo.evm.interface': 'Erc1155' },
|
|
102
|
-
)
|
|
103
|
-
profile('setup')
|
|
104
|
-
profile('manifest')
|
|
105
|
-
const manifest = new ManifestWrapper(erc721SentinelManifest as PackageManifestPayload, wallet, locator)
|
|
106
|
-
profile('manifest-load')
|
|
107
|
-
const node = await manifest.loadNodeFromIndex(0)
|
|
108
|
-
profile('manifest-load')
|
|
109
|
-
profile('manifest-resolve')
|
|
110
|
-
const mods = await node.resolve('*')
|
|
111
|
-
profile('manifest-resolve')
|
|
112
|
-
profile('manifest')
|
|
113
|
-
expect(mods.length).toBeGreaterThan(5)
|
|
114
|
-
|
|
115
|
-
const collectionSentinel = asSentinelInstance(await node.resolve('NftInfoSentinel'))
|
|
116
|
-
expect(collectionSentinel).toBeDefined()
|
|
117
|
-
|
|
118
|
-
const tokenSentinel = asSentinelInstance(await node.resolve('NftTokenInfoSentinel'))
|
|
119
|
-
expect(tokenSentinel).toBeDefined()
|
|
120
|
-
|
|
121
|
-
const nameWitness = asWitnessInstance(await node.resolve('Erc721NameWitness'))
|
|
122
|
-
expect(nameWitness).toBeDefined()
|
|
123
|
-
|
|
124
|
-
const symbolWitness = asWitnessInstance(await node.resolve('Erc721SymbolWitness'))
|
|
125
|
-
expect(symbolWitness).toBeDefined()
|
|
126
|
-
|
|
127
|
-
const diviner = asDivinerInstance(await node.resolve('Erc721ContractInfoDiviner'))
|
|
128
|
-
expect(diviner).toBeDefined()
|
|
129
|
-
|
|
130
|
-
const collectionCallPayload: EvmCall = { address, schema: EvmCallSchema }
|
|
131
|
-
profile('collectionReport')
|
|
132
|
-
const report = await collectionSentinel?.report([collectionCallPayload])
|
|
133
|
-
profile('collectionReport')
|
|
134
|
-
profile('tokenCallSetup')
|
|
135
|
-
const info = report?.find(isPayloadOfSchemaType<EvmCallResults>(EvmCallResultsSchema))
|
|
136
|
-
|
|
137
|
-
const totalSupply = info?.results?.totalSupply ? BigInt(hexFrom(info.results.totalSupply.result as string, { prefix: true })) : 0n
|
|
138
|
-
expect(totalSupply).toBeGreaterThan(0n)
|
|
139
|
-
|
|
140
|
-
const chunkSize = 100n
|
|
141
|
-
const maxChunks = totalSupply / chunkSize
|
|
142
|
-
const chunks: EvmCall[][] = []
|
|
143
|
-
|
|
144
|
-
let offset = 0n
|
|
145
|
-
while (offset < totalSupply && chunks.length < maxChunks) {
|
|
146
|
-
offset = BigInt(chunks.length) * chunkSize
|
|
147
|
-
|
|
148
|
-
const chunkList: EvmCall[] = []
|
|
149
|
-
|
|
150
|
-
for (let i = offset; i < offset + chunkSize && i < totalSupply; i++) {
|
|
151
|
-
const call: EvmCall = {
|
|
152
|
-
address,
|
|
153
|
-
args: [`0x${BigInt(i).toString(16)}`],
|
|
154
|
-
functionName: 'tokenByIndex',
|
|
155
|
-
schema: EvmCallSchema,
|
|
156
|
-
}
|
|
157
|
-
chunkList.push(call)
|
|
158
|
-
}
|
|
159
|
-
chunks.push(chunkList)
|
|
160
|
-
}
|
|
161
|
-
profile('tokenCallSetup')
|
|
162
|
-
const maxConcurrent = 8
|
|
163
|
-
if (tokenSentinel) {
|
|
164
|
-
profile('tokenReport')
|
|
165
|
-
const semaphore = new Semaphore(maxConcurrent)
|
|
166
|
-
const tokenReportArrays = await Promise.all(
|
|
167
|
-
chunks.map(async (chunk) => {
|
|
168
|
-
return await semaphore.runExclusive(async () => {
|
|
169
|
-
const result = await tokenSentinel.report(chunk)
|
|
170
|
-
return result
|
|
171
|
-
})
|
|
172
|
-
}),
|
|
173
|
-
)
|
|
174
|
-
profile('tokenReport')
|
|
175
|
-
const tokenReport = tokenReportArrays.flat()
|
|
176
|
-
tokenCount = tokenReport.length
|
|
177
|
-
const tokenInfoPayloads = tokenReport.filter(isPayloadOfSchemaType<EvmCallResult>(EvmCallResultSchema))
|
|
178
|
-
expect(BigInt(tokenInfoPayloads.length)).toBe(totalSupply)
|
|
179
|
-
}
|
|
180
|
-
})
|
|
181
|
-
afterAll(() => {
|
|
182
|
-
const profileData = profileReport()
|
|
183
|
-
if (profileData['tokenReport']) console.log(`Timer: ${profileData['tokenReport'] / tokenCount}ms`)
|
|
184
|
-
console.log(`Profile: ${JSON.stringify(profileData, null, 2)}`)
|
|
185
|
-
})
|
|
186
|
-
})
|
|
187
|
-
})
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import '@xylabs/vitest-extended'
|
|
2
|
-
|
|
3
|
-
import { delay } from '@xylabs/delay'
|
|
4
|
-
import { MemoryBoundWitnessDiviner } from '@xyo-network/diviner-boundwitness-memory'
|
|
5
|
-
import { asDivinerInstance } from '@xyo-network/diviner-model'
|
|
6
|
-
import { GenericPayloadDiviner } from '@xyo-network/diviner-payload-generic'
|
|
7
|
-
import { PayloadDivinerQuerySchema } from '@xyo-network/diviner-payload-model'
|
|
8
|
-
import {
|
|
9
|
-
TemporalIndexingDiviner,
|
|
10
|
-
TemporalIndexingDivinerDivinerQueryToIndexQueryDiviner,
|
|
11
|
-
TemporalIndexingDivinerIndexCandidateToIndexDiviner,
|
|
12
|
-
TemporalIndexingDivinerIndexQueryResponseToDivinerQueryResponseDiviner,
|
|
13
|
-
TemporalIndexingDivinerStateToIndexCandidateDiviner,
|
|
14
|
-
} from '@xyo-network/diviner-temporal-indexing'
|
|
15
|
-
import type { PackageManifestPayload } from '@xyo-network/manifest'
|
|
16
|
-
import { ManifestWrapper } from '@xyo-network/manifest'
|
|
17
|
-
import { ModuleFactoryLocator } from '@xyo-network/module-factory-locator'
|
|
18
|
-
import { ModuleFactory } from '@xyo-network/module-model'
|
|
19
|
-
import type { MemoryNode } from '@xyo-network/node-memory'
|
|
20
|
-
import { ERC721Enumerable__factory } from '@xyo-network/open-zeppelin-typechain'
|
|
21
|
-
import { asSentinelInstance } from '@xyo-network/sentinel-model'
|
|
22
|
-
import { HDWallet } from '@xyo-network/wallet'
|
|
23
|
-
import type { WalletInstance } from '@xyo-network/wallet-model'
|
|
24
|
-
import { getProvidersFromEnv } from '@xyo-network/witness-evm-abstract'
|
|
25
|
-
import { TimestampWitness } from '@xyo-network/witness-timestamp'
|
|
26
|
-
import {
|
|
27
|
-
beforeAll, describe, expect,
|
|
28
|
-
it,
|
|
29
|
-
} from 'vitest'
|
|
30
|
-
|
|
31
|
-
import { EvmCallDiviner } from '../../../Diviner.ts'
|
|
32
|
-
import type { EvmCallWitnessParams } from '../../../model.ts'
|
|
33
|
-
import {
|
|
34
|
-
EvmCallSchema, isEvmCallResult, isEvmCallSuccess,
|
|
35
|
-
} from '../../../Payload.ts'
|
|
36
|
-
import { EvmCallWitness } from '../../../Witness.ts'
|
|
37
|
-
import erc721TotalSupplyIndexManifest from './Erc721.TotalSupply.Index.json' with { type: 'json' }
|
|
38
|
-
|
|
39
|
-
describe.skipIf(!process.env.INFURA_PROJECT_ID)('Erc721.TotalSupply.Index', () => {
|
|
40
|
-
let wallet: WalletInstance
|
|
41
|
-
let node: MemoryNode
|
|
42
|
-
|
|
43
|
-
beforeAll(async () => {
|
|
44
|
-
const mnemonic = 'later puppy sound rebuild rebuild noise ozone amazing hope broccoli crystal grief'
|
|
45
|
-
wallet = await HDWallet.fromPhrase(mnemonic)
|
|
46
|
-
const locator = new ModuleFactoryLocator()
|
|
47
|
-
locator.register(MemoryBoundWitnessDiviner.factory())
|
|
48
|
-
locator.register(GenericPayloadDiviner.factory())
|
|
49
|
-
locator.register(TimestampWitness.factory())
|
|
50
|
-
locator.register(EvmCallDiviner.factory())
|
|
51
|
-
locator.register(TemporalIndexingDivinerDivinerQueryToIndexQueryDiviner.factory())
|
|
52
|
-
locator.register(TemporalIndexingDivinerIndexCandidateToIndexDiviner.factory())
|
|
53
|
-
locator.register(TemporalIndexingDivinerIndexQueryResponseToDivinerQueryResponseDiviner.factory())
|
|
54
|
-
locator.register(TemporalIndexingDivinerStateToIndexCandidateDiviner.factory())
|
|
55
|
-
locator.register(TemporalIndexingDiviner.factory())
|
|
56
|
-
|
|
57
|
-
locator.register(
|
|
58
|
-
new ModuleFactory(EvmCallWitness, {
|
|
59
|
-
config: { abi: ERC721Enumerable__factory.abi },
|
|
60
|
-
providers: getProvidersFromEnv,
|
|
61
|
-
} as EvmCallWitnessParams),
|
|
62
|
-
{ 'network.xyo.evm.interface': 'Erc721Enumerable' },
|
|
63
|
-
)
|
|
64
|
-
const manifest = new ManifestWrapper(erc721TotalSupplyIndexManifest as PackageManifestPayload, wallet, locator)
|
|
65
|
-
node = await manifest.loadNodeFromIndex(0)
|
|
66
|
-
})
|
|
67
|
-
type TestData = readonly [string]
|
|
68
|
-
const cases: readonly TestData[] = [
|
|
69
|
-
['0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D'], // BAYC
|
|
70
|
-
] as const
|
|
71
|
-
describe.skipIf(!process.env.INFURA_PROJECT_ID)('Sentinel', () => {
|
|
72
|
-
describe('Sentinel', () => {
|
|
73
|
-
it.each(cases)('returns totalSupply', async (address) => {
|
|
74
|
-
const sentinel = asSentinelInstance(await node.resolve('Sentinel'))
|
|
75
|
-
const input = {
|
|
76
|
-
address, chainId: 1, schema: EvmCallSchema,
|
|
77
|
-
}
|
|
78
|
-
const observations = await sentinel?.report([input])
|
|
79
|
-
expect(observations?.length).toBe(3)
|
|
80
|
-
const totalSupply = observations?.filter(isEvmCallResult).find(isEvmCallSuccess)
|
|
81
|
-
expect(totalSupply).toBeDefined()
|
|
82
|
-
expect(totalSupply?.result).toBeString()
|
|
83
|
-
const totalSupplyValue = totalSupply?.result as string
|
|
84
|
-
expect(Number.parseInt(totalSupplyValue)).toBeNumber()
|
|
85
|
-
})
|
|
86
|
-
})
|
|
87
|
-
describe.skip('Index', () => {
|
|
88
|
-
it.each(cases)('returns indexed result', async (address) => {
|
|
89
|
-
await delay(100)
|
|
90
|
-
const diviner = asDivinerInstance(await node.resolve('IndexDiviner'))
|
|
91
|
-
expect(diviner).toBeDefined()
|
|
92
|
-
const query = {
|
|
93
|
-
address, chainId: 1, schema: PayloadDivinerQuerySchema,
|
|
94
|
-
}
|
|
95
|
-
const result = await diviner?.divine([query])
|
|
96
|
-
expect(result).toBeDefined()
|
|
97
|
-
expect(result).toBeArrayOfSize(1)
|
|
98
|
-
})
|
|
99
|
-
})
|
|
100
|
-
})
|
|
101
|
-
})
|