From d4c9087fe6fa140c92ec90e9c3ae4f5a5f121690 Mon Sep 17 00:00:00 2001 From: Yogesh01000100 Date: Fri, 6 Dec 2024 21:16:11 +0000 Subject: [PATCH] fix: add knex config in gateway config Signed-off-by: Yogesh01000100 --- .../client/stage2-client-service.ts | 2 +- .../typescript/plugin-satp-hermes-gateway.ts | 6 +- .../integration/gateway-blo.test.ts | 3 + .../integration/gateway-init-startup.test.ts | 21 ++++++- ...e2e-transfer-1-gateway-with-bungee.test.ts | 5 ++ .../satp-e2e-transfer-1-gateway.test.ts | 25 ++++++++ ...tp-e2e-transfer-2-gateways-openapi.test.ts | 53 +++++++++++++++- .../satp-e2e-transfer-2-gateways.test.ts | 63 +++++++++++++++++-- .../src/test/typescript/knex.config.ts | 16 ++++- .../src/test/typescript/unit/services.test.ts | 6 +- 10 files changed, 183 insertions(+), 17 deletions(-) diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/client/stage2-client-service.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/client/stage2-client-service.ts index 10784597e4..99b8bda2e4 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/client/stage2-client-service.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/client/stage2-client-service.ts @@ -254,7 +254,7 @@ export class Stage2ClientService extends SATPService { this.dbLogger.storeProof({ sessionID: sessionData.id, type: "lock-asset", - operation: "done", + operation: "exec", data: safeStableStringify(sessionData), sequenceNumber: Number(sessionData.lastSequenceNumber), }); diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/plugin-satp-hermes-gateway.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/plugin-satp-hermes-gateway.ts index 4b2cda6d96..1f549a4a0b 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/plugin-satp-hermes-gateway.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/plugin-satp-hermes-gateway.ts @@ -34,7 +34,7 @@ import { DEFAULT_PORT_GATEWAY_API, DEFAULT_PORT_GATEWAY_CLIENT, DEFAULT_PORT_GATEWAY_SERVER, - SATP_ARCHITETURE_VERSION, + SATP_ARCHITECTURE_VERSION, SATP_CORE_VERSION, SATP_CRASH_VERSION, } from "./core/constants"; @@ -294,7 +294,7 @@ export class SATPGateway implements IPluginWebService, ICactusPlugin { version: [ { Core: SATP_CORE_VERSION, - Architecture: SATP_ARCHITETURE_VERSION, + Architecture: SATP_ARCHITECTURE_VERSION, Crash: SATP_CRASH_VERSION, }, ], @@ -324,7 +324,7 @@ export class SATPGateway implements IPluginWebService, ICactusPlugin { pluginOptions.gid.version = [ { Core: SATP_CORE_VERSION, - Architecture: SATP_ARCHITETURE_VERSION, + Architecture: SATP_ARCHITECTURE_VERSION, Crash: SATP_CRASH_VERSION, }, ]; diff --git a/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/gateway-blo.test.ts b/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/gateway-blo.test.ts index b32310c8c9..95b7f73be0 100644 --- a/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/gateway-blo.test.ts +++ b/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/gateway-blo.test.ts @@ -16,6 +16,7 @@ import { } from "../../../main/typescript/core/types"; import { createClient } from "../test-utils"; import { HealthCheckResponseStatusEnum } from "../../../main/typescript"; +import { knexClientConnection, knexRemoteConnection1 } from "../knex.config"; const logLevel: LogLevelDesc = "DEBUG"; const logger = LoggerProvider.getOrCreate({ @@ -57,6 +58,8 @@ const options: SATPGatewayConfig = { gatewayOpenAPIPort: 4010, address: "http://localhost", }, + knexLocalConfig: knexClientConnection, + knexRemoteConfig: knexRemoteConnection1, }; describe("GetStatus Endpoint and Functionality testing", () => { diff --git a/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/gateway-init-startup.test.ts b/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/gateway-init-startup.test.ts index 1ca2282beb..263f3db6c4 100644 --- a/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/gateway-init-startup.test.ts +++ b/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/gateway-init-startup.test.ts @@ -41,6 +41,7 @@ import { import { AddressInfo } from "net"; import { PluginRegistry } from "@hyperledger/cactus-core"; import { AdminApi } from "../../../main/typescript"; +import { knexClientConnection, knexRemoteConnection1 } from "../knex.config"; const logLevel: LogLevelDesc = "DEBUG"; const logger = LoggerProvider.getOrCreate({ @@ -65,7 +66,10 @@ beforeAll(async () => { describe("SATPGateway initialization", () => { it("should initiate gateway with default config", async () => { - const options: SATPGatewayConfig = {}; + const options: SATPGatewayConfig = { + knexLocalConfig: knexClientConnection, + knexRemoteConfig: knexRemoteConnection1, + }; const gateway = await factory.create(options); expect(gateway).toBeInstanceOf(SATPGateway); @@ -106,6 +110,8 @@ describe("SATPGateway initialization", () => { gatewayServerPort: 3010, address: "https://localhost", }, + knexLocalConfig: knexClientConnection, + knexRemoteConfig: knexRemoteConnection1, }; const gateway = await factory.create(options); @@ -148,6 +154,8 @@ describe("SATPGateway initialization", () => { proofID: "mockProofID10", address: "https://localhost", }, + knexLocalConfig: knexClientConnection, + knexRemoteConfig: knexRemoteConnection1, }; const gateway = await factory.create(options); expect(gateway).toBeInstanceOf(SATPGateway); @@ -179,6 +187,8 @@ describe("SATPGateway initialization", () => { gatewayClientPort: 3015, address: "https://localhost", }, + knexLocalConfig: knexClientConnection, + knexRemoteConfig: knexRemoteConnection1, }; const gateway = await factory.create(options); @@ -219,7 +229,10 @@ describe("SATPGateway initialization", () => { describe("SATPGateway startup", () => { it("initiates with default config", async () => { - const options: SATPGatewayConfig = {}; + const options: SATPGatewayConfig = { + knexLocalConfig: knexClientConnection, + knexRemoteConfig: knexRemoteConnection1, + }; const gateway = await factory.create(options); expect(gateway).toBeInstanceOf(SATPGateway); @@ -260,6 +273,8 @@ describe("SATPGateway startup", () => { gatewayClientPort: 3001, address: "https://localhost", }, + knexLocalConfig: knexClientConnection, + knexRemoteConfig: knexRemoteConnection1, }; const gateway = await factory.create(options); @@ -306,6 +321,8 @@ describe("SATPGateway startup", () => { address: "http://localhost", }, enableOpenAPI: true, + knexLocalConfig: knexClientConnection, + knexRemoteConfig: knexRemoteConnection1, }; const gateway = await factory.create(options); expect(gateway).toBeInstanceOf(SATPGateway); diff --git a/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/satp-e2e-transfer-1-gateway-with-bungee.test.ts b/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/satp-e2e-transfer-1-gateway-with-bungee.test.ts index b7bd79688e..aa6f9632cf 100644 --- a/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/satp-e2e-transfer-1-gateway-with-bungee.test.ts +++ b/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/satp-e2e-transfer-1-gateway-with-bungee.test.ts @@ -36,6 +36,7 @@ import { SATP_CRASH_VERSION, } from "../../../main/typescript/core/constants"; import { WHALE_ACCOUNT_ADDRESS } from "@hyperledger/cactus-test-geth-ledger"; +import { knexClientConnection, knexRemoteConnection1 } from "../knex.config"; const logLevel: LogLevelDesc = "DEBUG"; const log = LoggerProvider.getOrCreate({ @@ -137,6 +138,8 @@ describe("SATPGateway sending a token from Besu to Fabric", () => { gid: gatewayIdentity, counterPartyGateways: [], //only knows itself bridgesConfig: [besuEnv.besuConfig, fabricEnv.fabricConfig], + knexLocalConfig: knexClientConnection, + knexRemoteConfig: knexRemoteConnection1, }; const gateway = await factory.create(options); expect(gateway).toBeInstanceOf(SATPGateway); @@ -261,6 +264,8 @@ describe("SATPGateway sending a token from Ethereum to Fabric", () => { gid: gatewayIdentity, counterPartyGateways: [], //only knows itself bridgesConfig: [ethereumEnv.ethereumConfig, fabricEnv.fabricConfig], + knexLocalConfig: knexClientConnection, + knexRemoteConfig: knexRemoteConnection1, }; let initialBalance; diff --git a/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/satp-e2e-transfer-1-gateway.test.ts b/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/satp-e2e-transfer-1-gateway.test.ts index b59549cb5f..41c7c12e0b 100644 --- a/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/satp-e2e-transfer-1-gateway.test.ts +++ b/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/satp-e2e-transfer-1-gateway.test.ts @@ -34,6 +34,8 @@ import { SATP_CORE_VERSION, SATP_CRASH_VERSION, } from "../../../main/typescript/core/constants"; +import { knexClientConnection, knexRemoteConnection1 } from "../knex.config"; +import { Knex, knex } from "knex"; const logLevel: LogLevelDesc = "DEBUG"; const log = LoggerProvider.getOrCreate({ @@ -41,6 +43,8 @@ const log = LoggerProvider.getOrCreate({ label: "BUNGEE - Hermes", }); +let knexInstanceClient: Knex; +let knexInstanceRemote1: Knex; let fabricEnv: FabricTestEnvironment; let besuEnv: BesuTestEnvironment; let gateway: SATPGateway; @@ -49,6 +53,19 @@ const bridge_id = afterAll(async () => { await gateway.shutdown(); + + if (gateway) { + await gateway.localRepository?.destroy(); + await gateway.remoteRepository?.destroy(); + + if (knexInstanceClient) { + await knexInstanceClient.destroy(); + } + if (knexInstanceRemote1) { + await knexInstanceRemote1.destroy(); + } + await gateway.shutdown(); + } await besuEnv.tearDown(); await fabricEnv.tearDown(); @@ -122,11 +139,19 @@ describe("SATPGateway sending a token from Besu to Fabric", () => { address: "http://localhost" as Address, } as GatewayIdentity; + knexInstanceClient = knex(knexClientConnection); + await knexInstanceClient.migrate.latest(); + + knexInstanceRemote1 = knex(knexRemoteConnection1); + await knexInstanceRemote1.migrate.latest(); + const options: SATPGatewayConfig = { logLevel: "DEBUG", gid: gatewayIdentity, counterPartyGateways: [], //only knows itself bridgesConfig: [besuEnv.besuConfig, fabricEnv.fabricConfig], + knexLocalConfig: knexClientConnection, + knexRemoteConfig: knexRemoteConnection1, }; gateway = await factory.create(options); expect(gateway).toBeInstanceOf(SATPGateway); diff --git a/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/satp-e2e-transfer-2-gateways-openapi.test.ts b/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/satp-e2e-transfer-2-gateways-openapi.test.ts index f2de30961b..c4df981447 100644 --- a/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/satp-e2e-transfer-2-gateways-openapi.test.ts +++ b/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/satp-e2e-transfer-2-gateways-openapi.test.ts @@ -42,7 +42,18 @@ import { SATP_CORE_VERSION, SATP_CRASH_VERSION, } from "../../../main/typescript/core/constants"; +import { + knexClientConnection, + knexRemoteConnection1, + knexRemoteConnection2, + knexServerConnection, +} from "../knex.config"; +import { Knex, knex } from "knex"; +let knexInstanceClient: Knex; +let knexInstanceRemote1: Knex; +let knexInstanceRemote2: Knex; +let knexInstanceServer: Knex; const logLevel: LogLevelDesc = "DEBUG"; const log = LoggerProvider.getOrCreate({ level: logLevel, @@ -57,8 +68,31 @@ const bridge_id = "x509::/OU=org2/OU=client/OU=department1/CN=bridge::/C=UK/ST=Hampshire/L=Hursley/O=org2.example.com/CN=ca.org2.example.com"; afterAll(async () => { - await gateway1.shutdown(); - await gateway2.shutdown(); + if (gateway1) { + await gateway1.localRepository?.destroy(); + await gateway1.remoteRepository?.destroy(); + + if (knexInstanceClient) { + await knexInstanceClient.destroy(); + } + if (knexInstanceRemote1) { + await knexInstanceRemote1.destroy(); + } + await gateway1.shutdown(); + } + + if (gateway2) { + await gateway2.localRepository?.destroy(); + await gateway2.remoteRepository?.destroy(); + + if (knexInstanceRemote2) { + await knexInstanceRemote2.destroy(); + } + if (knexInstanceServer) { + await knexInstanceServer.destroy(); + } + await gateway2.shutdown(); + } await besuEnv.tearDown(); await fabricEnv.tearDown(); @@ -152,6 +186,12 @@ describe("2 SATPGateway sending a token from Besu to Fabric using openApi to req const gateway2KeyPair = Secp256k1Keys.generateKeyPairsBuffer(); + knexInstanceClient = knex(knexClientConnection); + await knexInstanceClient.migrate.latest(); + + knexInstanceRemote1 = knex(knexRemoteConnection1); + await knexInstanceRemote1.migrate.latest(); + const options1: SATPGatewayConfig = { logLevel: "DEBUG", gid: gatewayIdentity1, @@ -178,8 +218,15 @@ describe("2 SATPGateway sending a token from Besu to Fabric using openApi to req ], bridgesConfig: [besuEnv.besuConfig], keyPair: gateway1KeyPair, + knexLocalConfig: knexClientConnection, + knexRemoteConfig: knexRemoteConnection1, }; + knexInstanceServer = knex(knexServerConnection); + await knexInstanceServer.migrate.latest(); + + knexInstanceRemote2 = knex(knexRemoteConnection2); + await knexInstanceRemote2.migrate.latest(); const options2: SATPGatewayConfig = { logLevel: "DEBUG", gid: gatewayIdentity2, @@ -202,6 +249,8 @@ describe("2 SATPGateway sending a token from Besu to Fabric using openApi to req ], bridgesConfig: [fabricEnv.fabricConfig], keyPair: gateway2KeyPair, + knexLocalConfig: knexServerConnection, + knexRemoteConfig: knexRemoteConnection2, }; gateway1 = await factory.create(options1); expect(gateway1).toBeInstanceOf(SATPGateway); diff --git a/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/satp-e2e-transfer-2-gateways.test.ts b/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/satp-e2e-transfer-2-gateways.test.ts index 877d314100..24560163a6 100644 --- a/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/satp-e2e-transfer-2-gateways.test.ts +++ b/packages/cactus-plugin-satp-hermes/src/test/typescript/integration/satp-e2e-transfer-2-gateways.test.ts @@ -40,6 +40,13 @@ import { SATP_CORE_VERSION, SATP_CRASH_VERSION, } from "../../../main/typescript/core/constants"; +import { + knexClientConnection, + knexRemoteConnection1, + knexRemoteConnection2, + knexServerConnection, +} from "../knex.config"; +import { Knex, knex } from "knex"; const logLevel: LogLevelDesc = "DEBUG"; const log = LoggerProvider.getOrCreate({ @@ -47,6 +54,11 @@ const log = LoggerProvider.getOrCreate({ label: "BUNGEE - Hermes", }); +let knexInstanceClient: Knex; +let knexInstanceRemote1: Knex; +let knexInstanceRemote2: Knex; +let knexInstanceServer: Knex; + let fabricEnv: FabricTestEnvironment; let besuEnv: BesuTestEnvironment; let gateway1: SATPGateway; @@ -55,18 +67,43 @@ const bridge_id = "x509::/OU=org2/OU=client/OU=department1/CN=bridge::/C=UK/ST=Hampshire/L=Hursley/O=org2.example.com/CN=ca.org2.example.com"; afterAll(async () => { - await gateway1.shutdown(); - await gateway2.shutdown(); + if (gateway1) { + await gateway1.localRepository?.destroy(); + await gateway1.remoteRepository?.destroy(); + + if (knexInstanceClient) { + await knexInstanceClient.destroy(); + } + if (knexInstanceRemote1) { + await knexInstanceRemote1.destroy(); + } + await gateway1.shutdown(); + } + + if (gateway2) { + await gateway2.localRepository?.destroy(); + await gateway2.remoteRepository?.destroy(); + + if (knexInstanceRemote2) { + await knexInstanceRemote2.destroy(); + } + if (knexInstanceServer) { + await knexInstanceServer.destroy(); + } + await gateway2.shutdown(); + } + await besuEnv.tearDown(); await fabricEnv.tearDown(); await pruneDockerAllIfGithubAction({ logLevel }) .then(() => { - log.info("Pruning throw OK"); + log.info("Docker containers pruned successfully."); }) - .catch(async () => { + .catch(async (error) => { + log.warn("Docker pruning failed. Attempting diagnostics..."); await Containers.logDiagnostics({ logLevel }); - fail("Pruning didn't throw OK"); + throw error; }); }); @@ -150,6 +187,12 @@ describe("2 SATPGateway sending a token from Besu to Fabric", () => { const gateway2KeyPair = Secp256k1Keys.generateKeyPairsBuffer(); + knexInstanceClient = knex(knexClientConnection); + await knexInstanceClient.migrate.latest(); + + knexInstanceRemote1 = knex(knexRemoteConnection1); + await knexInstanceRemote1.migrate.latest(); + const options1: SATPGatewayConfig = { logLevel: "DEBUG", gid: gatewayIdentity1, @@ -176,8 +219,16 @@ describe("2 SATPGateway sending a token from Besu to Fabric", () => { ], bridgesConfig: [besuEnv.besuConfig], keyPair: gateway1KeyPair, + knexLocalConfig: knexClientConnection, + knexRemoteConfig: knexRemoteConnection1, }; + knexInstanceServer = knex(knexServerConnection); + await knexInstanceServer.migrate.latest(); + + knexInstanceRemote2 = knex(knexRemoteConnection2); + await knexInstanceRemote2.migrate.latest(); + const options2: SATPGatewayConfig = { logLevel: "DEBUG", gid: gatewayIdentity2, @@ -200,6 +251,8 @@ describe("2 SATPGateway sending a token from Besu to Fabric", () => { ], bridgesConfig: [fabricEnv.fabricConfig], keyPair: gateway2KeyPair, + knexLocalConfig: knexServerConnection, + knexRemoteConfig: knexRemoteConnection2, }; gateway1 = await factory.create(options1); expect(gateway1).toBeInstanceOf(SATPGateway); 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 c32d533a4b..9e4f6aace2 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 @@ -28,7 +28,21 @@ export const knexServerConnection = { useNullAsDefault: true, }; -export const knexRemoteConnection = { +export const knexRemoteConnection1 = { + client: "sqlite3", + connection: { + filename: + "./packages/cactus-plugin-satp-hermes/src/knex/.dev.remote-" + + uuidv4() + + ".sqlite3", + }, + migrations: { + directory: "./packages/cactus-plugin-satp-hermes/src/knex/migrations", + }, + useNullAsDefault: true, +}; + +export const knexRemoteConnection2 = { client: "sqlite3", connection: { filename: diff --git a/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/services.test.ts b/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/services.test.ts index a81a66110c..dad838634a 100644 --- a/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/services.test.ts +++ b/packages/cactus-plugin-satp-hermes/src/test/typescript/unit/services.test.ts @@ -71,7 +71,7 @@ import { ILocalLogRepository, IRemoteLogRepository, } from "../../../main/typescript/repository/interfaces/repository"; -import { knexClientConnection, knexRemoteConnection } from "../knex.config"; +import { knexClientConnection, knexRemoteConnection1 } from "../knex.config"; import { Knex, knex } from "knex"; import { KnexLocalLogRepository as LocalLogRepository } from "../../../main/typescript/repository/knex-local-log-repository"; import { KnexRemoteLogRepository as RemoteLogRepository } from "../../../main/typescript/repository/knex-remote-log-repository"; @@ -146,11 +146,11 @@ beforeAll(async () => { knexInstanceClient = knex(knexClientConnection); await knexInstanceClient.migrate.latest(); - knexInstanceRemote = knex(knexRemoteConnection); + knexInstanceRemote = knex(knexRemoteConnection1); await knexInstanceRemote.migrate.latest(); localRepository = new LocalLogRepository(knexClientConnection); - remoteRepository = new RemoteLogRepository(knexRemoteConnection); + remoteRepository = new RemoteLogRepository(knexRemoteConnection1); dbLogger = new SATPLogger({ localRepository, remoteRepository,