Skip to content

Commit

Permalink
test(connector-besu): migrate get-past-logs-endpoint to Jest
Browse files Browse the repository at this point in the history
     Primary Changes
     ------------------
     1. Updated the migrate get-past-logs-endpoint test
         to use Jest
     2. Updated the ci.yaml TAPE_TEST_PATTERN to
         incorporate the same

Fixes hyperledger-cacti#3505

Signed-off-by: Akshitha1020 <[email protected]>
  • Loading branch information
Akshitha1020 committed Nov 11, 2024
1 parent aa0108b commit f93bee4
Show file tree
Hide file tree
Showing 11 changed files with 259 additions and 220 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ jobs:
JEST_TEST_COVERAGE_PATH: ./code-coverage-ts/cactus-cmd-api-server
JEST_TEST_CODE_COVERAGE_ENABLED: true
TAPE_TEST_PATTERN: >-
--files={./packages/cactus-cmd-api-server/src/test/typescript/unit/config/self-signed-certificate-generator/certificates-work-for-mutual-tls.test.ts,./packages/cactus-cmd-api-server/src/test/typescript/unit/config/self-signed-certificate-generator/generates-working-certificates.test.ts,./packages/cactus-cmd-api-server/src/test/typescript/unit/grpc-js-proto-loader-client-healthcheck.test.ts,./packages/cactus-cmd-api-server/src/test/typescript/unit/grpc-proto-gen-ts-client-healthcheck.test.ts,./packages/cactus-cmd-api-server/src/test/typescript/unit/grpc-proto-gen-ts-client-m-tls-enabled.test.ts,./packages/cactus-cmd-api-server/src/test/typescript/unit/plugins/install-basic-plugin-ledger-connector-fabric-0-7-0.test.ts}
--files={./packages/cactus-cmd-api-server/src/test/typescript/unit/config/self-signed-certificate-generator/certificates-work-for-mutual-tls.test.ts,./packages/cactus-cmd-api-server/src/test/typescript/unit/config/self-signed-certificate-generator/generates-working-certificates.test.ts,./packages/cactus-cmd-api-server/src/test/typescript/unit/grpc-js-proto-loader-client-healthcheck.test.ts,./packages/cactus-cmd-api-server/src/test/typescript/unit/grpc-proto-gen-ts-client-m-tls-enabled.test.ts,./packages/cactus-cmd-api-server/src/test/typescript/unit/plugins/install-basic-plugin-ledger-connector-fabric-0-7-0.test.ts}
TAPE_TEST_RUNNER_DISABLED: false
runs-on: ubuntu-22.04
steps:
Expand Down Expand Up @@ -2381,7 +2381,7 @@ jobs:
JEST_TEST_COVERAGE_PATH: ./code-coverage-ts/ctp-ledger-connector-besu
JEST_TEST_CODE_COVERAGE_ENABLED: true
TAPE_TEST_PATTERN: >-
--files={./packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/get-block-endpoint.test.ts,./packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/get-past-logs-endpoint.test.ts,./packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/get-transaction-endpoint.test.ts,./packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/v21-get-block-endpoint.test.ts,./packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/v21-get-past-logs-endpoint.test.ts}
--files={./packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/get-block-endpoint.test.ts,./packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/get-transaction-endpoint.test.ts,./packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/v21-get-block-endpoint.test.ts,./packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/v21-get-past-logs-endpoint.test.ts}
TAPE_TEST_RUNNER_DISABLED: false
runs-on: ubuntu-22.04
steps:
Expand Down
2 changes: 0 additions & 2 deletions .taprc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ files:
- ./packages/cactus-common/src/test/typescript/unit/logging/logger.test.ts
- ./packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/v21-get-past-logs-endpoint.test.ts
- ./packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/v21-get-block-endpoint.test.ts
- ./packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/get-past-logs-endpoint.test.ts
- ./packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/get-transaction-endpoint.test.ts
- ./packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/get-block-endpoint.test.ts
- ./packages/cactus-plugin-ledger-connector-fabric/src/test/typescript/integration/identity-client.test.ts
Expand All @@ -48,7 +47,6 @@ files:
- ./packages/cactus-cmd-api-server/src/test/typescript/unit/plugins/install-basic-plugin-ledger-connector-fabric-0-7-0.test.ts
- ./packages/cactus-cmd-api-server/src/test/typescript/unit/config/self-signed-certificate-generator/generates-working-certificates.test.ts
- ./packages/cactus-cmd-api-server/src/test/typescript/unit/config/self-signed-certificate-generator/certificates-work-for-mutual-tls.test.ts
- ./packages/cactus-cmd-api-server/src/test/typescript/unit/grpc-proto-gen-ts-client-healthcheck.test.ts
- ./packages/cactus-cmd-api-server/src/test/typescript/unit/grpc-js-proto-loader-client-healthcheck.test.ts
- ./packages/cactus-cmd-api-server/src/test/typescript/unit/grpc-proto-gen-ts-client-m-tls-enabled.test.ts
- ./extensions/cactus-plugin-object-store-ipfs/src/test/typescript/integration/plugin-object-store-ipfs.test.ts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"importHelpers": true,
"target": "ES2022",
"lib": [
"es2018",
"ES2022",
"dom"
],
"resolveJsonModule": true,
Expand Down
6 changes: 2 additions & 4 deletions examples/test-run-transaction/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
"compilerOptions": {
/* Basic Options */
"incremental": true, /* Enable incremental compilation */
"target": "ES2017", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"target": "ES2022", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"module": "CommonJS", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"lib": [
"es2015",
"es2016",
"es2017",
"ES2022",
"dom"
], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
Expand Down
2 changes: 0 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ module.exports = {
`./packages/cactus-common/src/test/typescript/unit/logging/logger.test.ts`,
`./packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/v21-get-past-logs-endpoint.test.ts`,
`./packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/v21-get-block-endpoint.test.ts`,
`./packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/get-past-logs-endpoint.test.ts`,
`./packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/get-transaction-endpoint.test.ts`,
`./packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/get-block-endpoint.test.ts`,
`./packages/cactus-plugin-ledger-connector-fabric/src/test/typescript/integration/identity-client.test.ts`,
Expand All @@ -61,7 +60,6 @@ module.exports = {
`./packages/cactus-cmd-api-server/src/test/typescript/unit/plugins/install-basic-plugin-ledger-connector-fabric-0-7-0.test.ts`,
`./packages/cactus-cmd-api-server/src/test/typescript/unit/config/self-signed-certificate-generator/generates-working-certificates.test.ts`,
`./packages/cactus-cmd-api-server/src/test/typescript/unit/config/self-signed-certificate-generator/certificates-work-for-mutual-tls.test.ts`,
`./packages/cactus-cmd-api-server/src/test/typescript/unit/grpc-proto-gen-ts-client-healthcheck.test.ts`,
`./packages/cactus-cmd-api-server/src/test/typescript/unit/grpc-js-proto-loader-client-healthcheck.test.ts`,
`./packages/cactus-cmd-api-server/src/test/typescript/unit/grpc-proto-gen-ts-client-m-tls-enabled.test.ts`,
`./extensions/cactus-plugin-object-store-ipfs/src/test/typescript/integration/plugin-object-store-ipfs.test.ts`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ import {
import { ApiServer } from "../../../../main/typescript/public-api";
import { ConfigService } from "../../../../main/typescript/public-api";

const testcase = "";

describe(testcase, () => {
describe("ConfigService", () => {
const configService = new ConfigService();
let apiServer: ApiServer,
exampleConfig: ICactusApiServerOptions,
Expand All @@ -24,7 +22,7 @@ describe(testcase, () => {
exampleConfig = await configService.newExampleConfig();
const pluginsPath = path.join(
__dirname,
"../../../../../../", // walk back up to the project root
"../../../../../../../", // walk back up to the project root
".tmp/test/test-cmd-api-server/config-service-example-config-validity_test/", // the dir path from the root
uuidv4(), // then a random directory to ensure proper isolation
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,88 +1,97 @@
import test, { Test } from "tape-promise/tape";

import "jest-extended";
import * as grpc from "@grpc/grpc-js";
import { RuntimeError } from "run-time-error-cjs";

import { LogLevelDesc } from "@hyperledger/cactus-common";

import { ApiServer, ConfigService } from "../../../main/typescript/public-api";
import {
ApiServer,
ConfigService,
ICactusApiServerOptions,
} from "../../../main/typescript/public-api";
import { AuthorizationProtocol } from "../../../main/typescript/public-api";
import { default_service } from "../../../main/typescript/public-api";
import { health_check_response_pb } from "../../../main/typescript/public-api";
import { empty } from "../../../main/typescript/public-api";
import { RuntimeError } from "run-time-error-cjs";

const testCase = "API server: runs gRPC TS-proto web services";
const logLevel: LogLevelDesc = "TRACE";
const logLevel: LogLevelDesc = "INFO";

test(testCase, async (t: Test) => {
const configService = new ConfigService();
const apiSrvOpts = await configService.newExampleConfig();
apiSrvOpts.authorizationProtocol = AuthorizationProtocol.NONE;
apiSrvOpts.configFile = "";
apiSrvOpts.logLevel = logLevel;
apiSrvOpts.apiCorsDomainCsv = "*";
apiSrvOpts.apiPort = 0;
apiSrvOpts.grpcPort = 0;
apiSrvOpts.crpcPort = 0;
apiSrvOpts.cockpitPort = 0;
apiSrvOpts.grpcMtlsEnabled = false;
apiSrvOpts.apiTlsEnabled = false;
apiSrvOpts.plugins = [];
const config = await configService.newExampleConfigConvict(apiSrvOpts);
describe("ApiServer", () => {
let apiServer: ApiServer;
let config: ICactusApiServerOptions;
let apiClient: default_service.org.hyperledger.cactus.cmd_api_server.DefaultServiceClient;

const apiServer = new ApiServer({
config: config.getProperties(),
afterAll(async () => {
await apiServer.shutdown();
});
test.onFinish(async () => await apiServer.shutdown());

const startResponse = apiServer.start();
await t.doesNotReject(
startResponse,
"failed to start API server with dynamic plugin imports configured for it...",
);
t.ok(startResponse, "startResponse truthy OK");
beforeAll(async () => {
const configService = new ConfigService();
const apiSrvOpts = await configService.newExampleConfig();
apiSrvOpts.authorizationProtocol = AuthorizationProtocol.NONE;
apiSrvOpts.configFile = "";
apiSrvOpts.logLevel = logLevel;
apiSrvOpts.apiCorsDomainCsv = "*";
apiSrvOpts.apiPort = 0;
apiSrvOpts.grpcPort = 0;
apiSrvOpts.crpcPort = 0;
apiSrvOpts.cockpitPort = 0;
apiSrvOpts.grpcMtlsEnabled = false;
apiSrvOpts.apiTlsEnabled = false;
apiSrvOpts.plugins = [];
const convictCfg = await configService.newExampleConfigConvict(apiSrvOpts);
config = convictCfg.getProperties();

const addressInfoGrpc = (await startResponse).addressInfoGrpc;
const { address, port } = addressInfoGrpc;
const grpcHostAndPort = `${address}:${port}`;
apiServer = new ApiServer({
config,
});

const apiClient =
new default_service.org.hyperledger.cactus.cmd_api_server.DefaultServiceClient(
grpcHostAndPort,
grpc.credentials.createInsecure(),
);
t.ok(apiClient, "apiClient truthy OK");
const apiServerStart = apiServer.start();
await expect(apiServerStart).toResolve();
const addressInfoGrpc = (await apiServerStart).addressInfoGrpc;
const { address, port } = addressInfoGrpc;
const grpcHostAndPort = `${address}:${port}`;

const responsePromise =
new Promise<health_check_response_pb.org.hyperledger.cactus.cmd_api_server.HealthCheckResponsePB>(
(resolve, reject) => {
apiClient.GetHealthCheckV1(
new empty.google.protobuf.Empty(),
(
error: grpc.ServiceError | null,
response?: health_check_response_pb.org.hyperledger.cactus.cmd_api_server.HealthCheckResponsePB,
) => {
if (error) {
reject(error);
} else if (response) {
resolve(response);
} else {
throw new RuntimeError("No error, nor response received.");
}
},
);
},
);
apiClient =
new default_service.org.hyperledger.cactus.cmd_api_server.DefaultServiceClient(
grpcHostAndPort,
grpc.credentials.createInsecure(),
);
expect(apiClient).toBeTruthy();
});

await t.doesNotReject(responsePromise, "No error in healthcheck OK");
const res = await responsePromise;
test("runs gRPC TS-proto web services", async () => {
type HealthCheckResponsePB =
health_check_response_pb.org.hyperledger.cactus.cmd_api_server.HealthCheckResponsePB;

const resHc = res?.toObject();
const grpcReq = new Promise<HealthCheckResponsePB>((resolve, reject) => {
apiClient.GetHealthCheckV1(
new empty.google.protobuf.Empty(),
(error: grpc.ServiceError | null, response?: HealthCheckResponsePB) => {
if (error) {
reject(error);
} else if (response) {
resolve(response);
} else {
reject(new RuntimeError("No error, nor response received."));
}
},
);
});

t.ok(resHc, `healthcheck response truthy OK`);
t.ok(resHc?.createdAt, `resHc.createdAt truthy OK`);
t.ok(resHc?.memoryUsage, `resHc.memoryUsage truthy OK`);
t.ok(resHc?.memoryUsage?.rss, `resHc.memoryUsage.rss truthy OK`);
t.ok(resHc?.success, `resHc.success truthy OK`);
t.end();
await expect(grpcReq).resolves.toMatchObject({
toObject: expect.toBeFunction(),
});

const resPb = await grpcReq;
const res = resPb.toObject();

expect(res).toMatchObject({
createdAt: expect.toBeDateString(),
memoryUsage: expect.objectContaining({
rss: expect.toBeNumber(),
}),
success: true,
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@ import { RuntimeError } from "run-time-error-cjs";
import { coerceUnknownToError } from "./coerce-unknown-to-error";

/**
* ## DEPRECATED
*
* Instead of relying on this function, in the future, use the new `cause`
* property of the built-in `Error` type in combination
* with the `asError(unknown)` utility function:
* ```typescript
* import { asError } from "@hyperledger/cactus-common";
*
* try {
* await performSomeImportantOperation();
* } catch (ex: unknown) {
* const cause = asError(ex);
* throw new Error("Something went wrong while doing something.", { cause });
* }
* ```
* More information about the EcmaScript proposal that made this possible:
* https://github.com/tc39/proposal-error-cause
*
* ## The Old Documentation Prior to the Deprecation:
* ### STANDARD EXCEPTION HANDLING - EXAMPLE WITH RE-THROW:
*
* Use the this utility function and pass in any throwable of whatever type and format
Expand Down Expand Up @@ -77,6 +96,7 @@ import { coerceUnknownToError } from "./coerce-unknown-to-error";
* return result; // 42
* }
* ```
* @deprecated
*
* @param message The contextual information that will be passed into the
* constructor of the returned {@link RuntimeError} instance.
Expand All @@ -93,9 +113,28 @@ export function createRuntimeErrorWithCause(
}

/**
* ## DEPRECATED
*
* Instead of relying on this function, in the future, use the new `cause`
* property of the built-in `Error` type in combination
* with the `asError(unknown)` utility function:
* ```typescript
* import { asError } from "@hyperledger/cactus-common";
*
* try {
* await performSomeImportantOperation();
* } catch (ex: unknown) {
* const cause = asError(ex);
* throw new Error("Something went wrong while doing something.", { cause });
* }
* ```
* More information about the EcmaScript proposal that made this possible:
* https://github.com/tc39/proposal-error-cause
*
* An alias to the `createRuntimeErrorWithCause` function for those prefering
* a shorter utility for their personal style.
*
* @deprecated
* @see {@link createRuntimeErrorWithCause}
* @returns `RuntimeError`
*/
Expand Down
Loading

0 comments on commit f93bee4

Please sign in to comment.