Skip to content

Commit

Permalink
Merge remote-tracking branch 'ArkEcosystem/core/develop' into db-roun…
Browse files Browse the repository at this point in the history
…ds-id

* ArkEcosystem/core/develop:
  test(core-api): /node/fees endpoint (#2738)
  test(core-api): /node/configuration/crypto endpoint (#2737)
  test(core-api): test /transactions/fees and /blockchain endpoints (#2736)
  refactor(core-wallet-api): respect the whitelist of the public API (#2718)
  test(core-api): transformer service and 404 assertions (#2735)
  fix(core): check for user confirmation in snapshot commands (#2734)
  fix(core-p2p): off-by-one error when fetching blocks from peer (#2733)
  • Loading branch information
vasild committed Jun 21, 2019
2 parents 632425b + fd2d056 commit af10936
Show file tree
Hide file tree
Showing 42 changed files with 548 additions and 497 deletions.
21 changes: 21 additions & 0 deletions __tests__/integration/core-api/handlers/blockchain.test.ts
@@ -0,0 +1,21 @@
import "../../../utils";

import { setUp, tearDown } from "../__support__/setup";
import { utils } from "../utils";

beforeAll(async () => await setUp());
afterAll(async () => await tearDown());

describe("API 2.0 - Blockchain", () => {
describe("GET /blockchain", () => {
it("should GET the blockchain info", async () => {
const response = await utils.request("GET", "blockchain");
expect(response).toBeSuccessfulResponse();
expect(response.data.data).toBeObject();

expect(response.data.data.block.height).toBeNumber();
expect(response.data.data.block.id).toBeString();
expect(response.data.data.supply).toBeNumber();
});
});
});
18 changes: 17 additions & 1 deletion __tests__/integration/core-api/handlers/blocks.test.ts
Expand Up @@ -117,6 +117,10 @@ describe("API 2.0 - Blocks", () => {
"304402202fe5de5697fa25d3d3c0cb24617ac02ddfb1c915ee9194a89f8392f948c6076402200d07c5244642fe36afa53fb2d048735f1adfa623e8fa4760487e5f72e17d253b",
});
});

it("should fail to GET a block by the given identifier if it doesn't exist", async () => {
utils.expectError(await utils.request("GET", "blocks/27184958558311101492"), 404);
});
});

describe("GET /blocks/:height", () => {
Expand All @@ -133,6 +137,10 @@ describe("API 2.0 - Blocks", () => {
transactions: genesisBlock.numberOfTransactions,
});
});

it("should fail to GET a block by the given identifier if it doesn't exist", async () => {
utils.expectError(await utils.request("GET", "blocks/111111"), 404);
});
});

describe("GET /blocks/:id/transactions", () => {
Expand All @@ -145,10 +153,14 @@ describe("API 2.0 - Blocks", () => {
utils.expectTransaction(transaction);
expect(transaction.blockId).toBe(genesisBlock.id);
});

it("should fail to GET all the transactions for the given block by id if it doesn't exist", async () => {
utils.expectError(await utils.request("GET", "blocks/27184958558311101492/transactions"), 404);
});
});

describe("GET /blocks/:height/transactions", () => {
it("should GET all the transactions for the given block by id", async () => {
it("should GET all the transactions for the given block by height", async () => {
const response = await utils.request("GET", `blocks/${genesisBlock.height}/transactions`);
expect(response).toBeSuccessfulResponse();
expect(response.data.data).toBeArray();
Expand All @@ -157,6 +169,10 @@ describe("API 2.0 - Blocks", () => {
utils.expectTransaction(transaction);
expect(transaction.blockId).toBe(genesisBlock.id);
});

it("should fail to GET all the transactions for the given block by height if it doesn't exist", async () => {
utils.expectError(await utils.request("GET", "blocks/111111/transactions"), 404);
});
});

describe("POST /blocks/search", () => {
Expand Down
12 changes: 12 additions & 0 deletions __tests__/integration/core-api/handlers/delegates.test.ts
Expand Up @@ -139,6 +139,10 @@ describe("API 2.0 - Delegates", () => {
utils.expectDelegate(response.data.data);
expect(response.data.data.publicKey).toEqual(delegate.publicKey);
});

it("should fail to GET a delegate by the given identifier if it doesn't exist", async () => {
utils.expectError(await utils.request("GET", "delegates/fake_username"), 404);
});
});

describe("POST /delegates/search", () => {
Expand Down Expand Up @@ -444,6 +448,10 @@ describe("API 2.0 - Delegates", () => {

await databaseService.deleteBlocks([block2.data]); // reset to genesis block
});

it("should fail to GET a delegate by the given identifier if it doesn't exist", async () => {
utils.expectError(await utils.request("GET", "delegates/fake_username/blocks"), 404);
});
});

describe("GET /delegates/:id/voters", () => {
Expand All @@ -470,5 +478,9 @@ describe("API 2.0 - Delegates", () => {

expect(response.data.data.sort((a, b) => a.balance < b.balance)).toEqual(response.data.data);
});

it("should fail to GET a delegate by the given identifier if it doesn't exist", async () => {
utils.expectError(await utils.request("GET", "delegates/fake_username/voters"), 404);
});
});
});
19 changes: 19 additions & 0 deletions __tests__/integration/core-api/handlers/node.test.ts
@@ -1,6 +1,7 @@
import "../../../utils";

import { app } from "@arkecosystem/core-container";
import { Managers } from "@arkecosystem/crypto";
import { setUp, tearDown } from "../__support__/setup";
import { utils } from "../utils";

Expand Down Expand Up @@ -58,4 +59,22 @@ describe("API 2.0 - Loader", () => {
app.resolveOptions("transaction-pool").dynamicFees.enabled = true;
});
});

describe("GET /node/configuration/crypto", () => {
it("should GET the node crypto configuration", async () => {
const response = await utils.request("GET", "node/configuration/crypto");
expect(response).toBeSuccessfulResponse();
expect(response.data.data).toBeObject();
expect(response.data.data).toEqual(Managers.configManager.getPreset("testnet"));
});
});

describe("GET /node/fees", () => {
it("should GET the node fees", async () => {
const response = await utils.request("GET", "node/fees", { days: 14 });
expect(response).toBeSuccessfulResponse();
expect(response.data.meta.days).toBe(14);
expect(response.data.data).toBeArray();
});
});
});
4 changes: 4 additions & 0 deletions __tests__/integration/core-api/handlers/peers.test.ts
Expand Up @@ -75,5 +75,9 @@ describe("API 2.0 - Peers", () => {
expect(response.data.data.ip).toBe(peers[0].ip);
expect(response.data.data.port).toBe(peers[0].port);
});

