Skip to content

Commit

Permalink
Fix/loop nodes accounts (#1493)
Browse files Browse the repository at this point in the history
* fix loop when we set same proxies of one node id

Signed-off-by: ochikov <[email protected]>

* integration tests fix

Signed-off-by: ochikov <[email protected]>

* refactor tests

Signed-off-by: ochikov <[email protected]>

* refactor tests

Signed-off-by: ochikov <[email protected]>

---------

Signed-off-by: ochikov <[email protected]>
  • Loading branch information
ochikov authored Mar 10, 2023
1 parent 697a2ee commit 434b659
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/client/ManagedNetwork.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ export default class ManagedNetwork {
/** @type {NetworkNodeT[]} */
const nodes = [];
const keys = new Set();
const nodeAddresses = new Set();

// `this.getNode()` uses `Math.random()` internally to fetch
// nodes, this means _techically_ `this.getNode()` can return
Expand All @@ -290,8 +291,12 @@ export default class ManagedNetwork {

// Get a random node
let node = this.getNode();
if (!keys.has(node.getKey())) {
if (
!keys.has(node.getKey()) ||
!nodeAddresses.has(node.address._address)
) {
keys.add(node.getKey());
nodeAddresses.add(node.address._address);
nodes.push(node);
} else {
i--;
Expand Down
15 changes: 14 additions & 1 deletion test/integration/ClientIntegrationTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,11 @@ describe("ClientIntegration", function () {
});

it("can set network name on custom network", async function () {
this.timeout(120000);
expect(clientTestnet.ledgerId).to.be.equal(LedgerId.TESTNET);
expect(clientPreviewNet.ledgerId).to.be.equal(LedgerId.PREVIEWNET);

clientTestnet.setNetwork(clientPreviewNet.network);
await clientTestnet.setNetwork(clientPreviewNet.network);

expect(clientTestnet.ledgerId).to.be.null;

Expand All @@ -152,6 +153,18 @@ describe("ClientIntegration", function () {
expect(clientTestnet.ledgerId).to.be.equal(LedgerId.PREVIEWNET);
});

it("can use same proxies of one node", async function () {
let nodes = {
"0.testnet.hedera.com:50211": new AccountId(3),
"34.94.106.61:50211": new AccountId(3),
"50.18.132.211:50211": new AccountId(3),
"138.91.142.219:50211": new AccountId(3),
};

const clientForNetwork = Client.forNetwork(nodes);
await clientForNetwork.pingAll();
});

after(async function () {
await env.close();
clientTestnet.close();
Expand Down

0 comments on commit 434b659

Please sign in to comment.