Skip to content

Commit cbfe0a3

Browse files
authored
Merge pull request #375 from kleros/chore/initialize-relayer-testing
test(relayer): adds initial testing base
2 parents 1f6c3dd + 2f4cdb7 commit cbfe0a3

File tree

8 files changed

+2105
-437
lines changed

8 files changed

+2105
-437
lines changed

.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"es6": true,
88
"node": true,
99
"mocha": true,
10-
"es2020": true
10+
"es2020": true,
11+
"jest": true
1112
},
1213
"extends": [
1314
"eslint:recommended",

relayer-cli/.gitconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
coverage

relayer-cli/jest.config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type { Config } from "jest";
2+
3+
const config: Config = {
4+
preset: "ts-jest",
5+
testEnvironment: "node",
6+
collectCoverage: true,
7+
collectCoverageFrom: ["**/*.ts"],
8+
};
9+
10+
export default config;

relayer-cli/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"yarn": "4.2.2"
1111
},
1212
"scripts": {
13+
"test": "jest --coverage",
1314
"start-devnet-relayer": "npx ts-node ./src/devnetRelayExample.ts",
1415
"start-testnet-relayer": "npx ts-node ./src/testnetRelayer.ts"
1516
},
@@ -23,6 +24,9 @@
2324
"web3-batched-send": "^1.0.3"
2425
},
2526
"devDependencies": {
27+
"@types/jest": "^29.5.14",
28+
"jest": "^29.7.0",
29+
"ts-jest": "^29.2.5",
2630
"ts-node": "^10.9.2"
2731
}
2832
}

relayer-cli/src/utils/relayerHelpers.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
11
import * as fs from "fs";
2-
3-
class ShutdownManager {
4-
private isShuttingDown: boolean;
5-
6-
constructor(initialState: boolean = false) {
7-
this.isShuttingDown = initialState;
8-
}
9-
10-
public getIsShuttingDown(): boolean {
11-
return this.isShuttingDown;
12-
}
13-
14-
public triggerShutdown() {
15-
this.isShuttingDown = true;
16-
}
17-
}
2+
import ShutdownManager from "./shutdownManager";
183

194
async function initialize(chainId: number, network: string): Promise<number> {
205
const lockFileName = "./state/" + network + "_" + chainId + ".pid";
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import ShutdownManager from "./shutdownManager";
2+
3+
describe("ShutdownManager", () => {
4+
describe("constructor", () => {
5+
it("should create a new instance", () => {
6+
const instance = new ShutdownManager();
7+
expect(instance).toBeInstanceOf(ShutdownManager);
8+
});
9+
10+
it("should set isShuttingDown to the provided value", () => {
11+
const instance = new ShutdownManager(true);
12+
expect(instance["isShuttingDown"]).toBe(true);
13+
});
14+
15+
it("should set isShuttingDown to false if no value is provided", () => {
16+
const instance = new ShutdownManager();
17+
expect(instance["isShuttingDown"]).toBe(false);
18+
});
19+
});
20+
21+
describe("getIsShuttingDown", () => {
22+
it("should return true when isShuttingDown is true", () => {
23+
const instance = new ShutdownManager(true);
24+
expect(instance.getIsShuttingDown()).toBe(true);
25+
});
26+
27+
it("should return false when isShuttingDown is false", () => {
28+
const instance = new ShutdownManager(false);
29+
expect(instance.getIsShuttingDown()).toBe(false);
30+
});
31+
});
32+
33+
describe("triggerShutdown", () => {
34+
it.todo("should set isShuttingDown to true");
35+
});
36+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export default class ShutdownManager {
2+
private isShuttingDown: boolean;
3+
4+
constructor(initialState: boolean = false) {
5+
this.isShuttingDown = initialState;
6+
}
7+
8+
public getIsShuttingDown(): boolean {
9+
return this.isShuttingDown;
10+
}
11+
12+
public triggerShutdown() {
13+
this.isShuttingDown = true;
14+
}
15+
}

0 commit comments

Comments
 (0)