From 5ceeaf6927a508812f857038d388e26435e4b839 Mon Sep 17 00:00:00 2001 From: Air1 Date: Mon, 28 Sep 2020 17:47:41 +0200 Subject: [PATCH 1/4] chore: remove /search from api --- packages/core-api/src/controllers/blocks.ts | 22 ---------------- .../core-api/src/controllers/delegates.ts | 8 ------ packages/core-api/src/controllers/locks.ts | 8 ------ .../core-api/src/controllers/transactions.ts | 26 ------------------- packages/core-api/src/controllers/wallets.ts | 8 ------ .../core-api/src/resources-new/delegate.ts | 1 - packages/core-api/src/resources-new/lock.ts | 1 - packages/core-api/src/resources-new/wallet.ts | 1 - packages/core-api/src/routes/blocks.ts | 22 ---------------- packages/core-api/src/routes/delegates.ts | 16 ------------ packages/core-api/src/routes/locks.ts | 16 ------------ packages/core-api/src/routes/transactions.ts | 22 ---------------- packages/core-api/src/routes/wallets.ts | 16 ------------ 13 files changed, 167 deletions(-) diff --git a/packages/core-api/src/controllers/blocks.ts b/packages/core-api/src/controllers/blocks.ts index 99053b76d5..45ad074d33 100644 --- a/packages/core-api/src/controllers/blocks.ts +++ b/packages/core-api/src/controllers/blocks.ts @@ -105,28 +105,6 @@ export class BlocksController extends Controller { return this.toPagination(transactionListResult, TransactionResource, request.query.transform); } - public async search(request: Hapi.Request, h: Hapi.ResponseToolkit) { - if (request.query.transform) { - const blockWithSomeTransactionsListResult = await this.blockHistoryService.listByCriteriaJoinTransactions( - request.payload, - { typeGroup: Enums.TransactionTypeGroup.Core, type: Enums.TransactionType.MultiPayment }, - this.getListingOrder(request), - this.getListingPage(request), - this.getListingOptions(), - ); - - return this.toPagination(blockWithSomeTransactionsListResult, BlockWithTransactionsResource, true); - } else { - const blockListResult = await this.blockHistoryService.listByCriteria( - request.payload, - this.getListingOrder(request), - this.getListingPage(request), - ); - - return this.toPagination(blockListResult, BlockResource, false); - } - } - private getBlockCriteriaByIdOrHeight(idOrHeight: string): Contracts.Shared.OrBlockCriteria { const asHeight = parseFloat(idOrHeight); return asHeight && asHeight <= this.blockchain.getLastHeight() ? { height: asHeight } : { id: idOrHeight }; diff --git a/packages/core-api/src/controllers/delegates.ts b/packages/core-api/src/controllers/delegates.ts index 806d5beb6e..5468012a45 100644 --- a/packages/core-api/src/controllers/delegates.ts +++ b/packages/core-api/src/controllers/delegates.ts @@ -35,14 +35,6 @@ export class DelegatesController extends Controller { return this.delegateSearchService.getDelegatesPage(pagination, sorting, criteria); } - public search(request: Hapi.Request): Contracts.Search.ResultsPage { - const pagination = this.getQueryPagination(request.query); - const sorting = request.query.orderBy as Contracts.Search.Sorting; - const criteria = request.payload as DelegateCriteria; - - return this.delegateSearchService.getDelegatesPage(pagination, sorting, criteria); - } - public show(request: Hapi.Request): { data: DelegateResource } | Boom { const walletId = request.params.id as string; diff --git a/packages/core-api/src/controllers/locks.ts b/packages/core-api/src/controllers/locks.ts index c52b2ad64c..751ed6f7e3 100644 --- a/packages/core-api/src/controllers/locks.ts +++ b/packages/core-api/src/controllers/locks.ts @@ -25,14 +25,6 @@ export class LocksController extends Controller { return this.lockSearchService.getLocksPage(pagination, sorting, criteria); } - public search(request: Hapi.Request): Contracts.Search.ResultsPage { - const pagination = this.getQueryPagination(request.query); - const sorting = request.query.orderBy as Contracts.Search.Sorting; - const criteria = request.payload as LockCriteria; - - return this.lockSearchService.getLocksPage(pagination, sorting, criteria); - } - public show(request: Hapi.Request): { data: LockResource } | Boom { const lockId = request.params.id as string; diff --git a/packages/core-api/src/controllers/transactions.ts b/packages/core-api/src/controllers/transactions.ts index e339745cbe..542ff13b47 100644 --- a/packages/core-api/src/controllers/transactions.ts +++ b/packages/core-api/src/controllers/transactions.ts @@ -118,32 +118,6 @@ export class TransactionsController extends Controller { return super.respondWithResource(transaction.data, TransactionResource, !!request.query.transform); } - public async search(request: Hapi.Request, h: Hapi.ResponseToolkit) { - const criteria: Contracts.Shared.TransactionCriteria = request.payload; - const sorting: Contracts.Search.Sorting = this.getListingOrder(request); - const pagination: Contracts.Search.Pagination = this.getListingPage(request); - const options: Contracts.Search.Options = this.getListingOptions(); - - if (request.query.transform) { - const transactionListResult = await this.transactionHistoryService.listByCriteriaJoinBlock( - criteria, - sorting, - pagination, - options, - ); - - return this.toPagination(transactionListResult, TransactionWithBlockResource, true); - } else { - const transactionListResult = await this.transactionHistoryService.listByCriteria( - criteria, - sorting, - pagination, - options, - ); - return this.toPagination(transactionListResult, TransactionResource, false); - } - } - public async types(request: Hapi.Request, h: Hapi.ResponseToolkit) { const activatedTransactionHandlers = await this.nullHandlerRegistry.getActivatedHandlers(); const typeGroups: Record> = {}; diff --git a/packages/core-api/src/controllers/wallets.ts b/packages/core-api/src/controllers/wallets.ts index 5a6bf15a62..46cf708d03 100644 --- a/packages/core-api/src/controllers/wallets.ts +++ b/packages/core-api/src/controllers/wallets.ts @@ -46,14 +46,6 @@ export class WalletsController extends Controller { return this.walletSearchService.getWalletsPage(pagination, sorting, criteria); } - public search(request: Hapi.Request): Contracts.Search.ResultsPage { - const pagination = this.getQueryPagination(request.query); - const sorting = request.query.orderBy as Contracts.Search.Sorting; - const criteria = request.payload as WalletCriteria; - - return this.walletSearchService.getWalletsPage(pagination, sorting, criteria); - } - public show(request: Hapi.Request): { data: WalletResource } | Boom { const walletId = request.params.id as string; const walletResource = this.walletSearchService.getWallet(walletId); diff --git a/packages/core-api/src/resources-new/delegate.ts b/packages/core-api/src/resources-new/delegate.ts index b9b2bc8310..34955a0597 100644 --- a/packages/core-api/src/resources-new/delegate.ts +++ b/packages/core-api/src/resources-new/delegate.ts @@ -69,5 +69,4 @@ export const delegateCriteriaSchemaObject = { }; export const delegateCriteriaQuerySchema = Joi.object(delegateCriteriaSchemaObject); -export const delegateCriteriaPayloadSchema = Schemas.createCriteriaPayloadSchema(delegateCriteriaSchemaObject); export const delegateSortingSchema = Schemas.createSortingSchema(delegateCriteriaSchemaObject); diff --git a/packages/core-api/src/resources-new/lock.ts b/packages/core-api/src/resources-new/lock.ts index 2aa03fe865..a10d07ca6d 100644 --- a/packages/core-api/src/resources-new/lock.ts +++ b/packages/core-api/src/resources-new/lock.ts @@ -52,5 +52,4 @@ export const lockCriteriaSchemaObject = { export const lockParamSchema = transactionIdSchema; export const lockCriteriaQuerySchema = Joi.object(lockCriteriaSchemaObject); -export const lockCriteriaPayloadSchema = Schemas.createCriteriaPayloadSchema(lockCriteriaSchemaObject); export const lockSortingSchema = Schemas.createSortingSchema(lockCriteriaSchemaObject); diff --git a/packages/core-api/src/resources-new/wallet.ts b/packages/core-api/src/resources-new/wallet.ts index 05435dd785..60b5e03b3f 100644 --- a/packages/core-api/src/resources-new/wallet.ts +++ b/packages/core-api/src/resources-new/wallet.ts @@ -38,5 +38,4 @@ export const walletCriteriaSchemaObject = { export const walletParamSchema = Joi.alternatives(walletAddressSchema, walletPublicKeySchema, walletUsernameSchema); export const walletCriteriaQuerySchema = Joi.object(walletCriteriaSchemaObject); -export const walletCriteriaPayloadSchema = Schemas.createCriteriaPayloadSchema(walletCriteriaSchemaObject); export const walletSortingSchema = Schemas.createSortingSchema(walletCriteriaSchemaObject, ["attributes"]); diff --git a/packages/core-api/src/routes/blocks.ts b/packages/core-api/src/routes/blocks.ts index 41516d67a3..6c20e4a1cb 100644 --- a/packages/core-api/src/routes/blocks.ts +++ b/packages/core-api/src/routes/blocks.ts @@ -92,26 +92,4 @@ export const register = (server: Hapi.Server): void => { }, }, }); - - server.route({ - method: "POST", - path: "/blocks/search", - handler: (request: Hapi.Request) => controller.search(request), - options: { - validate: { - query: Joi.object({ - orderBy: server.app.schemas.blocksOrderBy, - transform: Joi.bool().default(true), - }).concat(Schemas.pagination), - payload: Joi.object({ - ...server.app.schemas.blockCriteriaSchemas, - }), - }, - plugins: { - pagination: { - enabled: true, - }, - }, - }, - }); }; diff --git a/packages/core-api/src/routes/delegates.ts b/packages/core-api/src/routes/delegates.ts index 6799fd2a09..c2434428de 100644 --- a/packages/core-api/src/routes/delegates.ts +++ b/packages/core-api/src/routes/delegates.ts @@ -3,7 +3,6 @@ import Joi from "@hapi/joi"; import { DelegatesController } from "../controllers/delegates"; import { - delegateCriteriaPayloadSchema, delegateCriteriaQuerySchema, delegateSortingSchema, walletCriteriaQuerySchema, @@ -33,21 +32,6 @@ export const register = (server: Hapi.Server): void => { }, }); - server.route({ - method: "POST", - path: "/delegates/search", - handler: (request: Hapi.Request) => controller.search(request), - options: { - validate: { - query: Joi.object().concat(delegateSortingSchema).concat(Schemas.pagination), - payload: delegateCriteriaPayloadSchema, - }, - plugins: { - pagination: { enabled: true }, - }, - }, - }); - server.route({ method: "GET", path: "/delegates/{id}", diff --git a/packages/core-api/src/routes/locks.ts b/packages/core-api/src/routes/locks.ts index fdfa004536..abf6fbf6a5 100644 --- a/packages/core-api/src/routes/locks.ts +++ b/packages/core-api/src/routes/locks.ts @@ -3,7 +3,6 @@ import Joi from "@hapi/joi"; import { LocksController } from "../controllers/locks"; import { - lockCriteriaPayloadSchema, lockCriteriaQuerySchema, lockParamSchema, lockSortingSchema, @@ -31,21 +30,6 @@ export const register = (server: Hapi.Server): void => { }, }); - server.route({ - method: "POST", - path: "/locks/search", - handler: (request: Hapi.Request) => controller.search(request), - options: { - validate: { - query: Joi.object().concat(lockSortingSchema).concat(Schemas.pagination), - payload: lockCriteriaPayloadSchema, - }, - plugins: { - pagination: { enabled: true }, - }, - }, - }); - server.route({ method: "GET", path: "/locks/{id}", diff --git a/packages/core-api/src/routes/transactions.ts b/packages/core-api/src/routes/transactions.ts index c4f96c4e86..287877fa82 100644 --- a/packages/core-api/src/routes/transactions.ts +++ b/packages/core-api/src/routes/transactions.ts @@ -106,28 +106,6 @@ export const register = (server: Hapi.Server): void => { }, }); - server.route({ - method: "POST", - path: "/transactions/search", - handler: (request: Hapi.Request) => controller.search(request), - options: { - validate: { - query: Joi.object({ - orderBy: server.app.schemas.transactionsOrderBy, - transform: Joi.bool().default(true), - }).concat(Schemas.pagination), - payload: Joi.object({ - ...server.app.schemas.transactionCriteriaSchemas, - }), - }, - plugins: { - pagination: { - enabled: true, - }, - }, - }, - }); - server.route({ method: "GET", path: "/transactions/types", diff --git a/packages/core-api/src/routes/wallets.ts b/packages/core-api/src/routes/wallets.ts index 333863043f..0c3d0fc294 100644 --- a/packages/core-api/src/routes/wallets.ts +++ b/packages/core-api/src/routes/wallets.ts @@ -6,7 +6,6 @@ import { lockCriteriaQuerySchema, lockParamSchema, lockSortingSchema, - walletCriteriaPayloadSchema, walletCriteriaQuerySchema, walletParamSchema, walletSortingSchema, @@ -51,21 +50,6 @@ export const register = (server: Hapi.Server): void => { }, }); - server.route({ - method: "POST", - path: "/wallets/search", - handler: (request: Hapi.Request) => controller.search(request), - options: { - validate: { - query: Joi.object().concat(walletSortingSchema).concat(Schemas.pagination), - payload: walletCriteriaPayloadSchema, - }, - plugins: { - pagination: { enabled: true }, - }, - }, - }); - server.route({ method: "GET", path: "/wallets/{id}", From 2af823894b1fa82eac68c8f5434955f68aa9a94a Mon Sep 17 00:00:00 2001 From: Air1 Date: Mon, 28 Sep 2020 17:48:05 +0200 Subject: [PATCH 2/4] test: remove /search from api --- .../core-api/controllers/delegates.test.ts | 23 -- .../core-api/controllers/wallets.test.ts | 57 --- .../core-api/handlers/transactions.test.ts | 334 ++++++++---------- .../unit/core-api/controllers/blocks.test.ts | 50 --- .../unit/core-api/controllers/locks.test.ts | 31 -- .../core-api/controllers/transactions.test.ts | 88 ----- .../unit/core-api/controllers/wallets.test.ts | 31 -- 7 files changed, 157 insertions(+), 457 deletions(-) diff --git a/__tests__/integration/core-api/controllers/delegates.test.ts b/__tests__/integration/core-api/controllers/delegates.test.ts index 37a85cb683..5e7921e86f 100644 --- a/__tests__/integration/core-api/controllers/delegates.test.ts +++ b/__tests__/integration/core-api/controllers/delegates.test.ts @@ -54,26 +54,3 @@ describe("/delegates", () => { } }); }); - -describe("/delegates/search", () => { - it("should return 10th, 11th, 12th ranked delegates", async () => { - const client = app.resolve(ApiInjectClient); - const response = await client.post("/delegates/search?orderBy=rank:asc", { - rank: [10, 11, 12], - }); - - expect(response).toMatchObject({ - status: 200, - body: { - data: expect.toBeArray(), - }, - }); - - const delegates = response.body.data; - - expect(delegates.length).toBe(3); - expect(delegates[0].rank).toBe(10); - expect(delegates[1].rank).toBe(11); - expect(delegates[2].rank).toBe(12); - }); -}); diff --git a/__tests__/integration/core-api/controllers/wallets.test.ts b/__tests__/integration/core-api/controllers/wallets.test.ts index 72fda12eac..ca96f1c101 100644 --- a/__tests__/integration/core-api/controllers/wallets.test.ts +++ b/__tests__/integration/core-api/controllers/wallets.test.ts @@ -96,60 +96,3 @@ describe("/wallets/:id", () => { }); }); }); - -describe("/wallets/search", () => { - it("should return 3 wallets with delegate username genesis_1 or genesis_2 or genesis_3", async () => { - const client = app.resolve(ApiInjectClient); - const response = await client.post("/wallets/search?orderBy=attributes.delegate.username", { - attributes: { - delegate: { - username: ["genesis_1", "genesis_2", "genesis_3"], - }, - }, - }); - - expect(response).toMatchObject({ - status: 200, - body: { - data: expect.toBeArray(), - }, - }); - - const wallets = response.body.data; - - expect(wallets.length).toBe(3); - expect(wallets[0].attributes.delegate.username).toBe("genesis_1"); - expect(wallets[1].attributes.delegate.username).toBe("genesis_2"); - expect(wallets[2].attributes.delegate.username).toBe("genesis_3"); - }); - - it("should return 5 wallets with delegate rank between 1 and 2, or 10 and 12", async () => { - const client = app.resolve(ApiInjectClient); - const response = await client.post("/wallets/search?orderBy=attributes.delegate.rank", { - attributes: { - delegate: { - rank: [ - { from: 1, to: 2 }, - { from: 10, to: 12 }, - ], - }, - }, - }); - - expect(response).toMatchObject({ - status: 200, - body: { - data: expect.toBeArray(), - }, - }); - - const wallets = response.body.data; - - expect(wallets.length).toBe(5); - expect(wallets[0].attributes.delegate.rank).toBe(1); - expect(wallets[1].attributes.delegate.rank).toBe(2); - expect(wallets[2].attributes.delegate.rank).toBe(10); - expect(wallets[3].attributes.delegate.rank).toBe(11); - expect(wallets[4].attributes.delegate.rank).toBe(12); - }); -}); diff --git a/__tests__/integration/core-api/handlers/transactions.test.ts b/__tests__/integration/core-api/handlers/transactions.test.ts index c979228a7e..4f6ebc01d8 100644 --- a/__tests__/integration/core-api/handlers/transactions.test.ts +++ b/__tests__/integration/core-api/handlers/transactions.test.ts @@ -106,136 +106,16 @@ describe("API 2.0 - Transactions", () => { api.expectTransaction(response.data.data[0]); }); - }); - describe("GET /transactions?limit=5", () => { it("should GET few transactions", async () => { const response = await api.request("GET", "transactions", { limit: 5 }); expect(response).toBeSuccessfulResponse(); expect(response.data.data).toBeArray(); expect(response.data.data.length).toBe(5); }); - }); - - describe("GET /transactions/:id", () => { - it("should GET a transaction by the given identifier", async () => { - const response = await api.request("GET", `transactions/${transactionId}`); - expect(response).toBeSuccessfulResponse(); - expect(response.data.data).toBeObject(); - - const transaction = response.data.data; - api.expectTransaction(transaction); - expect(transaction.id).toBe(transactionId); - }); - - it("should GET a transaction by the given identifier and not transform it", async () => { - const response = await api.request("GET", `transactions/${transactionId}`, { transform: false }); - expect(response).toBeSuccessfulResponse(); - expect(response.data.data).toBeObject(); - - expect(response.data.data).toEqual({ - id: genesisTransaction.id, - timestamp: 0, - version: 1, - type: 0, - typeGroup: 1, - fee: "0", - amount: "300000000000000", - blockId: expect.anything(), // ? how is that blockId isn't constant - blockHeight: expect.anything(), - recipientId: genesisTransaction.recipientId, - senderPublicKey: genesisTransaction.senderPublicKey, - expiration: 0, - network: 23, - nonce: "1", - signature: genesisTransaction.signature, - sequence: 0, - }); - }); - - it("should fail to GET a transaction by the given identifier if it doesn't exist", async () => { - api.expectError( - await api.request( - "GET", - "transactions/9816f8d8c257ea0c951deba911266394b0f2614df023f8b4ffd9da43d36efd9d", - ), - 404, - ); - }); - }); - - describe("GET /transactions/unconfirmed", () => { - it("should GET all the unconfirmed transactions", async () => { - // the wallet already send 1 transaction before that so 1 + 1 = 2 - // todo: maybe reset the db/wallets between every tests to clear nonces? - await api.createTransfer(undefined, 2); - - const response = await api.request("GET", "transactions/unconfirmed"); - expect(response).toBeSuccessfulResponse(); - expect(response.data.data).toBeArray(); - expect(response.data.data).not.toBeEmpty(); - }); - }); - - describe("GET /transactions/unconfirmed/:id", () => { - it("should GET an unconfirmed transaction by the given identifier", async () => { - // the wallet already send 2 transactions before that so 2 + 1 = 3 - // todo: maybe reset the db/wallets between every tests to clear nonces? - const transaction = await api.createTransfer(undefined, 3); - - const response = await api.request("GET", `transactions/unconfirmed/${transaction.id}`); - expect(response).toBeSuccessfulResponse(); - 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 () => { - api.expectError( - await api.request( - "GET", - "transactions/unconfirmed/9816f8d8c257ea0c951deba911266394b0f2614df023f8b4ffd9da43d36efd9d", - ), - 404, - ); - }); - }); - - describe("GET /transactions/types", () => { - it("should GET transaction types", async () => { - const response = await api.request("GET", "transactions/types"); - expect(response).toBeSuccessfulResponse(); - expect(response.data.data).toBeObject(); - expect(response.data.data).toEqual({ - 1: { - Transfer: 0, - SecondSignature: 1, - DelegateRegistration: 2, - Vote: 3, - MultiSignature: 4, - Ipfs: 5, - MultiPayment: 6, - DelegateResignation: 7, - HtlcLock: 8, - HtlcClaim: 9, - HtlcRefund: 10, - }, - 2: { - // Marketplace stuff - BusinessRegistration: 0, - BusinessResignation: 1, - BusinessUpdate: 2, - BridgechainRegistration: 3, - BridgechainResignation: 4, - BridgechainUpdate: 5, - // Entity: 6, // no "Entity" because aip36 is not enabled - }, - }); - }); - }); - describe("POST /transactions/search", () => { - it("should POST a search for transactions with the exact specified transactionId", async () => { - const response = await api.request("POST", "transactions/search", { + it("should GET transactions with the exact specified transactionId", async () => { + const response = await api.request("GET", "transactions", { id: transactionId, }); @@ -249,8 +129,8 @@ describe("API 2.0 - Transactions", () => { } }); - it("should POST a search for transactions with the exact specified blockId", async () => { - const response = await api.request("POST", "transactions/search", { blockId }); + it("should GET transactions with the exact specified blockId", async () => { + const response = await api.request("GET", "transactions", { blockId }); expect(response).toBeSuccessfulResponse(); expect(response.data.data).toBeArray(); expect(response.data.data).toHaveLength(100); @@ -261,8 +141,8 @@ describe("API 2.0 - Transactions", () => { } }); - it("should POST a search for transactions with the exact specified type", async () => { - const response = await api.request("POST", "transactions/search", { type }); + it("should GET transactions with the exact specified type", async () => { + const response = await api.request("GET", "transactions", { type }); expect(response).toBeSuccessfulResponse(); expect(response.data.data).toBeArray(); expect(response.data.data).toHaveLength(51); @@ -273,8 +153,8 @@ describe("API 2.0 - Transactions", () => { } }); - it("should POST a search for transactions with the exact specified version", async () => { - const response = await api.request("POST", "transactions/search", { version }); + it("should GET transactions with the exact specified version", async () => { + const response = await api.request("GET", "transactions", { version }); expect(response).toBeSuccessfulResponse(); expect(response.data.data).toBeArray(); expect(response.data.data).toHaveLength(100); @@ -285,8 +165,8 @@ describe("API 2.0 - Transactions", () => { } }); - it("should POST a search for transactions with the exact specified senderPublicKey", async () => { - const response = await api.request("POST", "transactions/search", { senderPublicKey }); + it("should GET transactions with the exact specified senderPublicKey", async () => { + const response = await api.request("GET", "transactions", { senderPublicKey }); expect(response).toBeSuccessfulResponse(); @@ -296,8 +176,8 @@ describe("API 2.0 - Transactions", () => { } }); - it("should POST a search for transactions with the exact specified senderId", async () => { - const response = await api.request("POST", "transactions/search", { senderId: senderAddress }); + it("should GET transactions with the exact specified senderId", async () => { + const response = await api.request("GET", "transactions", { senderId: senderAddress }); expect(response).toBeSuccessfulResponse(); @@ -307,9 +187,10 @@ describe("API 2.0 - Transactions", () => { } }); - it("should POST a search for transactions with the exact specified senderId in descending order by nonce", async () => { - const response = await api.request("POST", "transactions/search?orderBy=nonce:desc", { + it("should GET transactions with the exact specified senderId in descending order by nonce", async () => { + const response = await api.request("GET", "transactions", { senderId: senderAddress, + orderBy: "nonce:desc", }); expect(response).toBeSuccessfulResponse(); @@ -323,8 +204,8 @@ describe("API 2.0 - Transactions", () => { } }); - it("should POST a search for transactions with the exact specified recipientId (Address)", async () => { - const response = await api.request("POST", "transactions/search", { recipientId: recipientAddress }); + it("should GET transactions with the exact specified recipientId (Address)", async () => { + const response = await api.request("GET", "transactions", { recipientId: recipientAddress }); expect(response).toBeSuccessfulResponse(); expect(response.data.data).toBeArray(); expect(response.data.data).toHaveLength(3); @@ -335,8 +216,8 @@ describe("API 2.0 - Transactions", () => { } }); - it("should POST a search for transactions with the any of the specified addresses", async () => { - const response = await api.request("POST", "transactions/search", { + it("should GET transactions with the any of the specified addresses", async () => { + const response = await api.request("GET", "transactions", { recipientId: [genesisTransactions[3].recipientId, genesisTransactions[8].recipientId], }); @@ -350,8 +231,8 @@ describe("API 2.0 - Transactions", () => { } }); - it("should POST a search for transactions with the exact specified timestamp", async () => { - const response = await api.request("POST", "transactions/search", { timestamp }); + it("should GET transactions with the exact specified timestamp", async () => { + const response = await api.request("GET", "transactions", { timestamp }); expect(response).toBeSuccessfulResponse(); expect(response.data.data).toBeArray(); @@ -364,9 +245,10 @@ describe("API 2.0 - Transactions", () => { }); // FIXME - it("should POST a search for transactions with the specified timestamp range", async () => { - const response = await api.request("POST", "transactions/search", { - timestamp: { from: timestampFrom, to: timestampTo }, + it("should GET transactions with the specified timestamp range", async () => { + const response = await api.request("GET", "transactions", { + "timestamp.from": timestampFrom, + "timestamp.to": timestampTo, }); expect(response).toBeSuccessfulResponse(); @@ -380,8 +262,8 @@ describe("API 2.0 - Transactions", () => { } }); - it("should POST a search for transactions with the exact specified amount", async () => { - const response = await api.request("POST", "transactions/search", { amount }); + it("should GET transactions with the exact specified amount", async () => { + const response = await api.request("GET", "transactions", { amount }); expect(response).toBeSuccessfulResponse(); expect(response.data.data).toBeArray(); @@ -393,9 +275,10 @@ describe("API 2.0 - Transactions", () => { } }); - it("should POST a search for transactions with the specified amount range", async () => { - const response = await api.request("POST", "transactions/search", { - amount: { from: amountFrom, to: amountTo }, + it("should GET transactions with the specified amount range", async () => { + const response = await api.request("GET", "transactions", { + "amount.from": amountFrom, + "amount.to": amountTo, }); expect(response).toBeSuccessfulResponse(); @@ -409,8 +292,8 @@ describe("API 2.0 - Transactions", () => { } }); - it("should POST a search for transactions with the exact specified fee", async () => { - const response = await api.request("POST", "transactions/search", { fee }); + it("should GET transactions with the exact specified fee", async () => { + const response = await api.request("GET", "transactions", { fee }); expect(response).toBeSuccessfulResponse(); expect(response.data.data).toBeArray(); @@ -422,9 +305,10 @@ describe("API 2.0 - Transactions", () => { } }); - it("should POST a search for transactions with the specified fee range", async () => { - const response = await api.request("POST", "transactions/search", { - fee: { from: feeFrom, to: feeTo }, + it("should GET transactions with the specified fee range", async () => { + const response = await api.request("GET", "transactions", { + "fee.from": feeFrom, + "fee.to": feeTo, }); expect(response).toBeSuccessfulResponse(); @@ -438,10 +322,10 @@ describe("API 2.0 - Transactions", () => { } }); - it("should POST a search for transactions with the exact specified vendorField", async () => { + it("should GET transactions with the exact specified vendorField", async () => { const dummyTransaction = await api.createTransfer(); - const response = await api.request("POST", "transactions/search", { + const response = await api.request("GET", "transactions", { vendorField: dummyTransaction.vendorField, }); @@ -456,8 +340,8 @@ describe("API 2.0 - Transactions", () => { } }); - it("should POST a search for transactions with the wrong specified type", async () => { - const response = await api.request("POST", "transactions/search", { + it("should GET transactions with the wrong specified type", async () => { + const response = await api.request("GET", "transactions", { id: transactionId, type: wrongType, }); @@ -466,45 +350,141 @@ describe("API 2.0 - Transactions", () => { expect(response.data.data).toHaveLength(0); }); - it("should POST a search for transactions with the specific criteria", async () => { - const response = await api.request("POST", "transactions/search", { + it("should GET transactions with the specific criteria", async () => { + const response = await api.request("GET", "transactions", { senderPublicKey, type, - timestamp: { from: timestampFrom, to: timestampTo }, + "timestamp.from": timestampFrom, + "timestamp.to": timestampTo, }); expect(response).toBeSuccessfulResponse(); expect(response.data.data).toBeArray(); api.expectTransaction(response.data.data[0]); }); - it("should POST a search for transactions with an asset matching any delegate", async () => { - const response = await api.request("POST", "transactions/search", { - asset: { delegate: {} }, + it("should GET transactions with an wrong asset", async () => { + const response = await api.request("GET", "transactions", { + "asset.garbage": {}, }); expect(response).toBeSuccessfulResponse(); expect(response.data.data).toBeArray(); - expect(response.data.data).toHaveLength(51); - api.expectTransaction(response.data.data[0]); + expect(response.data.data).toHaveLength(0); }); + }); - it("should POST a search for transactions with an asset matching any delegate and sender public key", async () => { - const response = await api.request("POST", "transactions/search", { - asset: { delegate: {} }, - senderPublicKey: "02275d8577a0ec2b75fc8683282d53c5db76ebc54514a80c2854e419b793ea259a", - }); + describe("GET /transactions/:id", () => { + it("should GET a transaction by the given identifier", async () => { + const response = await api.request("GET", `transactions/${transactionId}`); expect(response).toBeSuccessfulResponse(); - expect(response.data.data).toBeArray(); - expect(response.data.data).toHaveLength(1); - api.expectTransaction(response.data.data[0]); + expect(response.data.data).toBeObject(); + + const transaction = response.data.data; + api.expectTransaction(transaction); + expect(transaction.id).toBe(transactionId); }); - it("should POST a search for transactions with an wrong asset", async () => { - const response = await api.request("POST", "transactions/search", { - asset: { garbage: {} }, + it("should GET a transaction by the given identifier and not transform it", async () => { + const response = await api.request("GET", `transactions/${transactionId}`, { transform: false }); + expect(response).toBeSuccessfulResponse(); + expect(response.data.data).toBeObject(); + + expect(response.data.data).toEqual({ + id: genesisTransaction.id, + timestamp: 0, + version: 1, + type: 0, + typeGroup: 1, + fee: "0", + amount: "300000000000000", + blockId: expect.anything(), // ? how is that blockId isn't constant + blockHeight: expect.anything(), + recipientId: genesisTransaction.recipientId, + senderPublicKey: genesisTransaction.senderPublicKey, + expiration: 0, + network: 23, + nonce: "1", + signature: genesisTransaction.signature, + sequence: 0, }); + }); + + it("should fail to GET a transaction by the given identifier if it doesn't exist", async () => { + api.expectError( + await api.request( + "GET", + "transactions/9816f8d8c257ea0c951deba911266394b0f2614df023f8b4ffd9da43d36efd9d", + ), + 404, + ); + }); + }); + + describe("GET /transactions/unconfirmed", () => { + it("should GET all the unconfirmed transactions", async () => { + // the wallet already send 1 transaction before that so 1 + 1 = 2 + // todo: maybe reset the db/wallets between every tests to clear nonces? + await api.createTransfer(undefined, 2); + + const response = await api.request("GET", "transactions/unconfirmed"); expect(response).toBeSuccessfulResponse(); expect(response.data.data).toBeArray(); - expect(response.data.data).toHaveLength(0); + expect(response.data.data).not.toBeEmpty(); + }); + }); + + describe("GET /transactions/unconfirmed/:id", () => { + it("should GET an unconfirmed transaction by the given identifier", async () => { + // the wallet already send 2 transactions before that so 2 + 1 = 3 + // todo: maybe reset the db/wallets between every tests to clear nonces? + const transaction = await api.createTransfer(undefined, 3); + + const response = await api.request("GET", `transactions/unconfirmed/${transaction.id}`); + expect(response).toBeSuccessfulResponse(); + 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 () => { + api.expectError( + await api.request( + "GET", + "transactions/unconfirmed/9816f8d8c257ea0c951deba911266394b0f2614df023f8b4ffd9da43d36efd9d", + ), + 404, + ); + }); + }); + + describe("GET /transactions/types", () => { + it("should GET transaction types", async () => { + const response = await api.request("GET", "transactions/types"); + expect(response).toBeSuccessfulResponse(); + expect(response.data.data).toBeObject(); + expect(response.data.data).toEqual({ + 1: { + Transfer: 0, + SecondSignature: 1, + DelegateRegistration: 2, + Vote: 3, + MultiSignature: 4, + Ipfs: 5, + MultiPayment: 6, + DelegateResignation: 7, + HtlcLock: 8, + HtlcClaim: 9, + HtlcRefund: 10, + }, + 2: { + // Marketplace stuff + BusinessRegistration: 0, + BusinessResignation: 1, + BusinessUpdate: 2, + BridgechainRegistration: 3, + BridgechainResignation: 4, + BridgechainUpdate: 5, + // Entity: 6, // no "Entity" because aip36 is not enabled + }, + }); }); }); diff --git a/__tests__/unit/core-api/controllers/blocks.test.ts b/__tests__/unit/core-api/controllers/blocks.test.ts index 3bef2236db..8adb7665ae 100644 --- a/__tests__/unit/core-api/controllers/blocks.test.ts +++ b/__tests__/unit/core-api/controllers/blocks.test.ts @@ -440,54 +440,4 @@ describe("BlocksController", () => { await expect(controller.transactions(request, undefined)).resolves.toThrowError("Block not found"); }); }); - - describe("search", () => { - it("should return found blocks from store", async () => { - blockHistoryService.listByCriteria.mockResolvedValue({ - results: [mockBlock as any], - totalCount: 1, - meta: { totalCountIsEstimate: false }, - }); - - const request: Hapi.Request = { - params: { - id: mockBlock.id, - }, - query: { - transform: false, - }, - }; - - const response = (await controller.search(request, undefined)) as PaginatedResponse; - - expect(response.totalCount).toBeDefined(); - expect(response.meta).toBeDefined(); - expect(response.results).toBeDefined(); - expect(response.results[0]).toEqual(mockBlockJson); - }); - - it("should return found blocks from store using transform", async () => { - blockHistoryService.listByCriteriaJoinTransactions.mockResolvedValue({ - results: [{ data: mockBlock, transactions: [] } as any], - totalCount: 1, - meta: { totalCountIsEstimate: false }, - }); - - const request: Hapi.Request = { - params: { - id: mockBlock.id, - }, - query: { - transform: true, - }, - }; - - const response = (await controller.search(request, undefined)) as PaginatedResponse; - - expect(response.totalCount).toBeDefined(); - expect(response.meta).toBeDefined(); - expect(response.results).toBeDefined(); - expect(response.results[0]).toEqual(mockBlockTransformed); - }); - }); }); diff --git a/__tests__/unit/core-api/controllers/locks.test.ts b/__tests__/unit/core-api/controllers/locks.test.ts index 07c075178a..1a44f16d36 100644 --- a/__tests__/unit/core-api/controllers/locks.test.ts +++ b/__tests__/unit/core-api/controllers/locks.test.ts @@ -84,37 +84,6 @@ describe("LocksController.index", () => { }); }); -describe("LocksController.search", () => { - it("should get criteria from payload and return locks page from LockSearchService", () => { - const locksPage: Contracts.Search.ResultsPage = { - results: [lockResource1], - totalCount: 1, - meta: { totalCountIsEstimate: false }, - }; - lockSearchService.getLocksPage.mockReturnValueOnce(locksPage); - - const locksController = container.resolve(LocksController); - const result = locksController.search({ - query: { - page: 1, - limit: 100, - orderBy: ["amount:desc", "timestamp.epoch:desc"], - }, - payload: { - recipientId: "AXm433vapiwt83xfh8x9ciNxYkVd76pbNe", - }, - }); - - expect(lockSearchService.getLocksPage).toBeCalledWith( - { offset: 0, limit: 100 }, - ["amount:desc", "timestamp.epoch:desc"], - { recipientId: "AXm433vapiwt83xfh8x9ciNxYkVd76pbNe" }, - ); - - expect(result).toBe(locksPage); - }); -}); - describe("LocksController.show", () => { it("should get lockId from pathname and return lock from LockSearchService", () => { lockSearchService.getLock.mockReturnValueOnce(lockResource1); diff --git a/__tests__/unit/core-api/controllers/transactions.test.ts b/__tests__/unit/core-api/controllers/transactions.test.ts index a7f2bbaecc..d18596ac88 100644 --- a/__tests__/unit/core-api/controllers/transactions.test.ts +++ b/__tests__/unit/core-api/controllers/transactions.test.ts @@ -273,94 +273,6 @@ describe("TransactionsController", () => { }); }); - describe("search", () => { - it("should return list of transactions", async () => { - transactionHistoryService.listByCriteria.mockResolvedValue({ - results: [transferTransaction.data], - totalCount: 1, - meta: { totalCountIsEstimate: false }, - }); - - const request: Hapi.Request = { - params: { - id: transferTransaction.id, - }, - query: { - page: 1, - limit: 100, - transform: false, - }, - }; - - const response = (await controller.search(request, undefined)) as PaginatedResponse; - - expect(response.totalCount).toBeDefined(); - expect(response.meta).toBeDefined(); - expect(response.results).toBeDefined(); - expect(response.results[0]).toEqual( - expect.objectContaining({ - id: transferTransaction.id, - }), - ); - }); - - it("should return list of transactions using transform", async () => { - transactionHistoryService.listByCriteriaJoinBlock.mockResolvedValue({ - results: [{ data: transferTransaction.data, block: block }], - totalCount: 1, - meta: { totalCountIsEstimate: false }, - }); - - const request: Hapi.Request = { - params: { - id: transferTransaction.id, - }, - query: { - page: 1, - limit: 100, - transform: true, - }, - }; - - const response = (await controller.search(request, undefined)) as PaginatedResponse; - - expect(response.totalCount).toBeDefined(); - expect(response.meta).toBeDefined(); - expect(response.results).toBeDefined(); - expect(response.results[0]).toEqual( - expect.objectContaining({ - id: transferTransaction.id, - }), - ); - }); - - it("should return paginated response when defined offset", async () => { - transactionHistoryService.listByCriteria.mockResolvedValue({ - results: [transferTransaction.data], - totalCount: 1, - meta: { totalCountIsEstimate: false }, - }); - - const request: Hapi.Request = { - params: { - id: transferTransaction.id, - }, - query: { - page: 1, - limit: 100, - offset: 1, - transform: false, - }, - }; - - const response = (await controller.search(request, undefined)) as PaginatedResponse; - - expect(response.totalCount).toBeDefined(); - expect(response.meta).toBeDefined(); - expect(response.results).toBeDefined(); - }); - }); - describe("types", () => { it("should return registered types", async () => { const response = (await controller.types(undefined, undefined)) as ItemResponse; diff --git a/__tests__/unit/core-api/controllers/wallets.test.ts b/__tests__/unit/core-api/controllers/wallets.test.ts index 0f16660695..71c8db2828 100644 --- a/__tests__/unit/core-api/controllers/wallets.test.ts +++ b/__tests__/unit/core-api/controllers/wallets.test.ts @@ -141,37 +141,6 @@ describe("WalletsController.top", () => { }); }); -describe("WalletsController.search", () => { - it("should get criteria from payload and return wallets page from WalletSearchService", () => { - const walletsPage: Contracts.Search.ResultsPage = { - results: [walletResource1], - totalCount: 1, - meta: { totalCountIsEstimate: false }, - }; - walletSearchService.getWalletsPage.mockReturnValueOnce(walletsPage); - - const walletsController = container.resolve(WalletsController); - const result = walletsController.search({ - query: { - page: 1, - limit: 100, - orderBy: ["balance:desc", "address:asc"], - }, - payload: { - address: "ATrkBiUXGDKduaSjqez2Ar7T9rQW6cnaeu", - }, - }); - - expect(walletSearchService.getWalletsPage).toBeCalledWith( - { offset: 0, limit: 100 }, - ["balance:desc", "address:asc"], - { address: "ATrkBiUXGDKduaSjqez2Ar7T9rQW6cnaeu" }, - ); - - expect(result).toBe(walletsPage); - }); -}); - describe("WalletsController.show", () => { it("should get wallet id from pathname and criteria from query and return wallet from WalletSearchService", () => { walletSearchService.getWallet.mockReturnValueOnce(walletResource1); From 2efd1d52d441222d0a3dab48843645ac557d002a Mon Sep 17 00:00:00 2001 From: Brian Faust Date: Mon, 28 Sep 2020 19:39:44 +0300 Subject: [PATCH 3/4] wip --- .../core-api/handlers/blocks.test.ts | 394 ------------------ 1 file changed, 394 deletions(-) diff --git a/__tests__/integration/core-api/handlers/blocks.test.ts b/__tests__/integration/core-api/handlers/blocks.test.ts index 4afc8ebf40..0fc9e63bbf 100644 --- a/__tests__/integration/core-api/handlers/blocks.test.ts +++ b/__tests__/integration/core-api/handlers/blocks.test.ts @@ -174,398 +174,4 @@ describe("API 2.0 - Blocks", () => { api.expectError(await api.request("GET", "blocks/111111/transactions"), 404); }); }); - - describe("POST /blocks/search", () => { - it("should POST a search for blocks with the exact specified blockId", async () => { - const response = await api.request("POST", "blocks/search", { - id: genesisBlock.id, - }); - expect(response).toBeSuccessfulResponse(); - expect(response.data.data).toBeArray(); - - expect(response.data.data).toHaveLength(1); - - const block = response.data.data[0]; - api.expectBlock(block); - expect(block.id).toBe(genesisBlock.id); - }); - - it("should POST a search for blocks with the exact specified version", async () => { - const response = await api.request("POST", "blocks/search", { - id: genesisBlock.id, - version: genesisBlock.version, - }); - expect(response).toBeSuccessfulResponse(); - expect(response.data.data).toBeArray(); - - expect(response.data.data).toHaveLength(1); - - const block = response.data.data[0]; - api.expectBlock(block); - expect(block.id).toBe(genesisBlock.id); - expect(block.version).toBe(genesisBlock.version); - }); - - it("should POST a search for blocks with the exact specified previousBlock", async () => { - const block2: Interfaces.IBlock = Factories.factory("Block") - .withOptions({ - config: Managers.configManager.all(), - }) - .make(); - - // save a new block so that we can make the request with previousBlock - await app - .get(Container.Identifiers.DatabaseBlockRepository) - .saveBlocks([block2]); - - const response = await api.request("POST", "blocks/search", { - id: block2.data.id, - previousBlock: block2.data.previousBlock, - }); - - expect(response).toBeSuccessfulResponse(); - expect(response.data.data).toBeArray(); - - expect(response.data.data).toHaveLength(1); - - const block = response.data.data[0]; - api.expectBlock(block); - expect(block.id).toBe(block2.data.id); - expect(block.previous).toBe(block2.data.previousBlock); - - await app - .get(Container.Identifiers.DatabaseBlockRepository) - .deleteBlocks([block2.data]); // reset to genesis block - }); - - it("should POST a search for blocks with the exact specified payloadHash", async () => { - const response = await api.request("POST", "blocks/search", { - id: genesisBlock.id, - payloadHash: genesisBlock.payloadHash, - }); - - expect(response).toBeSuccessfulResponse(); - expect(response.data.data).toBeArray(); - - expect(response.data.data).toHaveLength(1); - - const block = response.data.data[0]; - api.expectBlock(block); - expect(block.id).toBe(genesisBlock.id); - expect(block.payload.length).toBe(genesisBlock.payloadLength); - expect(block.payload.hash).toBe(genesisBlock.payloadHash); - }); - - it("should POST a search for blocks with the exact specified generatorPublicKey", async () => { - const response = await api.request("POST", "blocks/search", { - id: genesisBlock.id, - generatorPublicKey: genesisBlock.generatorPublicKey, - }); - - expect(response).toBeSuccessfulResponse(); - expect(response.data.data).toBeArray(); - - expect(response.data.data).toHaveLength(1); - - const block = response.data.data[0]; - api.expectBlock(block); - expect(block.id).toBe(genesisBlock.id); - expect(block.generator.publicKey).toBe(genesisBlock.generatorPublicKey); - }); - - it("should POST a search for blocks with the exact specified blockSignature", async () => { - const response = await api.request("POST", "blocks/search", { - id: genesisBlock.id, - blockSignature: genesisBlock.blockSignature, - }); - - expect(response).toBeSuccessfulResponse(); - expect(response.data.data).toBeArray(); - - expect(response.data.data).toHaveLength(1); - - const block = response.data.data[0]; - api.expectBlock(block); - expect(block.id).toBe(genesisBlock.id); - expect(block.signature).toBe(genesisBlock.blockSignature); - }); - - it("should POST a search for blocks with the exact specified timestamp", async () => { - const response = await api.request("POST", "blocks/search", { - id: genesisBlock.id, - timestamp: genesisBlock.timestamp, - }); - expect(response).toBeSuccessfulResponse(); - expect(response.data.data).toBeArray(); - - expect(response.data.data).toHaveLength(1); - - const block = response.data.data[0]; - api.expectBlock(block); - expect(block.id).toBe(genesisBlock.id); - }); - - it("should POST a search for blocks with the exact specified height", async () => { - const response = await api.request("POST", "blocks/search", { - id: genesisBlock.id, - height: genesisBlock.height, - }); - - expect(response).toBeSuccessfulResponse(); - expect(response.data.data).toBeArray(); - - expect(response.data.data).toHaveLength(1); - - const block = response.data.data[0]; - api.expectBlock(block); - expect(block.id).toBe(genesisBlock.id); - expect(block.height).toBe(genesisBlock.height); - }); - - it("should POST a search for blocks with the specified height range", async () => { - const response = await api.request("POST", "blocks/search", { - id: genesisBlock.id, - height: { from: genesisBlock.height, to: genesisBlock.height }, - }); - - expect(response).toBeSuccessfulResponse(); - expect(response.data.data).toBeArray(); - - expect(response.data.data).toHaveLength(1); - - const block = response.data.data[0]; - api.expectBlock(block); - expect(block.id).toBe(genesisBlock.id); - expect(block.height).toBe(genesisBlock.height); - }); - - it("should POST a search for blocks with the exact specified numberOfTransactions", async () => { - const response = await api.request("POST", "blocks/search", { - id: genesisBlock.id, - numberOfTransactions: genesisBlock.numberOfTransactions, - }); - - expect(response).toBeSuccessfulResponse(); - expect(response.data.data).toBeArray(); - - expect(response.data.data).toHaveLength(1); - - const block = response.data.data[0]; - api.expectBlock(block); - expect(block.id).toBe(genesisBlock.id); - expect(block.transactions).toBe(genesisBlock.numberOfTransactions); - }); - - it("should POST a search for blocks with the specified numberOfTransactions range", async () => { - const response = await api.request("POST", "blocks/search", { - id: genesisBlock.id, - numberOfTransactions: { - from: genesisBlock.numberOfTransactions, - to: genesisBlock.numberOfTransactions, - }, - }); - expect(response).toBeSuccessfulResponse(); - expect(response.data.data).toBeArray(); - - expect(response.data.data).toHaveLength(1); - - const block = response.data.data[0]; - api.expectBlock(block); - expect(block.id).toBe(genesisBlock.id); - expect(block.transactions).toBe(genesisBlock.numberOfTransactions); - }); - - it("should POST a search for blocks with the exact specified totalAmount", async () => { - const nextBlock: Interfaces.IBlock = Factories.factory("Block") - .withOptions({ - config: Managers.configManager.all(), - }) - .make(); - - await app - .get(Container.Identifiers.DatabaseBlockRepository) - .saveBlocks([nextBlock]); - - const response = await api.request("POST", "blocks/search", { - id: nextBlock.data.id, - totalAmount: +nextBlock.data.totalAmount, - }); - - expect(response).toBeSuccessfulResponse(); - expect(response.data.data).toBeArray(); - - expect(response.data.data).toHaveLength(1); - - const block = response.data.data[0]; - api.expectBlock(block); - expect(block.id).toBe(nextBlock.data.id); - }); - - it("should POST a search for blocks with the specified totalAmount range", async () => { - const nextBlock: Interfaces.IBlock = Factories.factory("Block") - .withOptions({ - config: Managers.configManager.all(), - }) - .make(); - - await app - .get(Container.Identifiers.DatabaseBlockRepository) - .saveBlocks([nextBlock]); - - const response = await api.request("POST", "blocks/search", { - id: nextBlock.data.id, - totalAmount: { - from: +nextBlock.data.totalAmount, - to: +nextBlock.data.totalAmount, - }, - }); - - expect(response).toBeSuccessfulResponse(); - expect(response.data.data).toBeArray(); - - expect(response.data.data).toHaveLength(1); - - const block = response.data.data[0]; - api.expectBlock(block); - expect(block.id).toBe(nextBlock.data.id); - }); - - it("should POST a search for blocks with the exact specified totalFee", async () => { - const response = await api.request("POST", "blocks/search", { - id: genesisBlock.id, - totalFee: 0, - }); - - expect(response).toBeSuccessfulResponse(); - expect(response.data.data).toBeArray(); - - expect(response.data.data).toHaveLength(1); - - const block = response.data.data[0]; - api.expectBlock(block); - expect(block.id).toBe(genesisBlock.id); - expect(+block.forged.fee).toBe(+genesisBlock.totalFee); - }); - - it("should POST a search for blocks with the specified totalFee range", async () => { - const response = await api.request("POST", "blocks/search", { - id: genesisBlock.id, - totalFee: { - from: genesisBlock.totalFee, - to: genesisBlock.totalFee, - }, - }); - - expect(response).toBeSuccessfulResponse(); - expect(response.data.data).toBeArray(); - - expect(response.data.data).toHaveLength(1); - - const block = response.data.data[0]; - api.expectBlock(block); - expect(block.id).toBe(genesisBlock.id); - expect(+block.forged.fee).toBe(+genesisBlock.totalFee); - }); - - it("should POST a search for blocks with the exact specified reward", async () => { - const response = await api.request("POST", "blocks/search", { - id: genesisBlock.id, - reward: genesisBlock.reward, - }); - - expect(response).toBeSuccessfulResponse(); - expect(response.data.data).toBeArray(); - - expect(response.data.data).toHaveLength(1); - - const block = response.data.data[0]; - api.expectBlock(block); - expect(block.id).toBe(genesisBlock.id); - expect(+block.forged.reward).toBe(+genesisBlock.reward); - }); - - it("should POST a search for blocks with the specified reward range", async () => { - const response = await api.request("POST", "blocks/search", { - id: genesisBlock.id, - reward: { - from: genesisBlock.reward, - to: genesisBlock.reward, - }, - }); - expect(response).toBeSuccessfulResponse(); - expect(response.data.data).toBeArray(); - - expect(response.data.data).toHaveLength(1); - - const block = response.data.data[0]; - api.expectBlock(block); - expect(block.id).toBe(genesisBlock.id); - expect(+block.forged.reward).toBe(+genesisBlock.reward); - }); - - it("should POST a search for blocks with the exact specified payloadLength", async () => { - const response = await api.request("POST", "blocks/search", { - id: genesisBlock.id, - payloadLength: genesisBlock.payloadLength, - }); - - expect(response).toBeSuccessfulResponse(); - expect(response.data.data).toBeArray(); - - expect(response.data.data).toHaveLength(1); - - const block = response.data.data[0]; - api.expectBlock(block); - expect(block.id).toBe(genesisBlock.id); - expect(block.payload.length).toBe(genesisBlock.payloadLength); - }); - - it("should POST a search for blocks with the specified payloadLength range", async () => { - const response = await api.request("POST", "blocks/search", { - id: genesisBlock.id, - payloadLength: { - from: genesisBlock.payloadLength, - to: genesisBlock.payloadLength, - }, - }); - expect(response).toBeSuccessfulResponse(); - expect(response.data.data).toBeArray(); - - expect(response.data.data).toHaveLength(1); - - const block = response.data.data[0]; - api.expectBlock(block); - expect(block.id).toBe(genesisBlock.id); - expect(block.payload.length).toBe(genesisBlock.payloadLength); - }); - - it("should POST a search for blocks with the wrong specified version", async () => { - const response = await api.request("POST", "blocks/search", { - id: genesisBlock.id, - version: 2, - }); - - expect(response).toBeSuccessfulResponse(); - expect(response.data.data).toBeArray(); - - expect(response.data.data).toHaveLength(0); - }); - - it("should POST a search for blocks with the specific criteria", async () => { - const response = await api.request("POST", "blocks/search", { - generatorPublicKey: genesisBlock.generatorPublicKey, - version: genesisBlock.version, - timestamp: genesisBlock.timestamp, - }); - - expect(response).toBeSuccessfulResponse(); - expect(response.data.data).toBeArray(); - - expect(response.data.data).toHaveLength(1); - - const block = response.data.data[0]; - api.expectBlock(block); - expect(block.id).toBe(genesisBlock.id); - }); - }); }); From 64edb471684930c8abdd20a7a6051cce6b7381d4 Mon Sep 17 00:00:00 2001 From: Brian Faust Date: Tue, 29 Sep 2020 08:02:44 +0300 Subject: [PATCH 4/4] wip --- __tests__/integration/core-api/handlers/blocks.test.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/__tests__/integration/core-api/handlers/blocks.test.ts b/__tests__/integration/core-api/handlers/blocks.test.ts index 0fc9e63bbf..0a618e4651 100644 --- a/__tests__/integration/core-api/handlers/blocks.test.ts +++ b/__tests__/integration/core-api/handlers/blocks.test.ts @@ -1,9 +1,8 @@ import "@packages/core-test-framework/src/matchers"; -import { Repositories } from "@arkecosystem/core-database"; -import { Container, Contracts } from "@arkecosystem/core-kernel"; -import { Interfaces, Managers } from "@arkecosystem/crypto"; -import { ApiHelpers, Factories } from "@packages/core-test-framework/src"; +import { Contracts } from "@arkecosystem/core-kernel"; +import { Managers } from "@arkecosystem/crypto"; +import { ApiHelpers } from "@packages/core-test-framework/src"; import { setUp, tearDown } from "../__support__/setup";