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

Fix/loop nodes accounts #1493

Merged
merged 4 commits into from
Mar 10, 2023
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
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