Skip to content

Commit 2705f2d

Browse files
fix: dab tests
Signed-off-by: venilinvasilev <[email protected]>
1 parent fca0fed commit 2705f2d

File tree

10 files changed

+94
-33
lines changed

10 files changed

+94
-33
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ jobs:
224224
225225
- name: Run DAB Integration Tests
226226
if: ${{ steps.build-sdk.conclusion == 'success' && !cancelled() && always() }}
227-
run: npx vitest --coverage --poolOptions.threads.singleThread --config=test/vitest-node-integration-dual-mode.config.ts NodeUpdateIntegrationTest.js
227+
run: task test:integration:dual-mode
228228

229229
examples:
230230
name: Run examples using Node ${{ matrix.node }}

Taskfile.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,12 @@ tasks:
168168
cmds:
169169
- npx vitest --coverage --config=test/vitest-node-integration.config.ts
170170
- npx vitest --coverage --config=test/vitest-browser-integration.config.ts
171+
172+
"test:integration:dual-mode":
173+
cmds:
174+
- npx vitest --poolOptions.threads.singleThread --config=test/vitest-node-integration-dual-mode.config.ts
175+
- npx vitest --poolOptions.threads.singleThread --config=test/vitest-browser-integration-dual-mode.config.ts
176+
171177
"update:proto":
172178
deps:
173179
- "proto:update"

