Skip to content

Commit

Permalink
fix: add knex config in gateway config
Browse files Browse the repository at this point in the history
Signed-off-by: Yogesh01000100 <[email protected]>
  • Loading branch information
Yogesh01000100 committed Dec 9, 2024
1 parent 83b105b commit d4c9087
Show file tree
Hide file tree
Showing 10 changed files with 183 additions and 17 deletions.
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 @@ -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";
Expand Down Expand Up @@ -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,
},
],
Expand Down Expand Up @@ -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,
},
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -57,6 +58,8 @@ const options: SATPGatewayConfig = {
gatewayOpenAPIPort: 4010,
address: "http://localhost",
},
knexLocalConfig: knexClientConnection,
knexRemoteConfig: knexRemoteConnection1,
};

describe("GetStatus Endpoint and Functionality testing", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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);
Expand Down Expand Up @@ -106,6 +110,8 @@ describe("SATPGateway initialization", () => {
gatewayServerPort: 3010,
address: "https://localhost",
},
knexLocalConfig: knexClientConnection,
knexRemoteConfig: knexRemoteConnection1,
};
const gateway = await factory.create(options);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -179,6 +187,8 @@ describe("SATPGateway initialization", () => {
gatewayClientPort: 3015,
address: "https://localhost",
},
knexLocalConfig: knexClientConnection,
knexRemoteConfig: knexRemoteConnection1,
};

const gateway = await factory.create(options);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -260,6 +273,8 @@ describe("SATPGateway startup", () => {
gatewayClientPort: 3001,
address: "https://localhost",
},
knexLocalConfig: knexClientConnection,
knexRemoteConfig: knexRemoteConnection1,
};
const gateway = await factory.create(options);

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,17 @@ 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({
level: logLevel,
label: "BUNGEE - Hermes",
});

let knexInstanceClient: Knex;
let knexInstanceRemote1: Knex;
let fabricEnv: FabricTestEnvironment;
let besuEnv: BesuTestEnvironment;
let gateway: SATPGateway;
Expand All @@ -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();

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();

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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();

Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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);
Expand Down
Loading

0 comments on commit d4c9087

Please sign in to comment.