Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(connector-corda): fix flow-database-access-v4-8 test case #3388

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/cactus-plugin-ledger-connector-corda/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,11 @@ full name of the container image otherwise referred to as `cactus-corda-connecto
From the project root:

```sh
DOCKER_BUILDKIT=1 docker build ./packages/cactus-plugin-ledger-connector-corda/src/main-server/ -t cccs
DOCKER_BUILDKIT=1 docker build \
./packages/cactus-plugin-ledger-connector-corda/src/main-server/ \
--progress=plain \
--tag cccs \
--tag "ghcr.io/hyperledger/cactus-connector-corda-server:$(date +%F)-$(git rev-parse --symbolic-full-name --abbrev-ref HEAD)-$(git rev-parse --short HEAD)"
```

## Scan The Locally Built Container Image for Vulnerabilities with Trivy
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { JvmObject } from "../../../generated/openapi/typescript-axios/api";
import { JvmTypeKind } from "../../../generated/openapi/typescript-axios/api";

export function createJvmInt(data: number): JvmObject {
return {
jvmTypeKind: JvmTypeKind.Primitive,
jvmType: {
fqClassName: "java.lang.Integer",
},
primitiveValue: data,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export {
createJvmCordaX500Name,
} from "./jvm/serde/factory/create-jvm-corda-x500-name";

export { createJvmInt } from "./jvm/serde/factory/create-jvm-int";
export { createJvmLong } from "./jvm/serde/factory/create-jvm-long";
export { createJvmCurrency } from "./jvm/serde/factory/create-jvm-currency";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,20 @@ import {
Containers,
CordaTestLedger,
pruneDockerAllIfGithubAction,
} from "@hyperledger/cactus-test-tooling";
import { LogLevelDesc } from "@hyperledger/cactus-common";
import {
SampleCordappEnum,
CordaConnectorContainer,
} from "@hyperledger/cactus-test-tooling";
import { LogLevelDesc } from "@hyperledger/cactus-common";

import {
CordappDeploymentConfig,
DefaultApi as CordaApi,
DeployContractJarsV1Request,
FlowInvocationType,
InvokeContractV1Request,
JvmTypeKind,
} from "../../../main/typescript/generated/openapi/typescript-axios/index";
import { Configuration } from "@hyperledger/cactus-core-api";
import { createJvmString } from "../../../main/typescript/jvm/serde/factory/create-jvm-string";
import { createJvmInt } from "../../../main/typescript";

const testCase = "Tests are passing on the JVM side";
const logLevel: LogLevelDesc = "TRACE";
Expand All @@ -38,8 +36,9 @@ test("BEFORE " + testCase, async (t: Test) => {
test(testCase, async (t: Test) => {
const ledger = new CordaTestLedger({
imageName: "ghcr.io/hyperledger/cactus-corda-4-8-all-in-one-flowdb",
imageVersion: "2021-11-23--feat-1493",
imageVersion: "2024-07-08-hotfix-1",
logLevel,
rpcPortA: 10006, // @see: ./tools/docker/corda-all-in-one/corda-v4_8-flowdb/build.gradle
});
t.ok(ledger, "CordaTestLedger v4.8 instantaited OK");

Expand All @@ -48,7 +47,7 @@ test(testCase, async (t: Test) => {
await ledger.destroy();
await pruneDockerAllIfGithubAction({ logLevel });
});
const ledgerContainer = await ledger.start();
const ledgerContainer = await ledger.start(false);
t.ok(
ledgerContainer,
"CordaTestLedger v4.8 container truthy post-start() OK",
Expand All @@ -57,7 +56,13 @@ test(testCase, async (t: Test) => {
await ledger.logDebugPorts();
const partyARpcPort = await ledger.getRpcAPublicPort();

const jarFiles = await ledger.pullCordappJars(SampleCordappEnum.BASIC_FLOW);
// We cannot import SampleCordappEnum here because it causes a circular
// import cycle which means that the import statement does compile but will
// yield undefinedat runtime and the test will crash on this line.
// So, instead of importing the enum, we just hardcode a magic string which is
// the exact opposite of what we should be doing but until we figure out the
// circular imports problem it's an acceptable workaround.
const jarFiles = await ledger.pullCordappJars("BASIC_FLOW" as never);
t.comment(`Fetched ${jarFiles.length} cordapp jars OK`);

const internalIpOrUndefined = await internalIpV4();
Expand All @@ -66,13 +71,14 @@ test(testCase, async (t: Test) => {
t.comment(`Internal IP (based on default gateway): ${internalIp}`);

const partyARpcUsername = "user1";
const partyARpcPassword = "password";
const partyARpcPassword = "test";
const springAppConfig = {
logging: {
level: {
root: "INFO",
"net.corda": "INFO",
"org.hyperledger.cactus": "DEBUG",
"org.hyperledger.cacti": "DEBUG",
},
},
cactus: {
Expand All @@ -92,8 +98,6 @@ test(testCase, async (t: Test) => {

const connector = new CordaConnectorContainer({
logLevel,
imageName: "ghcr.io/hyperledger/cactus-connector-corda-server",
imageVersion: "2021-11-23--feat-1493",
envVars: [envVarSpringAppJson],
});
t.ok(CordaConnectorContainer, "CordaConnectorContainer instantiated OK");
Expand All @@ -106,7 +110,7 @@ test(testCase, async (t: Test) => {
}
});

const connectorContainer = await connector.start();
const connectorContainer = await connector.start(false);
t.ok(connectorContainer, "CordaConnectorContainer started OK");

await connector.logDebugPorts();
Expand Down Expand Up @@ -146,22 +150,12 @@ test(testCase, async (t: Test) => {
flowFullClassName: "net.corda.samples.flowdb.AddTokenValueFlow",
flowInvocationType: FlowInvocationType.FlowDynamic,
params: [
{
jvmTypeKind: JvmTypeKind.Primitive,
jvmType: {
fqClassName: "java.lang.String",
},
primitiveValue: myToken,
},
{
jvmTypeKind: JvmTypeKind.Primitive,
jvmType: {
fqClassName: "java.lang.Integer",
},
primitiveValue: initialValue,
},
createJvmString({
data: myToken,
}),
createJvmInt(initialValue),
],
} as unknown as InvokeContractV1Request;
};

const resAdd = await apiClient.invokeContractV1(reqAdd);
t.ok(resAdd, "InvokeContractV1Request truthy OK");
Expand All @@ -173,15 +167,11 @@ test(testCase, async (t: Test) => {
flowFullClassName: "net.corda.samples.flowdb.QueryTokenValueFlow",
flowInvocationType: FlowInvocationType.FlowDynamic,
params: [
{
jvmTypeKind: JvmTypeKind.Primitive,
jvmType: {
fqClassName: "java.lang.String",
},
primitiveValue: myToken,
},
createJvmString({
data: myToken,
}),
],
} as unknown as InvokeContractV1Request;
};

const resQuery = await apiClient.invokeContractV1(reqQuery);
t.ok(resQuery, "InvokeContractV1Request truthy OK");
Expand All @@ -202,22 +192,12 @@ test(testCase, async (t: Test) => {
flowFullClassName: "net.corda.samples.flowdb.UpdateTokenValueFlow",
flowInvocationType: FlowInvocationType.FlowDynamic,
params: [
{
jvmTypeKind: JvmTypeKind.Primitive,
jvmType: {
fqClassName: "java.lang.String",
},
primitiveValue: myToken,
},
{
jvmTypeKind: JvmTypeKind.Primitive,
jvmType: {
fqClassName: "java.lang.Integer",
},
primitiveValue: finalValue,
},
createJvmString({
data: myToken,
}),
createJvmInt(finalValue),
],
} as unknown as InvokeContractV1Request;
};

const resUpd = await apiClient.invokeContractV1(reqUpd);
t.ok(resUpd, "InvokeContractV1Request truthy OK");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import { Containers } from "../common/containers";
* Provides default options for Corda connector server
*/
const DEFAULTS = Object.freeze({
imageVersion: "2021-03-01-7e07b5b",
imageName: "petermetz/cactus-connector-corda-server",
imageVersion:
"2024-07-09-test-connector-corda-fix-flow-database-access-v4-8-37919dc84",
imageName: "ghcr.io/hyperledger/cactus-connector-corda-server",
apiPort: 8080,
envVars: [],
});
Expand Down Expand Up @@ -120,7 +121,9 @@ export class CordaConnectorContainer {
[`${this.apiPort}/tcp`]: {}, // REST API HTTP port
[`9001/tcp`]: {}, // SupervisorD Web UI
},
PublishAllPorts: true,
HostConfig: {
PublishAllPorts: true,
},
Env: this.envVars,
},
{},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ export class CordaTestLedger implements ITestLedger {
[`${this.rpcPortC}/tcp`]: {}, // corda PartyC RPC
"22/tcp": {}, // ssh server
},
PublishAllPorts: true,
HostConfig: {
PublishAllPorts: true,
},
// TODO: this can be removed once the new docker image is published and
// specified as the default one to be used by the tests.
// Healthcheck: {
Expand Down
Loading