From 6af24169f4010ae8aae2bb0567333fc18f19324f Mon Sep 17 00:00:00 2001 From: ashnashahgrover Date: Thu, 8 Aug 2024 18:25:07 +0000 Subject: [PATCH] test(besu): refactor jest test negative test cases Primary Changes ---------------- 1. Refactored all negative test case exception assertions for cactus-plugin-ledger-connector-besu. Removed try-catch blocks, replaced with declarations through jest and jest-extended's own API. 2. Noted two tests within openapi-validation.test.ts (GetPastLogsEndpoint and GetBesuRecordEndpointV1 with empty parameters) where the status code returned should be 400 but is 200. This could be investigated in a seperate issue. Fixes #3467 Signed-off-by: ashnashahgrover --- .../get-record-locator.test.ts | 49 +- .../deploy-contract/invoke-contract.test.ts | 49 +- .../v21-get-record-locator.test.ts | 2 +- .../openapi/openapi-validation.test.ts | 565 ++++++++++-------- 4 files changed, 361 insertions(+), 304 deletions(-) diff --git a/packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/get-record-locator.test.ts b/packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/get-record-locator.test.ts index bdcb244cfb..e26212749c 100644 --- a/packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/get-record-locator.test.ts +++ b/packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/get-record-locator.test.ts @@ -265,34 +265,27 @@ describe("PluginLedgerConnectorBesu", () => { }); expect(setNameOut).toBeTruthy(); - try { - await connector.invokeContract({ - contractName: HelloWorldContractJson.contractName, - contractAbi: HelloWorldContractJson.abi, - contractAddress, - invocationType: EthContractInvocationType.Send, - methodName: "setName", - params: [newName], - gas: 1000000, - signingCredential: { - ethAccount: testEthAccount.address, - secret: testEthAccount.privateKey, - type: Web3SigningCredentialType.PrivateKeyHex, - }, - nonce: 1, - }); - throw new Error("This operation should not have succeeded, but it did."); - } catch (ex: unknown) { - // 'Returned error: Nonce too low' - expect(ex).toHaveProperty( - "message", - expect.stringContaining("Nonce too low"), - ); - expect(ex).toHaveProperty( - "stack", - expect.stringContaining("Nonce too low"), - ); - } + await expect(connector.invokeContract({ + contractName: HelloWorldContractJson.contractName, + contractAbi: HelloWorldContractJson.abi, + contractAddress, + invocationType: EthContractInvocationType.Send, + methodName: "setName", + params: [newName], + gas: 1000000, + signingCredential: { + ethAccount: testEthAccount.address, + secret: testEthAccount.privateKey, + type: Web3SigningCredentialType.PrivateKeyHex, + }, + nonce: 1, + })).rejects.toThrowError( + expect.objectContaining({ + message: expect.stringContaining("Nonce too low"), + stack: expect.stringContaining("Nonce too low"), + }) + ); + const req: InvokeContractV1Request = { contractName: HelloWorldContractJson.contractName, contractAbi: HelloWorldContractJson.abi, diff --git a/packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/invoke-contract.test.ts b/packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/invoke-contract.test.ts index d596bceea2..0bd2e45db2 100644 --- a/packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/invoke-contract.test.ts +++ b/packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/invoke-contract.test.ts @@ -183,25 +183,25 @@ describe(testCase, () => { }); expect(setNameOut).toBeTruthy(); - try { - const setNameOutInvalid = await connector.invokeContract({ - contractName, - keychainId: keychainPlugin.getKeychainId(), - invocationType: EthContractInvocationType.Send, - methodName: "setName", - params: [newName], - gas: 1000000, - signingCredential: { - ethAccount: testEthAccount.address, - secret: testEthAccount.privateKey, - type: Web3SigningCredentialType.PrivateKeyHex, - }, - nonce: 1, - }); - expect(setNameOutInvalid.transactionReceipt).toBeFalsy(); - } catch (error) { - expect(error.message).toMatch("Nonce too low"); - } + await expect(connector.invokeContract({ + contractName, + keychainId: keychainPlugin.getKeychainId(), + invocationType: EthContractInvocationType.Send, + methodName: "setName", + params: [newName], + gas: 1000000, + signingCredential: { + ethAccount: testEthAccount.address, + secret: testEthAccount.privateKey, + type: Web3SigningCredentialType.PrivateKeyHex, + }, + nonce: 1, + })).rejects.toThrowError( + expect.objectContaining({ + message: expect.stringContaining("Nonce too low"), + }) + ); + const { callOutput: getNameOut } = await connector.invokeContract({ contractName, @@ -286,8 +286,8 @@ describe(testCase, () => { }); expect(setNameOut).toBeTruthy(); - try { - const setNameOutInvalid = await connector.invokeContract({ + await expect( + connector.invokeContract({ contractName, keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.Send, @@ -296,11 +296,8 @@ describe(testCase, () => { gas: 1000000, signingCredential, nonce: 4, - }); - expect(setNameOutInvalid.transactionReceipt).toBeFalsy(); - } catch (error) { - expect(error.message).toMatch("Nonce too low"); - } + }) + ).rejects.toThrow("Nonce too low"); const { callOutput: getNameOut } = await connector.invokeContract({ contractName, diff --git a/packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-get-record-locator.test.ts b/packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-get-record-locator.test.ts index b7126d7f51..f6ee6831e6 100644 --- a/packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-get-record-locator.test.ts +++ b/packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-get-record-locator.test.ts @@ -342,4 +342,4 @@ test("AFTER " + testCase, async (t: Test) => { const pruning = pruneDockerAllIfGithubAction({ logLevel }); await t.doesNotReject(pruning, "Pruning didn't throw OK"); t.end(); -}); +}); \ No newline at end of file diff --git a/packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/openapi/openapi-validation.test.ts b/packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/openapi/openapi-validation.test.ts index 95ae330f70..a56b534c1a 100644 --- a/packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/openapi/openapi-validation.test.ts +++ b/packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/openapi/openapi-validation.test.ts @@ -198,58 +198,62 @@ describe("PluginLedgerConnectorBesu", () => { }); test(`${testCase} - ${fDeploy} - ${cWithoutParams}`, async () => { - try { - const parameters = { - keychainId: keychainIdForUnsigned, - contractAbi: HelloWorldContractJson.abi, - constructorArgs: [], - web3SigningCredential: { - ethAccount: testEthAccount1.address, - secret: testEthAccount1.privateKey, - type: Web3SigningCredentialType.PrivateKeyHex, - }, - }; - await apiClient.deployContractSolBytecodeV1( - parameters as unknown as DeployContractSolidityBytecodeV1Request, - ); - } catch (e) { - expect(e.response.status).toEqual(400); - const fields = e.response.data.map((param: { readonly path: string }) => - param.path.replace("/body/", ""), - ); - expect(fields.includes("contractName")).toBeTrue(); - expect(fields.includes("bytecode")).toBeTrue(); - expect(fields.includes("gas")).toBeFalse(); - } + const parameters = { + keychainId: keychainIdForUnsigned, + contractAbi: HelloWorldContractJson.abi, + constructorArgs: [], + web3SigningCredential: { + ethAccount: testEthAccount1.address, + secret: testEthAccount1.privateKey, + type: Web3SigningCredentialType.PrivateKeyHex, + }, + }; + + await expect(apiClient.deployContractSolBytecodeV1( + parameters as unknown as DeployContractSolidityBytecodeV1Request, + )).rejects.toMatchObject({ + response: { + status: 400, + data: expect.arrayContaining([ + expect.objectContaining({ path: expect.stringContaining("/body/contractName") }), + expect.objectContaining({ path: expect.stringContaining("/body/bytecode") }), + expect.not.objectContaining({ path: expect.stringContaining("/body/gas") }) + ]) + } + }); + + }); test(`${testCase} - ${fDeploy} - ${cInvalidParams}`, async () => { - try { - const parameters = { - keychainId: keychainIdForUnsigned, - contractName: HelloWorldContractJson.contractName, - contractAbi: HelloWorldContractJson.abi, - constructorArgs: [], - web3SigningCredential: { - ethAccount: testEthAccount1.address, - secret: testEthAccount1.privateKey, - type: Web3SigningCredentialType.PrivateKeyHex, - }, - bytecode: HelloWorldContractJson.bytecode, - gas: 1000000, - fake: 4, - }; - await apiClient.deployContractSolBytecodeV1( - parameters as DeployContractSolidityBytecodeV1Request, - ); - } catch (e) { - expect(e.response.status).toEqual(400); - const fields = e.response.data.map((param: { readonly path: string }) => - param.path.replace("/body/", ""), - ); - expect(fields.includes("fake")).toBeTrue(); - } + + const parameters = { + keychainId: keychainIdForUnsigned, + contractName: HelloWorldContractJson.contractName, + contractAbi: HelloWorldContractJson.abi, + constructorArgs: [], + web3SigningCredential: { + ethAccount: testEthAccount1.address, + secret: testEthAccount1.privateKey, + type: Web3SigningCredentialType.PrivateKeyHex, + }, + bytecode: HelloWorldContractJson.bytecode, + gas: 1000000, + fake: 4, + }; + + await expect(apiClient.deployContractSolBytecodeV1( + parameters as DeployContractSolidityBytecodeV1Request, + )).rejects.toMatchObject({ + response: { + status: 400, + data: expect.arrayContaining([ + expect.objectContaining({ path: "/body/fake" }), + ]), + }, + }); + }); test(`${testCase} - ${fInvoke} - ${cOk}`, async () => { @@ -274,54 +278,59 @@ describe("PluginLedgerConnectorBesu", () => { }); test(`${testCase} - ${fInvoke} - ${cWithoutParams}`, async () => { - try { - const parameters = { - keychainId: keychainIdForUnsigned, - invocationType: EthContractInvocationType.Call, - methodName: "sayHello", - params: [], - signingCredential: { - ethAccount: testEthAccount1.address, - secret: testEthAccount1.privateKey, - type: Web3SigningCredentialType.PrivateKeyHex, - }, - }; - await apiClient.invokeContractV1( - parameters as any as InvokeContractV1Request, - ); - } catch (e) { - expect(e.response.status).toEqual(400); - const fields = e.response.data.map((param: { readonly path: string }) => - param.path.replace("/body/", ""), - ); - expect(fields.includes("contractName")).toBeTrue(); - expect(fields.includes("gas")).toBeFalse(); - } + + const parameters = { + keychainId: keychainIdForUnsigned, + invocationType: EthContractInvocationType.Call, + methodName: "sayHello", + params: [], + signingCredential: { + ethAccount: testEthAccount1.address, + secret: testEthAccount1.privateKey, + type: Web3SigningCredentialType.PrivateKeyHex, + }, + }; + + await expect(apiClient.invokeContractV1( + parameters as any as InvokeContractV1Request, + )).rejects.toMatchObject({ + response: { + status: 400, + data: expect.arrayContaining([ + expect.objectContaining({ path: expect.stringContaining("/body/contractName") }), + expect.not.objectContaining({ path: expect.stringContaining("/body/gas") }) + ]) + } + }); + }); test(`${testCase} - ${fInvoke} - ${cInvalidParams}`, async () => { - try { - const parameters = { - contractName: "HelloWorld", - keychainId: keychainIdForUnsigned, - invocationType: EthContractInvocationType.Call, - methodName: "sayHello", - params: [], - signingCredential: { - ethAccount: testEthAccount1.address, - secret: testEthAccount1.privateKey, - type: Web3SigningCredentialType.PrivateKeyHex, - }, - fake: 4, - }; - await apiClient.invokeContractV1(parameters as InvokeContractV1Request); - } catch (e) { - expect(e.response.status).toEqual(400); - const fields = e.response.data.map((param: { readonly path: string }) => - param.path.replace("/body/", ""), - ); - expect(fields.includes("fake")).toBeTrue(); - } + + const parameters = { + contractName: "HelloWorld", + keychainId: keychainIdForUnsigned, + invocationType: EthContractInvocationType.Call, + methodName: "sayHello", + params: [], + signingCredential: { + ethAccount: testEthAccount1.address, + secret: testEthAccount1.privateKey, + type: Web3SigningCredentialType.PrivateKeyHex, + }, + fake: 4, + }; + + await expect(apiClient.invokeContractV1(parameters as InvokeContractV1Request)) + .rejects.toMatchObject({ + response: { + status: 400, + data: expect.arrayContaining([ + expect.objectContaining({ path: expect.stringContaining("/body/fake") }) + ]) + } + }); + }); test(`${testCase} - ${fRun} - ${cOk}`, async () => { @@ -353,59 +362,65 @@ describe("PluginLedgerConnectorBesu", () => { }); test(`${testCase} - ${fRun} - ${cWithoutParams}`, async () => { - try { - const parameters = { - web3SigningCredential: { - ethAccount: testEthAccount1.address, - secret: testEthAccount1.privateKey, - type: Web3SigningCredentialType.PrivateKeyHex, - }, - transactionConfig: { - from: testEthAccount1.address, - to: testEthAccount2.address, - value: 10e7, - gas: 1000000, - }, - }; - await apiClient.runTransactionV1(parameters as RunTransactionRequest); - } catch (e) { - expect(e.response.status).toEqual(400); - const fields = e.response.data.map((param: { readonly path: string }) => - param.path.replace("/body/", ""), - ); - expect(fields.includes("consistencyStrategy")).toBeTrue(); - } + + const parameters = { + web3SigningCredential: { + ethAccount: testEthAccount1.address, + secret: testEthAccount1.privateKey, + type: Web3SigningCredentialType.PrivateKeyHex, + }, + transactionConfig: { + from: testEthAccount1.address, + to: testEthAccount2.address, + value: 10e7, + gas: 1000000, + }, + }; + + await expect(apiClient.runTransactionV1(parameters as RunTransactionRequest)) + .rejects.toMatchObject({ + response: { + status: 400, + data: expect.arrayContaining([ + expect.objectContaining({ path: expect.stringContaining("/body/consistencyStrategy") }) + ]) + } + }); + }); test(`${testCase} - ${fRun} - ${cInvalidParams}`, async () => { - try { - const parameters = { - web3SigningCredential: { - ethAccount: testEthAccount1.address, - secret: testEthAccount1.privateKey, - type: Web3SigningCredentialType.PrivateKeyHex, - }, - transactionConfig: { - from: testEthAccount1.address, - to: testEthAccount2.address, - value: 10e7, - gas: 1000000, - }, - consistencyStrategy: { - blockConfirmations: 0, - receiptType: ReceiptType.NodeTxPoolAck, - timeoutMs: 5000, - }, - fake: 4, - }; - await apiClient.runTransactionV1(parameters as RunTransactionRequest); - } catch (e) { - expect(e.response.status).toEqual(400); - const fields = e.response.data.map((param: { readonly path: string }) => - param.path.replace("/body/", ""), - ); - expect(fields.includes("fake")).toBeTrue(); - } + + const parameters = { + web3SigningCredential: { + ethAccount: testEthAccount1.address, + secret: testEthAccount1.privateKey, + type: Web3SigningCredentialType.PrivateKeyHex, + }, + transactionConfig: { + from: testEthAccount1.address, + to: testEthAccount2.address, + value: 10e7, + gas: 1000000, + }, + consistencyStrategy: { + blockConfirmations: 0, + receiptType: ReceiptType.NodeTxPoolAck, + timeoutMs: 5000, + }, + fake: 4, + }; + + await expect(apiClient.runTransactionV1(parameters as RunTransactionRequest)) + .rejects.toMatchObject({ + response: { + status: 400, + data: expect.arrayContaining([ + expect.objectContaining({ path: expect.stringContaining("/body/fake") }) + ]) + } + }); + }); test(`${testCase} - ${fSign} - ${cOk}`, async () => { @@ -482,21 +497,21 @@ describe("PluginLedgerConnectorBesu", () => { expect(runTxRes.data).toBeTruthy(); expect((runTxRes.data as any).data.transactionReceipt).toBeTruthy(); - try { - const parameters = { - keychainRef: keychainRefForSigned, - transactionHash: (runTxRes.data as any).data.transactionReceipt - .transactionHash, - }; - - await apiClient.signTransactionV1(parameters as SignTransactionRequest); - } catch (e) { - expect(e.response.status).toEqual(400); - const fields = e.response.data.map((param: any) => - param.path.replace("/body/", ""), - ); - expect(fields.includes("keychainId")).toBeTrue(); - } + const parameters = { + keychainRef: keychainRefForSigned, + transactionHash: (runTxRes.data as any).data.transactionReceipt.transactionHash, + }; + + await expect(apiClient.signTransactionV1(parameters as SignTransactionRequest)) + .rejects.toMatchObject({ + response: { + status: 400, + data: expect.arrayContaining([ + expect.objectContaining({ path: expect.stringContaining("/body/keychainId") }) + ]) + } + }); + }); test(`${testCase} - ${fSign} - ${cInvalidParams}`, async () => { @@ -523,23 +538,23 @@ describe("PluginLedgerConnectorBesu", () => { expect(runTxRes.data).toBeTruthy(); expect((runTxRes.data as any).data.transactionReceipt).toBeTruthy(); - try { - const parameters = { - keychainId: keychainIdForSigned, - keychainRef: keychainRefForSigned, - transactionHash: (runTxRes.data as any).data.transactionReceipt - .transactionHash, - fake: 4, - }; - - await apiClient.signTransactionV1(parameters as SignTransactionRequest); - } catch (e) { - expect(e.response.status).toEqual(400); - const fields = e.response.data.map((param: { readonly path: string }) => - param.path.replace("/body/", ""), - ); - expect(fields.includes("fake")).toBeTrue(); - } + const parameters = { + keychainId: keychainIdForSigned, + keychainRef: keychainRefForSigned, + transactionHash: (runTxRes.data as any).data.transactionReceipt.transactionHash, + fake: 4, + }; + + await expect(apiClient.signTransactionV1(parameters as SignTransactionRequest)) + .rejects.toMatchObject({ + response: { + status: 400, + data: expect.arrayContaining([ + expect.objectContaining({ path: expect.stringContaining("/body/fake") }) + ]) + } + }); + }); test(`${testCase} - ${fBalance} - ${cOk}`, async () => { @@ -550,32 +565,38 @@ describe("PluginLedgerConnectorBesu", () => { }); test(`${testCase} - ${fBalance} - ${cWithoutParams}`, async () => { - try { - const parameters = {}; - await apiClient.getBalanceV1(parameters as GetBalanceV1Request); - } catch (e) { - expect(e.response.status).toEqual(400); - const fields = e.response.data.map((param: { readonly path: string }) => - param.path.replace("/body/", ""), - ); - expect(fields.includes("address")).toBeTrue(); - } + + const parameters = {}; // Empty parameters object + + await expect(apiClient.getBalanceV1(parameters as GetBalanceV1Request)) + .rejects.toMatchObject({ + response: { + status: 400, + data: expect.arrayContaining([ + expect.objectContaining({ path: expect.stringContaining("/body/address") }) + ]) + } + }); + }); test(`${testCase} - ${fBalance} - ${cInvalidParams}`, async () => { - try { - const parameters = { - address: firstHighNetWorthAccount, - fake: 4, - }; - await apiClient.getBalanceV1(parameters as GetBalanceV1Request); - } catch (e) { - expect(e.response.status).toEqual(400); - const fields = e.response.data.map((param: { readonly path: string }) => - param.path.replace("/body/", ""), - ); - expect(fields.includes("fake")).toBeTrue(); - } + + const parameters = { + address: firstHighNetWorthAccount, + fake: 4, + }; + + await expect(apiClient.getBalanceV1(parameters as GetBalanceV1Request)) + .rejects.toMatchObject({ + response: { + status: 400, + data: expect.arrayContaining([ + expect.objectContaining({ path: expect.stringContaining("/body/fake") }) + ]) + } + }); + }); test(`${testCase} - ${fBlock} - ${cOk}`, async () => { @@ -586,32 +607,38 @@ describe("PluginLedgerConnectorBesu", () => { }); test(`${testCase} - ${fBlock} - ${cWithoutParams}`, async () => { - try { - const parameters = {}; - await apiClient.getBlockV1(parameters as GetBlockV1Request); - } catch (e) { - expect(e.response.status).toEqual(400); - const fields = e.response.data.map((param: { readonly path: string }) => - param.path.replace("/body/", ""), - ); - expect(fields.includes("blockHashOrBlockNumber")).toBeTrue(); - } + + const parameters = {}; // Empty parameters object + + await expect(apiClient.getBlockV1(parameters as GetBlockV1Request)) + .rejects.toMatchObject({ + response: { + status: 400, + data: expect.arrayContaining([ + expect.objectContaining({ path: expect.stringContaining("/body/blockHashOrBlockNumber") }) + ]) + } + }); + }); test(`${testCase} - ${fBlock} - ${cInvalidParams}`, async () => { - try { - const parameters = { - blockHashOrBlockNumber: 0, - fake: 4, - }; - await apiClient.getBlockV1(parameters as GetBlockV1Request); - } catch (e) { - expect(e.response.status).toEqual(400); - const fields = e.response.data.map((param: { readonly path: string }) => - param.path.replace("/body/", ""), - ); - expect(fields.includes("fake")).toBeTrue(); - } + + const parameters = { + blockHashOrBlockNumber: 0, + fake: 4, + }; + + await expect(apiClient.getBlockV1(parameters as GetBlockV1Request)) + .rejects.toMatchObject({ + response: { + status: 400, + data: expect.arrayContaining([ + expect.objectContaining({ path: expect.stringContaining("/body/fake") }) + ]) + } + }); + }); test(`${testCase} - ${fPastLogs} - ${cOk}`, async () => { @@ -624,9 +651,11 @@ describe("PluginLedgerConnectorBesu", () => { }); test(`${testCase} - ${fPastLogs} - ${cWithoutParams}`, async () => { + try { const parameters = {}; - await apiClient.getPastLogsV1(parameters as GetPastLogsV1Request); + const response = await apiClient.getPastLogsV1(parameters as GetPastLogsV1Request); + console.log("e.response.status should be 400 but actually is,", response.status) } catch (e) { expect(e.response.status).toEqual(400); const fields = e.response.data.map((param: { readonly path: string }) => @@ -634,22 +663,41 @@ describe("PluginLedgerConnectorBesu", () => { ); expect(fields.includes("address")).toBeTrue(); } + + //since status code is actually 200 refactored approach does not work + + // const parameters = {}; // Empty parameters object + + // await expect(apiClient.getPastLogsV1(parameters as GetPastLogsV1Request)) + // .rejects.toMatchObject({ + // response: { + // status: 400, + // data: expect.arrayContaining([ + // expect.objectContaining({ path: expect.stringContaining("/body/address") }) + // ]) + // } + // }); + + }); test(`${testCase} - ${fPastLogs} - ${cInvalidParams}`, async () => { - try { - const parameters = { - address: firstHighNetWorthAccount, - fake: 4, - }; - await apiClient.getPastLogsV1(parameters as GetPastLogsV1Request); - } catch (e) { - expect(e.response.status).toEqual(400); - const fields = e.response.data.map((param: { readonly path: string }) => - param.path.replace("/body/", ""), - ); - expect(fields.includes("fake")).toBeTrue(); - } + + const parameters = { + address: firstHighNetWorthAccount, + fake: 4, + }; + + await expect(apiClient.getPastLogsV1(parameters as GetPastLogsV1Request)) + .rejects.toMatchObject({ + response: { + status: 400, + data: expect.arrayContaining([ + expect.objectContaining({ path: expect.stringContaining("/body/fake") }) + ]) + } + }); + }); test(`${testCase} - ${fRecord} - ${cOk}`, async () => { @@ -692,7 +740,8 @@ describe("PluginLedgerConnectorBesu", () => { test(`${testCase} - ${fRecord} - ${cWithoutParams}`, async () => { try { const parameters = {}; - await apiClient.getBesuRecordV1(parameters as GetBesuRecordV1Request); + const response = await apiClient.getBesuRecordV1(parameters as GetBesuRecordV1Request); + console.log("e.response.status should be 400 but actually is,", response.status) } catch (e) { expect(e.response.status).toEqual(400); const fields = e.response.data.map((param: any) => @@ -700,22 +749,40 @@ describe("PluginLedgerConnectorBesu", () => { ); expect(fields.includes("transactionHash")).toBeTrue(); } + + // since status code is actually 200 refactored approach does not work + + // const parameters = {}; // Empty parameters object + + // await expect(apiClient.getBesuRecordV1(parameters as GetBesuRecordV1Request)) + // .rejects.toMatchObject({ + // response: { + // status: 400, + // data: expect.arrayContaining([ + // expect.objectContaining({ path: expect.stringContaining("/body/transactionHash") }) + // ]) + // } + // }); + }); test(`${testCase} - ${fRecord} - ${cInvalidParams}`, async () => { - try { - const parameters = { - transactionHash: "", - fake: 5, - }; - await apiClient.getBesuRecordV1(parameters as GetBesuRecordV1Request); - } catch (e) { - expect(e.response.status).toEqual(400); - const fields = e.response.data.map((param: { readonly path: string }) => - param.path.replace("/body/", ""), - ); - expect(fields.includes("fake")).toBeTrue(); - } + + const parameters = { + transactionHash: "", + fake: 5, + }; + + await expect(apiClient.getBesuRecordV1(parameters as GetBesuRecordV1Request)) + .rejects.toMatchObject({ + response: { + status: 400, + data: expect.arrayContaining([ + expect.objectContaining({ path: expect.stringContaining("/body/fake") }) + ]) + } + }); + }); afterAll(async () => {