src/Executable.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,15 @@ export default class Executable {
815815
// Initiate addressbook query and update the client's network
816816
// This will make the SDK client have the latest node account IDs for subsequent transactions
817817
try {
818-
await client.updateNetwork();
818+
if (client.mirrorNetwork.length > 0) {
819+
await client.updateNetwork();
820+
} else {
821+
if (this._logger) {
822+
this._logger.warn(
823+
"Cannot update address book: no mirror network configured. Retrying with existing network configuration.",
824+
);
825+
}
826+
}
819827
} catch (error) {
820828
if (this._logger) {
821829
const errorMessage =

src/channel/WebChannel.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ export default class WebChannel extends Channel {
5050
*/
5151
_shouldUseHttps(address) {
5252
return !(
53-
address.includes("localhost") || address.includes("127.0.0.1")
53+
address.includes("localhost") ||
54+
address.includes("127.0.0.1") ||
55+
address.includes(".cluster.local")
5456
);
5557
}
5658

src/client/Network.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ export default class Network extends ManagedNetwork {
284284
if (this._maxNodesPerTransaction > 0) {
285285
return this._maxNodesPerTransaction;
286286
}
287-
return this._healthyNodes.length;
287+
return this._nodes.length;
288288
}
289289

290290
/**
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const node2Address = "network-node2-svc.solo.svc.cluster.local:50211";
2+
const node2PortToReplace = 51211;
3+
const network = {
4+
"127.0.0.1:50211": "0.0.3",
5+
"127.0.0.1:51211": "0.0.4",
6+
};
7+
8+
const mirrorNetwork = ["localhost:5600"];
9+
10+
export { network, mirrorNetwork, node2Address, node2PortToReplace };

test/integration/dual-mode/NodeUpdateIntegrationTest.js

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,35 @@ import {
1111
ServiceEndpoint,
1212
} from "../../../src/exports.js";
1313
import { Client } from "../../../src/index.js";
14-
15-
describe("Node Update Integration Network Tests", function () {
14+
import {
15+
mirrorNetwork,
16+
node2Address,
17+
node2PortToReplace,
18+
network,
19+
} from "./NodeConstants.js";
20+
21+
const restoreOriginalGrpcWebProxyEndpoint = async (client) => {
22+
const response = await new NodeUpdateTransaction()
23+
.setNodeId(1)
24+
.setNodeAccountIds([AccountId.fromString("0.0.3")])
25+
.setGrpcWebProxyEndpoint(
26+
new ServiceEndpoint()
27+
.setDomainName("envoy-proxy-node2-svc.solo.svc.cluster.local")
28+
.setPort(8080),
29+
)
30+
.execute(client);
31+
const receipt = await response.getReceipt(client);
32+
expect(receipt.status).to.equal(Status.Success);
33+
};
34+
35+
describe("Node Update Integration Tests", function () {
1636
let client;
1737
let operatorAccountId;
1838
let operatorKey;
1939

2040
beforeEach(function () {
2141
// Initialize client with integration network
22-
client = Client.forNetwork({
23-
"127.0.0.1:50211": "0.0.3",
24-
"127.0.0.1:51211": "0.0.4",
25-
}).setMirrorNetwork(["localhost:5600"]);
42+
client = Client.forNetwork(network).setMirrorNetwork(mirrorNetwork);
2643

2744
// Set the operator to be account 0.0.2
2845
operatorAccountId = AccountId.fromString("0.0.2");
@@ -41,8 +58,8 @@ describe("Node Update Integration Network Tests", function () {
4158

4259
it("should execute node update transaction", async function () {
4360
const response = await new NodeUpdateTransaction()
44-
.setNodeId(0)
45-
.setNodeAccountIds([AccountId.fromString("0.0.4")])
61+
.setNodeId(1)
62+
.setNodeAccountIds([AccountId.fromString("0.0.3")])
4663
.setDescription("testUpdated")
4764
.setDeclineReward(true)
4865
.setGrpcWebProxyEndpoint(
@@ -58,18 +75,23 @@ describe("Node Update Integration Network Tests", function () {
5875

5976
it("should delete grpc web proxy endpoint", async function () {
6077
const response = await new NodeUpdateTransaction()
61-
.setNodeId(0)
78+
.setNodeId(1)
79+
.setNodeAccountIds([AccountId.fromString("0.0.3")])
6280
.deleteGrpcWebProxyEndpoint()
6381
.execute(client);
6482

6583
const receipt = await response.getReceipt(client);
6684
expect(receipt.status).to.equal(Status.Success);
85+
86+
// Restore the original grpc web proxy endpoint
87+
await restoreOriginalGrpcWebProxyEndpoint(client);
6788
});
6889

6990
it("should change node account ID and revert back", async function () {
7091
// Change node account ID from 0.0.3 to 0.0.2
7192
const response1 = await new NodeUpdateTransaction()
7293
.setNodeId(0)
94+
.setNodeAccountIds([AccountId.fromString("0.0.4")])
7395
.setAccountId(AccountId.fromString("0.0.2"))
7496
.execute(client);
7597

@@ -79,6 +101,7 @@ describe("Node Update Integration Network Tests", function () {
79101
// Revert the ID back to 0.0.3
80102
const response2 = await new NodeUpdateTransaction()
81103
.setNodeId(0)
104+
.setNodeAccountIds([AccountId.fromString("0.0.4")])
82105
.setAccountId(AccountId.fromString("0.0.3"))
83106
.execute(client);
84107

@@ -115,10 +138,11 @@ describe("Node Update Integration Network Tests", function () {
115138
});
116139

117140
it("should change node account ID to the same account", async function () {
141+
console.log(client.network);
118142
const response = await new NodeUpdateTransaction()
119-
.setNodeId(0)
120-
.setNodeAccountIds([AccountId.fromString("0.0.4")])
121-
.setAccountId(AccountId.fromString("0.0.3"))
143+
.setNodeId(1)
144+
.setNodeAccountIds([AccountId.fromString("0.0.3")])
145+
.setAccountId(AccountId.fromString("0.0.4"))
122146
.execute(client);
123147

124148
const receipt = await response.getReceipt(client);
@@ -271,7 +295,7 @@ describe("Node Update Integration Network Tests", function () {
271295
AccountId.fromString("0.0.3"),
272296
])
273297
.execute(client);
274-
298+
console.log("tuka se ebava v maikata");
275299
const testReceipt = await testResp.getReceipt(client);
276300
expect(testReceipt.status).to.equal(Status.Success);
277301
// Verify address book has been updated
@@ -288,21 +312,19 @@ describe("Node Update Integration Network Tests", function () {
288312
)?.[0];
289313

290314
// Assert the address matches the expected value
291-
expect(newNodeAddress).to.equal(
292-
"network-node2-svc.solo.svc.cluster.local:50211",
293-
);
315+
expect(newNodeAddress).to.equal(node2Address);
294316

295317
// This is not an ideal workaround - reconstruct the network state
296318
// because the mirror node returns a different address than expected
297-
if (
298-
newNodeAddress === "network-node2-svc.solo.svc.cluster.local:50211"
299-
) {
319+
if (newNodeAddress === node2Address) {
300320
const oldNetworkState = { ...network };
301321
delete oldNetworkState[newNodeAddress];
302322
const newNetworkState = {
303323
...oldNetworkState,
304-
"network-node2-svc.solo.svc.cluster.local:51211":
305-
newNodeAccountID,
324+
[node2Address.replace(
325+
node2Address.split(":")[1],
326+
node2PortToReplace,
327+
)]: newNodeAccountID,
306328
};
307329
client.setNetwork(newNetworkState);
308330
}
@@ -328,10 +350,7 @@ describe("Node Update Integration Network Tests", function () {
328350

329351
it("should handle node account ID change without mirror node setup", async function () {
330352
// Create a client without mirror network
331-
const networkClient = Client.forNetwork({
332-
"127.0.0.1:50211": "0.0.3",
333-
"127.0.0.1:51211": "0.0.4",
334-
});
353+
const networkClient = Client.forNetwork(network);
335354

336355
networkClient.setOperator(operatorAccountId, operatorKey);
337356

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const node2Address = "envoy-proxy-node2-svc.solo.svc.cluster.local:8080";
2+
const node2PortToReplace = 8081;
3+
const network = {
4+
"localhost:8080": "0.0.3",
5+
"localhost:8081": "0.0.4",
6+
};
7+
8+
const mirrorNetwork = ["localhost:5551"];
9+
10+
export { network, mirrorNetwork, node2Address, node2PortToReplace };

test/vitest-browser-integration-dual-mode.config.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,15 @@ export default defineConfig({
2222
instances: [{ browser: "chromium" }],
2323
},
2424
include: ["test/integration/dual-mode/**/*.js"],
25+
exclude: [
26+
"test/integration/client/*",
27+
"test/integration/resources/*",
28+
"test/integration/utils/*",
29+
"test/integration/dual-mode/NodeConstants.js",
30+
"test/integration/dual-mode/WebConstants.js",
31+
],
2532
hookTimeout: 120000,
2633
testTimeout: 120000,
27-
maxWorkers: 4,
28-
minWorkers: 4,
2934
coverage: {
3035
include: ["src/**/*.js"],
3136
provider: "v8",
@@ -79,7 +84,7 @@ export default defineConfig({
7984
"../../src/LocalProvider.js": "../../src/LocalProviderWeb.js",
8085
"../src/LocalProvider.js": "../src/LocalProviderWeb.js",
8186
"src/LocalProvider.js": "src/LocalProviderWeb.js",
82-
87+
"./NodeConstants.js": "./WebConstants.js",
8388
// Add more comprehensive aliases for NodeIntegrationTestEnv
8489
"NodeIntegrationTestEnv.js": "WebIntegrationTestEnv.js",
8590
"./client/NodeIntegrationTestEnv": "./client/WebIntegrationTestEnv",

test/vitest-node-integration-dual-mode.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ const pkg = JSON.parse(
1010
/** @type {import("vitest").UserConfig} */
1111
export default defineConfig({
1212
test: {
13-
allowOnly: true,
1413
watch: false,
1514
globals: true,
1615
environment: "node",
@@ -19,6 +18,8 @@ export default defineConfig({
1918
"test/integration/client/*",
2019
"test/integration/resources/*",
2120
"test/integration/utils/*",
21+
"test/integration/dual-mode/NodeConstants.js",
22+
"test/integration/dual-mode/WebConstants.js",
2223
],
2324
hookTimeout: 120000,
2425
testTimeout: 120000,

0 commit comments

Comments
 (0)