2023-11-28 11:00:45 -08:00
|
|
|
import { beforeEach, describe, expect, it } from "@jest/globals";
|
|
|
|
import fs from "fs";
|
|
|
|
import { SnsEventRepository, StaticJobRepository } from "../../../src/infrastructure/repositories";
|
|
|
|
import {
|
|
|
|
EvmBlockRepository,
|
|
|
|
MetadataRepository,
|
2023-11-30 07:05:43 -08:00
|
|
|
SolanaSlotRepository,
|
2023-11-28 11:00:45 -08:00
|
|
|
StatRepository,
|
|
|
|
} from "../../../src/domain/repositories";
|
|
|
|
|
|
|
|
const dirPath = "./metadata-repo/jobs";
|
|
|
|
const blockRepo: EvmBlockRepository = {} as any as EvmBlockRepository;
|
|
|
|
const metadataRepo = {} as MetadataRepository<any>;
|
|
|
|
const statsRepo = {} as any as StatRepository;
|
|
|
|
const snsRepo = {} as any as SnsEventRepository;
|
2023-11-30 07:05:43 -08:00
|
|
|
const solanaSlotRepo = {} as any as SolanaSlotRepository;
|
2023-11-28 11:00:45 -08:00
|
|
|
|
|
|
|
let repo: StaticJobRepository;
|
|
|
|
|
|
|
|
describe("StaticJobRepository", () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
if (fs.existsSync(dirPath)) {
|
|
|
|
fs.rmSync(dirPath, { recursive: true, force: true });
|
|
|
|
}
|
2023-12-22 12:50:38 -08:00
|
|
|
repo = new StaticJobRepository("testnet", dirPath, false, () => blockRepo, {
|
2023-11-28 11:00:45 -08:00
|
|
|
metadataRepo,
|
|
|
|
statsRepo,
|
|
|
|
snsRepo,
|
2023-11-30 07:05:43 -08:00
|
|
|
solanaSlotRepo,
|
2023-11-28 11:00:45 -08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should return empty when no file available", async () => {
|
|
|
|
const jobs = await repo.getJobDefinitions();
|
|
|
|
expect(jobs).toHaveLength(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should read jobs from file", async () => {
|
|
|
|
givenJobsPresent();
|
|
|
|
const jobs = await repo.getJobDefinitions();
|
|
|
|
expect(jobs).toHaveLength(1);
|
|
|
|
expect(jobs[0].id).toEqual("poll-log-message-published-ethereum");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
const givenJobsPresent = () => {
|
|
|
|
const jobs = [
|
|
|
|
{
|
|
|
|
id: "poll-log-message-published-ethereum",
|
|
|
|
chain: "ethereum",
|
|
|
|
source: {
|
2023-12-22 12:50:38 -08:00
|
|
|
action: "PollEvm",
|
2023-11-28 11:00:45 -08:00
|
|
|
config: {
|
|
|
|
fromBlock: 10012499n,
|
|
|
|
blockBatchSize: 100,
|
|
|
|
commitment: "latest",
|
|
|
|
interval: 15_000,
|
|
|
|
addresses: ["0x706abc4E45D419950511e474C7B9Ed348A4a716c"],
|
|
|
|
chain: "ethereum",
|
|
|
|
topics: [],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
handlers: [
|
|
|
|
{
|
|
|
|
action: "HandleEvmLogs",
|
|
|
|
target: "sns",
|
|
|
|
mapper: "evmLogMessagePublishedMapper",
|
|
|
|
config: {
|
|
|
|
abi: "event LogMessagePublished(address indexed sender, uint64 sequence, uint32 nonce, bytes payload, uint8 consistencyLevel)",
|
|
|
|
filter: {
|
|
|
|
addresses: ["0x706abc4E45D419950511e474C7B9Ed348A4a716c"],
|
|
|
|
topics: ["0x6eb224fb001ed210e379b335e35efe88672a8ce935d981a6896b27ffdf52a3b2"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
];
|
|
|
|
fs.writeFileSync(dirPath + "/jobs.json", JSON.stringify(jobs));
|
|
|
|
};
|