-
Notifications
You must be signed in to change notification settings - Fork 272
/
deploy-cordapp-jars-to-nodes.test.ts
301 lines (275 loc) · 10 KB
/
deploy-cordapp-jars-to-nodes.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
import test, { Test } from "tape-promise/tape";
import { v4 as internalIpV4 } from "internal-ip";
import { CordaTestLedger } from "@hyperledger/cactus-test-tooling";
import { LogLevelDesc } from "@hyperledger/cactus-common";
import {
SampleCordappEnum,
CordaConnectorContainer,
} from "@hyperledger/cactus-test-tooling";
import {
CordappDeploymentConfig,
DefaultApi as CordaApi,
DeployContractJarsV1Request,
FlowInvocationType,
InvokeContractV1Request,
JvmTypeKind,
} from "../../../main/typescript/generated/openapi/typescript-axios/index";
const logLevel: LogLevelDesc = "TRACE";
test("Tests are passing on the JVM side", async (t: Test) => {
const ledger = new CordaTestLedger({
imageName: "hyperledger/cactus-corda-4-6-all-in-one-obligation",
imageVersion: "2021-03-19-feat-686",
// imageName: "caio",
// imageVersion: "latest",
logLevel,
});
t.ok(ledger, "CordaTestLedger instantaited OK");
test.onFinish(async () => {
await ledger.stop();
await ledger.destroy();
});
const ledgerContainer = await ledger.start();
t.ok(ledgerContainer, "CordaTestLedger container truthy post-start() OK");
const corDappsDirPartyA = await ledger.getCorDappsDirPartyA();
const corDappsDirPartyB = await ledger.getCorDappsDirPartyB();
t.comment(`corDappsDirPartyA=${corDappsDirPartyA}`);
t.comment(`corDappsDirPartyB=${corDappsDirPartyB}`);
await ledger.logDebugPorts();
const partyARpcPort = await ledger.getRpcAPublicPort();
const partyBRpcPort = await ledger.getRpcBPublicPort();
const jarFiles = await ledger.pullCordappJars(
SampleCordappEnum.BASIC_CORDAPP,
);
t.comment(`Fetched ${jarFiles.length} cordapp jars OK`);
const internalIpOrUndefined = await internalIpV4();
t.ok(internalIpOrUndefined, "Determined LAN IPv4 address successfully OK");
const internalIp = internalIpOrUndefined as string;
t.comment(`Internal IP (based on default gateway): ${internalIp}`);
// TODO: parse the gradle build files to extract the credentials?
const partyARpcUsername = "user1";
const partyARpcPassword = "password";
const partyBRpcUsername = partyARpcUsername;
const partyBRpcPassword = partyARpcPassword;
const springAppConfig = {
logging: {
level: {
root: "INFO",
"net.corda": "INFO",
"org.hyperledger.cactus": "DEBUG",
},
},
cactus: {
corda: {
node: { host: internalIp },
rpc: {
port: partyARpcPort,
username: partyARpcUsername,
password: partyARpcPassword,
},
},
},
};
const springApplicationJson = JSON.stringify(springAppConfig);
const envVarSpringAppJson = `SPRING_APPLICATION_JSON=${springApplicationJson}`;
t.comment(envVarSpringAppJson);
const connector = new CordaConnectorContainer({
logLevel,
imageName: "hyperledger/cactus-connector-corda-server",
imageVersion: "2021-03-25-feat-622",
// imageName: "cccs",
// imageVersion: "latest",
envVars: [envVarSpringAppJson],
});
t.ok(CordaConnectorContainer, "CordaConnectorContainer instantiated OK");
test.onFinish(async () => {
try {
await connector.stop();
} finally {
await connector.destroy();
}
});
const connectorContainer = await connector.start();
t.ok(connectorContainer, "CordaConnectorContainer started OK");
await connector.logDebugPorts();
const apiUrl = await connector.getApiLocalhostUrl();
const apiClient = new CordaApi({ basePath: apiUrl });
const flowsRes1 = await apiClient.listFlowsV1();
t.ok(flowsRes1.status === 200, "flowsRes1.status === 200 OK");
t.ok(flowsRes1.data, "flowsRes1.data truthy OK");
t.ok(flowsRes1.data.flowNames, "flowsRes1.data.flowNames truthy OK");
t.comment(`apiClient.listFlowsV1() => ${JSON.stringify(flowsRes1.data)}`);
const flowNamesPreDeploy = flowsRes1.data.flowNames;
const sshConfig = await ledger.getSshConfig();
const hostKeyEntry = "not-used-right-now-so-this-does-not-matter... ;-(";
const cdcA: CordappDeploymentConfig = {
cordappDir: corDappsDirPartyA,
cordaNodeStartCmd: "supervisorctl start corda-a",
cordaJarPath:
"/samples-kotlin/Advanced/obligation-cordapp/build/nodes/ParticipantA/corda.jar",
nodeBaseDirPath:
"/samples-kotlin/Advanced/obligation-cordapp/build/nodes/ParticipantA/",
rpcCredentials: {
hostname: internalIp,
port: partyARpcPort,
username: partyARpcUsername,
password: partyARpcPassword,
},
sshCredentials: {
hostKeyEntry,
hostname: internalIp,
password: "root",
port: sshConfig.port as number,
username: sshConfig.username as string,
},
};
const cdcB: CordappDeploymentConfig = {
cordappDir: corDappsDirPartyB,
cordaNodeStartCmd: "supervisorctl start corda-b",
cordaJarPath:
"/samples-kotlin/Advanced/obligation-cordapp/build/nodes/ParticipantB/corda.jar",
nodeBaseDirPath:
"/samples-kotlin/Advanced/obligation-cordapp/build/nodes/ParticipantB/",
rpcCredentials: {
hostname: internalIp,
port: partyBRpcPort,
username: partyBRpcUsername,
password: partyBRpcPassword,
},
sshCredentials: {
hostKeyEntry,
hostname: internalIp,
password: "root",
port: sshConfig.port as number,
username: sshConfig.username as string,
},
};
const cordappDeploymentConfigs: CordappDeploymentConfig[] = [cdcA, cdcB];
const depReq: DeployContractJarsV1Request = {
jarFiles,
cordappDeploymentConfigs,
};
const depRes = await apiClient.deployContractJarsV1(depReq);
t.ok(depRes, "Jar deployment response truthy OK");
t.equal(depRes.status, 200, "Jar deployment status code === 200 OK");
t.ok(depRes.data, "Jar deployment response body truthy OK");
t.ok(depRes.data.deployedJarFiles, "Jar deployment body deployedJarFiles OK");
t.equal(
depRes.data.deployedJarFiles.length,
jarFiles.length,
"Deployed jar file count equals count in request OK",
);
const flowsRes2 = await apiClient.listFlowsV1();
t.ok(flowsRes2.status === 200, "flowsRes2.status === 200 OK");
t.comment(`apiClient.listFlowsV1() => ${JSON.stringify(flowsRes2.data)}`);
t.ok(flowsRes2.data, "flowsRes2.data truthy OK");
t.ok(flowsRes2.data.flowNames, "flowsRes2.data.flowNames truthy OK");
const flowNamesPostDeploy = flowsRes2.data.flowNames;
t.notDeepLooseEqual(
flowNamesPostDeploy,
flowNamesPreDeploy,
"New flows detected post Cordapp Jar deployment OK",
);
// let's see if this makes a difference and if yes, then we know that the issue
// is a race condition for sure
// await new Promise((r) => setTimeout(r, 120000));
t.comment("Fetching network map for Corda network...");
const networkMapRes = await apiClient.networkMapV1();
t.ok(networkMapRes, "networkMapRes truthy OK");
t.ok(networkMapRes.status, "networkMapRes.status truthy OK");
t.ok(networkMapRes.data, "networkMapRes.data truthy OK");
t.true(Array.isArray(networkMapRes.data), "networkMapRes.data isArray OK");
t.true(networkMapRes.data.length > 0, "networkMapRes.data not empty OK");
// const partyA = networkMapRes.data.find((it) =>
// it.legalIdentities.some((it2) => it2.name.organisation === "ParticipantA"),
// );
// const partyAPublicKey = partyA?.legalIdentities[0].owningKey;
const partyB = networkMapRes.data.find((it) =>
it.legalIdentities.some((it2) => it2.name.organisation === "ParticipantB"),
);
const partyBPublicKey = partyB?.legalIdentities[0].owningKey;
const req: InvokeContractV1Request = ({
timeoutMs: 60000,
flowFullClassName: "net.corda.samples.example.flows.ExampleFlow$Initiator",
flowInvocationType: FlowInvocationType.FLOWDYNAMIC,
params: [
{
jvmTypeKind: JvmTypeKind.PRIMITIVE,
jvmType: {
fqClassName: "java.lang.Integer",
},
primitiveValue: 42,
},
{
jvmTypeKind: JvmTypeKind.REFERENCE,
jvmType: {
fqClassName: "net.corda.core.identity.Party",
},
jvmCtorArgs: [
{
jvmTypeKind: JvmTypeKind.REFERENCE,
jvmType: {
fqClassName: "net.corda.core.identity.CordaX500Name",
},
jvmCtorArgs: [
{
jvmTypeKind: JvmTypeKind.PRIMITIVE,
jvmType: {
fqClassName: "java.lang.String",
},
primitiveValue: "ParticipantB",
},
{
jvmTypeKind: JvmTypeKind.PRIMITIVE,
jvmType: {
fqClassName: "java.lang.String",
},
primitiveValue: "New York",
},
{
jvmTypeKind: JvmTypeKind.PRIMITIVE,
jvmType: {
fqClassName: "java.lang.String",
},
primitiveValue: "US",
},
],
},
{
jvmTypeKind: JvmTypeKind.REFERENCE,
jvmType: {
fqClassName:
"org.hyperledger.cactus.plugin.ledger.connector.corda.server.impl.PublicKeyImpl",
},
jvmCtorArgs: [
{
jvmTypeKind: JvmTypeKind.PRIMITIVE,
jvmType: {
fqClassName: "java.lang.String",
},
primitiveValue: partyBPublicKey?.algorithm,
},
{
jvmTypeKind: JvmTypeKind.PRIMITIVE,
jvmType: {
fqClassName: "java.lang.String",
},
primitiveValue: partyBPublicKey?.format,
},
{
jvmTypeKind: JvmTypeKind.PRIMITIVE,
jvmType: {
fqClassName: "java.lang.String",
},
primitiveValue: partyBPublicKey?.encoded,
},
],
},
],
},
],
} as unknown) as InvokeContractV1Request;
const res = await apiClient.invokeContractV1(req);
t.ok(res, "InvokeContractV1Request truthy OK");
t.equal(res.status, 200, "InvokeContractV1Request status code === 200 OK");
t.end();
});