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

New web proxy for nodeAccountId 3 #2051

Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions src/constants/ClientConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import AccountId from "../account/AccountId.js";
// MAINNET node proxies are the same for both 'WebClient' and 'NativeClient'
export const MAINNET = {
"https://grpc-web.myhbarwallet.com:443": new AccountId(3),
"https://node00.swirldslabs.com:443": new AccountId(3),
"https://node01-00-grpc.swirlds.com:443": new AccountId(4),
"https://node02.swirldslabs.com:443": new AccountId(5),
"https://node03.swirldslabs.com:443": new AccountId(6),
Expand Down
97 changes: 97 additions & 0 deletions test/integration/ClientConstantsIntegrationTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/* eslint-disable mocha/no-setup-in-describe */
import {
MAINNET,
WEB_TESTNET,
WEB_PREVIEWNET,
NATIVE_PREVIEWNET,
NATIVE_TESTNET,
} from "../../src/constants/ClientConstants.js";
import {
AccountBalance,
AccountBalanceQuery,
Hbar,
} from "../../src/exports.js";
import IntegrationTestEnv from "./client/NodeIntegrationTestEnv.js";

describe("ClientConstantsIntegrationTest", function () {
let env;

before(async function () {
env = await IntegrationTestEnv.new();
});

describe("MAINNET node proxies", function () {
const proxies = Object.keys(MAINNET);
proxies.forEach((proxy) => {
it(`should fetch ${MAINNET[proxy]} account balnace`, async function () {
const accountBalance = await new AccountBalanceQuery()
.setNodeAccountIds([MAINNET[proxy]])
.setAccountId(env.operatorId)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should use a known account like 0.0.3 for checking the balance as we might run into some problems if the operator account id doesn't exist on all networks

.execute(env.client);

expect(accountBalance instanceof AccountBalance).to.be.true;
expect(accountBalance.hbars instanceof Hbar).to.be.true;
});
});
});

describe("WEB TESTNET node proxies", function () {
const proxies = Object.keys(WEB_TESTNET);
proxies.forEach((proxy) => {
it(`should fetch ${WEB_TESTNET[proxy]} account balnace`, async function () {
const accountBalance = await new AccountBalanceQuery()
.setNodeAccountIds([WEB_TESTNET[proxy]])
.setAccountId(env.operatorId)
.execute(env.client);

expect(accountBalance instanceof AccountBalance).to.be.true;
expect(accountBalance.hbars instanceof Hbar).to.be.true;
});
});
});

describe("WEB PREVIEWNET node proxies", function () {
const proxies = Object.keys(WEB_PREVIEWNET);
proxies.forEach((proxy) => {
it(`should fetch ${WEB_PREVIEWNET[proxy]} account balnace`, async function () {
const accountBalance = await new AccountBalanceQuery()
.setNodeAccountIds([WEB_PREVIEWNET[proxy]])
.setAccountId(env.operatorId)
.execute(env.client);

expect(accountBalance instanceof AccountBalance).to.be.true;
expect(accountBalance.hbars instanceof Hbar).to.be.true;
});
});
});

describe("NATIVE PREVIEWNET node proxies", function () {
const proxies = Object.keys(NATIVE_PREVIEWNET);
proxies.forEach((proxy) => {
it(`should fetch ${NATIVE_PREVIEWNET[proxy]} account balnace`, async function () {
const accountBalance = await new AccountBalanceQuery()
.setNodeAccountIds([NATIVE_PREVIEWNET[proxy]])
.setAccountId(env.operatorId)
.execute(env.client);

expect(accountBalance instanceof AccountBalance).to.be.true;
expect(accountBalance.hbars instanceof Hbar).to.be.true;
});
});
});

describe("NATIVE TESTNET node proxies", function () {
const proxies = Object.keys(NATIVE_TESTNET);
proxies.forEach((proxy) => {
it(`should fetch ${NATIVE_TESTNET[proxy]} account balnace`, async function () {
const accountBalance = await new AccountBalanceQuery()
.setNodeAccountIds([NATIVE_TESTNET[proxy]])
.setAccountId(env.operatorId)
.execute(env.client);

expect(accountBalance instanceof AccountBalance).to.be.true;
expect(accountBalance.hbars instanceof Hbar).to.be.true;
});
});
});
});
4 changes: 4 additions & 0 deletions test/integration/ClientIntegrationTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ describe("ClientIntegration", function () {
await clientForNetwork.pingAll();
});

it("should return a boolean for client transport security", function () {
expect(clientTestnet.isTransportSecurity()).to.be.an("boolean");
});

after(async function () {
await env.close();
clientTestnet.close();
Expand Down
13 changes: 13 additions & 0 deletions test/integration/WalletIntegrationTest.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { expect } from "chai";
import {
AccountCreateTransaction,
Hbar,
Expand All @@ -8,6 +9,18 @@ import { Wallet, LocalProvider } from "../../src/index.js";
import IntegrationTestEnv from "./client/NodeIntegrationTestEnv.js";

describe("WalletIntegration", function () {
it("should create a wallet (ECDSA)", async function () {
const wallet = await Wallet.createRandomECDSA();
expect(wallet.getAccountKey()).to.not.equal(null);
expect(wallet.getAccountId()).to.not.equal(null);
});

it("should create a wallet (ED25519)", async function () {
const wallet = await Wallet.createRandomED25519();
expect(wallet.getAccountKey()).to.not.equal(null);
expect(wallet.getAccountId()).to.not.equal(null);
});

it("issue-1530", async function () {
this.timeout(30000);
const env = await IntegrationTestEnv.new();
Expand Down
40 changes: 36 additions & 4 deletions test/unit/EcdsaPrivateKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ import * as bip32 from "../../packages/cryptography/src/primitive/bip32.js";

const RAW_KEY =
"8776c6b831a1b61ac10dac0304a2843de4716f54b1919bb91a2685d0fe3f3048";
const DER_PRIVATE_KEY =
"3030020100300706052b8104000a04220420e06ecd79f00124bfc030b0321006683a6a579be7602f2eb52ca73e2901880682";
const DER_PRIVATE_KEY_BYTES = new Uint8Array([
48, 48, 2, 1, 0, 48, 7, 6, 5, 43, 129, 4, 0, 10, 4, 34, 4, 32, 224, 110,
205, 121, 240, 1, 36, 191, 192, 48, 176, 50, 16, 6, 104, 58, 106, 87, 155,
231, 96, 47, 46, 181, 44, 167, 62, 41, 1, 136, 6, 130,
]);
const DER_PUBLIC_KEY =
"302d300706052b8104000a032200033697a2b3f9f0b9f4831b39986f7f3885636a3e8622a0bc3814a4a56f7ecdc4f1";

describe("EcdsaPrivateKey", function () {
it("generate should return object", function () {
Expand All @@ -23,10 +32,6 @@ describe("EcdsaPrivateKey", function () {
});

it("should return a public key from a der private key", function () {
const DER_PRIVATE_KEY =
"3030020100300706052b8104000a04220420e06ecd79f00124bfc030b0321006683a6a579be7602f2eb52ca73e2901880682";
const DER_PUBLIC_KEY =
"302d300706052b8104000a032200033697a2b3f9f0b9f4831b39986f7f3885636a3e8622a0bc3814a4a56f7ecdc4f1";
const publicKey =
PrivateKey.fromStringDer(DER_PRIVATE_KEY).publicKey.toStringDer();
expect(publicKey).to.be.equal(DER_PUBLIC_KEY);
Expand Down Expand Up @@ -352,4 +357,31 @@ describe("EcdsaPrivateKey", function () {
PUBLIC_KEY4
);
});

it("should return private key from bytes", async function () {
const privateKeyFromBytes = PrivateKey.fromBytesECDSA(
DER_PRIVATE_KEY_BYTES
);
const publicKeyDer = privateKeyFromBytes.toStringDer();
expect(publicKeyDer).to.be.equal(DER_PRIVATE_KEY);
});

it("should return a constructed aliasKey accountId", async function () {
const privateKey = PrivateKey.generateECDSA();
const publicKey = privateKey.publicKey;

console.log(privateKey.type);

const aliasAccountId = publicKey.toAccountId(0, 0);

expect(aliasAccountId.toString()).to.be.equal(
`0.0.${publicKey.toString()}`
);
});

it("should return type of the private key", async function () {
const privateKey = PrivateKey.generateECDSA();

expect(privateKey.type).to.be.string("secp256k1");
});
});
38 changes: 34 additions & 4 deletions test/unit/Ed25519PrivateKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ import * as hex from "../../src/encoding/hex.js";

const RAW_KEY =
"302e020100300506032b657004220420a7bd8982bb05415bbc1e2dc2ae6aced66cba5eb871a4afd1579f8620b8c00d37";
// ED25519 key
const DER_PRIVATE_KEY =
"302e020100300506032b6570042204203a056f85d71921be62466f5e93a4af0aa2e09a9eb4b2d839e06d805366659a74";
const DER_PRIVATE_KEY_BYTES = new Uint8Array([
58, 5, 111, 133, 215, 25, 33, 190, 98, 70, 111, 94, 147, 164, 175, 10, 162,
224, 154, 158, 180, 178, 216, 57, 224, 109, 128, 83, 102, 101, 154, 116,
]);
const DER_PUBLIC_KEY =
"302a300506032b65700321004a6892f034d2d1c9b1a76acca8e34884055172f4210a0c02e3c7d55084f224d1";

describe("Ed25519PrivateKey", function () {
it("generate should return object", function () {
Expand All @@ -22,10 +31,6 @@ describe("Ed25519PrivateKey", function () {
});

it("should return a public key from a der private key", function () {
const DER_PRIVATE_KEY =
"302e020100300506032b6570042204203a056f85d71921be62466f5e93a4af0aa2e09a9eb4b2d839e06d805366659a74";
const DER_PUBLIC_KEY =
"302a300506032b65700321004a6892f034d2d1c9b1a76acca8e34884055172f4210a0c02e3c7d55084f224d1";
const publicKey =
PrivateKey.fromStringDer(DER_PRIVATE_KEY).publicKey.toStringDer();
expect(publicKey).to.be.equal(DER_PUBLIC_KEY);
Expand Down Expand Up @@ -269,4 +274,29 @@ describe("Ed25519PrivateKey", function () {
PUBLIC_KEY1
);
});

it("should return private key from bytes", async function () {
const privateKeyFromBytes = PrivateKey.fromBytesED25519(
DER_PRIVATE_KEY_BYTES
);
const publicKeyDer = privateKeyFromBytes.toStringDer();
expect(publicKeyDer).to.be.equal(DER_PRIVATE_KEY);
});

it("should return a constructed aliasKey accountId", async function () {
const privateKey = PrivateKey.generateED25519();
const publicKey = privateKey.publicKey;

const aliasAccountId = publicKey.toAccountId(0, 0);

expect(aliasAccountId.toString()).to.be.equal(
`0.0.${publicKey.toString()}`
);
});

it("should return type of the private key", async function () {
const privateKey = PrivateKey.generateED25519();

expect(privateKey.type).to.be.string("ED25519");
});
});