Skip to content

Commit

Permalink
fix: add knex config in gateway
Browse files Browse the repository at this point in the history
1.Integrated knexLocalConfig and knexRemoteConfig into SATPGatewayConfig

Fixes #3665

Signed-off-by: Yogesh01000100 <[email protected]>
  • Loading branch information
Yogesh01000100 authored and RafaelAPB committed Dec 11, 2024
1 parent 947ec03 commit 3222474
Show file tree
Hide file tree
Showing 12 changed files with 249 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ export class Stage0ClientService extends SATPService {
this.Log.info(`init-${stepTag}`);
this.dbLogger.persistLogEntry({
sessionID: sessionData.id,
type: "wrap-token",
type: "wrap-token-client",
operation: "init",
data: safeStableStringify(sessionData),
sequenceNumber: Number(sessionData.lastSequenceNumber),
Expand All @@ -390,7 +390,7 @@ export class Stage0ClientService extends SATPService {
this.Log.info(`exec-${stepTag}`);
this.dbLogger.persistLogEntry({
sessionID: sessionData.id,
type: "wrap-token",
type: "wrap-token-client",
operation: "exec",
data: safeStableStringify(sessionData),
sequenceNumber: Number(sessionData.lastSequenceNumber),
Expand Down Expand Up @@ -441,7 +441,7 @@ export class Stage0ClientService extends SATPService {

this.dbLogger.storeProof({
sessionID: sessionData.id,
type: "wrap-token",
type: "wrap-token-client",
operation: "done",
data: safeStableStringify(sessionData.senderWrapAssertionClaim.proof),
sequenceNumber: Number(sessionData.lastSequenceNumber),
Expand All @@ -451,7 +451,7 @@ export class Stage0ClientService extends SATPService {
this.logger.debug(`Crash in ${fnTag}`, error);
this.dbLogger.persistLogEntry({
sessionID: sessionData.id,
type: "wrap-token",
type: "wrap-token-client",
operation: "fail",
data: safeStableStringify(sessionData),
sequenceNumber: Number(sessionData.lastSequenceNumber),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ export class Stage0ServerService extends SATPService {
this.Log.info(`init-${stepTag}`);
this.dbLogger.persistLogEntry({
sessionID: sessionData.id,
type: "wrap-token",
type: "wrap-token-server",
operation: "init",
data: safeStableStringify(sessionData),
sequenceNumber: Number(sessionData.lastSequenceNumber),
Expand All @@ -526,7 +526,7 @@ export class Stage0ServerService extends SATPService {
this.Log.info(`exec-${stepTag}`);
this.dbLogger.persistLogEntry({
sessionID: sessionData.id,
type: "wrap-token",
type: "wrap-token-server",
operation: "exec",
data: safeStableStringify(sessionData),
sequenceNumber: Number(sessionData.lastSequenceNumber),
Expand Down Expand Up @@ -574,7 +574,7 @@ export class Stage0ServerService extends SATPService {

this.dbLogger.storeProof({
sessionID: sessionData.id,
type: "wrap-token",
type: "wrap-token-server",
operation: "done",
data: safeStableStringify(sessionData.receiverWrapAssertionClaim.proof),
sequenceNumber: Number(sessionData.lastSequenceNumber),
Expand All @@ -585,7 +585,7 @@ export class Stage0ServerService extends SATPService {

this.dbLogger.persistLogEntry({
sessionID: sessionData.id,
type: "wrap-token",
type: "wrap-token-server",
operation: "fail",
data: safeStableStringify(sessionData),
sequenceNumber: Number(sessionData.lastSequenceNumber),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,18 @@ export class SATPGateway implements IPluginWebService, ICactusPlugin {

this.logger.info(`Closed ${connectionsClosed} connections`);
this.logger.info("Gateway Coordinator shut down");

if (this.localRepository) {
this.logger.debug("Destroying local repository...");
await this.localRepository.destroy();
this.logger.info("Local repository destroyed");
}

if (this.remoteRepository) {
this.logger.debug("Destroying remote repository...");
await this.remoteRepository.destroy();
this.logger.info("Remote repository destroyed");
}
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import {
} from "../../../main/typescript/core/types";
import { createClient } from "../test-utils";
import { HealthCheckResponseStatusEnum } from "../../../main/typescript";
import {
knexClientConnection,
knexSourceRemoteConnection,
} from "../knex.config";

const logLevel: LogLevelDesc = "DEBUG";
const logger = LoggerProvider.getOrCreate({
Expand Down Expand Up @@ -57,6 +61,8 @@ const options: SATPGatewayConfig = {
gatewayOpenAPIPort: 4010,
address: "http://localhost",
},
knexLocalConfig: knexClientConnection,
knexRemoteConfig: knexSourceRemoteConnection,
};

describe("GetStatus Endpoint and Functionality testing", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ import {
import { AddressInfo } from "net";
import { PluginRegistry } from "@hyperledger/cactus-core";
import { AdminApi } from "../../../main/typescript";
import {
knexClientConnection,
knexSourceRemoteConnection,
} from "../knex.config";

const logLevel: LogLevelDesc = "DEBUG";
const logger = LoggerProvider.getOrCreate({
Expand All @@ -65,7 +69,10 @@ beforeAll(async () => {

describe("SATPGateway initialization", () => {
it("should initiate gateway with default config", async () => {
const options: SATPGatewayConfig = {};
const options: SATPGatewayConfig = {
knexLocalConfig: knexClientConnection,
knexRemoteConfig: knexSourceRemoteConnection,
};
const gateway = await factory.create(options);

expect(gateway).toBeInstanceOf(SATPGateway);
Expand Down Expand Up @@ -106,6 +113,8 @@ describe("SATPGateway initialization", () => {
gatewayServerPort: 3010,
address: "https://localhost",
},
knexLocalConfig: knexClientConnection,
knexRemoteConfig: knexSourceRemoteConnection,
};
const gateway = await factory.create(options);

Expand Down Expand Up @@ -148,6 +157,8 @@ describe("SATPGateway initialization", () => {
proofID: "mockProofID10",
address: "https://localhost",
},
knexLocalConfig: knexClientConnection,
knexRemoteConfig: knexSourceRemoteConnection,
};
const gateway = await factory.create(options);
expect(gateway).toBeInstanceOf(SATPGateway);
Expand Down Expand Up @@ -179,6 +190,8 @@ describe("SATPGateway initialization", () => {
gatewayClientPort: 3015,
address: "https://localhost",
},
knexLocalConfig: knexClientConnection,
knexRemoteConfig: knexSourceRemoteConnection,
};

const gateway = await factory.create(options);
Expand Down Expand Up @@ -219,7 +232,10 @@ describe("SATPGateway initialization", () => {

describe("SATPGateway startup", () => {
it("initiates with default config", async () => {
const options: SATPGatewayConfig = {};
const options: SATPGatewayConfig = {
knexLocalConfig: knexClientConnection,
knexRemoteConfig: knexSourceRemoteConnection,
};
const gateway = await factory.create(options);

expect(gateway).toBeInstanceOf(SATPGateway);
Expand Down Expand Up @@ -260,6 +276,8 @@ describe("SATPGateway startup", () => {
gatewayClientPort: 3001,
address: "https://localhost",
},
knexLocalConfig: knexClientConnection,
knexRemoteConfig: knexSourceRemoteConnection,
};
const gateway = await factory.create(options);

Expand Down Expand Up @@ -306,6 +324,8 @@ describe("SATPGateway startup", () => {
address: "http://localhost",
},
enableOpenAPI: true,
knexLocalConfig: knexClientConnection,
knexRemoteConfig: knexSourceRemoteConnection,
};
const gateway = await factory.create(options);
expect(gateway).toBeInstanceOf(SATPGateway);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ import {
SATP_CRASH_VERSION,
} from "../../../main/typescript/core/constants";
import { WHALE_ACCOUNT_ADDRESS } from "@hyperledger/cactus-test-geth-ledger";
import {
knexClientConnection,
knexSourceRemoteConnection,
} from "../knex.config";
import { knex } from "knex";

const logLevel: LogLevelDesc = "DEBUG";
const log = LoggerProvider.getOrCreate({
Expand Down Expand Up @@ -132,11 +137,19 @@ describe("SATPGateway sending a token from Besu to Fabric", () => {
address: "http://localhost" as Address,
} as GatewayIdentity;

const knexInstanceClient = knex(knexClientConnection);
await knexInstanceClient.migrate.latest();

const knexSourceRemoteInstance = knex(knexSourceRemoteConnection);
await knexSourceRemoteInstance.migrate.latest();

const options: SATPGatewayConfig = {
logLevel: "DEBUG",
gid: gatewayIdentity,
counterPartyGateways: [], //only knows itself
bridgesConfig: [besuEnv.besuConfig, fabricEnv.fabricConfig],
knexLocalConfig: knexClientConnection,
knexRemoteConfig: knexSourceRemoteConnection,
};
const gateway = await factory.create(options);
expect(gateway).toBeInstanceOf(SATPGateway);
Expand Down Expand Up @@ -228,7 +241,14 @@ describe("SATPGateway sending a token from Besu to Fabric", () => {
expect(responseBalance2.data).not.toBeUndefined();
expect(responseBalance2.data.functionOutput).toBe("1");
log.info("Amount was transfer correctly to the Owner account");

if (gateway) {
if (knexInstanceClient) {
await knexInstanceClient.destroy();
}
if (knexSourceRemoteInstance) {
await knexSourceRemoteInstance.destroy();
}
}
await gateway.shutdown();
});
});
Expand Down Expand Up @@ -256,11 +276,19 @@ describe("SATPGateway sending a token from Ethereum to Fabric", () => {
address: "http://localhost" as Address,
} as GatewayIdentity;

const knexInstanceClient = knex(knexClientConnection);
await knexInstanceClient.migrate.latest();

const knexSourceRemoteInstance = knex(knexSourceRemoteConnection);
await knexSourceRemoteInstance.migrate.latest();

const options: SATPGatewayConfig = {
logLevel: "DEBUG",
gid: gatewayIdentity,
counterPartyGateways: [], //only knows itself
bridgesConfig: [ethereumEnv.ethereumConfig, fabricEnv.fabricConfig],
knexLocalConfig: knexClientConnection,
knexRemoteConfig: knexSourceRemoteConnection,
};

let initialBalance;
Expand Down Expand Up @@ -371,7 +399,14 @@ describe("SATPGateway sending a token from Ethereum to Fabric", () => {
(Number(initialBalance.data.functionOutput) + 1).toString(),
);
log.info("Amount was transfer correctly to the Owner account");

await gateway.shutdown();
if (gateway) {
if (knexInstanceClient) {
await knexInstanceClient.destroy();
}
if (knexSourceRemoteInstance) {
await knexSourceRemoteInstance.destroy();
}
await gateway.shutdown();
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,20 @@ import {
SATP_CORE_VERSION,
SATP_CRASH_VERSION,
} from "../../../main/typescript/core/constants";
import {
knexClientConnection,
knexSourceRemoteConnection,
} from "../knex.config";
import { Knex, knex } from "knex";

const logLevel: LogLevelDesc = "DEBUG";
const log = LoggerProvider.getOrCreate({
level: logLevel,
label: "BUNGEE - Hermes",
});

let knexInstanceClient: Knex;
let knexSourceRemoteInstance: Knex;
let fabricEnv: FabricTestEnvironment;
let besuEnv: BesuTestEnvironment;
let gateway: SATPGateway;
Expand All @@ -49,6 +56,16 @@ const bridge_id =

afterAll(async () => {
await gateway.shutdown();

if (gateway) {
if (knexInstanceClient) {
await knexInstanceClient.destroy();
}
if (knexSourceRemoteInstance) {
await knexSourceRemoteInstance.destroy();
}
await gateway.shutdown();
}
await besuEnv.tearDown();
await fabricEnv.tearDown();

Expand Down Expand Up @@ -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();

knexSourceRemoteInstance = knex(knexSourceRemoteConnection);
await knexSourceRemoteInstance.migrate.latest();

const options: SATPGatewayConfig = {
logLevel: "DEBUG",
gid: gatewayIdentity,
counterPartyGateways: [], //only knows itself
bridgesConfig: [besuEnv.besuConfig, fabricEnv.fabricConfig],
knexLocalConfig: knexClientConnection,
knexRemoteConfig: knexSourceRemoteConnection,
};
gateway = await factory.create(options);
expect(gateway).toBeInstanceOf(SATPGateway);
Expand Down
Loading

0 comments on commit 3222474

Please sign in to comment.