it("should fail to GET a peer by the given ip if it doesn't exist", async () => {
utils.expectError(await utils.request("GET", "peers/127.0.0.1"), 404);
});
});
});
39 changes: 39 additions & 0 deletions __tests__/integration/core-api/handlers/transactions.test.ts
Expand Up @@ -107,6 +107,16 @@ describe("API 2.0 - Transactions", () => {
id: "8816f8d8c257ea0c951deba911266394b0f2614df023f8b4ffd9da43d36efd9d",
});
});

it("should fail to GET a transaction by the given identifier if it doesn't exist", async () => {
utils.expectError(
await utils.request(
"GET",
"transactions/9816f8d8c257ea0c951deba911266394b0f2614df023f8b4ffd9da43d36efd9d",
),
404,
);
});
});

describe("GET /transactions/unconfirmed", () => {
Expand All @@ -129,6 +139,16 @@ describe("API 2.0 - Transactions", () => {
expect(response.data.data).toBeObject();
expect(response.data.data).toHaveProperty("id", transaction.id);
});

it("should fail to GET a transaction by the given identifier if it doesn't exist", async () => {
utils.expectError(
await utils.request(
"GET",
"transactions/unconfirmed/9816f8d8c257ea0c951deba911266394b0f2614df023f8b4ffd9da43d36efd9d",
),
404,
);
});
});

describe("GET /transactions/types", () => {
Expand Down Expand Up @@ -572,4 +592,23 @@ describe("API 2.0 - Transactions", () => {
},
);
});

describe("GET /transactions/fees", () => {
it("should GET all the transaction fees", async () => {
const response = await utils.request("GET", "transactions/fees");

expect(response).toBeSuccessfulResponse();
expect(response.data.data).toEqual({
delegateRegistration: 2500000000,
delegateResignation: 2500000000,
ipfs: 500000000,
multiPayment: 0,
multiSignature: 500000000,
secondSignature: 500000000,
timelockTransfer: 0,
transfer: 10000000,
vote: 100000000,
});
});
});
});
7 changes: 7 additions & 0 deletions __tests__/integration/core-api/handlers/votes.test.ts
Expand Up @@ -29,5 +29,12 @@ describe("API 2.0 - Votes", () => {
expect(response.data.data).toBeObject();
expect(response.data.data.id).toBe(voteId);
});

