-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsetup.ts
More file actions
82 lines (76 loc) · 2.31 KB
/
setup.ts
File metadata and controls
82 lines (76 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import { vi } from "vitest";
import type { Address, ChainId, Hex, ILogger } from "@grants-stack-indexer/shared";
import { type IIndexerClient } from "@grants-stack-indexer/indexer-client";
import { IEventRegistryRepository } from "@grants-stack-indexer/repository";
import { ExponentialBackoff } from "@grants-stack-indexer/shared";
import { CoreDependencies, IStrategyRegistry } from "../../../src/internal.js";
import { Orchestrator } from "../../../src/orchestrator.js";
import {
createMockIndexerClient,
createMockProviders,
createMockRegistries,
createMockRepositories,
DEFAULT_STRATEGY_MAP,
} from "./dependencies.js";
export const createTestOrchestrator = (
config: {
chainId: ChainId;
strategiesMap: Map<ChainId, Map<Address, Hex>>;
} = { chainId: 1 as ChainId, strategiesMap: DEFAULT_STRATEGY_MAP },
): {
orchestrator: Orchestrator;
mocks: {
dependencies: CoreDependencies;
indexerClient: IIndexerClient;
registries: {
eventsRegistry: IEventRegistryRepository;
strategyRegistry: IStrategyRegistry;
};
logger: ILogger;
};
} => {
const repositories = createMockRepositories();
const providers = createMockProviders();
const mockNotifier = {
send: vi.fn(),
};
const mockLogger = {
info: vi.fn(),
error: vi.fn(),
warn: vi.fn(),
debug: vi.fn(),
verbose: vi.fn(),
};
const mockIndexerClient = createMockIndexerClient();
const { eventsRegistry, strategyRegistry } = createMockRegistries(config.strategiesMap);
const dependencies: CoreDependencies = {
...repositories,
...providers,
};
const orchestrator = new Orchestrator(
config.chainId,
dependencies,
mockIndexerClient,
{
eventsRegistry,
strategyRegistry,
},
1000,
0, // No delay in tests
new ExponentialBackoff({ baseDelay: 10, factor: 2, maxAttempts: 1 }),
mockLogger,
mockNotifier,
);
return {
orchestrator,
mocks: {
dependencies,
logger: mockLogger,
indexerClient: mockIndexerClient,
registries: {
eventsRegistry,
strategyRegistry,
},
},
};
};