Skip to content

Commit

Permalink
Merge pull request #375 from kleros/chore/initialize-relayer-testing
Browse files Browse the repository at this point in the history
test(relayer): adds initial testing base
  • Loading branch information
mani99brar authored Dec 13, 2024
2 parents 1f6c3dd + 2f4cdb7 commit cbfe0a3
Show file tree
Hide file tree
Showing 8 changed files with 2,105 additions and 437 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"es6": true,
"node": true,
"mocha": true,
"es2020": true
"es2020": true,
"jest": true
},
"extends": [
"eslint:recommended",
Expand Down
1 change: 1 addition & 0 deletions relayer-cli/.gitconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
coverage
10 changes: 10 additions & 0 deletions relayer-cli/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { Config } from "jest";

const config: Config = {
preset: "ts-jest",
testEnvironment: "node",
collectCoverage: true,
collectCoverageFrom: ["**/*.ts"],
};

export default config;
4 changes: 4 additions & 0 deletions relayer-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"yarn": "4.2.2"
},
"scripts": {
"test": "jest --coverage",
"start-devnet-relayer": "npx ts-node ./src/devnetRelayExample.ts",
"start-testnet-relayer": "npx ts-node ./src/testnetRelayer.ts"
},
Expand All @@ -23,6 +24,9 @@
"web3-batched-send": "^1.0.3"
},
"devDependencies": {
"@types/jest": "^29.5.14",
"jest": "^29.7.0",
"ts-jest": "^29.2.5",
"ts-node": "^10.9.2"
}
}
17 changes: 1 addition & 16 deletions relayer-cli/src/utils/relayerHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
import * as fs from "fs";

class ShutdownManager {
private isShuttingDown: boolean;

constructor(initialState: boolean = false) {
this.isShuttingDown = initialState;
}

public getIsShuttingDown(): boolean {
return this.isShuttingDown;
}

public triggerShutdown() {
this.isShuttingDown = true;
}
}
import ShutdownManager from "./shutdownManager";

async function initialize(chainId: number, network: string): Promise<number> {
const lockFileName = "./state/" + network + "_" + chainId + ".pid";
Expand Down
36 changes: 36 additions & 0 deletions relayer-cli/src/utils/shutdownManager.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import ShutdownManager from "./shutdownManager";

describe("ShutdownManager", () => {
describe("constructor", () => {
it("should create a new instance", () => {
const instance = new ShutdownManager();
expect(instance).toBeInstanceOf(ShutdownManager);
});

it("should set isShuttingDown to the provided value", () => {
const instance = new ShutdownManager(true);
expect(instance["isShuttingDown"]).toBe(true);
});

it("should set isShuttingDown to false if no value is provided", () => {
const instance = new ShutdownManager();
expect(instance["isShuttingDown"]).toBe(false);
});
});

describe("getIsShuttingDown", () => {
it("should return true when isShuttingDown is true", () => {
const instance = new ShutdownManager(true);
expect(instance.getIsShuttingDown()).toBe(true);
});

it("should return false when isShuttingDown is false", () => {
const instance = new ShutdownManager(false);
expect(instance.getIsShuttingDown()).toBe(false);
});
});

describe("triggerShutdown", () => {
it.todo("should set isShuttingDown to true");
});
});
15 changes: 15 additions & 0 deletions relayer-cli/src/utils/shutdownManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export default class ShutdownManager {
private isShuttingDown: boolean;

constructor(initialState: boolean = false) {
this.isShuttingDown = initialState;
}

public getIsShuttingDown(): boolean {
return this.isShuttingDown;
}

public triggerShutdown() {
this.isShuttingDown = true;
}
}
Loading

0 comments on commit cbfe0a3

Please sign in to comment.