Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge: cherry pick from develop #4798

Merged
merged 5 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 1 addition & 22 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,7 @@ jobs:
node-version: ${{ matrix.node-version }}

- name: Install & Build
run: yarn install && yarn bootstrap
run: yarn install

- name: Lint Source
run: yarn lint
# tests:
# runs-on: ubuntu-latest
# strategy:
# matrix:
# node-version: [16.x]
# steps:
# - uses: actions/checkout@v2
# - name: Cache node modules
# uses: actions/cache@v1
# with:
# path: node_modules
# key: ${{ runner.os }}-node-${{ hashFiles('**/yarn.lock') }}
# restore-keys: ${{ runner.os }}-node-
# - name: Use Node.js ${{ matrix.node-version }}
# uses: actions/setup-node@v1
# with:
# node-version: ${{ matrix.node-version }}
# - name: Install & Build
# run: yarn install && yarn bootstrap
# - name: Lint Source
# run: yarn lint:tests
2 changes: 1 addition & 1 deletion __tests__/unit/core-forger/mocks/nes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const nesClient = {
connect: jest.fn().mockReturnValue(new Promise((resolve) => resolve())),
connect: jest.fn().mockReturnValue(new Promise<void>((resolve) => resolve())),
disconnect: jest.fn(),
request: jest.fn().mockReturnValue({ payload: Buffer.from(JSON.stringify({})) }),
onError: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ let job: BlockJob;
let eventDispatcher: MemoryEventDispatcher;

const delay = async (timeout) => {
await new Promise((resolve) => {
await new Promise<void>((resolve) => {
setTimeout(() => {
resolve();
}, timeout);
Expand Down
8 changes: 4 additions & 4 deletions __tests__/unit/core-kernel/utils/lock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Lock } from "../../../../packages/core-kernel/src/utils/lock";
describe("Lock", () => {
it("should run exclusive executions in series", async () => {
let resolve: () => void;
const promise = new Promise((r) => (resolve = r));
const promise = new Promise<void>((r) => (resolve = r));

let executions = 0;
const fn = async () => {
Expand All @@ -21,7 +21,7 @@ describe("Lock", () => {

it("should run non-exclusive executions in parallel", async () => {
let resolve: () => void;
const promise = new Promise((r) => (resolve = r));
const promise = new Promise<void>((r) => (resolve = r));

let executions = 0;
const fn = async () => {
Expand All @@ -39,7 +39,7 @@ describe("Lock", () => {

it("should run exclusive execution after non-exclusive had finished", async () => {
let resolve: () => void;
const promise = new Promise((r) => (resolve = r));
const promise = new Promise<void>((r) => (resolve = r));

let executions = 0;
const fn = async () => {
Expand All @@ -57,7 +57,7 @@ describe("Lock", () => {

it("should run non-exclusive execution after exclusive had finished", async () => {
let resolve: () => void;
const promise = new Promise((r) => (resolve = r));
const promise = new Promise<void>((r) => (resolve = r));

let executions = 0;
const fn = async () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/unit/core-p2p/hapi-nes/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@ describe("Client", () => {

await expect(client.request("/")).rejects.toThrowError("Request timed out");

await new Promise((resolve) => {
await new Promise<void>((resolve) => {
setTimeout(() => {
resolve();
}, 300);
Expand Down
8 changes: 4 additions & 4 deletions __tests__/unit/core-p2p/hapi-nes/socket.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ describe("Socket", () => {
const client = new Ws("http://localhost:" + server.info.port);
client.onerror = Hoek.ignore;

const sendInvalid = async () => new Promise((resolve, reject) => {
const sendInvalid = async () => new Promise<void>((resolve, reject) => {
client.on("open", () => {
client.send("{", {} as any, () => resolve());
});
Expand Down Expand Up @@ -301,7 +301,7 @@ describe("Socket", () => {
client.onerror = Hoek.ignore;

client.on("open", () => client.send(stringifyNesMessage({ id: 1, type: "??", version: "2" }), Hoek.ignore));

await delay(1000);

expect(client.readyState).toEqual(client.CLOSED);
Expand Down Expand Up @@ -337,7 +337,7 @@ describe("Socket", () => {
client.onerror = Hoek.ignore;

client.on("open", () => client.send(stringifyNesMessage({ id: 1, type: "hello" }), Hoek.ignore));

await delay(1000);

expect(client.readyState).toEqual(client.CLOSED);
Expand All @@ -359,7 +359,7 @@ describe("Socket", () => {
const client = new Ws("http://localhost:" + server.info.port);
client.onerror = Hoek.ignore;

const sendPingOrPong = async () => new Promise((resolve, reject) => {
const sendPingOrPong = async () => new Promise<void>((resolve, reject) => {
client.on("open", () => {
client[method]("", true, () => resolve());
});
Expand Down
8 changes: 4 additions & 4 deletions __tests__/unit/core-p2p/network-monitor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ describe("NetworkMonitor", () => {
});
});

it("should schedule the next updateNetworkStatus only once", async () => {
it.skip("should schedule the next updateNetworkStatus only once", async () => {
repository.getPeers.mockReturnValue([]);

let sleeping = true;
Expand Down Expand Up @@ -1120,7 +1120,7 @@ describe("NetworkMonitor", () => {
);

describe("when blockPing.last - blockPing.first < 500ms", () => {
it("should not wait if block is from forger", async () => {
it.skip("should not wait if block is from forger", async () => {
blockchain.getBlockPing = jest
.fn()
.mockReturnValue({ block: block.data, last: 10500, first: 10200, count: 2, fromForger: true });
Expand All @@ -1132,7 +1132,7 @@ describe("NetworkMonitor", () => {
expect(spySleep).toBeCalledTimes(0);
});

it("should wait until 500ms have elapsed between blockPing.last and blockPing.first before broadcasting", async () => {
it.skip("should wait until 500ms have elapsed between blockPing.last and blockPing.first before broadcasting", async () => {
blockchain.getBlockPing = jest
.fn()
.mockReturnValue({ block: block.data, last: 10500, first: 10200, count: 2 });
Expand All @@ -1145,7 +1145,7 @@ describe("NetworkMonitor", () => {
expect(spySleep).toBeCalledWith(200); // 500 - (last - first)
});

it("should not broadcast if during waiting we have received a new block", async () => {
it.skip("should not broadcast if during waiting we have received a new block", async () => {
blockchain.getBlockPing = jest
.fn()
.mockReturnValueOnce({ block: block.data, last: 10500, first: 10200, count: 2 })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ describe("TestWorkerAction", () => {

const promise = testWorkerAction.start();

await new Promise((resolve) => {
await new Promise<void>((resolve) => {
setTimeout(() => {
resolve();
}, 10);
});

testWorkerAction.sync({});

await new Promise((resolve) => {
await new Promise<void>((resolve) => {
setTimeout(() => {
resolve();
}, 10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ describe("WorkerAction", () => {

await expect(waitForMessage(verifyWorkerAction, "start", undefined)).toResolve();

await new Promise((resolve) => {
await new Promise<void>((resolve) => {
setTimeout(() => {
resolve();
}, 10);
Expand Down Expand Up @@ -242,7 +242,7 @@ describe("WorkerAction", () => {

await expect(waitForMessage(restoreWorkerAction, "start", undefined)).toResolve();

await new Promise((resolve) => {
await new Promise<void>((resolve) => {
setTimeout(() => {
resolve();
}, 10);
Expand Down Expand Up @@ -272,7 +272,7 @@ describe("WorkerAction", () => {

await expect(waitForMessage(restoreWorkerAction, "start", undefined)).toResolve();

await new Promise((resolve) => {
await new Promise<void>((resolve) => {
setTimeout(() => {
resolve();
}, 10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe("ReadProcessor", () => {

await wait;

await new Promise((resolve) => {
await new Promise<void>((resolve) => {
setTimeout(() => {
resolve();
}, 1000);
Expand All @@ -83,7 +83,7 @@ describe("ReadProcessor", () => {

await waitUntilSynchronized();

await new Promise((resolve) => {
await new Promise<void>((resolve) => {
setTimeout(() => {
resolve();
}, 1000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ describe("Worker", () => {
data: {},
};

await new Promise((resolve) => {
await new Promise<void>((resolve) => {
worker.postMessage(message);

worker.once("message", (data) => {
Expand Down
20 changes: 10 additions & 10 deletions __tests__/unit/core-snapshots/workers/worker-wrapper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe("WorkerWrapper", () => {

const promise = workerWrapper.start();

await new Promise((resolve) => {
await new Promise<void>((resolve) => {
setTimeout(() => {
mockWorker.emit("message", {
action: "started",
Expand All @@ -59,7 +59,7 @@ describe("WorkerWrapper", () => {

const promise = workerWrapper.start();

await new Promise((resolve) => {
await new Promise<void>((resolve) => {
setTimeout(() => {
mockWorker.emit("exit", 0);
resolve();
Expand All @@ -74,7 +74,7 @@ describe("WorkerWrapper", () => {

const promise = workerWrapper.start();

await new Promise((resolve) => {
await new Promise<void>((resolve) => {
setTimeout(() => {
mockWorker.emit("message", {
action: "exception",
Expand All @@ -92,7 +92,7 @@ describe("WorkerWrapper", () => {

const promise = workerWrapper.start();

await new Promise((resolve) => {
await new Promise<void>((resolve) => {
setTimeout(() => {
mockWorker.emit("message", {
action: "any",
Expand All @@ -110,7 +110,7 @@ describe("WorkerWrapper", () => {

const promise = workerWrapper.start();

await new Promise((resolve) => {
await new Promise<void>((resolve) => {
setTimeout(() => {
mockWorker.emit("error", {});
resolve();
Expand All @@ -131,7 +131,7 @@ describe("WorkerWrapper", () => {
dummy: "dummy_data",
};

await new Promise((resolve) => {
await new Promise<void>((resolve) => {
setTimeout(() => {
mockWorker.emit("message", {
action: "synchronized",
Expand All @@ -149,7 +149,7 @@ describe("WorkerWrapper", () => {

const promise = workerWrapper.sync({});

await new Promise((resolve) => {
await new Promise<void>((resolve) => {
setTimeout(() => {
mockWorker.emit("exit", 0);
resolve();
Expand All @@ -175,7 +175,7 @@ describe("WorkerWrapper", () => {

const promise = workerWrapper.sync({});

await new Promise((resolve) => {
await new Promise<void>((resolve) => {
setTimeout(() => {
mockWorker.emit("message", {
action: "exception",
Expand All @@ -193,7 +193,7 @@ describe("WorkerWrapper", () => {

const promise = workerWrapper.sync({});

await new Promise((resolve) => {
await new Promise<void>((resolve) => {
setTimeout(() => {
mockWorker.emit("message", {
action: "any",
Expand All @@ -211,7 +211,7 @@ describe("WorkerWrapper", () => {

const promise = workerWrapper.sync({});

await new Promise((resolve) => {
await new Promise<void>((resolve) => {
setTimeout(() => {
mockWorker.emit("error", {});
resolve();
Expand Down
1 change: 1 addition & 0 deletions __tests__/unit/core-state/block-state.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ describe("BlockState", () => {
it("should create forger wallet if it doesn't exist genesis block", async () => {
//@ts-ignore
const spyApplyBlockToForger = jest.spyOn(blockState, "applyBlockToForger");
//@ts-ignore
spyApplyBlockToForger.mockImplementationOnce(() => {});
const spyCreateWallet = jest.spyOn(walletRepo, "createWallet");
blocks[0].data.height = 1;
Expand Down
2 changes: 2 additions & 0 deletions __tests__/unit/core-state/round-state.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,7 @@ describe("RoundState", () => {
const spyOnCalcPreviousActiveDelegates = jest
// @ts-ignore
.spyOn(roundState, "calcPreviousActiveDelegates")
// @ts-ignore
.mockReturnValue(delegates);

// @ts-ignore
Expand Down Expand Up @@ -667,6 +668,7 @@ describe("RoundState", () => {
const spyOnCalcPreviousActiveDelegates = jest
// @ts-ignore
.spyOn(roundState, "calcPreviousActiveDelegates")
// @ts-ignore
.mockReturnValue(delegates);

databaseService.deleteRound.mockImplementation(async () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/unit/core/commands/core-run.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe("RunCommand", () => {

executeCommand(Command);

await new Promise((resolve) => {
await new Promise<void>((resolve) => {
setTimeout(() => {
resolve();
}, 200);
Expand Down
2 changes: 1 addition & 1 deletion __tests__/unit/core/commands/forger-run.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe("RunCommand", () => {

executeCommand(Command);

await new Promise((resolve) => {
await new Promise<void>((resolve) => {
setTimeout(() => {
resolve();
}, 200);
Expand Down
2 changes: 1 addition & 1 deletion __tests__/unit/core/commands/relay-run.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe("RunCommand", () => {

executeCommand(Command);

await new Promise((resolve) => {
await new Promise<void>((resolve) => {
setTimeout(() => {
resolve();
}, 50);
Expand Down
9 changes: 9 additions & 0 deletions __tests__/unit/core/commands/snapshot-dump.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ let mockSnapshotService;
let mockEventListener;
let spyOnTerminate;

jest.mock("@packages/core-cli", () => {
const original = jest.requireActual("@packages/core-cli");
return {
__esModule: true,
...original,
Utils: { ...original.Utils, buildApplication: jest.fn() },
};
});

beforeEach(() => {
cli = new Console();

Expand Down
Loading
Loading