From 8dcb4516d9b879c0fa6093d85980bb68c4fd1752 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Augusto?= Date: Mon, 4 Mar 2024 18:37:03 +0000 Subject: [PATCH] fix(satp-hermes): fix build bugs and hanging tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: André Augusto Co-authored-by: Peter Somogyvari Co-authored-by: Rafael Belchior Signed-off-by: Rafael Belchior test(satp-hermes): fix hanging tests Signed-off-by: Rafael Belchior refactor(SATP-Hermes): fix cspell and lint Signed-off-by: André Augusto --- .../cactus-plugin-satp-hermes/package.json | 4 +- .../{ => src}/knex/knexfile-remote.ts | 2 +- .../{ => src}/knex/knexfile.ts | 0 .../20220331132128_create_logs_table.js | 0 ...20240130234303_create_remote_logs_table.js | 0 .../src/main/typescript/core/constants.ts | 3 + .../typescript/core/stage-services/stage3.ts | 1 - .../core/stage-services/test-services.ts | 7 +- .../src/main/typescript/core/types.ts | 19 +- .../plugin-factory-gateway-orchestrator.ts | 9 +- .../src/main/typescript/gateway-refactor.ts | 372 ++++++++++++------ .../typescript/gol/gateway-orchestrator.ts | 29 +- .../src/main/typescript/public-api.ts | 1 - .../repository/knex-local-log-repository.ts | 2 +- .../repository/knex-remote-log-repository.ts | 2 +- .../main/typescript/web-services/router.ts | 12 +- .../main/typescript/web-services/test/test.ts | 30 +- .../typescript/web-services/test/test2.ts | 8 +- .../src/test/cucumber/placeholder | 1 + .../backup-gateway-after-client-crash.test.ts | 67 ++-- .../client-crash-after-delete-asset.test.ts | 67 ++-- .../client-crash-after-lock-asset.test.ts | 66 ++-- ...nt-crash-after-transfer-initiation.test.ts | 27 +- .../gateway-coordinator-init.test.ts | 102 ++++- ...dap-api-call-with-ledger-connector.test.ts | 64 ++- .../integration/odap-api-call.test.ts | 27 +- .../integration/odap-rollback.test.ts | 69 ++-- .../test/typescript/integration/odap.test.ts | 28 +- .../server-crash-after-create-asset.test.ts | 66 ++-- ...er-crash-after-transfer-initiation.test.ts | 39 +- .../src/test/typescript/knex.config.ts | 14 +- .../unit/client/commit-final.test.ts | 24 +- .../unit/client/commit-preparation.test.ts | 14 +- .../unit/client/lock-evidence.test.ts | 14 +- .../unit/client/transfer-commence.test.ts | 14 +- .../client/transfer-initialization.test.ts | 14 +- .../typescript/unit/recovery/logging.test.ts | 16 +- .../unit/recovery/recover-success.test.ts | 9 + .../unit/recovery/recover-update-ack.test.ts | 14 +- .../unit/recovery/recover-update.test.ts | 15 +- .../typescript/unit/recovery/recover.test.ts | 14 +- .../unit/server/commit-final.test.ts | 24 +- .../unit/server/commit-preparation.test.ts | 14 +- .../unit/server/lock-evidence.test.ts | 31 +- .../unit/server/transfer-commence.test.ts | 14 +- .../unit/server/transfer-complete.test.ts | 14 +- .../server/transfer-initialization.test.ts | 14 +- 47 files changed, 778 insertions(+), 619 deletions(-) rename packages/cactus-plugin-satp-hermes/{ => src}/knex/knexfile-remote.ts (76%) rename packages/cactus-plugin-satp-hermes/{ => src}/knex/knexfile.ts (100%) rename packages/cactus-plugin-satp-hermes/{ => src}/knex/migrations/20220331132128_create_logs_table.js (100%) rename packages/cactus-plugin-satp-hermes/{ => src}/knex/migrations/20240130234303_create_remote_logs_table.js (100%) create mode 100644 packages/cactus-plugin-satp-hermes/src/main/typescript/core/constants.ts create mode 100644 packages/cactus-plugin-satp-hermes/src/test/cucumber/placeholder diff --git a/packages/cactus-plugin-satp-hermes/package.json b/packages/cactus-plugin-satp-hermes/package.json index c0b5ae3ca70..2f1a85c0acd 100644 --- a/packages/cactus-plugin-satp-hermes/package.json +++ b/packages/cactus-plugin-satp-hermes/package.json @@ -45,8 +45,8 @@ "scripts": { "build": "run-p tsc codegen", "build-proto": "buf build --path src/main/proto --verbose", - "build:dev:backend:postbuild": "mkdir -p ./dist/lib/main/knex && cp -r ./knex/* ./dist/lib/main/knex", - "codegen": "yarn run --top-level run-s 'codegen:*'", + "build:dev:backend:postbuild": "mkdir -p ./dist/lib/knex && cp -r ./src/knex/* ./dist/lib/knex", + "codegen": "run-p 'codegen:*'", "codegen:openapi": "npm run generate-sdk", "codegen:proto": "npm run generate-proto", "generate-proto": "cd src/main/proto && buf generate --template buf.gen.yaml --config buf.yaml --verbose", diff --git a/packages/cactus-plugin-satp-hermes/knex/knexfile-remote.ts b/packages/cactus-plugin-satp-hermes/src/knex/knexfile-remote.ts similarity index 76% rename from packages/cactus-plugin-satp-hermes/knex/knexfile-remote.ts rename to packages/cactus-plugin-satp-hermes/src/knex/knexfile-remote.ts index 7966df074d3..6b368365104 100644 --- a/packages/cactus-plugin-satp-hermes/knex/knexfile-remote.ts +++ b/packages/cactus-plugin-satp-hermes/src/knex/knexfile-remote.ts @@ -5,7 +5,7 @@ module.exports = { development: { client: "sqlite3", connection: { - filename: path.resolve(__dirname, ".dev-remote.sqlite3"), + filename: path.resolve(__dirname, ".dev.remote-" + uuidv4() + ".sqlite3"), }, migrations: { directory: path.resolve(__dirname, "migrations"), diff --git a/packages/cactus-plugin-satp-hermes/knex/knexfile.ts b/packages/cactus-plugin-satp-hermes/src/knex/knexfile.ts similarity index 100% rename from packages/cactus-plugin-satp-hermes/knex/knexfile.ts rename to packages/cactus-plugin-satp-hermes/src/knex/knexfile.ts diff --git a/packages/cactus-plugin-satp-hermes/knex/migrations/20220331132128_create_logs_table.js b/packages/cactus-plugin-satp-hermes/src/knex/migrations/20220331132128_create_logs_table.js similarity index 100% rename from packages/cactus-plugin-satp-hermes/knex/migrations/20220331132128_create_logs_table.js rename to packages/cactus-plugin-satp-hermes/src/knex/migrations/20220331132128_create_logs_table.js diff --git a/packages/cactus-plugin-satp-hermes/knex/migrations/20240130234303_create_remote_logs_table.js b/packages/cactus-plugin-satp-hermes/src/knex/migrations/20240130234303_create_remote_logs_table.js similarity index 100% rename from packages/cactus-plugin-satp-hermes/knex/migrations/20240130234303_create_remote_logs_table.js rename to packages/cactus-plugin-satp-hermes/src/knex/migrations/20240130234303_create_remote_logs_table.js diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/constants.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/constants.ts new file mode 100644 index 00000000000..4c2a8ac472f --- /dev/null +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/constants.ts @@ -0,0 +1,3 @@ +export const DEFAULT_PORT_GATEWAY_SERVER = 3010; +export const DEFAULT_PORT_GATEWAY_CLIENT = DEFAULT_PORT_GATEWAY_SERVER + 1; +export const DEFAULT_PORT_GATEWAY_UI = DEFAULT_PORT_GATEWAY_SERVER + 2; \ No newline at end of file diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/stage3.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/stage3.ts index 991aa1a51e7..e69de29bb2d 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/stage3.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/stage3.ts @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/test-services.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/test-services.ts index 4be9bb56536..0cb18dc8343 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/test-services.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/test-services.ts @@ -1,5 +1,5 @@ import { ConnectRouter } from "@connectrpc/connect"; -import { Message } from "../../generated/proto/test/message_pb"; +// import { Message } from "../../generated/proto/test/message_pb"; import { TestService } from "../../generated/proto/test/message_connect"; export const testRouter = (router: ConnectRouter) => @@ -8,8 +8,7 @@ export const testRouter = (router: ConnectRouter) => // implements rpc Say async sendMessage(req) { return { - sentence: `You said: ${req}` - } + sentence: `You said: ${req}`, + }; }, }); - diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/types.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/types.ts index 956150b24db..e534679f3d9 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/types.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/types.ts @@ -1,12 +1,4 @@ -import { - Secp256k1Keys, - Logger, - Checks, - LoggerProvider, - JsObjectSigner, - IJsObjectSignerOptions, - LogLevelDesc, -} from "@hyperledger/cactus-common"; +import { Secp256k1Keys, LogLevelDesc } from "@hyperledger/cactus-common"; import { ValidatorOptions } from "class-validator"; export enum CurrentDrafts { @@ -18,7 +10,11 @@ export enum CurrentDrafts { export type DraftVersions = { [K in CurrentDrafts]: string; }; -export type ShutdownHook = () => Promise; + +export type ShutdownHook = { + name: string; + hook: () => Promise; +}; export enum SupportedGatewayImplementations { FABRIC = "FabricSATPGateway", @@ -35,7 +31,8 @@ export type GatewayIdentity = { version: DraftVersions[]; supportedChains: SupportedGatewayImplementations[]; proofID?: string; - port?: number; + gatewayServerPort?: number; + gatewayClientPort?: number; address?: | `http://${string}` | `https://${string}` diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/factory/plugin-factory-gateway-orchestrator.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/factory/plugin-factory-gateway-orchestrator.ts index e4b53d98e94..cfbc9c20c5f 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/factory/plugin-factory-gateway-orchestrator.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/factory/plugin-factory-gateway-orchestrator.ts @@ -2,10 +2,7 @@ import { IPluginFactoryOptions, PluginFactory, } from "@hyperledger/cactus-core-api"; -import { - SATPGateway, - SATPGatewayConfig, -} from "../gateway-refactor"; +import { SATPGateway, SATPGatewayConfig } from "../gateway-refactor"; import { validateOrReject } from "class-validator"; export class PluginFactorySATPGateway extends PluginFactory< @@ -13,9 +10,7 @@ export class PluginFactorySATPGateway extends PluginFactory< SATPGatewayConfig, IPluginFactoryOptions > { - async create( - pluginOptions: SATPGatewayConfig, - ): Promise { + async create(pluginOptions: SATPGatewayConfig): Promise { const coordinator = new SATPGateway(pluginOptions); try { diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/gateway-refactor.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/gateway-refactor.ts index 2b3385119fc..3f23bbfbb4b 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/gateway-refactor.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/gateway-refactor.ts @@ -3,56 +3,33 @@ import { Logger, Checks, LoggerProvider, - JsObjectSigner, - IJsObjectSignerOptions, ILoggerOptions, } from "@hyperledger/cactus-common"; import { v4 as uuidv4 } from "uuid"; import { - ICactusPlugin, - IPluginWebService, - IWebServiceEndpoint, - Configuration, -} from "@hyperledger/cactus-core-api"; - -import { - MinLength, - MaxLength, - IsNotEmpty, - ValidateNested, IsDefined, IsNotEmptyObject, IsObject, IsString, Contains, } from "class-validator"; -import { Type } from "class-transformer"; -import fs from "fs"; import path from "path"; -import swaggerUi = require("swagger-ui-express"); -import { - IPluginSatpGatewayConstructorOptions, - PluginSATPGateway, -} from "./plugin-satp-gateway"; -import { Server } from "node:http"; + import { - CurrentDrafts, - DraftVersions, SATPGatewayConfig, GatewayIdentity, ShutdownHook, SupportedGatewayImplementations, } from "./core/types"; -import { pass } from "jest-extended"; import { GatewayOrchestrator } from "./gol/gateway-orchestrator"; -import { log } from "console"; export { SATPGatewayConfig }; -import express, { Express, Request, Response } from 'express'; +import express, { Express } from 'express'; import { expressConnectMiddleware } from "@connectrpc/connect-express"; import http from "http"; import { configureRoutes } from "./web-services/router"; +import { DEFAULT_PORT_GATEWAY_CLIENT, DEFAULT_PORT_GATEWAY_SERVER } from "./core/constants"; export class SATPGateway { // todo more checks; example port from config is between 3000 and 9000 @@ -71,12 +48,17 @@ export class SATPGateway { @Contains("Gateway") public readonly label = "SATPGateway"; - private gatewayConnectionManager: GatewayOrchestrator; private readonly shutdownHooks: ShutdownHook[]; - private server: any | undefined; + private gatewayConnectionManager: GatewayOrchestrator; + + private gatewayApplication?: Express; + private gatewayServer?: http.Server; + private BOLApplication?: Express; + private BOLServer?: http.Server; + // TODO!: add logic to manage sessions (parallelization, user input, freeze, unfreeze, rollback, recovery) // private sessions: Map = new Map(); - + constructor(public readonly options: SATPGatewayConfig) { const fnTag = `${this.label}#constructor()`; Checks.truthy(options, `${fnTag} arg options`); @@ -103,38 +85,173 @@ export class SATPGateway { }); } - async startupServer(): Promise { + // todo load docs for gateway coordinator and expose them in a http gatewayApplication + setupOpenAPI(): void { + const fnTag = `${this.label}#setupOpenAPI()`; + this.logger.trace(`Entering ${fnTag}`); + + this.logger.error("OpenAPI setup not implemented"); + return; + const specPath = path.join(__dirname, "../../", "/json", "openapi.json"); + this.logger.debug(`Loading OpenAPI specification from ${specPath}`); + + /*const OpenAPISpec = JSON.parse(fs.readFileSync(specPath).toString()); + this.logger.info( + `OpenAPI docs and documentation set up at 📖: \n ${this.config.gid?.address}:${this.config.gid?.gatewayServerPort}/api-docs`, + ); + */ + // todo bind to grpc gateway + // this._app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(OpenAPISpec)); + } + + + static ProcessGatewayCoordinatorConfig( + pluginOptions: SATPGatewayConfig, + ): SATPGatewayConfig { + if (!pluginOptions.keys) { + pluginOptions.keys = Secp256k1Keys.generateKeyPairsBuffer(); + } + + const id = uuidv4(); + if (!pluginOptions.gid) { + pluginOptions.gid = { + id: id, + name: id, + version: [ + { + Core: "v02", + Architecture: "v02", + Crash: "v02", + }, + ], + supportedChains: [ + SupportedGatewayImplementations.FABRIC, + SupportedGatewayImplementations.BESU, + ], + proofID: "mockProofID1", + gatewayServerPort: DEFAULT_PORT_GATEWAY_SERVER, + gatewayClientPort: DEFAULT_PORT_GATEWAY_CLIENT, + address: "http://localhost", + }; + } else { + if (!pluginOptions.gid.id) { + pluginOptions.gid.id = id; + } + + if (!pluginOptions.gid.name) { + pluginOptions.gid.name = id; + } + + if (!pluginOptions.gid.version) { + pluginOptions.gid.version = [ + { + Core: "v02", + Architecture: "v02", + Crash: "v02", + }, + ]; + } + + if (!pluginOptions.gid.supportedChains) { + pluginOptions.gid.supportedChains = [ + SupportedGatewayImplementations.FABRIC, + SupportedGatewayImplementations.BESU, + ]; + } + + if (!pluginOptions.gid.proofID) { + pluginOptions.gid.proofID = "mockProofID1"; + } + + if (!pluginOptions.gid.gatewayServerPort) { + pluginOptions.gid.gatewayServerPort = DEFAULT_PORT_GATEWAY_SERVER; + } + + if (!pluginOptions.gid.gatewayClientPort) { + pluginOptions.gid.gatewayClientPort = DEFAULT_PORT_GATEWAY_CLIENT; + } + + + if (!pluginOptions.logLevel) { + pluginOptions.logLevel = "DEBUG"; + } + + if (!pluginOptions.environment) { + pluginOptions.environment = "development"; + } + + if (!pluginOptions.enableOpenAPI) { + pluginOptions.enableOpenAPI = true; + } + + if (!pluginOptions.validationOptions) { + // do nothing + } + } + return pluginOptions; + } + + /** + * Startup Methods + * ---------------- + * This section includes methods responsible for starting up the server and its associated services. + * It ensures that both the GatewayServer and BOLServer are initiated concurrently for efficient launch. + */ + async startup(): Promise { const fnTag = `${this.label}#startup()`; - this.logger.debug(`Entering ${fnTag}`); - if (!this.server) { - this.server = express(); - this.server.use(expressConnectMiddleware({ routes: configureRoutes })); - http.createServer(this.server).listen(this.options.gid?.port); + this.logger.trace(`Entering ${fnTag}`); + + await Promise.all([ + this.startupGatewayServer(), + this.startupBOLServer(), + ]); - } else { + this.logger.info("Both GatewayServer and BOLServer have started"); + } + + async startupGatewayServer(): Promise { + const fnTag = `${this.label}#startupGatewayServer()`; + this.logger.trace(`Entering ${fnTag}`); + this.logger.info("Starting gateway server"); + const port = this.options.gid?.gatewayServerPort ?? DEFAULT_PORT_GATEWAY_SERVER; + + if (!this.gatewayApplication || !this.gatewayServer) { + this.gatewayApplication = express(); + this.gatewayApplication.use(expressConnectMiddleware({ routes: configureRoutes })); + this.gatewayServer = http.createServer(this.gatewayApplication).listen(port); + } else { this.logger.warn("Server already running"); } } -async shutdownServer(): Promise { - const fnTag = `${this.label}#shutdown()`; - this.logger.debug(`Entering ${fnTag}`); - if (this.server) { - try { - this.server.close(); - this.server = undefined; - this.logger.info("Server shut down"); - } catch (error) { - this.logger.error(`Error shutting down the server: ${error}`); + + + async startupBOLServer(): Promise { + const fnTag = `${this.label}#startupBOLServer()`; + this.logger.trace(`Entering ${fnTag}`); + this.logger.info("Starting BOL server"); + const port = (this.options.gid?.gatewayClientPort ?? DEFAULT_PORT_GATEWAY_CLIENT); + + if (!this.BOLApplication || !this.BOLServer) { + this.BOLApplication = express(); + // todo + // this.BOLApplication.use(expressConnectMiddleware()); + this.BOLServer = http.createServer(this.BOLApplication).listen(port); + } else { + this.logger.warn("Server already running"); } - } else { - this.logger.warn("Server is not running."); } -} + /** + * Gateway Connection Methods + * -------------------------- + * This section encompasses methods dedicated to establishing connections with gateways. + * It includes functionalities to add gateways based on provided IDs and resolve specific gateway identities. + * These operations are fundamental for setting up and managing gateway connections within the system. + */ - async addGateways(IDs: string[]): Promise { - const fnTag = `${this.label}#connectToGateway()`; - this.logger.debug(`Entering ${fnTag}`); + public async addGateways(IDs: string[]): Promise { + const fnTag = `${this.label}#addGateways()`; + this.logger.trace(`Entering ${fnTag}`); this.logger.info("Connecting to gateway"); const gatewaysToAdd: GatewayIdentity[] = []; const thisID = this.config.gid!.id; @@ -150,9 +267,9 @@ async shutdownServer(): Promise { } // gets an ID, queries a repository, returns an address, port, and proof of identity - resolveGatewayID(ID: string): GatewayIdentity { + private resolveGatewayID(ID: string): GatewayIdentity { const fnTag = `${this.label}#resolveGatewayID()`; - this.logger.debug(`Entering ${fnTag}`); + this.logger.trace(`Entering ${fnTag}`); this.logger.info(`Resolving gateway with ID: ${ID}`); const mockGatewayIdentity: GatewayIdentity[] = [ @@ -171,7 +288,7 @@ async shutdownServer(): Promise { SupportedGatewayImplementations.BESU, ], proofID: "mockProofID1", - port: 3011, + gatewayServerPort: 3011, address: "http://localhost", }, { @@ -189,35 +306,16 @@ async shutdownServer(): Promise { SupportedGatewayImplementations.BESU, ], proofID: "mockProofID1", - port: 3012, + gatewayServerPort: 3012, address: "http://localhost", }, ]; return mockGatewayIdentity.filter((gateway) => gateway.id === ID)[0]; } - // todo load docs for gateway coordinator and expose them in a http server - setupOpenAPI(): void { - const fnTag = `${this.label}#setupOpenAPI()`; - this.logger.debug(`Entering ${fnTag}`); - - this.logger.error("OpenAPI setup not implemented"); - return; - const specPath = path.join(__dirname, "../../", "/json", "openapi.json"); - this.logger.debug(`Loading OpenAPI specification from ${specPath}`); - - const OpenAPISpec = JSON.parse(fs.readFileSync(specPath).toString()); - this.logger.info( - `OpenAPI docs and documentation set up at 📖: \n ${this.config.gid?.address}:${this.config.gid?.port}/api-docs`, - ); - - // todo bind to grpc gateway - // this._app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(OpenAPISpec)); - } - - getGatewaySeeds(): GatewayIdentity[] { + private getGatewaySeeds(): GatewayIdentity[] { const fnTag = `${this.label}#getGatewaySeeds()`; - this.logger.debug(`Entering ${fnTag}`); + this.logger.trace(`Entering ${fnTag}`); const mockGatewayIdentity: GatewayIdentity[] = [ { @@ -235,7 +333,7 @@ async shutdownServer(): Promise { SupportedGatewayImplementations.BESU, ], proofID: "mockProofID1", - port: 3011, + gatewayServerPort: 3011, address: "http://localhost", }, { @@ -253,68 +351,86 @@ async shutdownServer(): Promise { SupportedGatewayImplementations.BESU, ], proofID: "mockProofID1", - port: 3012, + gatewayServerPort: 3014, address: "http://localhost", }, ]; return mockGatewayIdentity; } - static ProcessGatewayCoordinatorConfig( - pluginOptions: SATPGatewayConfig, - ): SATPGatewayConfig { - if (!pluginOptions.keys) { - pluginOptions.keys = Secp256k1Keys.generateKeyPairsBuffer(); - } - if (!pluginOptions.gid) { - const id = uuidv4(); - pluginOptions.gid = { - id: id, - name: id, - version: [ - { - Core: "v02", - Architecture: "v02", - Crash: "v02", - }, - ], - supportedChains: [ - SupportedGatewayImplementations.FABRIC, - SupportedGatewayImplementations.BESU, - ], - proofID: "mockProofID1", - port: 3000, - address: "http://localhost", - }; - } + public getIdentity(): GatewayIdentity { + const fnTag = `${this.label}#getIdentity()`; + this.logger.trace(`Entering ${fnTag}`); + return this.config.gid!; + } - if (!pluginOptions.logLevel) { - pluginOptions.logLevel = "DEBUG"; - } +/** + * Shutdown Methods + * ----------------- + * This section includes methods responsible for cleanly shutting down the server and its associated services. + */ + public onShutdown(hook: ShutdownHook): void { + const fnTag = `${this.label}#onShutdown()`; + this.logger.trace(`Entering ${fnTag}`); + this.logger.debug(`Adding shutdown hook: ${hook.name}`); + this.shutdownHooks.push(hook); + } - if (!pluginOptions.environment) { - pluginOptions.environment = "development"; - } + public async shutdown(): Promise { + const fnTag = `${this.label}#getGatewaySeeds()`; + this.logger.debug(`Entering ${fnTag}`); - if (!pluginOptions.enableOpenAPI) { - pluginOptions.enableOpenAPI = true; - } + this.logger.info("Shutting down Node server - Gateway"); + await this.shutdownGatewayServer(); + + this.logger.info("Shutting down Node server - BOL"); + await this.shutdownBOLServer(); - if (!pluginOptions.validationOptions) { - // do nothing + this.logger.debug("Running shutdown hooks"); + for (const hook of this.shutdownHooks) { + this.logger.debug(`Running shutdown hook: ${hook.name}`); + await hook.hook(); } - return pluginOptions; - } + this.logger.info("Shutting down Gateway Connection Manager") + const connectionsClosed = await this.gatewayConnectionManager.disconnectAll(); - // generate getter for identity - getIdentity(): GatewayIdentity { - return this.config.gid!; + this.logger.info(`Closed ${connectionsClosed} connections`); + this.logger.info("Gateway Coordinator shut down"); + return connectionsClosed; } - - async shutdown(): Promise { - this.logger.info("Shutting down Gateway Coordinator"); - return await this.gatewayConnectionManager.disconnectAll(); - + + private async shutdownGatewayServer(): Promise { + const fnTag = `${this.label}#shutdownServer()`; + this.logger.debug(`Entering ${fnTag}`); + if (this.gatewayServer) { + try { + await this.gatewayServer.close(); + this.gatewayServer = undefined; + this.logger.info("Server shut down"); + } catch (error) { + this.logger.error(`Error shutting down the gatewayApplication: ${error}`); + } + } else { + this.logger.warn("Server is not running."); + } } -} + + private async shutdownBOLServer(): Promise { + const fnTag = `${this.label}#shutdownBOLServer()`; + this.logger.debug(`Entering ${fnTag}`); + if (this.BOLServer) { + try { + await this.BOLServer.close(); + this.BOLServer = undefined; + this.logger.info("Server shut down"); + } catch (error) { + this.logger.error(`Error shutting down the gatewayApplication: ${error}`); + } + } else { + this.logger.warn("Server is not running."); + } + } + +} + diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/gol/gateway-orchestrator.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/gol/gateway-orchestrator.ts index b1b3031c646..28866805a30 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/gol/gateway-orchestrator.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/gol/gateway-orchestrator.ts @@ -1,4 +1,4 @@ -// a helper class to manage connections to counteryparty gateways +// a helper class to manage connections to counterparty gateways import { Logger } from "@hyperledger/cactus-common"; import { GatewayIdentity, GatewayChannel } from "../core/types"; @@ -18,7 +18,6 @@ export class GatewayOrchestrator { public readonly identities: GatewayIdentity[], options: GatewayOrchestratorOptions, ) { - const fnTag = `${this.label}#constructor()`; // add checks this.logger = options.logger; this.logger.info("Initializing Gateway Connection Manager"); @@ -34,7 +33,9 @@ export class GatewayOrchestrator { async connectToCounterPartyGateways(): Promise { const fnTag = `${this.label}#connectToCounterPartyGateways()`; // add checks - this.logger.info(`Connecting to ${this.gatewayIDs.length} gateways`); + this.logger.info( + `${fnTag}, Connecting to ${this.gatewayIDs.length} gateways`, + ); let connected = 0; try { for (const id of this.gatewayIDs) { @@ -47,7 +48,7 @@ export class GatewayOrchestrator { } } } catch (ex) { - this.logger.error(`Failed to connect to gateway`); + this.logger.error(`${fnTag}, Failed to connect to gateway`); this.logger.error(ex); } return connected; @@ -56,17 +57,19 @@ export class GatewayOrchestrator { async addGateways(gateways: GatewayIdentity[]): Promise { const fnTag = `${this.label}#addGateways()`; // add checks - this.logger.info(`Adding ${gateways.length} gateways`); + this.logger.info(`${fnTag}, Adding ${gateways.length} gateways`); for (const gateway of gateways) { const id = gateway.id; if (this.gatewayIDs.includes(id)) { - this.logger.info(`Gateway with id ${id} already exists, igonoring`); + this.logger.info( + `${fnTag}, ${fnTag}, Gateway with id ${id} already exists, ignoring`, + ); continue; } this.gatewayIDs.push(id); this.gateways.set(id, gateway); } - return this.connectToCounterPartyGateways(); + return this.connectToCounterPartyGateways(); } alreadyConnected(ID: string): boolean { @@ -74,7 +77,6 @@ export class GatewayOrchestrator { } // make singleton async createChannels(): Promise { - const fnTag = `${this.label}#boostrapChannels()`; // Add checks and the rest of your logic here const channels: GatewayChannel[] = []; this.gateways.forEach(async (identity) => { @@ -83,7 +85,6 @@ export class GatewayOrchestrator { } async createChannel(identity: GatewayIdentity): Promise { - const fnTag = `${this.label}#createChannel()`; // add checks const channel: GatewayChannel = { id: identity.id, @@ -91,13 +92,17 @@ export class GatewayOrchestrator { return channel; } - async disconnectAll(): Promise { + async disconnectAll(): Promise { + const fnTag = `${this.label}#disconnectAll()`; + let counter = 0; this.channels.forEach(async (channel) => { - this.logger.info(`Disconnecting from ${channel.id}`); - this.logger.error("Not implemented") + this.logger.info(`${fnTag}, Disconnecting from ${channel.id}`); + // ! todo implement disconnect + this.logger.error("Not implemented"); counter++; }); + this.channels.clear(); return counter; } } diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/public-api.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/public-api.ts index 3d3afb7425b..e55548a7dc1 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/public-api.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/public-api.ts @@ -10,7 +10,6 @@ export { import { IPluginFactoryOptions } from "@hyperledger/cactus-core-api"; import { PluginFactoryFabricSATPGateway } from "./factory/plugin-factory-fabric-satp-gateway"; import { PluginFactoryBesuSATPGateway } from "./factory/plugin-factory-besu-satp-gateway"; -import { fileURLToPath } from "url"; export async function createFabricPluginFactory( pluginFactoryOptions: IPluginFactoryOptions, diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/repository/knex-local-log-repository.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/repository/knex-local-log-repository.ts index b977e3e1113..65c07b10dee 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/repository/knex-local-log-repository.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/repository/knex-local-log-repository.ts @@ -7,7 +7,7 @@ export class KnexLocalLogRepository implements ILocalLogRepository { public constructor(config: Knex.Config | undefined) { // eslint-disable-next-line @typescript-eslint/no-var-requires - const configFile = require("../../../../knex/knexfile.ts")[ + const configFile = require("../../../knex/knexfile.ts")[ process.env.ENVIRONMENT || "development" ]; diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/repository/knex-remote-log-repository.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/repository/knex-remote-log-repository.ts index 9431076d0a6..8d064da275d 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/repository/knex-remote-log-repository.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/repository/knex-remote-log-repository.ts @@ -10,7 +10,7 @@ export class KnexRemoteLogRepository implements IRemoteLogRepository { // simulating a remote log storage public constructor(config: Knex.Config | undefined) { // eslint-disable-next-line @typescript-eslint/no-var-requires - const configFile = require("../../../../knex/knexfile-remote.ts")[ + const configFile = require("../../../knex/knexfile-remote.ts")[ process.env.ENVIRONMENT || "development" ]; diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/router.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/router.ts index 9f0248e2754..781507d1ccb 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/router.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/router.ts @@ -1,12 +1,12 @@ import { ConnectRouter } from "@connectrpc/connect"; -import { TestService } from '../generated/proto/test/message_connect'; -import { TestService2 } from '../generated/proto/test/message_connect'; +import { TestService } from "../generated/proto/test/message_connect"; +import { TestService2 } from "../generated/proto/test/message_connect"; import { TestImplementation } from "./test/test"; import { TestImplementation2 } from "./test/test2"; export const configureRoutes = (router: ConnectRouter): void => { - // TODO: add all services and respective implementations - router.service(TestService, TestImplementation); - router.service(TestService2, TestImplementation2); -}; \ No newline at end of file + // TODO: add all services and respective implementations + router.service(TestService, TestImplementation); + router.service(TestService2, TestImplementation2); +}; diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/test/test.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/test/test.ts index 2ed4a41ecf8..6138e2c46a5 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/test/test.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/test/test.ts @@ -1,6 +1,10 @@ import { Empty } from "@bufbuild/protobuf"; -import { Message, ModifyMessageRequest, ModifyMessageResponse } from '../../generated/proto/test/message_pb'; -import { HandlerContext } from '@connectrpc/connect'; +import { + Message, + ModifyMessageRequest, + ModifyMessageResponse, +} from "../../generated/proto/test/message_pb"; +import { HandlerContext } from "@connectrpc/connect"; // TODO: investigate how we can get type security, without doing the following: /* @@ -18,19 +22,21 @@ const TestImplementation: ITestServiceImplementation = { export const TestImplementation: any = { async getMessage(req: Empty, context: HandlerContext): Promise { - console.log("Received request", req); + console.log("Received request", req, context); return new Message({ - content: "Hello, SATP!" + content: "Hello, SATP!", }); }, - async sendMessage(req: Message): Promise { - console.log("Received request", req); - return new Empty(); - }, - async modifyMessage(req: ModifyMessageRequest): Promise { - console.log("Received request", req); - return new ModifyMessageResponse({ - content: "You said " + req.content + async sendMessage(req: Message): Promise { + console.log("Received request", req); + return new Empty(); + }, + async modifyMessage( + req: ModifyMessageRequest, + ): Promise { + console.log("Received request", req); + return new ModifyMessageResponse({ + content: "You said " + req.content, }); }, }; diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/test/test2.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/test/test2.ts index 44d134d2ba3..8bea6562cf8 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/test/test2.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/test/test2.ts @@ -1,12 +1,12 @@ import { Empty } from "@bufbuild/protobuf"; -import { Message, ModifyMessageRequest, ModifyMessageResponse } from '../../generated/proto/test/message_pb'; -import { HandlerContext } from '@connectrpc/connect'; +import { Message } from "../../generated/proto/test/message_pb"; +import { HandlerContext } from "@connectrpc/connect"; export const TestImplementation2: any = { async getMessage(req: Empty, context: HandlerContext): Promise { - console.log("Received request", req); + console.log("Received request", req, context); return new Message({ - content: "Hello, SATP!" + "2" + content: "Hello, SATP!" + "2", }); }, }; diff --git a/packages/cactus-plugin-satp-hermes/src/test/cucumber/placeholder b/packages/cactus-plugin-satp-hermes/src/test/cucumber/placeholder new file mode 100644 index 00000000000..8abb1dbfe4d --- /dev/null +++ b/packages/cactus-plugin-satp-hermes/src/test/cucumber/placeholder @@ -0,0 +1 @@ +acceptance tests go here \ No newline at end of file diff --git a/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/backup-gateway-after-client-crash.test.ts b/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/backup-gateway-after-client-crash.test.ts index b51eb5dd6de..175229bdcf8 100644 --- a/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/backup-gateway-after-client-crash.test.ts +++ b/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/backup-gateway-after-client-crash.test.ts @@ -20,6 +20,10 @@ import { FabricTestLedgerV1, pruneDockerAllIfGithubAction, BesuTestLedger, + FABRIC_25_LTS_AIO_IMAGE_VERSION, + FABRIC_25_LTS_AIO_FABRIC_VERSION, + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1, + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_2, } from "@hyperledger/cactus-test-tooling"; import { PluginKeychainMemory } from "@hyperledger/cactus-plugin-keychain-memory"; import { ClientV1Request } from "../../../main/typescript/public-api"; @@ -109,7 +113,7 @@ const BESU_ASSET_ID = uuidv4(); const log = LoggerProvider.getOrCreate({ level: "INFO", - label: "satpTestWithBackupGateway", + label: "backup-gateway-after-client-crash", }); beforeAll(async () => { @@ -131,7 +135,8 @@ beforeAll(async () => { emitContainerLogs: true, publishAllPorts: true, imageName: "ghcr.io/hyperledger/cactus-fabric2-all-in-one", - envVars: new Map([["FABRIC_VERSION", "2.2.0"]]), + imageVersion: FABRIC_25_LTS_AIO_IMAGE_VERSION, + envVars: new Map([["FABRIC_VERSION", FABRIC_25_LTS_AIO_FABRIC_VERSION]]), logLevel, }); @@ -167,50 +172,13 @@ beforeAll(async () => { asLocalhost: true, }; - // This is the directory structure of the Fabirc 2.x CLI container (fabric-tools image) - // const orgCfgDir = "/fabric-samples/test-network/organizations/"; - const orgCfgDir = - "/opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/"; - - // these below mirror how the fabric-samples sets up the configuration - const org1Env = { - CORE_LOGGING_LEVEL: "debug", - FABRIC_LOGGING_SPEC: "debug", - CORE_PEER_LOCALMSPID: "Org1MSP", - - ORDERER_CA: `${orgCfgDir}ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem`, - - FABRIC_CFG_PATH: "/etc/hyperledger/fabric", - CORE_PEER_TLS_ENABLED: "true", - CORE_PEER_TLS_ROOTCERT_FILE: `${orgCfgDir}peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt`, - CORE_PEER_MSPCONFIGPATH: `${orgCfgDir}peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp`, - CORE_PEER_ADDRESS: "peer0.org1.example.com:7051", - ORDERER_TLS_ROOTCERT_FILE: `${orgCfgDir}ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem`, - }; - - // these below mirror how the fabric-samples sets up the configuration - const org2Env = { - CORE_LOGGING_LEVEL: "debug", - FABRIC_LOGGING_SPEC: "debug", - CORE_PEER_LOCALMSPID: "Org2MSP", - - FABRIC_CFG_PATH: "/etc/hyperledger/fabric", - CORE_PEER_TLS_ENABLED: "true", - ORDERER_CA: `${orgCfgDir}ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem`, - - CORE_PEER_ADDRESS: "peer0.org2.example.com:9051", - CORE_PEER_MSPCONFIGPATH: `${orgCfgDir}peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp`, - CORE_PEER_TLS_ROOTCERT_FILE: `${orgCfgDir}peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt`, - ORDERER_TLS_ROOTCERT_FILE: `${orgCfgDir}ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem`, - }; - const pluginOptions: IPluginLedgerConnectorFabricOptions = { instanceId: uuidv4(), dockerBinary: "/usr/local/bin/docker", peerBinary: "/fabric-samples/bin/peer", goBinary: "/usr/local/go/bin/go", pluginRegistry, - cliContainerEnv: org1Env, + cliContainerEnv: FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1, sshConfig, logLevel, connectionProfile, @@ -316,8 +284,12 @@ beforeAll(async () => { ccVersion: "1.0.0", sourceFiles, ccName: fabricContractName, - targetOrganizations: [org1Env, org2Env], - caFile: `${orgCfgDir}ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem`, + targetOrganizations: [ + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1, + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_2, + ], + caFile: + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1.ORDERER_TLS_ROOTCERT_FILE, ccLabel: "basic-asset-transfer-2", ccLang: ChainCodeProgrammingLanguage.Typescript, ccSequence: 1, @@ -551,8 +523,16 @@ beforeAll(async () => { pluginRecipientGateway.localRepository?.database, ).not.toBeUndefined(); + expect(pluginSourceGateway.remoteRepository?.database).not.toBeUndefined(); + expect( + pluginRecipientGateway.remoteRepository?.database, + ).not.toBeUndefined(); + await pluginSourceGateway.localRepository?.reset(); await pluginRecipientGateway.localRepository?.reset(); + + await pluginSourceGateway.remoteRepository?.reset(); + await pluginRecipientGateway.remoteRepository?.reset(); } { // Server Gateway configuration @@ -738,6 +718,7 @@ test("client gateway crashes after lock fabric asset", async () => { // now we simulate the crash of the client gateway pluginSourceGateway.localRepository?.destroy(); + pluginSourceGateway.remoteRepository?.destroy(); await Servers.shutdown(sourceGatewayServer); const expressApp = express(); @@ -798,7 +779,9 @@ afterAll(async () => { await besuTestLedger.destroy(); pluginSourceGateway.localRepository?.destroy(); + pluginSourceGateway.remoteRepository?.destroy(); pluginRecipientGateway.localRepository?.destroy(); + pluginRecipientGateway.remoteRepository?.destroy(); await Servers.shutdown(besuServer); await Servers.shutdown(fabricServer); diff --git a/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/client-crash-after-delete-asset.test.ts b/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/client-crash-after-delete-asset.test.ts index 86c59845407..37381f052d6 100644 --- a/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/client-crash-after-delete-asset.test.ts +++ b/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/client-crash-after-delete-asset.test.ts @@ -20,6 +20,10 @@ import { FabricTestLedgerV1, pruneDockerAllIfGithubAction, BesuTestLedger, + FABRIC_25_LTS_AIO_IMAGE_VERSION, + FABRIC_25_LTS_AIO_FABRIC_VERSION, + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1, + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_2, } from "@hyperledger/cactus-test-tooling"; import { PluginKeychainMemory } from "@hyperledger/cactus-plugin-keychain-memory"; import { ClientV1Request } from "../../../main/typescript/public-api"; @@ -112,8 +116,8 @@ const FABRIC_ASSET_ID = uuidv4(); const BESU_ASSET_ID = uuidv4(); const log = LoggerProvider.getOrCreate({ - level: "INFO", - label: "satpTestWithLedgerConnectors", + level: logLevel, + label: "client-crash-after-delete-asset", }); beforeAll(async () => { @@ -135,7 +139,8 @@ beforeAll(async () => { emitContainerLogs: true, publishAllPorts: true, imageName: "ghcr.io/hyperledger/cactus-fabric2-all-in-one", - envVars: new Map([["FABRIC_VERSION", "2.2.0"]]), + imageVersion: FABRIC_25_LTS_AIO_IMAGE_VERSION, + envVars: new Map([["FABRIC_VERSION", FABRIC_25_LTS_AIO_FABRIC_VERSION]]), logLevel, }); @@ -171,50 +176,13 @@ beforeAll(async () => { asLocalhost: true, }; - // This is the directory structure of the Fabirc 2.x CLI container (fabric-tools image) - // const orgCfgDir = "/fabric-samples/test-network/organizations/"; - const orgCfgDir = - "/opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/"; - - // these below mirror how the fabric-samples sets up the configuration - const org1Env = { - CORE_LOGGING_LEVEL: "debug", - FABRIC_LOGGING_SPEC: "debug", - CORE_PEER_LOCALMSPID: "Org1MSP", - - ORDERER_CA: `${orgCfgDir}ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem`, - - FABRIC_CFG_PATH: "/etc/hyperledger/fabric", - CORE_PEER_TLS_ENABLED: "true", - CORE_PEER_TLS_ROOTCERT_FILE: `${orgCfgDir}peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt`, - CORE_PEER_MSPCONFIGPATH: `${orgCfgDir}peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp`, - CORE_PEER_ADDRESS: "peer0.org1.example.com:7051", - ORDERER_TLS_ROOTCERT_FILE: `${orgCfgDir}ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem`, - }; - - // these below mirror how the fabric-samples sets up the configuration - const org2Env = { - CORE_LOGGING_LEVEL: "debug", - FABRIC_LOGGING_SPEC: "debug", - CORE_PEER_LOCALMSPID: "Org2MSP", - - FABRIC_CFG_PATH: "/etc/hyperledger/fabric", - CORE_PEER_TLS_ENABLED: "true", - ORDERER_CA: `${orgCfgDir}ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem`, - - CORE_PEER_ADDRESS: "peer0.org2.example.com:9051", - CORE_PEER_MSPCONFIGPATH: `${orgCfgDir}peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp`, - CORE_PEER_TLS_ROOTCERT_FILE: `${orgCfgDir}peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt`, - ORDERER_TLS_ROOTCERT_FILE: `${orgCfgDir}ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem`, - }; - const pluginOptions: IPluginLedgerConnectorFabricOptions = { instanceId: uuidv4(), dockerBinary: "/usr/local/bin/docker", peerBinary: "/fabric-samples/bin/peer", goBinary: "/usr/local/go/bin/go", pluginRegistry, - cliContainerEnv: org1Env, + cliContainerEnv: FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1, sshConfig, logLevel, connectionProfile, @@ -320,8 +288,12 @@ beforeAll(async () => { ccVersion: "1.0.0", sourceFiles, ccName: fabricContractName, - targetOrganizations: [org1Env, org2Env], - caFile: `${orgCfgDir}ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem`, + targetOrganizations: [ + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1, + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_2, + ], + caFile: + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1.ORDERER_TLS_ROOTCERT_FILE, ccLabel: "basic-asset-transfer-2", ccLang: ChainCodeProgrammingLanguage.Typescript, ccSequence: 1, @@ -548,8 +520,16 @@ beforeAll(async () => { pluginRecipientGateway.localRepository?.database, ).not.toBeUndefined(); + expect(pluginSourceGateway.remoteRepository?.database).not.toBeUndefined(); + expect( + pluginRecipientGateway.remoteRepository?.database, + ).not.toBeUndefined(); + await pluginSourceGateway.localRepository?.reset(); await pluginRecipientGateway.localRepository?.reset(); + + await pluginSourceGateway.remoteRepository?.reset(); + await pluginRecipientGateway.remoteRepository?.reset(); } { // Server Gateway configuration @@ -771,6 +751,7 @@ test("client gateway crashes after deleting fabric asset", async () => { // now we simulate the crash of the client gateway pluginSourceGateway.localRepository?.destroy(); + pluginSourceGateway.remoteRepository?.destroy(); await Servers.shutdown(sourceGatewayServer); const expressApp = express(); diff --git a/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/client-crash-after-lock-asset.test.ts b/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/client-crash-after-lock-asset.test.ts index d8dae075614..29020202701 100644 --- a/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/client-crash-after-lock-asset.test.ts +++ b/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/client-crash-after-lock-asset.test.ts @@ -20,6 +20,10 @@ import { FabricTestLedgerV1, pruneDockerAllIfGithubAction, BesuTestLedger, + FABRIC_25_LTS_AIO_IMAGE_VERSION, + FABRIC_25_LTS_AIO_FABRIC_VERSION, + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1, + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_2, } from "@hyperledger/cactus-test-tooling"; import { PluginKeychainMemory } from "@hyperledger/cactus-plugin-keychain-memory"; import { ClientV1Request } from "../../../main/typescript/public-api"; @@ -112,8 +116,8 @@ const FABRIC_ASSET_ID = uuidv4(); const BESU_ASSET_ID = uuidv4(); const log = LoggerProvider.getOrCreate({ - level: "INFO", - label: "satpTestWithLedgerConnectors", + level: logLevel, + label: "client-crash-after-lock-asset", }); beforeAll(async () => { @@ -135,7 +139,8 @@ beforeAll(async () => { emitContainerLogs: true, publishAllPorts: true, imageName: "ghcr.io/hyperledger/cactus-fabric2-all-in-one", - envVars: new Map([["FABRIC_VERSION", "2.2.0"]]), + imageVersion: FABRIC_25_LTS_AIO_IMAGE_VERSION, + envVars: new Map([["FABRIC_VERSION", FABRIC_25_LTS_AIO_FABRIC_VERSION]]), logLevel, }); @@ -171,50 +176,13 @@ beforeAll(async () => { asLocalhost: true, }; - // This is the directory structure of the Fabirc 2.x CLI container (fabric-tools image) - // const orgCfgDir = "/fabric-samples/test-network/organizations/"; - const orgCfgDir = - "/opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/"; - - // these below mirror how the fabric-samples sets up the configuration - const org1Env = { - CORE_LOGGING_LEVEL: "debug", - FABRIC_LOGGING_SPEC: "debug", - CORE_PEER_LOCALMSPID: "Org1MSP", - - ORDERER_CA: `${orgCfgDir}ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem`, - - FABRIC_CFG_PATH: "/etc/hyperledger/fabric", - CORE_PEER_TLS_ENABLED: "true", - CORE_PEER_TLS_ROOTCERT_FILE: `${orgCfgDir}peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt`, - CORE_PEER_MSPCONFIGPATH: `${orgCfgDir}peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp`, - CORE_PEER_ADDRESS: "peer0.org1.example.com:7051", - ORDERER_TLS_ROOTCERT_FILE: `${orgCfgDir}ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem`, - }; - - // these below mirror how the fabric-samples sets up the configuration - const org2Env = { - CORE_LOGGING_LEVEL: "debug", - FABRIC_LOGGING_SPEC: "debug", - CORE_PEER_LOCALMSPID: "Org2MSP", - - FABRIC_CFG_PATH: "/etc/hyperledger/fabric", - CORE_PEER_TLS_ENABLED: "true", - ORDERER_CA: `${orgCfgDir}ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem`, - - CORE_PEER_ADDRESS: "peer0.org2.example.com:9051", - CORE_PEER_MSPCONFIGPATH: `${orgCfgDir}peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp`, - CORE_PEER_TLS_ROOTCERT_FILE: `${orgCfgDir}peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt`, - ORDERER_TLS_ROOTCERT_FILE: `${orgCfgDir}ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem`, - }; - const pluginOptions: IPluginLedgerConnectorFabricOptions = { instanceId: uuidv4(), dockerBinary: "/usr/local/bin/docker", peerBinary: "/fabric-samples/bin/peer", goBinary: "/usr/local/go/bin/go", pluginRegistry, - cliContainerEnv: org1Env, + cliContainerEnv: FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1, sshConfig, logLevel, connectionProfile, @@ -320,8 +288,12 @@ beforeAll(async () => { ccVersion: "1.0.0", sourceFiles, ccName: fabricContractName, - targetOrganizations: [org1Env, org2Env], - caFile: `${orgCfgDir}ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem`, + targetOrganizations: [ + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1, + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_2, + ], + caFile: + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1.ORDERER_TLS_ROOTCERT_FILE, ccLabel: "basic-asset-transfer-2", ccLang: ChainCodeProgrammingLanguage.Typescript, ccSequence: 1, @@ -549,8 +521,16 @@ beforeAll(async () => { pluginRecipientGateway.localRepository?.database, ).not.toBeUndefined(); + expect(pluginSourceGateway.remoteRepository?.database).not.toBeUndefined(); + expect( + pluginRecipientGateway.remoteRepository?.database, + ).not.toBeUndefined(); + await pluginSourceGateway.localRepository?.reset(); await pluginRecipientGateway.localRepository?.reset(); + + await pluginSourceGateway.remoteRepository?.reset(); + await pluginRecipientGateway.remoteRepository?.reset(); } { // Server Gateway configuration diff --git a/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/client-crash-after-transfer-initiation.test.ts b/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/client-crash-after-transfer-initiation.test.ts index 60a3521d692..8c3a4f5ff08 100644 --- a/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/client-crash-after-transfer-initiation.test.ts +++ b/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/client-crash-after-transfer-initiation.test.ts @@ -6,6 +6,8 @@ import bodyParser from "body-parser"; import express, { Express } from "express"; import { IListenOptions, + LogLevelDesc, + LoggerProvider, Secp256k1Keys, Servers, } from "@hyperledger/cactus-common"; @@ -29,6 +31,9 @@ import { knexRemoteConnection, knexServerConnection, } from "../knex.config"; +import { Containers, pruneDockerAllIfGithubAction } from "@hyperledger/cactus-test-tooling"; + +const logLevel: LogLevelDesc = "INFO"; const MAX_RETRIES = 5; const MAX_TIMEOUT = 5000; @@ -56,7 +61,21 @@ let serverListenOptions: IListenOptions; let clientExpressApp: Express; let clientListenOptions: IListenOptions; +const log = LoggerProvider.getOrCreate({ + level: "INFO", + label: "client-crash-after-transfer-initiation", +}); + beforeAll(async () => { + pruneDockerAllIfGithubAction({ logLevel }) + .then(() => { + log.info("Pruning throw OK"); + }) + .catch(async () => { + await Containers.logDiagnostics({ logLevel }); + fail("Pruning didn't throw OK"); + }); + { // Server Gateway configuration serverGatewayPluginOptions = { @@ -88,11 +107,11 @@ beforeAll(async () => { pluginRecipientGateway = new BesuSATPGateway(serverGatewayPluginOptions); - expect( - pluginRecipientGateway.localRepository?.database, - ).not.toBeUndefined(); - + expect(pluginRecipientGateway.localRepository?.database).not.toBeUndefined(); + expect(pluginRecipientGateway.remoteRepository?.database).not.toBeUndefined(); + await pluginRecipientGateway.localRepository?.reset(); + await pluginRecipientGateway.remoteRepository?.reset(); await pluginRecipientGateway.registerWebServices(serverExpressApp); } diff --git a/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/gateway-coordinator-init.test.ts b/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/gateway-coordinator-init.test.ts index 7ddc8a62d98..e1ec6bbe273 100644 --- a/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/gateway-coordinator-init.test.ts +++ b/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/gateway-coordinator-init.test.ts @@ -1,33 +1,42 @@ import "jest-extended"; import { Containers, - FabricTestLedgerV1, pruneDockerAllIfGithubAction, - BesuTestLedger, } from "@hyperledger/cactus-test-tooling"; -import { LogLevelDesc, LoggerProvider } from "@hyperledger/cactus-common"; +import { + LogLevelDesc, + Logger, + LoggerProvider, +} from "@hyperledger/cactus-common"; // import coordinator factory, coordinator and coordinator options -import { SATPGateway, SATPGatewayConfig } from "../../../main/typescript/gateway-refactor"; +import { + SATPGateway, + SATPGatewayConfig, +} from "../../../main/typescript/gateway-refactor"; import { PluginFactorySATPGateway } from "../../../main/typescript/factory/plugin-factory-gateway-orchestrator"; import { - IPluginFactoryOptions, PluginImportType, + IPluginFactoryOptions, + PluginImportType, } from "@hyperledger/cactus-core-api"; -import { SupportedGatewayImplementations } from './../../../main/typescript/core/types'; +import { + ShutdownHook, + SupportedGatewayImplementations, +} from "./../../../main/typescript/core/types"; const logLevel: LogLevelDesc = "INFO"; -const log = LoggerProvider.getOrCreate({ +const logger = LoggerProvider.getOrCreate({ level: "INFO", label: "satp-gateway-orchestrator-init-test", }); const factoryOptions: IPluginFactoryOptions = { pluginImportType: PluginImportType.Local, -} +}; const factory = new PluginFactorySATPGateway(factoryOptions); beforeAll(async () => { pruneDockerAllIfGithubAction({ logLevel }) .then(() => { - log.info("Pruning throw OK"); + logger.info("Pruning throw OK"); }) .catch(async () => { await Containers.logDiagnostics({ logLevel }); @@ -36,7 +45,6 @@ beforeAll(async () => { }); describe("SATPGateway initialization", () => { - it("initiates with default config", async () => { const options: SATPGatewayConfig = {}; const gateway = await factory.create(options); @@ -59,7 +67,7 @@ describe("SATPGateway initialization", () => { SupportedGatewayImplementations.BESU, ]); expect(identity.proofID).toBe("mockProofID1"); - expect(identity.port).toBe(3000); + expect(identity.gatewayServerPort).toBe(3010); expect(identity.address).toBe("http://localhost"); }); @@ -81,7 +89,7 @@ describe("SATPGateway initialization", () => { SupportedGatewayImplementations.BESU, ], proofID: "mockProofID10", - port: 3001, + gatewayServerPort: 3010, address: "https://localhost", }, }; @@ -105,7 +113,7 @@ describe("SATPGateway initialization", () => { SupportedGatewayImplementations.BESU, ]); expect(identity.proofID).toBe("mockProofID10"); - expect(identity.port).toBe(3001); + expect(identity.gatewayServerPort).toBe(3010); expect(identity.address).toBe("https://localhost"); }); @@ -127,7 +135,6 @@ describe("SATPGateway initialization", () => { SupportedGatewayImplementations.BESU, ], proofID: "mockProofID10", - port: 3010, address: "https://localhost", }, }; @@ -135,20 +142,77 @@ describe("SATPGateway initialization", () => { expect(gateway).toBeInstanceOf(SATPGateway); const identity = gateway.getIdentity(); - expect(identity.port).toBe(3010); + // default servers + expect(identity.gatewayServerPort).toBe(3010); + expect(identity.gatewayClientPort).toBe(3011); expect(identity.address).toBe("https://localhost"); - await gateway.startupServer(); + await gateway.startup(); await gateway.shutdown(); }); + it("shutdown hooks work", async () => { + const options: SATPGatewayConfig = { + gid: { + id: "mockID", + name: "CustomGateway", + version: [ + { + Core: "v02", + Architecture: "v02", + Crash: "v02", + }, + ], + supportedChains: [ + SupportedGatewayImplementations.FABRIC, + SupportedGatewayImplementations.BESU, + ], + proofID: "mockProofID10", + gatewayServerPort: 3014, + gatewayClientPort: 3015, + address: "https://localhost", + }, + }; + + const gateway = await factory.create(options); + expect(gateway).toBeInstanceOf(SATPGateway); + + // ensure logger is called with "mockHook" + const loggerSpy = jest.spyOn(logger, "info"); + + // ensure mockHookFn is called on shutdown + const mockHookFn = jest.fn(async () => { + logger.info("mockHook"); + }); + + const shutdownHook: ShutdownHook = { + name: "mockHook", + hook: async () => { + logger.info("mockHook"); + }, + }; + + const shutdownHookFn: ShutdownHook = { + name: "mockHookFn", + hook: mockHookFn, + }; + + gateway.onShutdown(shutdownHook); + gateway.onShutdown(shutdownHookFn); + await gateway.startup(); + await gateway.shutdown(); + + expect(loggerSpy).toHaveBeenCalledWith("mockHook"); + expect(mockHookFn).toHaveBeenCalled(); + + // for now, technically not needed. However if we use more tests with loggerSpy, conflicts could arise. This is a reminder to restore the spy after each test + loggerSpy.mockRestore(); + }); }); afterAll(async () => { - // shutdown channels - await pruneDockerAllIfGithubAction({ logLevel }) .then(() => { - log.info("Pruning throw OK"); + logger.info("Pruning throw OK"); }) .catch(async () => { await Containers.logDiagnostics({ logLevel }); diff --git a/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/odap-api-call-with-ledger-connector.test.ts b/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/odap-api-call-with-ledger-connector.test.ts index 51ce6221347..3a42c977a92 100644 --- a/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/odap-api-call-with-ledger-connector.test.ts +++ b/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/odap-api-call-with-ledger-connector.test.ts @@ -19,6 +19,10 @@ import { FabricTestLedgerV1, pruneDockerAllIfGithubAction, BesuTestLedger, + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1, + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_2, + FABRIC_25_LTS_AIO_IMAGE_VERSION, + FABRIC_25_LTS_AIO_FABRIC_VERSION, } from "@hyperledger/cactus-test-tooling"; import { PluginKeychainMemory } from "@hyperledger/cactus-plugin-keychain-memory"; import { @@ -105,7 +109,7 @@ const BESU_ASSET_ID = uuidv4(); const log = LoggerProvider.getOrCreate({ level: "INFO", - label: "satpTestWithLedgerConnectors", + label: "odap-api-call-with-ledger-connector", }); beforeAll(async () => { @@ -127,7 +131,8 @@ beforeAll(async () => { emitContainerLogs: true, publishAllPorts: true, imageName: "ghcr.io/hyperledger/cactus-fabric2-all-in-one", - envVars: new Map([["FABRIC_VERSION", "2.2.0"]]), + imageVersion: FABRIC_25_LTS_AIO_IMAGE_VERSION, + envVars: new Map([["FABRIC_VERSION", FABRIC_25_LTS_AIO_FABRIC_VERSION]]), logLevel, }); @@ -163,50 +168,13 @@ beforeAll(async () => { asLocalhost: true, }; - // This is the directory structure of the Fabirc 2.x CLI container (fabric-tools image) - // const orgCfgDir = "/fabric-samples/test-network/organizations/"; - const orgCfgDir = - "/opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/"; - - // these below mirror how the fabric-samples sets up the configuration - const org1Env = { - CORE_LOGGING_LEVEL: "debug", - FABRIC_LOGGING_SPEC: "debug", - CORE_PEER_LOCALMSPID: "Org1MSP", - - ORDERER_CA: `${orgCfgDir}ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem`, - - FABRIC_CFG_PATH: "/etc/hyperledger/fabric", - CORE_PEER_TLS_ENABLED: "true", - CORE_PEER_TLS_ROOTCERT_FILE: `${orgCfgDir}peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt`, - CORE_PEER_MSPCONFIGPATH: `${orgCfgDir}peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp`, - CORE_PEER_ADDRESS: "peer0.org1.example.com:7051", - ORDERER_TLS_ROOTCERT_FILE: `${orgCfgDir}ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem`, - }; - - // these below mirror how the fabric-samples sets up the configuration - const org2Env = { - CORE_LOGGING_LEVEL: "debug", - FABRIC_LOGGING_SPEC: "debug", - CORE_PEER_LOCALMSPID: "Org2MSP", - - FABRIC_CFG_PATH: "/etc/hyperledger/fabric", - CORE_PEER_TLS_ENABLED: "true", - ORDERER_CA: `${orgCfgDir}ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem`, - - CORE_PEER_ADDRESS: "peer0.org2.example.com:9051", - CORE_PEER_MSPCONFIGPATH: `${orgCfgDir}peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp`, - CORE_PEER_TLS_ROOTCERT_FILE: `${orgCfgDir}peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt`, - ORDERER_TLS_ROOTCERT_FILE: `${orgCfgDir}ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem`, - }; - const pluginOptions: IPluginLedgerConnectorFabricOptions = { instanceId: uuidv4(), dockerBinary: "/usr/local/bin/docker", peerBinary: "/fabric-samples/bin/peer", goBinary: "/usr/local/go/bin/go", pluginRegistry, - cliContainerEnv: org1Env, + cliContainerEnv: FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1, sshConfig, logLevel, connectionProfile, @@ -312,8 +280,12 @@ beforeAll(async () => { ccVersion: "1.0.0", sourceFiles, ccName: fabricContractName, - targetOrganizations: [org1Env, org2Env], - caFile: `${orgCfgDir}ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem`, + targetOrganizations: [ + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1, + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_2, + ], + caFile: + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1.ORDERER_TLS_ROOTCERT_FILE, ccLabel: "basic-asset-transfer-2", ccLang: ChainCodeProgrammingLanguage.Typescript, ccSequence: 1, @@ -511,8 +483,16 @@ beforeAll(async () => { pluginRecipientGateway.localRepository?.database, ).not.toBeUndefined(); + expect(pluginSourceGateway.remoteRepository?.database).not.toBeUndefined(); + expect( + pluginRecipientGateway.remoteRepository?.database, + ).not.toBeUndefined(); + await pluginSourceGateway.localRepository?.reset(); await pluginRecipientGateway.localRepository?.reset(); + + await pluginSourceGateway.remoteRepository?.reset(); + await pluginRecipientGateway.remoteRepository?.reset(); } { // Server Gateway configuration diff --git a/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/odap-api-call.test.ts b/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/odap-api-call.test.ts index 2f5ec22b1cf..e49f1b8b5f1 100644 --- a/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/odap-api-call.test.ts +++ b/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/odap-api-call.test.ts @@ -6,7 +6,7 @@ import bodyParser from "body-parser"; import express from "express"; import { DefaultApi as SatpApi } from "../../../main/typescript/public-api"; -import { IListenOptions, Servers } from "@hyperledger/cactus-common"; +import { IListenOptions, LogLevelDesc, LoggerProvider, Servers } from "@hyperledger/cactus-common"; import { Configuration } from "@hyperledger/cactus-core-api"; @@ -25,6 +25,9 @@ import { FabricSATPGateway } from "../../../main/typescript/core/fabric-satp-gat import { ClientGatewayHelper } from "../../../main/typescript/core/client-helper"; import { ServerGatewayHelper } from "../../../main/typescript/core/server-helper"; import { knexRemoteConnection } from "../knex.config"; +import { Containers, pruneDockerAllIfGithubAction } from "@hyperledger/cactus-test-tooling"; + +const logLevel: LogLevelDesc = "INFO"; const MAX_RETRIES = 5; const MAX_TIMEOUT = 5000; @@ -38,6 +41,22 @@ let recipientGatewayserver: Server; let pluginSourceGateway: PluginSATPGateway; let pluginRecipientGateway: PluginSATPGateway; +const log = LoggerProvider.getOrCreate({ + level: "INFO", + label: "odap-api-call-with-ledger-connector", +}); + +beforeAll(async () => { + pruneDockerAllIfGithubAction({ logLevel }) + .then(() => { + log.info("Pruning throw OK"); + }) + .catch(async () => { + await Containers.logDiagnostics({ logLevel }); + fail("Pruning didn't throw OK"); + }); +}); + test("runs ODAP between two gateways via openApi", async () => { const clientGatewayPluginOptions: IPluginSatpGatewayConstructorOptions = { name: "cactus-plugin#satpGateway", @@ -62,9 +81,15 @@ test("runs ODAP between two gateways via openApi", async () => { expect(pluginSourceGateway.localRepository?.database).not.toBeUndefined(); expect(pluginRecipientGateway.localRepository?.database).not.toBeUndefined(); + + expect(pluginSourceGateway.remoteRepository?.database).not.toBeUndefined(); + expect(pluginRecipientGateway.remoteRepository?.database).not.toBeUndefined(); await pluginSourceGateway.localRepository?.reset(); await pluginRecipientGateway.localRepository?.reset(); + + await pluginSourceGateway.remoteRepository?.reset(); + await pluginRecipientGateway.remoteRepository?.reset(); let serverGatewayApiHost: string; diff --git a/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/odap-rollback.test.ts b/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/odap-rollback.test.ts index af92b02d7d8..10da0d1578f 100644 --- a/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/odap-rollback.test.ts +++ b/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/odap-rollback.test.ts @@ -21,8 +21,10 @@ import { pruneDockerAllIfGithubAction, BesuTestLedger, DEFAULT_FABRIC_2_AIO_IMAGE_NAME, - DEFAULT_FABRIC_2_AIO_IMAGE_VERSION, - DEFAULT_FABRIC_2_AIO_FABRIC_VERSION, + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1, + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_2, + FABRIC_25_LTS_AIO_IMAGE_VERSION, + FABRIC_25_LTS_AIO_FABRIC_VERSION, } from "@hyperledger/cactus-test-tooling"; import { PluginKeychainMemory } from "@hyperledger/cactus-plugin-keychain-memory"; import { ClientV1Request } from "../../../main/typescript/public-api"; @@ -110,7 +112,7 @@ const BESU_ASSET_ID = uuidv4(); const log = LoggerProvider.getOrCreate({ level: "INFO", - label: "odap-rollback-after-crash-test", + label: "odap-rollback", }); beforeAll(async () => { @@ -132,10 +134,8 @@ beforeAll(async () => { emitContainerLogs: true, publishAllPorts: true, imageName: DEFAULT_FABRIC_2_AIO_IMAGE_NAME, - imageVersion: DEFAULT_FABRIC_2_AIO_IMAGE_VERSION, - envVars: new Map([ - ["FABRIC_VERSION", DEFAULT_FABRIC_2_AIO_FABRIC_VERSION], - ]), + imageVersion: FABRIC_25_LTS_AIO_IMAGE_VERSION, + envVars: new Map([["FABRIC_VERSION", FABRIC_25_LTS_AIO_FABRIC_VERSION]]), logLevel, }); @@ -171,50 +171,13 @@ beforeAll(async () => { asLocalhost: true, }; - // This is the directory structure of the Fabirc 2.x CLI container (fabric-tools image) - // const orgCfgDir = "/fabric-samples/test-network/organizations/"; - const orgCfgDir = - "/opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/"; - - // these below mirror how the fabric-samples sets up the configuration - const org1Env = { - CORE_LOGGING_LEVEL: "debug", - FABRIC_LOGGING_SPEC: "debug", - CORE_PEER_LOCALMSPID: "Org1MSP", - - ORDERER_CA: `${orgCfgDir}ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem`, - - FABRIC_CFG_PATH: "/etc/hyperledger/fabric", - CORE_PEER_TLS_ENABLED: "true", - CORE_PEER_TLS_ROOTCERT_FILE: `${orgCfgDir}peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt`, - CORE_PEER_MSPCONFIGPATH: `${orgCfgDir}peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp`, - CORE_PEER_ADDRESS: "peer0.org1.example.com:7051", - ORDERER_TLS_ROOTCERT_FILE: `${orgCfgDir}ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem`, - }; - - // these below mirror how the fabric-samples sets up the configuration - const org2Env = { - CORE_LOGGING_LEVEL: "debug", - FABRIC_LOGGING_SPEC: "debug", - CORE_PEER_LOCALMSPID: "Org2MSP", - - FABRIC_CFG_PATH: "/etc/hyperledger/fabric", - CORE_PEER_TLS_ENABLED: "true", - ORDERER_CA: `${orgCfgDir}ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem`, - - CORE_PEER_ADDRESS: "peer0.org2.example.com:9051", - CORE_PEER_MSPCONFIGPATH: `${orgCfgDir}peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp`, - CORE_PEER_TLS_ROOTCERT_FILE: `${orgCfgDir}peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt`, - ORDERER_TLS_ROOTCERT_FILE: `${orgCfgDir}ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem`, - }; - const pluginOptions: IPluginLedgerConnectorFabricOptions = { instanceId: uuidv4(), dockerBinary: "/usr/local/bin/docker", peerBinary: "/fabric-samples/bin/peer", goBinary: "/usr/local/go/bin/go", pluginRegistry, - cliContainerEnv: org1Env, + cliContainerEnv: FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1, sshConfig, logLevel, connectionProfile, @@ -320,8 +283,12 @@ beforeAll(async () => { ccVersion: "1.0.0", sourceFiles, ccName: fabricContractName, - targetOrganizations: [org1Env, org2Env], - caFile: `${orgCfgDir}ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem`, + targetOrganizations: [ + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1, + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_2, + ], + caFile: + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1.ORDERER_TLS_ROOTCERT_FILE, ccLabel: "basic-asset-transfer-2", ccLang: ChainCodeProgrammingLanguage.Typescript, ccSequence: 1, @@ -546,8 +513,16 @@ beforeAll(async () => { pluginRecipientGateway.localRepository?.database, ).not.toBeUndefined(); + expect(pluginSourceGateway.remoteRepository?.database).not.toBeUndefined(); + expect( + pluginRecipientGateway.remoteRepository?.database, + ).not.toBeUndefined(); + await pluginSourceGateway.localRepository?.reset(); await pluginRecipientGateway.localRepository?.reset(); + + await pluginSourceGateway.remoteRepository?.reset(); + await pluginRecipientGateway.remoteRepository?.reset(); } { // Server Gateway configuration diff --git a/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/odap.test.ts b/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/odap.test.ts index 145762dd291..c09f08c65ae 100644 --- a/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/odap.test.ts +++ b/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/odap.test.ts @@ -13,6 +13,8 @@ import { FabricSATPGateway } from "../../../main/typescript/core/fabric-satp-gat import { ClientGatewayHelper } from "../../../main/typescript/core/client-helper"; import { ServerGatewayHelper } from "../../../main/typescript/core/server-helper"; import { knexRemoteConnection } from "../knex.config"; +import { LogLevelDesc, LoggerProvider } from "@hyperledger/cactus-common"; +import { pruneDockerAllIfGithubAction, Containers } from "@hyperledger/cactus-test-tooling"; const MAX_RETRIES = 5; const MAX_TIMEOUT = 5000; @@ -20,8 +22,26 @@ const MAX_TIMEOUT = 5000; let pluginSourceGateway: PluginSATPGateway; let pluginRecipientGateway: PluginSATPGateway; +const logLevel: LogLevelDesc = "INFO"; + +const log = LoggerProvider.getOrCreate({ + level: "INFO", + label: "odap", +}); + +beforeAll(async () => { + pruneDockerAllIfGithubAction({ logLevel }) + .then(() => { + log.info("Pruning throw OK"); + }) + .catch(async () => { + await Containers.logDiagnostics({ logLevel }); + fail("Pruning didn't throw OK"); + }); +}); + test("successful run ODAP instance", async () => { - console.log(knexRemoteConnection) + console.log(knexRemoteConnection); const sourceGatewayConstructor = { name: "plugin-satp-gateway#sourceGateway", dltIDs: ["DLT2"], @@ -44,9 +64,15 @@ test("successful run ODAP instance", async () => { expect(pluginSourceGateway.localRepository?.database).not.toBeUndefined(); expect(pluginRecipientGateway.localRepository?.database).not.toBeUndefined(); + + expect(pluginSourceGateway.remoteRepository?.database).not.toBeUndefined(); + expect(pluginRecipientGateway.remoteRepository?.database).not.toBeUndefined(); await pluginSourceGateway.localRepository?.reset(); await pluginRecipientGateway.localRepository?.reset(); + + await pluginSourceGateway.remoteRepository?.reset(); + await pluginRecipientGateway.remoteRepository?.reset(); const dummyPath = { apiHost: "dummyPath" }; diff --git a/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/server-crash-after-create-asset.test.ts b/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/server-crash-after-create-asset.test.ts index c0d496f64ea..a0ab3217f2e 100644 --- a/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/server-crash-after-create-asset.test.ts +++ b/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/server-crash-after-create-asset.test.ts @@ -20,6 +20,10 @@ import { FabricTestLedgerV1, pruneDockerAllIfGithubAction, BesuTestLedger, + FABRIC_25_LTS_AIO_FABRIC_VERSION, + FABRIC_25_LTS_AIO_IMAGE_VERSION, + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_2, + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1, } from "@hyperledger/cactus-test-tooling"; import { PluginKeychainMemory } from "@hyperledger/cactus-plugin-keychain-memory"; import { ClientV1Request } from "../../../main/typescript/public-api"; @@ -112,8 +116,8 @@ const FABRIC_ASSET_ID = uuidv4(); const BESU_ASSET_ID = uuidv4(); const log = LoggerProvider.getOrCreate({ - level: "INFO", - label: "satpTestWithLedgerConnectors", + level: logLevel, + label: "server-crash-after-create-asset", }); beforeAll(async () => { @@ -134,8 +138,9 @@ beforeAll(async () => { fabricLedger = new FabricTestLedgerV1({ emitContainerLogs: true, publishAllPorts: true, + imageVersion: FABRIC_25_LTS_AIO_IMAGE_VERSION, imageName: "ghcr.io/hyperledger/cactus-fabric2-all-in-one", - envVars: new Map([["FABRIC_VERSION", "2.2.0"]]), + envVars: new Map([["FABRIC_VERSION", FABRIC_25_LTS_AIO_FABRIC_VERSION]]), logLevel, }); @@ -171,50 +176,13 @@ beforeAll(async () => { asLocalhost: true, }; - // This is the directory structure of the Fabirc 2.x CLI container (fabric-tools image) - // const orgCfgDir = "/fabric-samples/test-network/organizations/"; - const orgCfgDir = - "/opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/"; - - // these below mirror how the fabric-samples sets up the configuration - const org1Env = { - CORE_LOGGING_LEVEL: "debug", - FABRIC_LOGGING_SPEC: "debug", - CORE_PEER_LOCALMSPID: "Org1MSP", - - ORDERER_CA: `${orgCfgDir}ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem`, - - FABRIC_CFG_PATH: "/etc/hyperledger/fabric", - CORE_PEER_TLS_ENABLED: "true", - CORE_PEER_TLS_ROOTCERT_FILE: `${orgCfgDir}peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt`, - CORE_PEER_MSPCONFIGPATH: `${orgCfgDir}peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp`, - CORE_PEER_ADDRESS: "peer0.org1.example.com:7051", - ORDERER_TLS_ROOTCERT_FILE: `${orgCfgDir}ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem`, - }; - - // these below mirror how the fabric-samples sets up the configuration - const org2Env = { - CORE_LOGGING_LEVEL: "debug", - FABRIC_LOGGING_SPEC: "debug", - CORE_PEER_LOCALMSPID: "Org2MSP", - - FABRIC_CFG_PATH: "/etc/hyperledger/fabric", - CORE_PEER_TLS_ENABLED: "true", - ORDERER_CA: `${orgCfgDir}ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem`, - - CORE_PEER_ADDRESS: "peer0.org2.example.com:9051", - CORE_PEER_MSPCONFIGPATH: `${orgCfgDir}peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp`, - CORE_PEER_TLS_ROOTCERT_FILE: `${orgCfgDir}peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt`, - ORDERER_TLS_ROOTCERT_FILE: `${orgCfgDir}ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem`, - }; - const pluginOptions: IPluginLedgerConnectorFabricOptions = { instanceId: uuidv4(), dockerBinary: "/usr/local/bin/docker", peerBinary: "/fabric-samples/bin/peer", goBinary: "/usr/local/go/bin/go", pluginRegistry, - cliContainerEnv: org1Env, + cliContainerEnv: FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1, sshConfig, logLevel, connectionProfile, @@ -320,8 +288,12 @@ beforeAll(async () => { ccVersion: "1.0.0", sourceFiles, ccName: fabricContractName, - targetOrganizations: [org1Env, org2Env], - caFile: `${orgCfgDir}ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem`, + targetOrganizations: [ + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1, + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_2, + ], + caFile: + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1.ORDERER_TLS_ROOTCERT_FILE, ccLabel: "basic-asset-transfer-2", ccLang: ChainCodeProgrammingLanguage.Typescript, ccSequence: 1, @@ -551,8 +523,16 @@ beforeEach(async () => { pluginRecipientGateway.localRepository?.database, ).not.toBeUndefined(); + expect(pluginSourceGateway.remoteRepository?.database).not.toBeUndefined(); + expect( + pluginRecipientGateway.remoteRepository?.database, + ).not.toBeUndefined(); + await pluginSourceGateway.localRepository?.reset(); await pluginRecipientGateway.localRepository?.reset(); + + await pluginSourceGateway.remoteRepository?.reset(); + await pluginRecipientGateway.remoteRepository?.reset(); } { // Server Gateway configuration diff --git a/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/server-crash-after-transfer-initiation.test.ts b/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/server-crash-after-transfer-initiation.test.ts index 92f0f6296a3..ad3fd420833 100644 --- a/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/server-crash-after-transfer-initiation.test.ts +++ b/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/server-crash-after-transfer-initiation.test.ts @@ -6,6 +6,8 @@ import bodyParser from "body-parser"; import express, { Express } from "express"; import { IListenOptions, + LogLevelDesc, + LoggerProvider, Secp256k1Keys, Servers, } from "@hyperledger/cactus-common"; @@ -27,6 +29,9 @@ import { ClientGatewayHelper } from "../../../main/typescript/core/client-helper import { ServerGatewayHelper } from "../../../main/typescript/core/server-helper"; import { knexClientConnection, knexRemoteConnection } from "../knex.config"; +import { pruneDockerAllIfGithubAction, Containers } from "@hyperledger/cactus-test-tooling"; + +const logLevel: LogLevelDesc = "INFO"; const MAX_RETRIES = 5; const MAX_TIMEOUT = 5000; @@ -53,7 +58,21 @@ let serverListenOptions: IListenOptions; let clientExpressApp: Express; let clientListenOptions: IListenOptions; +const log = LoggerProvider.getOrCreate({ + level: "INFO", + label: "server-crash-after-create-asset", +}); + beforeAll(async () => { + pruneDockerAllIfGithubAction({ logLevel }) + .then(() => { + log.info("Pruning throw OK"); + }) + .catch(async () => { + await Containers.logDiagnostics({ logLevel }); + fail("Pruning didn't throw OK"); + }); + { // Server Gateway configuration serverGatewayPluginOptions = { @@ -84,11 +103,11 @@ beforeAll(async () => { pluginRecipientGateway = new BesuSATPGateway(serverGatewayPluginOptions); - expect( - pluginRecipientGateway.localRepository?.database, - ).not.toBeUndefined(); + expect(pluginRecipientGateway.localRepository?.database).not.toBeUndefined(); + expect(pluginRecipientGateway.remoteRepository?.database).not.toBeUndefined(); await pluginRecipientGateway.localRepository?.reset(); + await pluginRecipientGateway.remoteRepository?.reset(); await pluginRecipientGateway.registerWebServices(serverExpressApp); } @@ -123,11 +142,11 @@ beforeAll(async () => { pluginSourceGateway = new FabricSATPGateway(clientGatewayPluginOptions); - if (pluginSourceGateway.localRepository?.database == undefined) { - throw new Error("Database is not correctly initialized"); - } + expect(pluginSourceGateway.localRepository?.database).not.toBeUndefined(); + expect(pluginSourceGateway.remoteRepository?.database).not.toBeUndefined(); await pluginSourceGateway.localRepository?.reset(); + await pluginSourceGateway.remoteRepository?.reset(); await pluginSourceGateway.registerWebServices(clientExpressApp); @@ -218,10 +237,10 @@ test("server gateway crashes after transfer initiation flow", async () => { }); afterAll(async () => { - pluginSourceGateway.localRepository?.destroy(); - pluginRecipientGateway.localRepository?.destroy(); - pluginSourceGateway.remoteRepository?.destroy(); - pluginRecipientGateway.remoteRepository?.destroy(); + await pluginSourceGateway.localRepository?.destroy(); + await pluginRecipientGateway.localRepository?.destroy(); + await pluginSourceGateway.remoteRepository?.destroy(); + await pluginRecipientGateway.remoteRepository?.destroy(); await Servers.shutdown(sourceGatewayServer); await Servers.shutdown(recipientGatewayserver); diff --git a/packages/cactus-plugin-satp-hermes/src/test/typescript/knex.config.ts b/packages/cactus-plugin-satp-hermes/src/test/typescript/knex.config.ts index 3376a92c91d..c5330746929 100644 --- a/packages/cactus-plugin-satp-hermes/src/test/typescript/knex.config.ts +++ b/packages/cactus-plugin-satp-hermes/src/test/typescript/knex.config.ts @@ -1,10 +1,12 @@ +import { v4 as uuidv4 } from "uuid"; + export const knexClientConnection = { client: "sqlite3", connection: { - filename: "./packages/cactus-plugin-satp-hermes/knex/.dev.client.sqlite3", + filename: "./packages/cactus-plugin-satp-hermes/src/knex/.dev.client-" + uuidv4() + ".sqlite3", }, migrations: { - directory: "./packages/cactus-plugin-satp-hermes/knex/migrations", + directory: "./packages/cactus-plugin-satp-hermes/src/knex/migrations", }, useNullAsDefault: true, }; @@ -12,10 +14,10 @@ export const knexClientConnection = { export const knexServerConnection = { client: "sqlite3", connection: { - filename: "./packages/cactus-plugin-satp-hermes/knex/.dev.server.sqlite3", + filename: "./packages/cactus-plugin-satp-hermes/src/knex/.dev.server-" + uuidv4() + ".sqlite3", }, migrations: { - directory: "./packages/cactus-plugin-satp-hermes/knex/migrations", + directory: "./packages/cactus-plugin-satp-hermes/src/knex/migrations", }, useNullAsDefault: true, }; @@ -23,10 +25,10 @@ export const knexServerConnection = { export const knexRemoteConnection = { client: "sqlite3", connection: { - filename: "./packages/cactus-plugin-satp-hermes/knex/.dev.remote.sqlite3", + filename: "./packages/cactus-plugin-satp-hermes/src/knex/.dev.remote-" + uuidv4() + ".sqlite3", }, migrations: { - directory: "./packages/cactus-plugin-satp-hermes/knex/migrations", + directory: "./packages/cactus-plugin-satp-hermes/src/knex/migrations", }, useNullAsDefault: true, }; diff --git a/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/client/commit-final.test.ts b/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/client/commit-final.test.ts index af553bf07f9..9a5c2a23b72 100644 --- a/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/client/commit-final.test.ts +++ b/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/client/commit-final.test.ts @@ -51,15 +51,17 @@ beforeEach(async () => { pluginSourceGateway = new FabricSATPGateway(sourceGatewayConstructor); pluginRecipientGateway = new BesuSATPGateway(recipientGatewayConstructor); - if ( - pluginSourceGateway.localRepository?.database == undefined || - pluginRecipientGateway.localRepository?.database == undefined - ) { - throw new Error("Database is not correctly initialized"); - } + expect(pluginSourceGateway.localRepository?.database).not.toBeUndefined(); + expect(pluginRecipientGateway.localRepository?.database).not.toBeUndefined(); + + expect(pluginSourceGateway.remoteRepository?.database).not.toBeUndefined(); + expect(pluginRecipientGateway.remoteRepository?.database).not.toBeUndefined(); await pluginSourceGateway.localRepository?.reset(); await pluginRecipientGateway.localRepository?.reset(); + + await pluginSourceGateway.remoteRepository?.reset(); + await pluginRecipientGateway.remoteRepository?.reset(); sequenceNumber = randomInt(100); sessionID = uuidv4(); @@ -88,16 +90,6 @@ beforeEach(async () => { operation: "create", data: COMMIT_ACK_CLAIM, }); - - if ( - pluginSourceGateway.localRepository?.database == undefined || - pluginRecipientGateway.localRepository?.database == undefined - ) { - throw new Error("Database is not correctly initialized"); - } - - await pluginSourceGateway.localRepository?.reset(); - await pluginRecipientGateway.localRepository?.reset(); }); afterEach(async () => { diff --git a/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/client/commit-preparation.test.ts b/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/client/commit-preparation.test.ts index 03494513f31..737549ed058 100644 --- a/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/client/commit-preparation.test.ts +++ b/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/client/commit-preparation.test.ts @@ -48,15 +48,17 @@ beforeEach(async () => { pluginSourceGateway = new FabricSATPGateway(sourceGatewayConstructor); pluginRecipientGateway = new BesuSATPGateway(recipientGatewayConstructor); - if ( - pluginSourceGateway.localRepository?.database == undefined || - pluginRecipientGateway.localRepository?.database == undefined - ) { - throw new Error("Database is not correctly initialized"); - } + expect(pluginSourceGateway.localRepository?.database).not.toBeUndefined(); + expect(pluginRecipientGateway.localRepository?.database).not.toBeUndefined(); + + expect(pluginSourceGateway.remoteRepository?.database).not.toBeUndefined(); + expect(pluginRecipientGateway.remoteRepository?.database).not.toBeUndefined(); await pluginSourceGateway.localRepository?.reset(); await pluginRecipientGateway.localRepository?.reset(); + + await pluginSourceGateway.remoteRepository?.reset(); + await pluginRecipientGateway.remoteRepository?.reset(); sequenceNumber = randomInt(100); sessionID = uuidV4(); diff --git a/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/client/lock-evidence.test.ts b/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/client/lock-evidence.test.ts index eec07d87638..ac3aa687306 100644 --- a/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/client/lock-evidence.test.ts +++ b/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/client/lock-evidence.test.ts @@ -47,15 +47,17 @@ beforeEach(async () => { pluginSourceGateway = new FabricSATPGateway(sourceGatewayConstructor); pluginRecipientGateway = new BesuSATPGateway(recipientGatewayConstructor); - if ( - pluginSourceGateway.localRepository?.database == undefined || - pluginRecipientGateway.localRepository?.database == undefined - ) { - throw new Error("Database is not correctly initialized"); - } + expect(pluginSourceGateway.localRepository?.database).not.toBeUndefined(); + expect(pluginRecipientGateway.localRepository?.database).not.toBeUndefined(); + + expect(pluginSourceGateway.remoteRepository?.database).not.toBeUndefined(); + expect(pluginRecipientGateway.remoteRepository?.database).not.toBeUndefined(); await pluginSourceGateway.localRepository?.reset(); await pluginRecipientGateway.localRepository?.reset(); + + await pluginSourceGateway.remoteRepository?.reset(); + await pluginRecipientGateway.remoteRepository?.reset(); sequenceNumber = randomInt(100); sessionID = uuidV4(); diff --git a/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/client/transfer-commence.test.ts b/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/client/transfer-commence.test.ts index 9a098ad4fa7..81da65aef60 100644 --- a/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/client/transfer-commence.test.ts +++ b/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/client/transfer-commence.test.ts @@ -47,15 +47,17 @@ beforeEach(async () => { pluginSourceGateway = new FabricSATPGateway(sourceGatewayConstructor); pluginRecipientGateway = new BesuSATPGateway(recipientGatewayConstructor); - if ( - pluginSourceGateway.localRepository?.database == undefined || - pluginRecipientGateway.localRepository?.database == undefined - ) { - throw new Error("Database is not correctly initialized"); - } + expect(pluginSourceGateway.localRepository?.database).not.toBeUndefined(); + expect(pluginRecipientGateway.localRepository?.database).not.toBeUndefined(); + + expect(pluginSourceGateway.remoteRepository?.database).not.toBeUndefined(); + expect(pluginRecipientGateway.remoteRepository?.database).not.toBeUndefined(); await pluginSourceGateway.localRepository?.reset(); await pluginRecipientGateway.localRepository?.reset(); + + await pluginSourceGateway.remoteRepository?.reset(); + await pluginRecipientGateway.remoteRepository?.reset(); sequenceNumber = randomInt(100); sessionID = uuidV4(); diff --git a/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/client/transfer-initialization.test.ts b/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/client/transfer-initialization.test.ts index 434e74777d0..ca998bc95d2 100644 --- a/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/client/transfer-initialization.test.ts +++ b/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/client/transfer-initialization.test.ts @@ -48,15 +48,17 @@ beforeEach(async () => { pluginSourceGateway = new FabricSATPGateway(sourceGatewayConstructor); pluginRecipientGateway = new BesuSATPGateway(recipientGatewayConstructor); - if ( - pluginSourceGateway.localRepository?.database == undefined || - pluginRecipientGateway.localRepository?.database == undefined - ) { - throw new Error("Database is not correctly initialized"); - } + expect(pluginSourceGateway.localRepository?.database).not.toBeUndefined(); + expect(pluginRecipientGateway.localRepository?.database).not.toBeUndefined(); + + expect(pluginSourceGateway.remoteRepository?.database).not.toBeUndefined(); + expect(pluginRecipientGateway.remoteRepository?.database).not.toBeUndefined(); await pluginSourceGateway.localRepository?.reset(); await pluginRecipientGateway.localRepository?.reset(); + + await pluginSourceGateway.remoteRepository?.reset(); + await pluginRecipientGateway.remoteRepository?.reset(); sequenceNumber = randomInt(100); sessionID = uuidV4(); diff --git a/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/recovery/logging.test.ts b/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/recovery/logging.test.ts index 5087233c803..a867986ceeb 100644 --- a/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/recovery/logging.test.ts +++ b/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/recovery/logging.test.ts @@ -86,15 +86,19 @@ beforeEach(async () => { pluginSourceGateway.sessions.set(sessionID, sessionData); pluginRecipientGateway.sessions.set(sessionID, sessionData); - if ( - pluginSourceGateway.localRepository?.database == undefined || - pluginRecipientGateway.localRepository?.database == undefined - ) { - throw new Error("Database is not correctly initialized"); - } + expect(pluginSourceGateway.localRepository?.database).not.toBeUndefined(); + expect(pluginRecipientGateway.localRepository?.database).not.toBeUndefined(); + + expect(pluginSourceGateway.remoteRepository?.database).not.toBeUndefined(); + expect(pluginRecipientGateway.remoteRepository?.database).not.toBeUndefined(); await pluginSourceGateway.localRepository?.reset(); await pluginRecipientGateway.localRepository?.reset(); + + await pluginSourceGateway.remoteRepository?.reset(); + await pluginRecipientGateway.remoteRepository?.reset(); + await pluginSourceGateway.remoteRepository?.reset(); + await pluginRecipientGateway.remoteRepository?.reset(); }); test("successful translation of log keys", async () => { diff --git a/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/recovery/recover-success.test.ts b/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/recovery/recover-success.test.ts index f788ac65719..a3e80345d04 100644 --- a/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/recovery/recover-success.test.ts +++ b/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/recovery/recover-success.test.ts @@ -57,8 +57,17 @@ beforeEach(async () => { throw new Error("Database is not correctly initialized"); } + expect(pluginSourceGateway.localRepository?.database).not.toBeUndefined(); + expect(pluginRecipientGateway.localRepository?.database).not.toBeUndefined(); + + expect(pluginSourceGateway.remoteRepository?.database).not.toBeUndefined(); + expect(pluginRecipientGateway.remoteRepository?.database).not.toBeUndefined(); + await pluginSourceGateway.localRepository?.reset(); await pluginRecipientGateway.localRepository?.reset(); + + await pluginSourceGateway.remoteRepository?.reset(); + await pluginRecipientGateway.remoteRepository?.reset(); sessionID = uuidv4(); sequenceNumber = randomInt(100); diff --git a/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/recovery/recover-update-ack.test.ts b/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/recovery/recover-update-ack.test.ts index d3222744660..83154dcc84c 100644 --- a/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/recovery/recover-update-ack.test.ts +++ b/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/recovery/recover-update-ack.test.ts @@ -50,15 +50,17 @@ beforeEach(async () => { pluginSourceGateway = new FabricSATPGateway(sourceGatewayConstructor); pluginRecipientGateway = new BesuSATPGateway(recipientGatewayConstructor); - if ( - pluginSourceGateway.localRepository?.database == undefined || - pluginRecipientGateway.localRepository?.database == undefined - ) { - throw new Error("Database is not correctly initialized"); - } + expect(pluginSourceGateway.localRepository?.database).not.toBeUndefined(); + expect(pluginRecipientGateway.localRepository?.database).not.toBeUndefined(); + + expect(pluginSourceGateway.remoteRepository?.database).not.toBeUndefined(); + expect(pluginRecipientGateway.remoteRepository?.database).not.toBeUndefined(); await pluginSourceGateway.localRepository?.reset(); await pluginRecipientGateway.localRepository?.reset(); + + await pluginSourceGateway.remoteRepository?.reset(); + await pluginRecipientGateway.remoteRepository?.reset(); sessionID = uuidv4(); sequenceNumber = randomInt(100); diff --git a/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/recovery/recover-update.test.ts b/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/recovery/recover-update.test.ts index 1f3ad2cc775..f56b917a089 100644 --- a/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/recovery/recover-update.test.ts +++ b/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/recovery/recover-update.test.ts @@ -62,15 +62,17 @@ beforeEach(async () => { pluginSourceGateway = new FabricSATPGateway(sourceGatewayConstructor); pluginRecipientGateway = new BesuSATPGateway(recipientGatewayConstructor); - if ( - pluginSourceGateway.localRepository?.database == undefined || - pluginRecipientGateway.localRepository?.database == undefined - ) { - throw new Error("Database is not correctly initialized"); - } + expect(pluginSourceGateway.localRepository?.database).not.toBeUndefined(); + expect(pluginRecipientGateway.localRepository?.database).not.toBeUndefined(); + + expect(pluginSourceGateway.remoteRepository?.database).not.toBeUndefined(); + expect(pluginRecipientGateway.remoteRepository?.database).not.toBeUndefined(); await pluginSourceGateway.localRepository?.reset(); await pluginRecipientGateway.localRepository?.reset(); + + await pluginSourceGateway.remoteRepository?.reset(); + await pluginRecipientGateway.remoteRepository?.reset(); sessionID = uuidv4(); sequenceNumber = randomInt(100); @@ -185,7 +187,6 @@ test("check valid build of recover update message", async () => { throw new Error("Test Failed"); } - console.log(recoverUpdateMessage.recoveredLogs); expect(recoverUpdateMessage.recoveredLogs.length).toBe(3); await checkValidRecoverUpdateMessage( diff --git a/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/recovery/recover.test.ts b/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/recovery/recover.test.ts index ad76becf891..f516efd8178 100644 --- a/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/recovery/recover.test.ts +++ b/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/recovery/recover.test.ts @@ -68,15 +68,17 @@ beforeEach(async () => { pluginSourceGateway.sessions.set(sessionID, sessionData); pluginRecipientGateway.sessions.set(sessionID, sessionData); - if ( - pluginSourceGateway.localRepository?.database == undefined || - pluginRecipientGateway.localRepository?.database == undefined - ) { - throw new Error("Database is not correctly initialized"); - } + expect(pluginSourceGateway.localRepository?.database).not.toBeUndefined(); + expect(pluginRecipientGateway.localRepository?.database).not.toBeUndefined(); + + expect(pluginSourceGateway.remoteRepository?.database).not.toBeUndefined(); + expect(pluginRecipientGateway.remoteRepository?.database).not.toBeUndefined(); await pluginSourceGateway.localRepository?.reset(); await pluginRecipientGateway.localRepository?.reset(); + + await pluginSourceGateway.remoteRepository?.reset(); + await pluginRecipientGateway.remoteRepository?.reset(); }); test("valid recover message request from client", async () => { diff --git a/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/server/commit-final.test.ts b/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/server/commit-final.test.ts index 68b49e8c2f1..fff1bf0a3ae 100644 --- a/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/server/commit-final.test.ts +++ b/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/server/commit-final.test.ts @@ -52,15 +52,17 @@ beforeEach(async () => { pluginSourceGateway = new FabricSATPGateway(sourceGatewayConstructor); pluginRecipientGateway = new BesuSATPGateway(recipientGatewayConstructor); - if ( - pluginSourceGateway.localRepository?.database == undefined || - pluginRecipientGateway.localRepository?.database == undefined - ) { - throw new Error("Database is not correctly initialized"); - } + expect(pluginSourceGateway.localRepository?.database).not.toBeUndefined(); + expect(pluginRecipientGateway.localRepository?.database).not.toBeUndefined(); + + expect(pluginSourceGateway.remoteRepository?.database).not.toBeUndefined(); + expect(pluginRecipientGateway.remoteRepository?.database).not.toBeUndefined(); await pluginSourceGateway.localRepository?.reset(); await pluginRecipientGateway.localRepository?.reset(); + + await pluginSourceGateway.remoteRepository?.reset(); + await pluginRecipientGateway.remoteRepository?.reset(); dummyCommitPreparationResponseMessageHash = SHA256( "commitPreparationResponseMessageData", @@ -93,16 +95,6 @@ beforeEach(async () => { operation: "delete", data: COMMIT_FINAL_CLAIM, } as ILocalLog); - - if ( - pluginSourceGateway.localRepository?.database == undefined || - pluginRecipientGateway.localRepository?.database == undefined - ) { - throw new Error("Database is not correctly initialized"); - } - - await pluginSourceGateway.localRepository?.reset(); - await pluginRecipientGateway.localRepository?.reset(); }); test("valid commit final request", async () => { diff --git a/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/server/commit-preparation.test.ts b/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/server/commit-preparation.test.ts index dfc48380daf..127ce29f9c2 100644 --- a/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/server/commit-preparation.test.ts +++ b/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/server/commit-preparation.test.ts @@ -43,15 +43,17 @@ beforeEach(async () => { pluginSourceGateway = new FabricSATPGateway(sourceGatewayConstructor); pluginRecipientGateway = new BesuSATPGateway(recipientGatewayConstructor); - if ( - pluginSourceGateway.localRepository?.database == undefined || - pluginRecipientGateway.localRepository?.database == undefined - ) { - throw new Error("Database is not correctly initialized"); - } + expect(pluginSourceGateway.localRepository?.database).not.toBeUndefined(); + expect(pluginRecipientGateway.localRepository?.database).not.toBeUndefined(); + + expect(pluginSourceGateway.remoteRepository?.database).not.toBeUndefined(); + expect(pluginRecipientGateway.remoteRepository?.database).not.toBeUndefined(); await pluginSourceGateway.localRepository?.reset(); await pluginRecipientGateway.localRepository?.reset(); + + await pluginSourceGateway.remoteRepository?.reset(); + await pluginRecipientGateway.remoteRepository?.reset(); dummyLockEvidenceResponseMessageHash = SHA256( "lockEvidenceResponseMessageData", diff --git a/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/server/lock-evidence.test.ts b/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/server/lock-evidence.test.ts index 093e73971eb..6c0552d18c2 100644 --- a/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/server/lock-evidence.test.ts +++ b/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/server/lock-evidence.test.ts @@ -50,16 +50,18 @@ beforeEach(async () => { pluginSourceGateway = new FabricSATPGateway(sourceGatewayConstructor); pluginRecipientGateway = new BesuSATPGateway(recipientGatewayConstructor); - if ( - pluginSourceGateway.localRepository?.database == undefined || - pluginRecipientGateway.localRepository?.database == undefined - ) { - throw new Error("Database is not correctly initialized"); - } + expect(pluginSourceGateway.localRepository?.database).not.toBeUndefined(); + expect(pluginRecipientGateway.localRepository?.database).not.toBeUndefined(); + + expect(pluginSourceGateway.remoteRepository?.database).not.toBeUndefined(); + expect(pluginRecipientGateway.remoteRepository?.database).not.toBeUndefined(); await pluginSourceGateway.localRepository?.reset(); await pluginRecipientGateway.localRepository?.reset(); - + + await pluginSourceGateway.remoteRepository?.reset(); + await pluginRecipientGateway.remoteRepository?.reset(); + dummyTransferCommenceResponseMessageHash = SHA256( "transferCommenceResponseMessageData", ).toString(); @@ -94,21 +96,6 @@ beforeEach(async () => { operation: "lock", data: LOCK_EVIDENCE_CLAIM, }); - - if ( - pluginSourceGateway.localRepository?.database == undefined || - pluginRecipientGateway.localRepository?.database == undefined - ) { - throw new Error("Database is not correctly initialized"); - } - - await pluginSourceGateway.localRepository?.reset(); - await pluginRecipientGateway.localRepository?.reset(); -}); - -afterEach(() => { - pluginSourceGateway.localRepository?.destroy(); - pluginRecipientGateway.localRepository?.destroy(); }); test("valid lock evidence request", async () => { diff --git a/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/server/transfer-commence.test.ts b/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/server/transfer-commence.test.ts index 59bbe0e80b4..e23bd5b7a91 100644 --- a/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/server/transfer-commence.test.ts +++ b/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/server/transfer-commence.test.ts @@ -47,15 +47,17 @@ beforeEach(async () => { pluginSourceGateway = new FabricSATPGateway(sourceGatewayConstructor); pluginRecipientGateway = new BesuSATPGateway(recipientGatewayConstructor); - if ( - pluginSourceGateway.localRepository?.database == undefined || - pluginRecipientGateway.localRepository?.database == undefined - ) { - throw new Error("Database is not correctly initialized"); - } + expect(pluginSourceGateway.localRepository?.database).not.toBeUndefined(); + expect(pluginRecipientGateway.localRepository?.database).not.toBeUndefined(); + + expect(pluginSourceGateway.remoteRepository?.database).not.toBeUndefined(); + expect(pluginRecipientGateway.remoteRepository?.database).not.toBeUndefined(); await pluginSourceGateway.localRepository?.reset(); await pluginRecipientGateway.localRepository?.reset(); + + await pluginSourceGateway.remoteRepository?.reset(); + await pluginRecipientGateway.remoteRepository?.reset(); dummyInitializationResponseMessageHash = SHA256( "initializationResponseMessageData", diff --git a/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/server/transfer-complete.test.ts b/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/server/transfer-complete.test.ts index dbd97be6d94..a2ad3a7cc16 100644 --- a/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/server/transfer-complete.test.ts +++ b/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/server/transfer-complete.test.ts @@ -44,15 +44,17 @@ beforeEach(async () => { pluginSourceGateway = new FabricSATPGateway(sourceGatewayConstructor); pluginRecipientGateway = new BesuSATPGateway(recipientGatewayConstructor); - if ( - pluginSourceGateway.localRepository?.database == undefined || - pluginRecipientGateway.localRepository?.database == undefined - ) { - throw new Error("Database is not correctly initialized"); - } + expect(pluginSourceGateway.localRepository?.database).not.toBeUndefined(); + expect(pluginRecipientGateway.localRepository?.database).not.toBeUndefined(); + + expect(pluginSourceGateway.remoteRepository?.database).not.toBeUndefined(); + expect(pluginRecipientGateway.remoteRepository?.database).not.toBeUndefined(); await pluginSourceGateway.localRepository?.reset(); await pluginRecipientGateway.localRepository?.reset(); + + await pluginSourceGateway.remoteRepository?.reset(); + await pluginRecipientGateway.remoteRepository?.reset(); dummyCommitFinalResponseMessageHash = SHA256( "commitFinalResponseMessageData", diff --git a/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/server/transfer-initialization.test.ts b/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/server/transfer-initialization.test.ts index c32508dcd9e..b8d3d5a26b4 100644 --- a/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/server/transfer-initialization.test.ts +++ b/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/server/transfer-initialization.test.ts @@ -44,15 +44,17 @@ beforeEach(async () => { pluginSourceGateway = new FabricSATPGateway(sourceGatewayConstructor); pluginRecipientGateway = new BesuSATPGateway(recipientGatewayConstructor); - if ( - pluginSourceGateway.localRepository?.database == undefined || - pluginRecipientGateway.localRepository?.database == undefined - ) { - throw new Error("Database is not correctly initialized"); - } + expect(pluginSourceGateway.localRepository?.database).not.toBeUndefined(); + expect(pluginRecipientGateway.localRepository?.database).not.toBeUndefined(); + + expect(pluginSourceGateway.remoteRepository?.database).not.toBeUndefined(); + expect(pluginRecipientGateway.remoteRepository?.database).not.toBeUndefined(); await pluginSourceGateway.localRepository?.reset(); await pluginRecipientGateway.localRepository?.reset(); + + await pluginSourceGateway.remoteRepository?.reset(); + await pluginRecipientGateway.remoteRepository?.reset(); expiryDate = new Date(2060, 11, 24).toString(); assetProfile = { expirationDate: expiryDate };