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 6, 2024
1 parent ad241ba commit 223f8f0
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 10 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,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 @@ -121,12 +138,18 @@ describe("SATPGateway sending a token from Besu to Fabric", () => {
proofID: "mockProofID10",
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 @@ -40,13 +40,25 @@ 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({
level: logLevel,
label: "BUNGEE - Hermes",
});

let knexInstanceClient: Knex;
let knexInstanceRemote1: Knex;
let knexInstanceRemote2: Knex;
let knexInstanceServer: Knex;

let fabricEnv: FabricTestEnvironment;
let besuEnv: BesuTestEnvironment;
let gateway1: SATPGateway;
Expand All @@ -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;
});
});

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

0 comments on commit 223f8f0

Please sign in to comment.