Skip to content

Commit 46bc977

Browse files
committed
Fix old test framework
1 parent ae15a41 commit 46bc977

File tree

6 files changed

+272
-275
lines changed

6 files changed

+272
-275
lines changed

codegenerator/cli/npm/envio/src/ChainFetcher.res

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -202,27 +202,27 @@ let make = (
202202
let sources = switch chainConfig.sourceConfig {
203203
| Config.EvmSourceConfig({hypersync, rpcs}) =>
204204
// Build Internal.evmContractConfig from contracts for EvmChain.makeSources
205-
let evmContracts: array<Internal.evmContractConfig> =
206-
chainConfig.contracts->Array.map((contract): Internal.evmContractConfig => {
207-
name: contract.name,
208-
abi: contract.abi,
209-
events: contract.events->(
210-
Utils.magic: array<Internal.eventConfig> => array<Internal.evmEventConfig>
211-
),
212-
})
205+
let evmContracts: array<Internal.evmContractConfig> = chainConfig.contracts->Array.map((
206+
contract
207+
): Internal.evmContractConfig => {
208+
name: contract.name,
209+
abi: contract.abi,
210+
events: contract.events->(
211+
Utils.magic: array<Internal.eventConfig> => array<Internal.evmEventConfig>
212+
),
213+
})
213214
// Collect all event signatures from contracts
214215
let allEventSignatures =
215216
chainConfig.contracts->Array.flatMap(contract => contract.eventSignatures)
216217
// Convert rpcs to EvmChain.rpc format
217-
let evmRpcs: array<EvmChain.rpc> =
218-
rpcs->Array.map((rpc): EvmChain.rpc => {
219-
let syncConfig = rpc.syncConfig
220-
{
221-
url: rpc.url,
222-
sourceFor: rpc.sourceFor,
223-
?syncConfig,
224-
}
225-
})
218+
let evmRpcs: array<EvmChain.rpc> = rpcs->Array.map((rpc): EvmChain.rpc => {
219+
let syncConfig = rpc.syncConfig
220+
{
221+
url: rpc.url,
222+
sourceFor: rpc.sourceFor,
223+
?syncConfig,
224+
}
225+
})
226226
EvmChain.makeSources(
227227
~chain,
228228
~contracts=evmContracts,
@@ -264,7 +264,13 @@ let make = (
264264
}
265265
}
266266

267-
let makeFromConfig = (chainConfig: Config.chain, ~config, ~registrations, ~targetBufferSize) => {
267+
let makeFromConfig = (
268+
chainConfig: Config.chain,
269+
~config,
270+
~registrations,
271+
~targetBufferSize,
272+
~knownHeight,
273+
) => {
268274
let logger = Logging.createChild(~params={"chainId": chainConfig.id})
269275

270276
make(
@@ -284,6 +290,7 @@ let makeFromConfig = (chainConfig: Config.chain, ~config, ~registrations, ~targe
284290
~logger,
285291
~dynamicContracts=[],
286292
~isInReorgThreshold=false,
293+
~knownHeight,
287294
)
288295
}
289296

codegenerator/cli/npm/envio/src/ChainManager.res

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,6 @@ let calculateTargetBufferSize = (~activeChainsCount) => {
3030
}
3131
}
3232

33-
let makeFromConfig = (~config: Config.t, ~registrations): t => {
34-
let targetBufferSize = calculateTargetBufferSize(
35-
~activeChainsCount=config.chainMap->ChainMap.size,
36-
)
37-
let chainFetchers =
38-
config.chainMap->ChainMap.map(
39-
ChainFetcher.makeFromConfig(_, ~config, ~registrations, ~targetBufferSize),
40-
)
41-
{
42-
committedCheckpointId: 0.,
43-
chainFetchers,
44-
multichain: config.multichain,
45-
isInReorgThreshold: false,
46-
}
47-
}
48-
4933
let makeFromDbState = async (
5034
~initialState: Persistence.initialState,
5135
~config: Config.t,

codegenerator/cli/npm/envio/src/FetchState.res

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ the are getting merged until the maxAddrInPartition is reached.
2929
*/
3030
type partition = {
3131
id: string,
32+
// The block number of the latest fetched query
33+
// which added all its events to the queue
3234
latestFetchedBlock: blockNumberAndTimestamp,
3335
selection: selection,
3436
addressesByContractName: dict<array<Address.t>>,
@@ -414,6 +416,7 @@ module OptimizedPartitions = {
414416
)
415417
}
416418

419+
@inline
417420
let getLatestFullyFetchedBlock = (optimizedPartitions: t) => {
418421
switch optimizedPartitions.idsInAscOrder->Array.get(0) {
419422
| Some(id) => Some((optimizedPartitions.entities->Js.Dict.unsafeGet(id)).latestFetchedBlock)
@@ -433,9 +436,6 @@ type t = {
433436
contractConfigs: dict<contractConfig>,
434437
// Not used for logic - only metadata
435438
chainId: int,
436-
// The block number of the latest block fetched
437-
// which added all its events to the queue
438-
latestFullyFetchedBlock: blockNumberAndTimestamp,
439439
// The block number of the latest block which was added to the queue
440440
// by the onBlock configs
441441
// Need a separate pointer for this
@@ -454,23 +454,34 @@ type t = {
454454
}
455455

456456
@inline
457-
let bufferBlockNumber = ({latestFullyFetchedBlock, latestOnBlockBlockNumber}: t) => {
458-
latestOnBlockBlockNumber < latestFullyFetchedBlock.blockNumber
459-
? latestOnBlockBlockNumber
460-
: latestFullyFetchedBlock.blockNumber
457+
let bufferBlockNumber = ({latestOnBlockBlockNumber, optimizedPartitions}: t) => {
458+
switch optimizedPartitions->OptimizedPartitions.getLatestFullyFetchedBlock {
459+
| None => latestOnBlockBlockNumber
460+
| Some(latestFullyFetchedBlock) =>
461+
latestOnBlockBlockNumber < latestFullyFetchedBlock.blockNumber
462+
? latestOnBlockBlockNumber
463+
: latestFullyFetchedBlock.blockNumber
464+
}
461465
}
462466

463467
/**
464468
* Returns the latest block which is ready to be consumed
465469
*/
466470
@inline
467-
let bufferBlock = ({latestFullyFetchedBlock, latestOnBlockBlockNumber}: t) => {
468-
latestOnBlockBlockNumber < latestFullyFetchedBlock.blockNumber
469-
? {
470-
blockNumber: latestOnBlockBlockNumber,
471-
blockTimestamp: 0,
472-
}
473-
: latestFullyFetchedBlock
471+
let bufferBlock = ({optimizedPartitions, latestOnBlockBlockNumber}: t) => {
472+
switch optimizedPartitions->OptimizedPartitions.getLatestFullyFetchedBlock {
473+
| None => {
474+
blockNumber: latestOnBlockBlockNumber,
475+
blockTimestamp: 0,
476+
}
477+
| Some(latestFullyFetchedBlock) =>
478+
latestOnBlockBlockNumber < latestFullyFetchedBlock.blockNumber
479+
? {
480+
blockNumber: latestOnBlockBlockNumber,
481+
blockTimestamp: 0,
482+
}
483+
: latestFullyFetchedBlock
484+
}
474485
}
475486

476487
/*
@@ -502,21 +513,10 @@ let updateInternal = (
502513
~blockLag=fetchState.blockLag,
503514
~knownHeight=fetchState.knownHeight,
504515
): t => {
505-
let latestFullyFetchedBlock = switch optimizedPartitions->OptimizedPartitions.getLatestFullyFetchedBlock {
506-
| Some(latestFullyFetchedBlock) => latestFullyFetchedBlock
507-
| None => {
508-
blockNumber: knownHeight,
509-
// The case is only possible when using only block handlers
510-
// so it's fine to have a zero timestamp
511-
// since we don't support ordered multichain mode anyways
512-
blockTimestamp: 0,
513-
}
514-
}
515-
516516
let mutItemsRef = ref(mutItems)
517517

518518
let latestOnBlockBlockNumber = switch fetchState.onBlockConfigs {
519-
| [] => latestFullyFetchedBlock.blockNumber
519+
| [] => knownHeight
520520
| onBlockConfigs => {
521521
// Calculate the max block number we are going to create items for
522522
// Use targetBufferSize to get the last target item in the buffer
@@ -530,7 +530,11 @@ let updateInternal = (
530530
| None => fetchState.buffer
531531
}->Belt.Array.get(fetchState.targetBufferSize - 1) {
532532
| Some(item) => item->Internal.getItemBlockNumber
533-
| None => latestFullyFetchedBlock.blockNumber
533+
| None =>
534+
switch optimizedPartitions->OptimizedPartitions.getLatestFullyFetchedBlock {
535+
| None => knownHeight
536+
| Some(latestFullyFetchedBlock) => latestFullyFetchedBlock.blockNumber
537+
}
534538
}
535539

536540
let mutItems = switch mutItemsRef.contents {
@@ -595,7 +599,6 @@ let updateInternal = (
595599
targetBufferSize: fetchState.targetBufferSize,
596600
optimizedPartitions,
597601
latestOnBlockBlockNumber,
598-
latestFullyFetchedBlock,
599602
indexingContracts,
600603
blockLag,
601604
knownHeight,
@@ -1388,7 +1391,6 @@ let make = (
13881391
chainId,
13891392
startBlock,
13901393
endBlock,
1391-
latestFullyFetchedBlock: latestFetchedBlock,
13921394
latestOnBlockBlockNumber: progressBlockNumber,
13931395
normalSelection,
13941396
indexingContracts,

codegenerator/cli/templates/dynamic/codegen/src/TestHelpers_MockDb.res.hbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ and makeProcessEvents = (mockDb: t, ~chainId=?) => async (
394394
~config,
395395
~registrations=ctx.registrations,
396396
~targetBufferSize=5000,
397+
~knownHeight=latestFetchedBlockNumber.contents,
397398
)
398399

399400
//Deep copy the data in mockDb, mutate the clone and return the clone

0 commit comments

Comments
 (0)