Skip to content

Commit

Permalink
test(connector-corda): fix flow-database-access-v4-8 test case
Browse files Browse the repository at this point in the history
Primary Change:
---------------

1. The test case was broken due to a number of different issues related
to the AIO image build an also the connector image build, but on top of
those problems it also had misconfiguration issues where the port number
wasn't set to what it should be for the RPC connection that the connector
container uses to establish communications with the AIO ledger image.

Secondary Change(s):
---------------------
1. Fixed 2 bugs in the test tooling package where the port configuration
was not randomizing the exposed ports of the corda connector container and
the corda test ledger leading to accessibility issues.
2. Also introduced a createJvmInt(...) utility function on the corda connector
package which allows the flowdb test case to construct the flow invocation
requests with much less manual labor (manual coding).

In order to properly verify that this test case is working, a few other
pull requests have to be merged first and container images from those
sources published as well.

In addition to the pull request dependencies we also depend on a permission
issue being resolved in the larger GitHub organization itself as well:
hyperledger/governance#299

Depends on #3386
Depends on #3387

Signed-off-by: Peter Somogyvari <[email protected]>
  • Loading branch information
petermetz committed Jul 9, 2024
1 parent 1994128 commit 224ae98
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 54 deletions.
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,12 +5,9 @@ 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,
Expand All @@ -21,6 +18,8 @@ import {
JvmTypeKind,

Check failure on line 18 in packages/cactus-plugin-ledger-connector-corda/src/test/typescript/integration/flow-database-access-v4.8.test.ts

View workflow job for this annotation

GitHub Actions / yarn_lint

'JvmTypeKind' is defined but never used
} 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 +37,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 +48,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 +57,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 +72,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 +99,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 +111,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 +151,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 +168,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 +193,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

0 comments on commit 224ae98

Please sign in to comment.