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

test(core-forger): Extend tests with a block with full sha256 id #2235

Merged
merged 1 commit into from
Mar 13, 2019
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
19 changes: 0 additions & 19 deletions __tests__/integration/core-forger/__fixtures__/block.ts

This file was deleted.

35 changes: 35 additions & 0 deletions __tests__/integration/core-forger/__fixtures__/blocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { models } from "@arkecosystem/crypto";

export const sampleBlocks = [ new models.Block({
id: "7686497416922799951",
version: 0,
timestamp: 62225384,
height: 1760011,
previousBlock: "1111111111111111111",
numberOfTransactions: 0,
totalAmount: 0,
totalFee: 0,
reward: 200000000,
payloadLength: 0,
payloadHash: "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
generatorPublicKey: "03287bfebba4c7881a0509717e71b34b63f31e40021c321f89ae04f84be6d6ac37",
blockSignature:
// tslint:disable-next-line:max-line-length
"304402205b5da8a3cfb28398baaa50e299d735226c4455bdfdf5cb650afb53b0f22a93c60220572c4a4652edcd1bb85720884a7b0732add4dd50e7a0984325807770c99939bd",
}), new models.Block({
id: "341e8008227a887b2f658f9071118ebe73720b7b8f58d2ae3d24ae933888f6d7",
version: 0,
timestamp: 62376432,
height: 1000000001,
previousBlock: "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
numberOfTransactions: 0,
totalAmount: 0,
totalFee: 0,
reward: 200000000,
payloadLength: 0,
payloadHash: "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
generatorPublicKey: "03287bfebba4c7881a0509717e71b34b63f31e40021c321f89ae04f84be6d6ac37",
blockSignature:
// tslint:disable-next-line:max-line-length
"3045022100afa57d28e227720b166d46c443e7a6c810c2442f4a00f4405258fd73d3806b7b02206f65bc93679f753d840fb5b168b04512aed9bb039f98178ce6b6237b65a8d9cf",
})];
40 changes: 21 additions & 19 deletions __tests__/integration/core-forger/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { httpie } from "@arkecosystem/core-utils";
import "jest-extended";
import nock from "nock";
import { Client } from "../../../packages/core-forger/src/client";
import { sampleBlock } from "./__fixtures__/block";
import { sampleBlocks } from "./__fixtures__/blocks";

jest.setTimeout(30000);

Expand Down Expand Up @@ -38,24 +38,26 @@ describe("Client", () => {

describe("broadcast", () => {
describe("when the host is available", () => {
it("should be truthy if broadcasts", async () => {
nock(host)
.post("/internal/blocks")
.reply(200, (_, requestBody) => {
expect(requestBody.block).toMatchObject(
expect.objectContaining({
id: sampleBlock.data.id,
}),
);

return requestBody;
});

await client.__chooseHost();

const wasBroadcasted = await client.broadcast(sampleBlock.toJson());
expect(wasBroadcasted).toBeTruthy();
});
for (const sampleBlock of sampleBlocks) {
it("should be truthy if broadcasts", async () => {
nock(host)
.post("/internal/blocks")
.reply(200, (_, requestBody) => {
expect(requestBody.block).toMatchObject(
expect.objectContaining({
id: sampleBlock.data.id,
}),
);

return requestBody;
});

await client.__chooseHost();

const wasBroadcasted = await client.broadcast(sampleBlock.toJson());
expect(wasBroadcasted).toBeTruthy();
});
}
});
});

Expand Down