it("should fail to GET a vote by the given identifier if it doesn't exist", async () => {
utils.expectError(
await utils.request("GET", "votes/9816f8d8c257ea0c951deba911266394b0f2614df023f8b4ffd9da43d36efd9d"),
404,
);
});
});
});
18 changes: 17 additions & 1 deletion __tests__/integration/core-api/handlers/wallets.test.ts
Expand Up @@ -81,10 +81,14 @@ describe("API 2.0 - Wallets", () => {

utils.expectTransaction(response.data.data[0]);
});

it("should fail to GET all the transactions for the given wallet if it doesn't exist", async () => {
utils.expectError(await utils.request("GET", "wallets/fake-address/transactions"), 404);
});
});

describe("GET /wallets/:id/transactions/sent", () => {
it("should GET all the send transactions for the given wallet by id", async () => {
it("should GET all the sent transactions for the given wallet by id", async () => {
const response = await utils.request("GET", `wallets/${address}/transactions/sent`);
expect(response).toBeSuccessfulResponse();
expect(response.data.data).toBeArray();
Expand All @@ -93,6 +97,10 @@ describe("API 2.0 - Wallets", () => {
utils.expectTransaction(transaction);
expect(transaction.sender).toBe(address);
});

it("should fail to GET all the sent transactions for the given wallet if it doesn't exist", async () => {
utils.expectError(await utils.request("GET", "wallets/fake-address/transactions/sent"), 404);
});
});

describe("GET /wallets/:id/transactions/received", () => {
Expand All @@ -103,6 +111,10 @@ describe("API 2.0 - Wallets", () => {

utils.expectTransaction(response.data.data[0]);
});

it("should fail to GET all the received transactions for the given wallet if it doesn't exist", async () => {
utils.expectError(await utils.request("GET", "wallets/fake-address/transactions/received"), 404);
});
});

describe("GET /wallets/:id/votes", () => {
Expand All @@ -113,6 +125,10 @@ describe("API 2.0 - Wallets", () => {

expect(response.data.data[0]).toBeObject();
});

it("should fail to GET all the votes for the given wallet if it doesn't exist", async () => {
utils.expectError(await utils.request("GET", "wallets/fake-address/votes"), 404);
});
});

describe("POST /wallets/search", () => {
Expand Down
15 changes: 15 additions & 0 deletions __tests__/integration/core-api/services/block-raw.json
@@ -0,0 +1,15 @@
{
"version": 0,
"totalAmount": "12500000000000000",
"totalFee": "0",
"reward": "0",
"payloadHash": "d9acd04bde4234a81addb8482333b4ac906bed7be5a9970ce8ada428bd083192",
"timestamp": 0,
"numberOfTransactions": 153,
"payloadLength": 35960,
"previousBlock": null,
"generatorPublicKey": "03b47f6b6719c76bad46a302d9cff7be9b1c2b2a20602a0d880f139b5b8901f068",
"height": 1,
"id": "17184958558311101492",
"blockSignature": "304402202fe5de5697fa25d3d3c0cb24617ac02ddfb1c915ee9194a89f8392f948c6076402200d07c5244642fe36afa53fb2d048735f1adfa623e8fa4760487e5f72e17d253b"
}
16 changes: 16 additions & 0 deletions __tests__/integration/core-api/services/block-transformed.json
@@ -0,0 +1,16 @@
{
"id": "17184958558311101492",
"version": 0,
"height": 1,
"previous": null,
"forged": { "reward": 0, "fee": 0, "total": 0, "amount": 12500000000000000 },
"payload": { "hash": "d9acd04bde4234a81addb8482333b4ac906bed7be5a9970ce8ada428bd083192", "length": 35960 },
"generator": {
"address": "AP6kAVdX1zQ3S8mfDnnHx9GaAohEqQUins",
"publicKey": "03b47f6b6719c76bad46a302d9cff7be9b1c2b2a20602a0d880f139b5b8901f068"
},
"signature": "304402202fe5de5697fa25d3d3c0cb24617ac02ddfb1c915ee9194a89f8392f948c6076402200d07c5244642fe36afa53fb2d048735f1adfa623e8fa4760487e5f72e17d253b",
"confirmations": 0,
"transactions": 153,
"timestamp": { "epoch": 0, "unix": 1490101200, "human": "2017-03-21T13:00:00.000Z" }
}
13 changes: 13 additions & 0 deletions __tests__/integration/core-api/services/transaction-raw.json
@@ -0,0 +1,13 @@
{
"version": 1,
"network": 23,
"type": 0,
"timestamp": 0,
"senderPublicKey": "035b63b4668ee261c16ca91443f3371e2fe349e131cb7bf5f8a3e93a3ddfdfc788",
"fee": "0",
"amount": "245098000000000",
"expiration": 0,
"recipientId": "AHXtmB84sTZ9Zd35h9Y1vfFvPE2Xzqj8ri",
"signature": "304402205fcb0677e06bde7aac3dc776665615f4b93ef8c3ed0fddecef9900e74fcb00f302206958a0c9868ea1b1f3d151bdfa92da1ce24de0b1fcd91933e64fb7971e92f48d",
"id": "db1aa687737858cc9199bfa336f9b1c035915c30aaee60b1e0f8afadfdb946bd"
}
@@ -0,0 +1,13 @@
{
"id": "db1aa687737858cc9199bfa336f9b1c035915c30aaee60b1e0f8afadfdb946bd",
"version": 1,
"type": 0,
"amount": 245098000000000,
"fee": 0,
"sender": "APnhwwyTbMiykJwYbGhYjNgtHiVJDSEhSn",
"senderPublicKey": "035b63b4668ee261c16ca91443f3371e2fe349e131cb7bf5f8a3e93a3ddfdfc788",
"recipient": "AHXtmB84sTZ9Zd35h9Y1vfFvPE2Xzqj8ri",
"signature": "304402205fcb0677e06bde7aac3dc776665615f4b93ef8c3ed0fddecef9900e74fcb00f302206958a0c9868ea1b1f3d151bdfa92da1ce24de0b1fcd91933e64fb7971e92f48d",
"confirmations": 0,
"timestamp": { "epoch": 0, "unix": 1490101200, "human": "2017-03-21T13:00:00.000Z" }
}
58 changes: 58 additions & 0 deletions __tests__/integration/core-api/services/transformer.test.ts
@@ -0,0 +1,58 @@
import { transformerService } from "../../../../packages/core-api/src/services/transformer";
import { Managers, Transactions } from "../../../../packages/crypto/src";
import { genesisBlock } from "../../../utils/config/testnet/genesisBlock";
import { setUp, tearDown } from "../__support__/setup";
import blockRaw from "./block-raw.json";
import blockTransformed from "./block-transformed.json";
import transactionRaw from "./transaction-raw.json";
import transactionTransformed from "./transaction-transformed.json";

Managers.configManager.setFromPreset("testnet");

const genesisTransaction = Transactions.TransactionFactory.fromData(genesisBlock.transactions[0]);
delete genesisBlock.transactions;

beforeAll(async () => setUp());
afterAll(async () => tearDown());

describe("Transformer", () => {
describe("toResource", () => {
it("should transform a block", () => {
expect(transformerService.toResource(genesisBlock, "block")).toEqual(blockTransformed);
});

it("should not transform a block", () => {
expect(transformerService.toResource(genesisBlock, "block", false)).toEqual(blockRaw);
});

it("should transform a transaction", () => {
expect(transformerService.toResource(genesisTransaction, "transaction")).toEqual(transactionTransformed);
});

it("should not transform a transaction", () => {
expect(transformerService.toResource(genesisTransaction, "transaction", false)).toEqual(transactionRaw);
});
});

describe("toCollection", () => {
it("should transform a block", () => {
expect(transformerService.toCollection([genesisBlock], "block")).toEqual([blockTransformed]);
});

it("should not transform a block", () => {
expect(transformerService.toCollection([genesisBlock], "block", false)).toEqual([blockRaw]);
});

it("should transform a transaction", () => {
expect(transformerService.toCollection([genesisTransaction], "transaction")).toEqual([
transactionTransformed,
]);
});

it("should not transform a transaction", () => {
expect(transformerService.toCollection([genesisTransaction], "transaction", false)).toEqual([
transactionRaw,
]);
});
});
});
2 changes: 1 addition & 1 deletion packages/core-api/src/defaults.ts
Expand Up @@ -60,6 +60,6 @@ export const defaults = {
"/api/wallets/search",
],
},
whitelist: ["127.0.0.1", "::ffff:127.0.0.1"],
whitelist: ["127.0.0.1", "::ffff:127.0.0.1", "192.168.*"],
plugins: [],
};

0 comments on commit af10936

Please sign in to comment.