From cd7779ad4c03b8404871eb332f1f6ccff93cd83c Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Fri, 10 May 2024 16:21:39 +0300 Subject: [PATCH 01/49] update: queries Signed-off-by: svetoslav-nikol0v --- src/Executable.js | 22 ++++ src/account/AccountBalanceQuery.js | 88 ++++++++++++- src/account/AccountInfoQuery.js | 85 +++++++++++-- src/contract/ContractInfoQuery.js | 81 ++++++++++-- src/exports.js | 2 + src/network/MirrorNodeGateway.js | 133 ++++++++++++++++++++ src/network/MirrorNodeRouter.js | 86 +++++++++++++ src/network/MirrorNodeService.js | 192 +++++++++++++++++++++++++++++ src/token/TokenFreezeStatus.js | 87 +++++++++++++ src/token/TokenKycStatus.js | 87 +++++++++++++ 10 files changed, 837 insertions(+), 26 deletions(-) create mode 100644 src/network/MirrorNodeGateway.js create mode 100644 src/network/MirrorNodeRouter.js create mode 100644 src/network/MirrorNodeService.js create mode 100644 src/token/TokenFreezeStatus.js create mode 100644 src/token/TokenKycStatus.js diff --git a/src/Executable.js b/src/Executable.js index 9d8140d64..c9da1140b 100644 --- a/src/Executable.js +++ b/src/Executable.js @@ -34,6 +34,7 @@ import HttpError from "./http/HttpError.js"; * @typedef {import("./Signer.js").Signer} Signer * @typedef {import("./PublicKey.js").default} PublicKey * @typedef {import("./logger/Logger.js").default} Logger + * @typedef {import("./LedgerId.js").default} LedgerId */ /** @@ -134,6 +135,20 @@ export default class Executable { * @type {Logger | null} */ this._logger = null; + + /** + * List of mirror network nodes with which execution will be attempted. + * @protected + * @type {string[]} + */ + this._mirrorNetwork = []; + + /** + * Current LedgerId of the network with which execution will be attempted. + * @protected + * @type {LedgerId | null} + */ + this._ledgerId = null; } /** @@ -511,6 +526,13 @@ export default class Executable { * @returns {Promise} */ async execute(client, requestTimeout) { + // Set list of mirror network nodes with + // which execution will be attempted + this._mirrorNetwork = client.mirrorNetwork; + // Set current LedgerId of the network with + // which execution will be attempted + this._ledgerId = client.ledgerId; + // If the logger on the request is not set, use the logger in client // (if set, otherwise do not use logger) this._logger = diff --git a/src/account/AccountBalanceQuery.js b/src/account/AccountBalanceQuery.js index 6b75557cd..0dd021e89 100644 --- a/src/account/AccountBalanceQuery.js +++ b/src/account/AccountBalanceQuery.js @@ -22,6 +22,8 @@ import Query, { QUERY_REGISTRY } from "../query/Query.js"; import AccountId from "./AccountId.js"; import ContractId from "../contract/ContractId.js"; import AccountBalance from "./AccountBalance.js"; +import MirrorNodeService from "../network/MirrorNodeService.js"; +import MirrorNodeGateway from "../network/MirrorNodeGateway.js"; /** * @namespace proto @@ -31,6 +33,7 @@ import AccountBalance from "./AccountBalance.js"; * @typedef {import("@hashgraph/proto").proto.IResponseHeader} HashgraphProto.proto.IResponseHeader * @typedef {import("@hashgraph/proto").proto.ICryptoGetAccountBalanceQuery} HashgraphProto.proto.ICryptoGetAccountBalanceQuery * @typedef {import("@hashgraph/proto").proto.ICryptoGetAccountBalanceResponse} HashgraphProto.proto.ICryptoGetAccountBalanceResponse + * @typedef {import("@hashgraph/proto").proto.ITokenBalance} HashgraphProto.proto.ITokenBalance */ /** @@ -69,6 +72,19 @@ export default class AccountBalanceQuery extends Query { */ this._contractId = null; + /** + * @type {?ContractId} + * @private + */ + this._contractId = null; + + /** + * @private + * @description Delay in ms if is necessary to wait for the mirror node to update the account balance + * @type {number} + */ + this._timeout = 0; + if (props.accountId != null) { this.setAccountId(props.accountId); } @@ -149,6 +165,16 @@ export default class AccountBalanceQuery extends Query { return this; } + /** + * + * @param {number} timeout + * @returns {this} + */ + setTimeout(timeout) { + this._timeout = timeout; + return this; + } + /** * @protected * @override @@ -210,13 +236,63 @@ export default class AccountBalanceQuery extends Query { */ // eslint-disable-next-line @typescript-eslint/no-unused-vars _mapResponse(response, nodeAccountId, request) { - const cryptogetAccountBalance = - /** @type {HashgraphProto.proto.ICryptoGetAccountBalanceResponse} */ ( - response.cryptogetAccountBalance + return new Promise((resolve, reject) => { + const mirrorNodeGateway = MirrorNodeGateway.forNetwork( + this._mirrorNetwork, + this._ledgerId, ); - return Promise.resolve( - AccountBalance._fromProtobuf(cryptogetAccountBalance), - ); + const mirrorNodeService = new MirrorNodeService(mirrorNodeGateway); + + const cryptogetAccountBalance = + /** @type {HashgraphProto.proto.ICryptoGetAccountBalanceResponse} */ ( + response.cryptogetAccountBalance + ); + + if (cryptogetAccountBalance.accountID) { + const accountIdFromConsensusNode = AccountId._fromProtobuf( + cryptogetAccountBalance.accountID, + ); + + mirrorNodeService + .setTimeout(this._timeout) + .getTokenBalancesForAccount( + accountIdFromConsensusNode.num.toString(), + ) + .then( + ( + /** @type {HashgraphProto.proto.ITokenBalance[]} */ tokenBalances, + ) => { + if ( + cryptogetAccountBalance && + cryptogetAccountBalance.tokenBalances && + tokenBalances && + tokenBalances.length > 0 + ) { + cryptogetAccountBalance.tokenBalances.splice( + 0, + cryptogetAccountBalance.tokenBalances + .length, + ); + + for (const tokenBalance of tokenBalances) { + cryptogetAccountBalance.tokenBalances.push( + tokenBalance, + ); + } + + resolve( + AccountBalance._fromProtobuf( + cryptogetAccountBalance, + ), + ); + } + }, + ) + .catch((error) => { + reject(error); + }); + } + }); } /** diff --git a/src/account/AccountInfoQuery.js b/src/account/AccountInfoQuery.js index db3d627e2..def0ac335 100644 --- a/src/account/AccountInfoQuery.js +++ b/src/account/AccountInfoQuery.js @@ -23,6 +23,8 @@ import AccountId from "./AccountId.js"; import AccountInfo from "./AccountInfo.js"; // eslint-disable-next-line @typescript-eslint/no-unused-vars import Hbar from "../Hbar.js"; +import MirrorNodeService from "../network/MirrorNodeService.js"; +import MirrorNodeGateway from "../network/MirrorNodeGateway.js"; /** * @namespace proto @@ -33,11 +35,13 @@ import Hbar from "../Hbar.js"; * @typedef {import("@hashgraph/proto").proto.CryptoGetInfoResponse.IAccountInfo} HashgraphProto.proto.CryptoGetInfoResponse.IAccountInfo * @typedef {import("@hashgraph/proto").proto.ICryptoGetInfoQuery} HashgraphProto.proto.ICryptoGetInfoQuery * @typedef {import("@hashgraph/proto").proto.ICryptoGetInfoResponse} HashgraphProto.proto.ICryptoGetInfoResponse + * @typedef {import("@hashgraph/proto").proto.ITokenRelationship} HashgraphProto.proto.ITokenRelationship */ /** * @typedef {import("../channel/Channel.js").default} Channel * @typedef {import("../client/Client.js").default<*, *>} Client + * @typedef {import("../account/TokenRelationship.js").default} TokenRelationship */ /** @@ -56,9 +60,17 @@ export default class AccountInfoQuery extends Query { * @type {?AccountId} */ this._accountId = null; + if (props.accountId != null) { this.setAccountId(props.accountId); } + + /** + * @private + * @description Delay in ms if is necessary to wait for the mirror node to update the account info + * @type {number} + */ + this._timeout = 0; } /** @@ -110,6 +122,16 @@ export default class AccountInfoQuery extends Query { } } + /** + * + * @param {number} timeout + * @returns {this} + */ + setTimeout(timeout) { + this._timeout = timeout; + return this; + } + /** * @override * @internal @@ -156,18 +178,61 @@ export default class AccountInfoQuery extends Query { */ // eslint-disable-next-line @typescript-eslint/no-unused-vars _mapResponse(response, nodeAccountId, request) { - const info = - /** @type {HashgraphProto.proto.ICryptoGetInfoResponse} */ ( - response.cryptoGetInfo + return new Promise((resolve, reject) => { + const mirrorNodeGateway = MirrorNodeGateway.forNetwork( + this._mirrorNetwork, + this._ledgerId, ); + const mirrorNodeService = new MirrorNodeService(mirrorNodeGateway); - return Promise.resolve( - AccountInfo._fromProtobuf( - /** @type {HashgraphProto.proto.CryptoGetInfoResponse.IAccountInfo} */ ( - info.accountInfo - ), - ), - ); + const info = + /** @type {HashgraphProto.proto.ICryptoGetInfoResponse} */ ( + response.cryptoGetInfo + ); + + if (info.accountInfo && info.accountInfo.accountID) { + const accountIdFromConsensusNode = AccountId._fromProtobuf( + info.accountInfo.accountID, + ); + + mirrorNodeService + .setTimeout(this._timeout) + .getTokenRelationshipsForAccount( + accountIdFromConsensusNode.num.toString(), + ) + .then((tokensRelationships) => { + if ( + info.accountInfo && + info.accountInfo.tokenRelationships && + tokensRelationships && + tokensRelationships.length > 0 + ) { + info.accountInfo.tokenRelationships.splice( + 0, + info.accountInfo.tokenRelationships.length, + ); + for (const tokenRelationship of tokensRelationships) { + info.accountInfo.tokenRelationships.push( + tokenRelationship, + ); + } + } + + resolve( + Promise.resolve( + AccountInfo._fromProtobuf( + /** @type {HashgraphProto.proto.CryptoGetInfoResponse.IAccountInfo} */ ( + info.accountInfo + ), + ), + ), + ); + }) + .catch((error) => { + reject(error); + }); + } + }); } /** diff --git a/src/contract/ContractInfoQuery.js b/src/contract/ContractInfoQuery.js index 27648c16f..9231b44c5 100644 --- a/src/contract/ContractInfoQuery.js +++ b/src/contract/ContractInfoQuery.js @@ -23,6 +23,8 @@ import ContractId from "./ContractId.js"; import ContractInfo from "./ContractInfo.js"; // eslint-disable-next-line @typescript-eslint/no-unused-vars import Hbar from "../Hbar.js"; +import MirrorNodeGateway from "../network/MirrorNodeGateway.js"; +import MirrorNodeService from "../network/MirrorNodeService.js"; /** * @namespace proto @@ -57,6 +59,14 @@ export default class ContractInfoQuery extends Query { * @private */ this._contractId = null; + + /** + * @private + * @description Delay in ms if is necessary to wait for the mirror node to update the contract info + * @type {number} + */ + this._timeout = 0; + if (props.contractId != null) { this.setContractId(props.contractId); } @@ -102,6 +112,16 @@ export default class ContractInfoQuery extends Query { return this; } + /** + * + * @param {number} timeout + * @returns {this} + */ + setTimeout(timeout) { + this._timeout = timeout; + return this; + } + /** * @param {Client} client */ @@ -157,18 +177,59 @@ export default class ContractInfoQuery extends Query { */ // eslint-disable-next-line @typescript-eslint/no-unused-vars _mapResponse(response, nodeAccountId, request) { - const info = - /** @type {HashgraphProto.proto.IContractGetInfoResponse} */ ( - response.contractGetInfo + return new Promise((resolve, reject) => { + const mirrorNodeGateway = MirrorNodeGateway.forNetwork( + this._mirrorNetwork, + this._ledgerId, ); + const mirrorNodeService = new MirrorNodeService(mirrorNodeGateway); - return Promise.resolve( - ContractInfo._fromProtobuf( - /** @type {HashgraphProto.proto.ContractGetInfoResponse.IContractInfo} */ ( - info.contractInfo - ), - ), - ); + const info = + /** @type {HashgraphProto.proto.IContractGetInfoResponse} */ ( + response.contractGetInfo + ); + + if (info.contractInfo && info.contractInfo.contractID) { + const contractIdFromConsensusNode = ContractId._fromProtobuf( + info.contractInfo.contractID, + ); + + mirrorNodeService + .setTimeout(this._timeout) + .getTokenRelationshipsForAccount( + contractIdFromConsensusNode.num.toString(), + ) + .then((tokensRelationships) => { + if ( + info.contractInfo && + info.contractInfo.tokenRelationships && + tokensRelationships && + tokensRelationships.length > 0 + ) { + info.contractInfo.tokenRelationships.splice( + 0, + info.contractInfo.tokenRelationships.length, + ); + for (const tokenRelationship of tokensRelationships) { + info.contractInfo.tokenRelationships.push( + tokenRelationship, + ); + } + } + + resolve( + ContractInfo._fromProtobuf( + /** @type {HashgraphProto.proto.ContractGetInfoResponse.IContractInfo} */ ( + info.contractInfo + ), + ), + ); + }) + .catch((error) => { + reject(error); + }); + } + }); } /** diff --git a/src/exports.js b/src/exports.js index 7d98dfbc2..1bd4994fe 100644 --- a/src/exports.js +++ b/src/exports.js @@ -49,6 +49,8 @@ export { default as AccountRecordsQuery } from "./account/AccountRecordsQuery.js export { default as AccountStakersQuery } from "./account/AccountStakersQuery.js"; export { default as AccountUpdateTransaction } from "./account/AccountUpdateTransaction.js"; export { default as AddressBookQuery } from "./network/AddressBookQuery.js"; +export { default as MirrorNodeGateway } from "./network/MirrorNodeGateway.js"; +export { default as MirrorNodeRouter } from "./network/MirrorNodeRouter.js"; export { default as AssessedCustomFee } from "./token/AssessedCustomFee.js"; export { default as ContractByteCodeQuery } from "./contract/ContractByteCodeQuery.js"; export { default as ContractCallQuery } from "./contract/ContractCallQuery.js"; diff --git a/src/network/MirrorNodeGateway.js b/src/network/MirrorNodeGateway.js new file mode 100644 index 000000000..a7abff129 --- /dev/null +++ b/src/network/MirrorNodeGateway.js @@ -0,0 +1,133 @@ +/*- + * ‌ + * Hedera JavaScript SDK + * ​ + * Copyright (C) 2020 - 2023 Hedera Hashgraph, LLC + * ​ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ‍ + */ + +import axios from "axios"; +import MirrorNodeRouter from "./MirrorNodeRouter.js"; + +/** + * @typedef {import("../contract/ContractId.js").default} ContractId + * @typedef {import("../account/AccountId.js").default} AccountId + * @typedef {import("../LedgerId.js").default} LedgerId + * / +/** + * @namespace proto + * @typedef {import("@hashgraph/proto").proto.IQuery} HashgraphProto.proto.IQuery + */ + +/** + * @typedef MirrorNodeTokenResponse + * @property {boolean} automatic_association + * @property {number} balance + * @property {string} created_timestamp + * @property {number} decimals + * @property {string} token_id + * @property {string} freeze_status + * @property {string} kyc_status + */ + +export const ACCOUNTS_ROUTE = "/accounts/%s"; +export const CONTRACT_ROUTE = "/contracts/%s"; +export const ACCOUNT_TOKENS_ROUTE = "/accounts/%s/tokens"; + +export default class MirrorNodeGateway { + /** + * @param {object} props + * @param {string} props.mirrorNodeUrl + */ + constructor(props) { + /** + * @type {string} + */ + this._mirrorNodeUrl = props.mirrorNodeUrl; + } + + /** + * Set mirror node url + * @param {string} mirrorNodeUrl + */ + static setMirrorNodeUrl(mirrorNodeUrl) { + this._mirrorNodeUrl = mirrorNodeUrl; + } + + /** + * @param {string[]} mirrorNetwork + * @param {?LedgerId} ledgerId + * @returns {MirrorNodeGateway} + */ + static forNetwork(mirrorNetwork, ledgerId) { + const mirrorNodeUrl = MirrorNodeRouter.getMirrorNodeUrl( + mirrorNetwork, + ledgerId, + ); + + return new MirrorNodeGateway({ mirrorNodeUrl }); + } + + /** + * @internal + * @param {string} url + * @returns {Promise} + */ + static executeRequest(url) { + return new Promise((resolve, reject) => { + axios + .get(url) + .then((response) => resolve(response)) + .catch((error) => reject(error)); + }); + } + + // /** + // * @internal + // * @param {string} id + // */ + // static async getAccountInfo(id) { + // var apiUrl = MirrorNodeRouter.buildApiUrl( + // this._mirrorNodeUrl, + // ACCOUNTS_ROUTE, + // id, + // ); + + // try { + // return MirrorNodeGateway.executeRequest(apiUrl); + // } catch (error) { + // throw error; + // } + // } + + /** + * @internal + * @param {string} idOrAliasOrEvmAddress + * @returns {Promise} + */ + getAccountTokens(idOrAliasOrEvmAddress) { + var apiUrl = MirrorNodeRouter.buildApiUrl( + this._mirrorNodeUrl, + ACCOUNT_TOKENS_ROUTE, + idOrAliasOrEvmAddress, + ); + + return new Promise((resolve, reject) => { + MirrorNodeGateway.executeRequest(apiUrl) + .then((response) => resolve(response)) + .catch((error) => reject(error)); + }); + } +} diff --git a/src/network/MirrorNodeRouter.js b/src/network/MirrorNodeRouter.js new file mode 100644 index 000000000..e6fdbfec7 --- /dev/null +++ b/src/network/MirrorNodeRouter.js @@ -0,0 +1,86 @@ +/*- + * ‌ + * Hedera JavaScript SDK + * ​ + * Copyright (C) 2020 - 2023 Hedera Hashgraph, LLC + * ​ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ‍ + */ + +/** + * @typedef {import("../contract/ContractId.js").default} ContractId + * @typedef {import("../account/AccountId.js").default} AccountId + * @typedef {import("../LedgerId.js").default} LedgerId + * / +/** + * @namespace proto + * @typedef {import("@hashgraph/proto").proto.IQuery} HashgraphProto.proto.IQuery + */ +/** + * Layer between the SDK and the Mirror Node + */ + +const API_VERSION = "/api/v1"; +const HTTP = "http://"; +const HTTPS = "https://"; +const LOCAL_NODE_PORT = "5551"; + +export default class MirrorNodeRouter { + /** + * Set mirror node url + * @param {string[]} mirrorNetwork + * @param {LedgerId | null} ledgerId + * @returns {string} + */ + static getMirrorNodeUrl(mirrorNetwork, ledgerId) { + let path; + let mirrorNodeAddress; + + mirrorNodeAddress = mirrorNetwork.map((a) => + a.substring(0, a.indexOf(":")), + ); + + if (mirrorNodeAddress.length == 0) { + throw new Error("Mirror address not found!"); + } + + if (ledgerId?.isLocalNode()) { + path = HTTP + mirrorNodeAddress.toString() + ":" + LOCAL_NODE_PORT; + } else { + path = HTTPS + mirrorNodeAddress.toString(); + } + + return path; + } + + /** + * + * @param {string} route + * @param {string} id + * @returns {string} + */ + static _getRoute = (route, id) => { + return route.replace("%s", id); + }; + + /** + * @param {string} mirrorNodeUrl + * @param {string} route + * @param {string} id + * @returns {string} + */ + static buildApiUrl(mirrorNodeUrl, route, id) { + return mirrorNodeUrl + API_VERSION + this._getRoute(route, id); + } +} diff --git a/src/network/MirrorNodeService.js b/src/network/MirrorNodeService.js new file mode 100644 index 000000000..4a662f723 --- /dev/null +++ b/src/network/MirrorNodeService.js @@ -0,0 +1,192 @@ +/*- + * ‌ + * Hedera JavaScript SDK + * ​ + * Copyright (C) 2020 - 2023 Hedera Hashgraph, LLC + * ​ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ‍ + */ +/** + * @namespace proto + * @typedef {import("@hashgraph/proto").proto.ITokenBalance} HashgraphProto.proto.ITokenBalance + * @typedef {import("@hashgraph/proto").proto.ITokenRelationship} HashgraphProto.proto.ITokenRelationship + * @typedef {import("@hashgraph/proto").proto.TokenKycStatus} HashgraphProto.proto.TokenKycStatus + * @typedef {import("@hashgraph/proto").proto.TokenFreezeStatus} HashgraphProto.proto.TokenFreezeStatus + */ +import TokenId from "../token/TokenId.js"; +import Long from "long"; +import TokenKycStatus from "../token/TokenKycStatus.js"; +import TokenFreezeStatus from "../token/TokenFreezeStatus.js"; + +/** + * @typedef MirrorNodeTokenResponse + * @property {boolean} automatic_association + * @property {number} balance + * @property {string} created_timestamp + * @property {number} decimals + * @property {string} token_id + * @property {string} freeze_status + * @property {string} kyc_status + */ + +/** + * @typedef {import("./MirrorNodeGateway.js").default} MirrorNodeGateway + */ + +export default class MirrorNodeService { + /** + * @param {MirrorNodeGateway} mirrorNodeGateway + */ + constructor(mirrorNodeGateway) { + /** + * @private + * @type {MirrorNodeGateway} + */ + this._mirrorNodeGateway = mirrorNodeGateway; + + /** + * @private + * @type {number} + */ + this._timeout = 0; + } + + /** + * @param {string} idOrAliasOrEvmAddress + * @returns {Promise} + */ + async getTokenBalancesForAccount(idOrAliasOrEvmAddress) { + return new Promise((resolve, reject) => { + setTimeout(() => { + this._mirrorNodeGateway + .getAccountTokens(idOrAliasOrEvmAddress) + .then( + ( + /** @type {import("axios").AxiosResponse<{ tokens: MirrorNodeTokenResponse[] }>} */ response, + ) => { + /** @type {HashgraphProto.proto.ITokenBalance[]} */ + const tokenBalances = response.data.tokens.map( + ( + /** @type {MirrorNodeTokenResponse} */ token, + ) => ({ + tokenId: TokenId.fromString( + token.token_id, + )._toProtobuf(), + balance: Long.fromNumber(token.balance), + decimals: token.decimals, + }), + ); + tokenBalances.map((t) => { + console.log(t.tokenId, t.balance, t.decimals); + }); + resolve(tokenBalances); + }, + ) + .catch((error) => { + reject(error); + }); + }, this._timeout); + }); + } + + /** + * @param {string} idOrAliasOrEvmAddress + * @returns {Promise} + */ + getTokenRelationshipsForAccount(idOrAliasOrEvmAddress) { + return new Promise((resolve, reject) => { + setTimeout(() => { + this._mirrorNodeGateway + .getAccountTokens(idOrAliasOrEvmAddress) + .then( + ( + /** @type {import("axios").AxiosResponse<{ tokens: MirrorNodeTokenResponse[] }>} */ response, + ) => { + /** @type {HashgraphProto.proto.ITokenRelationship[]} */ + const tokenRelationships = response.data.tokens.map( + ( + /** @type {MirrorNodeTokenResponse} */ token, + ) => ({ + tokenId: TokenId.fromString( + token.token_id, + )._toProtobuf(), + balance: Long.fromNumber(token.balance), + decimals: token.decimals, + kycStatus: this.getTokenKycStatusFrom( + token.kyc_status, + ), + freezeStatus: this.getTokenFreezeStatusFrom( + token.freeze_status, + ), + automaticAssociation: + token.automatic_association, + }), + ); + console.log(tokenRelationships); + resolve(tokenRelationships); + }, + ) + .catch((error) => { + reject(error); + }); + }, this._timeout); + }); + } + + /** + * + * @param {string} status + * @returns {HashgraphProto.proto.TokenKycStatus} + */ + getTokenKycStatusFrom(status) { + switch (status) { + case "NOT_APPLICABLE": + return TokenKycStatus.KycNotApplicable.valueOf(); + case "GRANTED": + return TokenKycStatus.Granted.valueOf(); + case "REVOKED": + return TokenKycStatus.Revoked.valueOf(); + default: + throw new Error(`Invalid token KYC status: ${status}`); + } + } + + /** + * + * @param {string} status + * @returns {HashgraphProto.proto.TokenFreezeStatus} + */ + getTokenFreezeStatusFrom(status) { + switch (status) { + case "NOT_APPLICABLE": + return TokenFreezeStatus.FreezeNotApplicable.valueOf(); + case "FROZEN": + return TokenFreezeStatus.Frozen.valueOf(); + case "UNFROZEN": + return TokenFreezeStatus.Unfrozen.valueOf(); + default: + throw new Error(`Invalid token freeze status: ${status}`); + } + } + + /** + * + * @param {number} timeout + * @returns {this} + */ + setTimeout(timeout) { + this._timeout = timeout; + return this; + } +} diff --git a/src/token/TokenFreezeStatus.js b/src/token/TokenFreezeStatus.js new file mode 100644 index 000000000..13b06c8cd --- /dev/null +++ b/src/token/TokenFreezeStatus.js @@ -0,0 +1,87 @@ +/*- + * ‌ + * Hedera JavaScript SDK + * ​ + * Copyright (C) 2020 - 2023 Hedera Hashgraph, LLC + * ​ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ‍ + */ + +/** + * @namespace proto + * @typedef {import("@hashgraph/proto").proto.TokenFreezeStatus} HashgraphProto.proto.TokenFreezeStatus + */ + +export default class TokenFreezeStatus { + /** + * @hideconstructor + * @internal + * @param {number} code + */ + constructor(code) { + /** @readonly */ + this._code = code; + + Object.freeze(this); + } + + /** + * @returns {string} + */ + toString() { + switch (this) { + case TokenFreezeStatus.FreezeNotApplicable: + return "NOT_APPLICABLE"; + case TokenFreezeStatus.Frozen: + return "GRANTED"; + case TokenFreezeStatus.Unfrozen: + return "REVOKED"; + default: + return `UNKNOWN (${this._code})`; + } + } + + /** + * @internal + * @param {number} code + * @returns {TokenFreezeStatus} + */ + static _fromCode(code) { + switch (code) { + case 0: + return TokenFreezeStatus.FreezeNotApplicable; + case 1: + return TokenFreezeStatus.Frozen; + case 2: + return TokenFreezeStatus.Unfrozen; + } + + throw new Error( + `(BUG) TokenFreezeStatus.fromCode() does not handle code: ${code}`, + ); + } + + /** + * @returns {HashgraphProto.proto.TokenFreezeStatus} + */ + valueOf() { + return this._code; + } +} + +TokenFreezeStatus.FreezeNotApplicable = new TokenFreezeStatus(0); + +TokenFreezeStatus.Frozen = new TokenFreezeStatus(1); + +TokenFreezeStatus.Unfrozen = new TokenFreezeStatus(2); diff --git a/src/token/TokenKycStatus.js b/src/token/TokenKycStatus.js new file mode 100644 index 000000000..53d0ad496 --- /dev/null +++ b/src/token/TokenKycStatus.js @@ -0,0 +1,87 @@ +/*- + * ‌ + * Hedera JavaScript SDK + * ​ + * Copyright (C) 2020 - 2023 Hedera Hashgraph, LLC + * ​ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ‍ + */ + +/** + * @namespace proto + * @typedef {import("@hashgraph/proto").proto.TokenKycStatus} HashgraphProto.proto.TokenKycStatus + */ + +export default class TokenKycStatus { + /** + * @hideconstructor + * @internal + * @param {number} code + */ + constructor(code) { + /** @readonly */ + this._code = code; + + Object.freeze(this); + } + + /** + * @returns {string} + */ + toString() { + switch (this) { + case TokenKycStatus.KycNotApplicable: + return "NOT_APPLICABLE"; + case TokenKycStatus.Granted: + return "GRANTED"; + case TokenKycStatus.Revoked: + return "REVOKED"; + default: + return `UNKNOWN (${this._code})`; + } + } + + /** + * @internal + * @param {number} code + * @returns {TokenKycStatus} + */ + static _fromCode(code) { + switch (code) { + case 0: + return TokenKycStatus.KycNotApplicable; + case 1: + return TokenKycStatus.Granted; + case 2: + return TokenKycStatus.Revoked; + } + + throw new Error( + `(BUG) TokenKycStatus.fromCode() does not handle code: ${code}`, + ); + } + + /** + * @returns {HashgraphProto.proto.TokenKycStatus} + */ + valueOf() { + return this._code; + } +} + +TokenKycStatus.KycNotApplicable = new TokenKycStatus(0); + +TokenKycStatus.Granted = new TokenKycStatus(1); + +TokenKycStatus.Revoked = new TokenKycStatus(2); From de0edbdfbabb2ec628d949cb8b93823dff136716 Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Wed, 15 May 2024 14:25:07 +0300 Subject: [PATCH 02/49] update: queries Signed-off-by: svetoslav-nikol0v --- src/account/AccountBalanceQuery.js | 3 +-- src/account/AccountInfoQuery.js | 11 ++++------- src/contract/ContractInfoQuery.js | 3 +-- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/account/AccountBalanceQuery.js b/src/account/AccountBalanceQuery.js index 0dd021e89..a3a352b00 100644 --- a/src/account/AccountBalanceQuery.js +++ b/src/account/AccountBalanceQuery.js @@ -265,8 +265,7 @@ export default class AccountBalanceQuery extends Query { if ( cryptogetAccountBalance && cryptogetAccountBalance.tokenBalances && - tokenBalances && - tokenBalances.length > 0 + tokenBalances ) { cryptogetAccountBalance.tokenBalances.splice( 0, diff --git a/src/account/AccountInfoQuery.js b/src/account/AccountInfoQuery.js index def0ac335..20cbd1512 100644 --- a/src/account/AccountInfoQuery.js +++ b/src/account/AccountInfoQuery.js @@ -204,8 +204,7 @@ export default class AccountInfoQuery extends Query { if ( info.accountInfo && info.accountInfo.tokenRelationships && - tokensRelationships && - tokensRelationships.length > 0 + tokensRelationships ) { info.accountInfo.tokenRelationships.splice( 0, @@ -219,11 +218,9 @@ export default class AccountInfoQuery extends Query { } resolve( - Promise.resolve( - AccountInfo._fromProtobuf( - /** @type {HashgraphProto.proto.CryptoGetInfoResponse.IAccountInfo} */ ( - info.accountInfo - ), + AccountInfo._fromProtobuf( + /** @type {HashgraphProto.proto.CryptoGetInfoResponse.IAccountInfo} */ ( + info.accountInfo ), ), ); diff --git a/src/contract/ContractInfoQuery.js b/src/contract/ContractInfoQuery.js index 9231b44c5..773f0979b 100644 --- a/src/contract/ContractInfoQuery.js +++ b/src/contract/ContractInfoQuery.js @@ -203,8 +203,7 @@ export default class ContractInfoQuery extends Query { if ( info.contractInfo && info.contractInfo.tokenRelationships && - tokensRelationships && - tokensRelationships.length > 0 + tokensRelationships ) { info.contractInfo.tokenRelationships.splice( 0, From cb91a79711f6fdf343400528f251bd32b59a2fcd Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Wed, 15 May 2024 14:25:57 +0300 Subject: [PATCH 03/49] fix: adjustments and formatting Signed-off-by: svetoslav-nikol0v --- src/Executable.js | 2 +- src/network/MirrorNodeGateway.js | 18 ------------------ src/network/MirrorNodeRouter.js | 7 ++++--- src/network/MirrorNodeService.js | 6 ++---- .../client/BaseIntegrationTestEnv.js | 4 +--- 5 files changed, 8 insertions(+), 29 deletions(-) diff --git a/src/Executable.js b/src/Executable.js index c9da1140b..ad42862ff 100644 --- a/src/Executable.js +++ b/src/Executable.js @@ -531,7 +531,7 @@ export default class Executable { this._mirrorNetwork = client.mirrorNetwork; // Set current LedgerId of the network with // which execution will be attempted - this._ledgerId = client.ledgerId; + this._ledgerId = this._ledgerId != null ? this._ledgerId : client.ledgerId; // If the logger on the request is not set, use the logger in client // (if set, otherwise do not use logger) diff --git a/src/network/MirrorNodeGateway.js b/src/network/MirrorNodeGateway.js index a7abff129..c9ca694ab 100644 --- a/src/network/MirrorNodeGateway.js +++ b/src/network/MirrorNodeGateway.js @@ -94,24 +94,6 @@ export default class MirrorNodeGateway { }); } - // /** - // * @internal - // * @param {string} id - // */ - // static async getAccountInfo(id) { - // var apiUrl = MirrorNodeRouter.buildApiUrl( - // this._mirrorNodeUrl, - // ACCOUNTS_ROUTE, - // id, - // ); - - // try { - // return MirrorNodeGateway.executeRequest(apiUrl); - // } catch (error) { - // throw error; - // } - // } - /** * @internal * @param {string} idOrAliasOrEvmAddress diff --git a/src/network/MirrorNodeRouter.js b/src/network/MirrorNodeRouter.js index e6fdbfec7..296a1e7a3 100644 --- a/src/network/MirrorNodeRouter.js +++ b/src/network/MirrorNodeRouter.js @@ -55,10 +55,11 @@ export default class MirrorNodeRouter { throw new Error("Mirror address not found!"); } - if (ledgerId?.isLocalNode()) { - path = HTTP + mirrorNodeAddress.toString() + ":" + LOCAL_NODE_PORT; - } else { + if (ledgerId != null && !ledgerId.isLocalNode()) { path = HTTPS + mirrorNodeAddress.toString(); + } else { + // local node case + path = HTTP + mirrorNodeAddress.toString() + ":" + LOCAL_NODE_PORT; } return path; diff --git a/src/network/MirrorNodeService.js b/src/network/MirrorNodeService.js index 4a662f723..d4b0384fe 100644 --- a/src/network/MirrorNodeService.js +++ b/src/network/MirrorNodeService.js @@ -87,9 +87,7 @@ export default class MirrorNodeService { decimals: token.decimals, }), ); - tokenBalances.map((t) => { - console.log(t.tokenId, t.balance, t.decimals); - }); + resolve(tokenBalances); }, ) @@ -133,7 +131,7 @@ export default class MirrorNodeService { token.automatic_association, }), ); - console.log(tokenRelationships); + resolve(tokenRelationships); }, ) diff --git a/test/integration/client/BaseIntegrationTestEnv.js b/test/integration/client/BaseIntegrationTestEnv.js index 5a0c4d0c9..0c5b5dc11 100644 --- a/test/integration/client/BaseIntegrationTestEnv.js +++ b/test/integration/client/BaseIntegrationTestEnv.js @@ -74,9 +74,7 @@ export default class BaseIntegrationTestEnv { options.env.HEDERA_NETWORK == "localhost") || options.env.HEDERA_NETWORK == "local-node" ) { - client = options.client.forNetwork({ - "127.0.0.1:50211": new AccountId(3), - }); + client = options.client.forLocalNode(); } else if (options.env.CONFIG_FILE != null) { client = await options.client.fromConfigFile( options.env.CONFIG_FILE From aba6d432003c0cc8dbf34f77f50a4226390d2ec5 Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Wed, 15 May 2024 14:47:27 +0300 Subject: [PATCH 04/49] update: increase timeout Signed-off-by: svetoslav-nikol0v --- common_js_test/src/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common_js_test/src/test.js b/common_js_test/src/test.js index 25296d198..a8b5f0050 100644 --- a/common_js_test/src/test.js +++ b/common_js_test/src/test.js @@ -2,7 +2,7 @@ const { Client, AccountBalanceQuery } = require("@hashgraph/sdk"); describe("CommonJS", function () { it("it should query each node's balance", async function () { - this.timeout(15000); + this.timeout(30000); const client = Client.forTestnet(); From 4e08ee98e44df3c1b819bfeeb1013e9df1850428 Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Tue, 21 May 2024 10:47:49 +0300 Subject: [PATCH 05/49] update: integration tests Signed-off-by: svetoslav-nikol0v --- src/Executable.js | 2 +- src/account/AccountBalanceQuery.js | 6 - src/network/MirrorNodeService.js | 4 +- .../AccountBalanceIntegrationTest.js | 57 +++--- .../AccountCreateIntegrationTest.js | 9 + .../AccountDeleteIntegrationTest.js | 1 + .../integration/AccountInfoIntegrationTest.js | 63 +++--- .../AccountUpdateIntegrationTest.js | 1 + test/integration/ClientIntegrationTest.js | 8 +- .../ContractCreateIntegrationTest.js | 1 + .../ContractDeleteIntegrationTest.js | 2 + .../ContractInfoIntegrationTest.js | 2 + .../ContractUpdateIntegrationTest.js | 2 + test/integration/GetCostIntegrationTest.js | 5 + .../TokenAssociateIntegrationTest.js | 136 ++++++------ test/integration/TokenBurnIntegrationTest.js | 100 +++++---- .../TokenDissociateIntegrationTest.js | 179 ++++++++-------- .../integration/TokenFreezeIntegrationTest.js | 138 ++++++------- .../TokenGrantKycIntegrationTest.js | 138 ++++++------- .../TokenRevokeKycIntegrationTest.js | 185 +++++++++-------- .../TokenTransferIntegrationTest.js | 2 + .../TokenUnfreezeIntegrationTest.js | 185 +++++++++-------- test/integration/TokenWipeIntegrationTest.js | 193 +++++++++--------- 23 files changed, 704 insertions(+), 715 deletions(-) diff --git a/src/Executable.js b/src/Executable.js index ad42862ff..c9da1140b 100644 --- a/src/Executable.js +++ b/src/Executable.js @@ -531,7 +531,7 @@ export default class Executable { this._mirrorNetwork = client.mirrorNetwork; // Set current LedgerId of the network with // which execution will be attempted - this._ledgerId = this._ledgerId != null ? this._ledgerId : client.ledgerId; + this._ledgerId = client.ledgerId; // If the logger on the request is not set, use the logger in client // (if set, otherwise do not use logger) diff --git a/src/account/AccountBalanceQuery.js b/src/account/AccountBalanceQuery.js index a3a352b00..729ff5665 100644 --- a/src/account/AccountBalanceQuery.js +++ b/src/account/AccountBalanceQuery.js @@ -72,12 +72,6 @@ export default class AccountBalanceQuery extends Query { */ this._contractId = null; - /** - * @type {?ContractId} - * @private - */ - this._contractId = null; - /** * @private * @description Delay in ms if is necessary to wait for the mirror node to update the account balance diff --git a/src/network/MirrorNodeService.js b/src/network/MirrorNodeService.js index d4b0384fe..a8a41d29a 100644 --- a/src/network/MirrorNodeService.js +++ b/src/network/MirrorNodeService.js @@ -91,9 +91,7 @@ export default class MirrorNodeService { resolve(tokenBalances); }, ) - .catch((error) => { - reject(error); - }); + .catch((error) => reject(error)); }, this._timeout); }); } diff --git a/test/integration/AccountBalanceIntegrationTest.js b/test/integration/AccountBalanceIntegrationTest.js index f2be8c9ca..af8f4b7d9 100644 --- a/test/integration/AccountBalanceIntegrationTest.js +++ b/test/integration/AccountBalanceIntegrationTest.js @@ -1,6 +1,7 @@ import { AccountBalanceQuery, Status, + TokenCreateTransaction, // TokenCreateTransaction, } from "../../src/exports.js"; import IntegrationTestEnv, { @@ -42,6 +43,7 @@ describe("AccountBalanceQuery", function () { expect(address.endsWith(":50212")).to.be.true; await new AccountBalanceQuery() + .setTimeout(1000) .setAccountId(nodeAccountId) .setMaxAttempts(10) .execute(clientPreviewNet); @@ -61,9 +63,10 @@ describe("AccountBalanceQuery", function () { expect(address.endsWith(":50212")).to.be.true; await new AccountBalanceQuery() - .setAccountId(nodeAccountId) - .setMaxAttempts(10) - .execute(clientTestnet); + .setTimeout(1000) + .setAccountId(nodeAccountId) + .setMaxAttempts(10) + .execute(clientTestnet); } }); @@ -85,32 +88,28 @@ describe("AccountBalanceQuery", function () { } }); - /** - * - * @description The test is temporarily commented because AccountBalanceQuery does a query to the consensus node which was deprecated. - * @todo Uncomment a test when the new query to the mirror node is implemented as it described here https://github.com/hashgraph/hedera-sdk-reference/issues/144 - */ - // it("should reflect token with no keys", async function () { - // this.timeout(120000); - - // const operatorId = env.operatorId; - - // const token = ( - // await ( - // await new TokenCreateTransaction() - // .setTokenName("ffff") - // .setTokenSymbol("F") - // .setTreasuryAccountId(operatorId) - // .execute(env.client) - // ).getReceipt(env.client) - // ).tokenId; - - // const balances = await new AccountBalanceQuery() - // .setAccountId(env.operatorId) - // .execute(env.client); - - // expect(balances.tokens.get(token).toInt()).to.be.equal(0); - // }); + it("should reflect token with no keys", async function () { + this.timeout(120000); + + const operatorId = env.operatorId; + + const token = ( + await ( + await new TokenCreateTransaction() + .setTokenName("ffff") + .setTokenSymbol("F") + .setTreasuryAccountId(operatorId) + .execute(env.client) + ).getReceipt(env.client) + ).tokenId; + + const balances = await new AccountBalanceQuery() + .setTimeout(2000) + .setAccountId(env.operatorId) + .execute(env.client); + + expect(balances.tokens.get(token).toInt()).to.be.equal(0); + }); after(async function () { clientPreviewNet.close(); diff --git a/test/integration/AccountCreateIntegrationTest.js b/test/integration/AccountCreateIntegrationTest.js index 2f150ada4..ffb1385a2 100644 --- a/test/integration/AccountCreateIntegrationTest.js +++ b/test/integration/AccountCreateIntegrationTest.js @@ -35,6 +35,7 @@ describe("AccountCreate", function () { const account = receipt.accountId; const info = await new AccountInfoQuery() + .setTimeout(1000) .setAccountId(account) .execute(env.client); @@ -76,6 +77,7 @@ describe("AccountCreate", function () { const account = receipt.accountId; const info = await new AccountInfoQuery() + .setTimeout(2000) .setNodeAccountIds([response.nodeId]) .setAccountId(account) .execute(env.client); @@ -117,6 +119,7 @@ describe("AccountCreate", function () { const account = receipt.accountId; const info = await new AccountInfoQuery() + .setTimeout(1000) .setAccountId(account) .execute(env.client); @@ -173,6 +176,7 @@ describe("AccountCreate", function () { const account = receipt.accountId; const info = await new AccountInfoQuery() + .setTimeout(1000) .setNodeAccountIds([response.nodeId]) .setAccountId(account) .execute(env.client); @@ -218,6 +222,7 @@ describe("AccountCreate", function () { expect(accountId).to.not.be.null; const info = await new AccountInfoQuery() + .setTimeout(1000) .setNodeAccountIds([txAccountCreate.nodeId]) .setAccountId(accountId) .execute(env.client); @@ -255,6 +260,7 @@ describe("AccountCreate", function () { expect(accountId).to.not.be.null; const info = await new AccountInfoQuery() + .setTimeout(2000) .setAccountId(accountId) .execute(env.client); @@ -296,6 +302,7 @@ describe("AccountCreate", function () { expect(accountId).to.not.be.null; const info = await new AccountInfoQuery() + .setTimeout(1000) .setAccountId(accountId) .execute(env.client); @@ -369,6 +376,7 @@ describe("AccountCreate", function () { expect(accountId).to.not.be.null; const info = await new AccountInfoQuery() + .setTimeout(1000) .setAccountId(accountId) .execute(env.client); @@ -447,6 +455,7 @@ describe("AccountCreate", function () { expect(accountId).to.not.be.null; const info = await new AccountInfoQuery() + .setTimeout(1000) .setAccountId(accountId) .execute(env.client); diff --git a/test/integration/AccountDeleteIntegrationTest.js b/test/integration/AccountDeleteIntegrationTest.js index abea8abd2..9fd932bae 100644 --- a/test/integration/AccountDeleteIntegrationTest.js +++ b/test/integration/AccountDeleteIntegrationTest.js @@ -33,6 +33,7 @@ describe("AccountDelete", function () { const account = receipt.accountId; const info = await new AccountInfoQuery() + .setTimeout(1000) .setAccountId(account) .execute(env.client); diff --git a/test/integration/AccountInfoIntegrationTest.js b/test/integration/AccountInfoIntegrationTest.js index ea6cfbbd5..267b316b7 100644 --- a/test/integration/AccountInfoIntegrationTest.js +++ b/test/integration/AccountInfoIntegrationTest.js @@ -5,7 +5,7 @@ import { Hbar, PrivateKey, Status, - // TokenCreateTransaction, + TokenCreateTransaction, TransactionId, } from "../../src/exports.js"; import IntegrationTestEnv from "./client/NodeIntegrationTestEnv.js"; @@ -86,6 +86,7 @@ describe("AccountInfo", function () { const account = receipt.accountId; const info = await new AccountInfoQuery() + .setTimeout(1000) .setAccountId(account) .execute(env.client); @@ -154,38 +155,34 @@ describe("AccountInfo", function () { } }); - /** - * - * @description The test is temporarily commented because AccountInfoQuery does a query to the consensus node which was deprecated. - * @todo Uncomment a test when the new query to the mirror node is implemented as it described here https://github.com/hashgraph/hedera-sdk-reference/issues/144 - */ - // it("should reflect token with no keys", async function () { - // this.timeout(120000); - - // const operatorId = env.operatorId; - - // const token = ( - // await ( - // await new TokenCreateTransaction() - // .setTokenName("ffff") - // .setTokenSymbol("F") - // .setTreasuryAccountId(operatorId) - // .execute(env.client) - // ).getReceipt(env.client) - // ).tokenId; - - // const info = await new AccountInfoQuery() - // .setAccountId(operatorId) - // .execute(env.client); - - // const relationship = info.tokenRelationships.get(token); - - // expect(relationship).to.be.not.null; - // expect(relationship.tokenId.toString()).to.be.equal(token.toString()); - // expect(relationship.balance.toInt()).to.be.equal(0); - // expect(relationship.isKycGranted).to.be.null; - // expect(relationship.isFrozen).to.be.null; - // }); + it("should reflect token with no keys", async function () { + this.timeout(120000); + + const operatorId = env.operatorId; + + const token = ( + await ( + await new TokenCreateTransaction() + .setTokenName("ffff") + .setTokenSymbol("F") + .setTreasuryAccountId(operatorId) + .execute(env.client) + ).getReceipt(env.client) + ).tokenId; + + const info = await new AccountInfoQuery() + .setTimeout(1000) + .setAccountId(operatorId) + .execute(env.client); + + const relationship = info.tokenRelationships.get(token); + + expect(relationship).to.be.not.null; + expect(relationship.tokenId.toString()).to.be.equal(token.toString()); + expect(relationship.balance.toInt()).to.be.equal(0); + expect(relationship.isKycGranted).to.be.null; + expect(relationship.isFrozen).to.be.null; + }); it("should be error with no account ID", async function () { this.timeout(120000); diff --git a/test/integration/AccountUpdateIntegrationTest.js b/test/integration/AccountUpdateIntegrationTest.js index bcc9bb7de..ee421deb4 100644 --- a/test/integration/AccountUpdateIntegrationTest.js +++ b/test/integration/AccountUpdateIntegrationTest.js @@ -39,6 +39,7 @@ describe("AccountUpdate", function () { const account = receipt.accountId; let info = await new AccountInfoQuery() + .setTimeout(1000) .setAccountId(account) .execute(env.client); diff --git a/test/integration/ClientIntegrationTest.js b/test/integration/ClientIntegrationTest.js index 204faaa38..eba0cd99f 100644 --- a/test/integration/ClientIntegrationTest.js +++ b/test/integration/ClientIntegrationTest.js @@ -81,6 +81,7 @@ describe("ClientIntegration", function () { const account = receipt.accountId; const info = await new AccountInfoQuery() + .setTimeout(1000) .setAccountId(account) .execute(env.client); @@ -156,15 +157,16 @@ describe("ClientIntegration", function () { }); it("can use same proxies of one node", async function () { - this.timeout(100000); + this.timeout(300000); 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); + const clientForNetwork = Client.forNetwork(nodes) + .setLedgerId(LedgerId.TESTNET) + .setMirrorNetwork("testnet.mirrornode.hedera.com:443"); await clientForNetwork.pingAll(); }); diff --git a/test/integration/ContractCreateIntegrationTest.js b/test/integration/ContractCreateIntegrationTest.js index 6e00e2c6b..b2089138e 100644 --- a/test/integration/ContractCreateIntegrationTest.js +++ b/test/integration/ContractCreateIntegrationTest.js @@ -58,6 +58,7 @@ describe("ContractCreate", function () { let contract = receipt.contractId; let info = await new ContractInfoQuery() + .setTimeout(1000) .setContractId(contract) .setQueryPayment(new Hbar(1)) .execute(env.client); diff --git a/test/integration/ContractDeleteIntegrationTest.js b/test/integration/ContractDeleteIntegrationTest.js index 7b10b278f..e31b032d0 100644 --- a/test/integration/ContractDeleteIntegrationTest.js +++ b/test/integration/ContractDeleteIntegrationTest.js @@ -58,6 +58,7 @@ describe("ContractDelete", function () { let contract = receipt.contractId; let info = await new ContractInfoQuery() + .setTimeout(3000) .setContractId(contract) .setQueryPayment(new Hbar(1)) .execute(env.client); @@ -179,6 +180,7 @@ describe("ContractDelete", function () { let contract = receipt.contractId; let info = await new ContractInfoQuery() + .setTimeout(3000) .setContractId(contract) .setQueryPayment(new Hbar(1)) .execute(env.client); diff --git a/test/integration/ContractInfoIntegrationTest.js b/test/integration/ContractInfoIntegrationTest.js index d38a6e7d4..4760068ed 100644 --- a/test/integration/ContractInfoIntegrationTest.js +++ b/test/integration/ContractInfoIntegrationTest.js @@ -57,6 +57,7 @@ describe("ContractInfo", function () { let contract = receipt.contractId; let info = await new ContractInfoQuery() + .setTimeout(1000) .setContractId(contract) .setQueryPayment(new Hbar(1)) .execute(env.client); @@ -126,6 +127,7 @@ describe("ContractInfo", function () { let contract = receipt.contractId; let info = await new ContractInfoQuery() + .setTimeout(1000) .setContractId(contract) .setQueryPayment(new Hbar(1)) .execute(env.client); diff --git a/test/integration/ContractUpdateIntegrationTest.js b/test/integration/ContractUpdateIntegrationTest.js index af2310ace..aa4ff9e9f 100644 --- a/test/integration/ContractUpdateIntegrationTest.js +++ b/test/integration/ContractUpdateIntegrationTest.js @@ -59,6 +59,7 @@ describe("ContractUpdate", function () { let contract = receipt.contractId; let info = await new ContractInfoQuery() + .setTimeout(1000) .setContractId(contract) .setQueryPayment(new Hbar(1)) .execute(env.client); @@ -85,6 +86,7 @@ describe("ContractUpdate", function () { ).getReceipt(env.client); info = await new ContractInfoQuery() + .setTimeout(1000) .setContractId(contract) .setQueryPayment(new Hbar(5)) .execute(env.client); diff --git a/test/integration/GetCostIntegrationTest.js b/test/integration/GetCostIntegrationTest.js index a27f533fc..b560a64d1 100644 --- a/test/integration/GetCostIntegrationTest.js +++ b/test/integration/GetCostIntegrationTest.js @@ -22,6 +22,7 @@ describe("GetCost", function () { .getCost(env.client); await new AccountInfoQuery() + .setTimeout(1000) .setAccountId(operatorId) .setQueryPayment(cost) .execute(env.client); @@ -39,6 +40,7 @@ describe("GetCost", function () { .getCost(env.client); await new AccountInfoQuery() + .setTimeout(1000) .setAccountId(operatorId) .setQueryPayment(cost) .execute(env.client); @@ -56,6 +58,7 @@ describe("GetCost", function () { .getCost(env.client); await new AccountInfoQuery() + .setTimeout(1000) .setAccountId(operatorId) .setQueryPayment(cost) .execute(env.client); @@ -72,6 +75,7 @@ describe("GetCost", function () { .execute(env.client); await new AccountBalanceQuery() + .setTimeout(1000) .setAccountId(operatorId) .setQueryPayment(new Hbar(0)) .execute(env.client); @@ -88,6 +92,7 @@ describe("GetCost", function () { .execute(env.client); await new AccountBalanceQuery() + .setTimeout(1000) .setAccountId(operatorId) .setQueryPayment(new Hbar(0)) .execute(env.client); diff --git a/test/integration/TokenAssociateIntegrationTest.js b/test/integration/TokenAssociateIntegrationTest.js index 020813a07..c2c12ad33 100644 --- a/test/integration/TokenAssociateIntegrationTest.js +++ b/test/integration/TokenAssociateIntegrationTest.js @@ -1,9 +1,9 @@ import { - // AccountBalanceQuery, - // AccountCreateTransaction, - // AccountInfoQuery, - // Hbar, - // PrivateKey, + AccountBalanceQuery, + AccountCreateTransaction, + AccountInfoQuery, + Hbar, + PrivateKey, Status, TokenAssociateTransaction, TokenCreateTransaction, @@ -17,71 +17,67 @@ describe("TokenAssociate", function () { env = await IntegrationTestEnv.new(); }); - /** - * - * @description The test is temporarily commented because AccountBalanceQuery does a query to the consensus node which was deprecated. - * @todo Uncomment a test when the new query to the mirror node is implemented as it described here https://github.com/hashgraph/hedera-sdk-reference/issues/144 - */ - // it("should be executable", async function () { - // this.timeout(120000); - - // const operatorId = env.operatorId; - // const operatorKey = env.operatorKey.publicKey; - // const key = PrivateKey.generateED25519(); - - // const response = await new AccountCreateTransaction() - // .setKey(key) - // .setInitialBalance(new Hbar(2)) - // .execute(env.client); - - // const account = (await response.getReceipt(env.client)).accountId; - - // const token = ( - // await ( - // await new TokenCreateTransaction() - // .setTokenName("ffff") - // .setTokenSymbol("F") - // .setDecimals(3) - // .setInitialSupply(1000000) - // .setTreasuryAccountId(operatorId) - // .setAdminKey(operatorKey) - // .setKycKey(operatorKey) - // .setFreezeKey(operatorKey) - // .setWipeKey(operatorKey) - // .setSupplyKey(operatorKey) - // .setFreezeDefault(false) - // .execute(env.client) - // ).getReceipt(env.client) - // ).tokenId; - - // await ( - // await ( - // await new TokenAssociateTransaction() - // .setTokenIds([token]) - // .setAccountId(account) - // .freezeWith(env.client) - // .sign(key) - // ).execute(env.client) - // ).getReceipt(env.client); - - // const balances = await new AccountBalanceQuery() - // .setAccountId(account) - // .execute(env.client); - - // expect(balances.tokens.get(token).toInt()).to.be.equal(0); - - // const info = await new AccountInfoQuery() - // .setAccountId(account) - // .execute(env.client); - - // const relationship = info.tokenRelationships.get(token); - - // expect(relationship).to.be.not.null; - // expect(relationship.tokenId.toString()).to.be.equal(token.toString()); - // expect(relationship.balance.toInt()).to.be.equal(0); - // expect(relationship.isKycGranted).to.be.false; - // expect(relationship.isFrozen).to.be.false; - // }); + it("should be executable", async function () { + this.timeout(120000); + + const operatorId = env.operatorId; + const operatorKey = env.operatorKey.publicKey; + const key = PrivateKey.generateED25519(); + + const response = await new AccountCreateTransaction() + .setKey(key) + .setInitialBalance(new Hbar(2)) + .execute(env.client); + + const account = (await response.getReceipt(env.client)).accountId; + + const token = ( + await ( + await new TokenCreateTransaction() + .setTokenName("ffff") + .setTokenSymbol("F") + .setDecimals(3) + .setInitialSupply(1000000) + .setTreasuryAccountId(operatorId) + .setAdminKey(operatorKey) + .setKycKey(operatorKey) + .setFreezeKey(operatorKey) + .setWipeKey(operatorKey) + .setSupplyKey(operatorKey) + .setFreezeDefault(false) + .execute(env.client) + ).getReceipt(env.client) + ).tokenId; + + await ( + await ( + await new TokenAssociateTransaction() + .setTokenIds([token]) + .setAccountId(account) + .freezeWith(env.client) + .sign(key) + ).execute(env.client) + ).getReceipt(env.client); + + const balances = await new AccountBalanceQuery() + .setTimeout(2000) + .setAccountId(account) + .execute(env.client); + + expect(balances.tokens.get(token).toInt()).to.be.equal(0); + + const info = await new AccountInfoQuery() + .setAccountId(account) + .execute(env.client); + + const relationship = info.tokenRelationships.get(token); + + expect(relationship).to.be.not.null; + expect(relationship.tokenId.toString()).to.be.equal(token.toString()); + expect(relationship.balance.toInt()).to.be.equal(0); + expect(relationship.isKycGranted).to.be.false; + expect(relationship.isFrozen).to.be.false; + }); it("should be executable even when no token IDs are set", async function () { this.timeout(120000); diff --git a/test/integration/TokenBurnIntegrationTest.js b/test/integration/TokenBurnIntegrationTest.js index 5c7fae214..0efaeb0c6 100644 --- a/test/integration/TokenBurnIntegrationTest.js +++ b/test/integration/TokenBurnIntegrationTest.js @@ -4,7 +4,7 @@ import { TokenCreateTransaction, TokenSupplyType, TokenType, - // AccountBalanceQuery, + AccountBalanceQuery, } from "../../src/exports.js"; import IntegrationTestEnv from "./client/NodeIntegrationTestEnv.js"; @@ -65,57 +65,53 @@ describe("TokenBurn", function () { } }); - /** - * - * @description The test is temporarily commented because AccountBalanceQuery does a query to the consensus node which was deprecated. - * @todo Uncomment a test when the new query to the mirror node is implemented as it described here https://github.com/hashgraph/hedera-sdk-reference/issues/144 - */ - // it("should not error when amount is not set", async function () { - // this.timeout(120000); - - // const operatorId = env.operatorId; - // const operatorKey = env.operatorKey.publicKey; - - // const response = await new TokenCreateTransaction() - // .setTokenName("ffff") - // .setTokenSymbol("F") - // .setDecimals(3) - // .setInitialSupply(1000000) - // .setTreasuryAccountId(operatorId) - // .setAdminKey(operatorKey) - // .setKycKey(operatorKey) - // .setFreezeKey(operatorKey) - // .setWipeKey(operatorKey) - // .setSupplyKey(operatorKey) - // .setFreezeDefault(false) - // .execute(env.client); - - // const token = (await response.getReceipt(env.client)).tokenId; - - // let err = false; - - // try { - // await ( - // await new TokenBurnTransaction() - // .setTokenId(token) - // .execute(env.client) - // ).getReceipt(env.client); - // } catch (error) { - // err = error; - // } - - // const accountBalance = await new AccountBalanceQuery() - // .setAccountId(operatorId) - // .execute(env.client); - - // expect( - // accountBalance.tokens._map.get(token.toString()).toNumber(), - // ).to.be.equal(1000000); - - // if (err) { - // throw new Error("token burn did error"); - // } - // }); + it("should not error when amount is not set", async function () { + this.timeout(120000); + + const operatorId = env.operatorId; + const operatorKey = env.operatorKey.publicKey; + + const response = await new TokenCreateTransaction() + .setTokenName("ffff") + .setTokenSymbol("F") + .setDecimals(3) + .setInitialSupply(1000000) + .setTreasuryAccountId(operatorId) + .setAdminKey(operatorKey) + .setKycKey(operatorKey) + .setFreezeKey(operatorKey) + .setWipeKey(operatorKey) + .setSupplyKey(operatorKey) + .setFreezeDefault(false) + .execute(env.client); + + const token = (await response.getReceipt(env.client)).tokenId; + + let err = false; + + try { + await ( + await new TokenBurnTransaction() + .setTokenId(token) + .execute(env.client) + ).getReceipt(env.client); + } catch (error) { + err = error; + } + + const accountBalance = await new AccountBalanceQuery() + .setTimeout(1000) + .setAccountId(operatorId) + .execute(env.client); + + expect( + accountBalance.tokens._map.get(token.toString()).toNumber(), + ).to.be.equal(1000000); + + if (err) { + throw new Error("token burn did error"); + } + }); it("cannot burn token with invalid metadata", async function () { this.timeout(120000); diff --git a/test/integration/TokenDissociateIntegrationTest.js b/test/integration/TokenDissociateIntegrationTest.js index 5b1e29414..5757a670f 100644 --- a/test/integration/TokenDissociateIntegrationTest.js +++ b/test/integration/TokenDissociateIntegrationTest.js @@ -1,8 +1,8 @@ import { - // AccountBalanceQuery, + AccountBalanceQuery, AccountCreateTransaction, - // AccountInfoQuery, - // Hbar, + AccountInfoQuery, + Hbar, PrivateKey, Status, TokenAssociateTransaction, @@ -23,93 +23,92 @@ describe("TokenDissociate", function () { env = await IntegrationTestEnv.new(); }); - /** - * - * @description The test is temporarily commented because AccountBalanceQuery does a query to the consensus node which was deprecated. - * @todo Uncomment a test when the new query to the mirror node is implemented as it described here https://github.com/hashgraph/hedera-sdk-reference/issues/144 - */ - // it("should be executable", async function () { - // this.timeout(120000); - - // const operatorId = env.operatorId; - // const operatorKey = env.operatorKey.publicKey; - // const key = PrivateKey.generateED25519(); - - // const response = await new AccountCreateTransaction() - // .setKey(key) - // .setInitialBalance(new Hbar(2)) - // .execute(env.client); - - // const account = (await response.getReceipt(env.client)).accountId; - - // const token = ( - // await ( - // await new TokenCreateTransaction() - // .setTokenName("ffff") - // .setTokenSymbol("F") - // .setDecimals(3) - // .setInitialSupply(1000000) - // .setTreasuryAccountId(operatorId) - // .setAdminKey(operatorKey) - // .setKycKey(operatorKey) - // .setFreezeKey(operatorKey) - // .setWipeKey(operatorKey) - // .setSupplyKey(operatorKey) - // .setFreezeDefault(false) - // .execute(env.client) - // ).getReceipt(env.client) - // ).tokenId; - - // await ( - // await ( - // await new TokenAssociateTransaction() - // .setTokenIds([token]) - // .setAccountId(account) - // .freezeWith(env.client) - // .sign(key) - // ).execute(env.client) - // ).getReceipt(env.client); - - // let balances = await new AccountBalanceQuery() - // .setAccountId(account) - // .execute(env.client); - - // expect(balances.tokens.get(token).toInt()).to.be.equal(0); - - // let info = await new AccountInfoQuery() - // .setAccountId(account) - // .execute(env.client); - - // const relationship = info.tokenRelationships.get(token); - - // expect(relationship).to.be.not.null; - // expect(relationship.tokenId.toString()).to.be.equal(token.toString()); - // expect(relationship.balance.toInt()).to.be.equal(0); - // expect(relationship.isKycGranted).to.be.false; - // expect(relationship.isFrozen).to.be.false; - - // await ( - // await ( - // await new TokenDissociateTransaction() - // .setTokenIds([token]) - // .setAccountId(account) - // .freezeWith(env.client) - // .sign(key) - // ).execute(env.client) - // ).getReceipt(env.client); - - // balances = await new AccountBalanceQuery() - // .setAccountId(account) - // .execute(env.client); - - // expect(balances.tokens.get(token)).to.be.null; - - // info = await new AccountInfoQuery() - // .setAccountId(account) - // .execute(env.client); - - // expect(info.tokenRelationships.get(token)).to.be.null; - // }); + it("should be executable", async function () { + this.timeout(120000); + + const operatorId = env.operatorId; + const operatorKey = env.operatorKey.publicKey; + const key = PrivateKey.generateED25519(); + + const response = await new AccountCreateTransaction() + .setKey(key) + .setInitialBalance(new Hbar(2)) + .execute(env.client); + + const account = (await response.getReceipt(env.client)).accountId; + + const token = ( + await ( + await new TokenCreateTransaction() + .setTokenName("ffff") + .setTokenSymbol("F") + .setDecimals(3) + .setInitialSupply(1000000) + .setTreasuryAccountId(operatorId) + .setAdminKey(operatorKey) + .setKycKey(operatorKey) + .setFreezeKey(operatorKey) + .setWipeKey(operatorKey) + .setSupplyKey(operatorKey) + .setFreezeDefault(false) + .execute(env.client) + ).getReceipt(env.client) + ).tokenId; + + await ( + await ( + await new TokenAssociateTransaction() + .setTokenIds([token]) + .setAccountId(account) + .freezeWith(env.client) + .sign(key) + ).execute(env.client) + ).getReceipt(env.client); + + let balances = await new AccountBalanceQuery() + .setTimeout(2000) + .setAccountId(account) + .execute(env.client); + + expect(balances.tokens.get(token).toInt()).to.be.equal(0); + + let info = await new AccountInfoQuery() + .setTimeout(1000) + .setAccountId(account) + .execute(env.client); + + const relationship = info.tokenRelationships.get(token); + + expect(relationship).to.be.not.null; + expect(relationship.tokenId.toString()).to.be.equal(token.toString()); + expect(relationship.balance.toInt()).to.be.equal(0); + expect(relationship.isKycGranted).to.be.false; + expect(relationship.isFrozen).to.be.false; + + await ( + await ( + await new TokenDissociateTransaction() + .setTokenIds([token]) + .setAccountId(account) + .freezeWith(env.client) + .sign(key) + ).execute(env.client) + ).getReceipt(env.client); + + balances = await new AccountBalanceQuery() + .setTimeout(1000) + .setAccountId(account) + .execute(env.client); + + expect(balances.tokens.get(token)).to.be.null; + + info = await new AccountInfoQuery() + .setTimeout(1000) + .setAccountId(account) + .execute(env.client); + + expect(info.tokenRelationships.get(token)).to.be.null; + }); it("should be executable even when no token IDs are set", async function () { this.timeout(120000); diff --git a/test/integration/TokenFreezeIntegrationTest.js b/test/integration/TokenFreezeIntegrationTest.js index f35aed9b6..a42f0af6a 100644 --- a/test/integration/TokenFreezeIntegrationTest.js +++ b/test/integration/TokenFreezeIntegrationTest.js @@ -1,10 +1,10 @@ import { AccountCreateTransaction, - // AccountInfoQuery, + AccountInfoQuery, Hbar, PrivateKey, Status, - // TokenAssociateTransaction, + TokenAssociateTransaction, TokenCreateTransaction, TokenFreezeTransaction, } from "../../src/exports.js"; @@ -17,75 +17,71 @@ describe("TokenFreeze", function () { env = await IntegrationTestEnv.new(); }); - /** - * - * @description The test is temporarily commented because AccountInfoQuery does a query to the consensus node which was deprecated. - * @todo Uncomment a test when the new query to the mirror node is implemented as it described here https://github.com/hashgraph/hedera-sdk-reference/issues/144 - */ - // it("should be executable", async function () { - // this.timeout(120000); - - // const operatorId = env.operatorId; - // const operatorKey = env.operatorKey.publicKey; - // const key = PrivateKey.generateED25519(); - - // const response = await new AccountCreateTransaction() - // .setKey(key) - // .setInitialBalance(new Hbar(2)) - // .execute(env.client); - - // const account = (await response.getReceipt(env.client)).accountId; - - // const token = ( - // await ( - // await new TokenCreateTransaction() - // .setTokenName("ffff") - // .setTokenSymbol("F") - // .setDecimals(3) - // .setInitialSupply(1000000) - // .setTreasuryAccountId(operatorId) - // .setAdminKey(operatorKey) - // .setKycKey(operatorKey) - // .setFreezeKey(operatorKey) - // .setWipeKey(operatorKey) - // .setSupplyKey(operatorKey) - // .setFreezeDefault(false) - // .execute(env.client) - // ).getReceipt(env.client) - // ).tokenId; - - // await ( - // await ( - // await new TokenAssociateTransaction() - // .setTokenIds([token]) - // .setAccountId(account) - // .freezeWith(env.client) - // .sign(key) - // ).execute(env.client) - // ).getReceipt(env.client); - - // await ( - // await ( - // await new TokenFreezeTransaction() - // .setTokenId(token) - // .setAccountId(account) - // .freezeWith(env.client) - // .sign(key) - // ).execute(env.client) - // ).getReceipt(env.client); - - // const info = await new AccountInfoQuery() - // .setAccountId(account) - // .execute(env.client); - - // const relationship = info.tokenRelationships.get(token); - - // expect(relationship).to.be.not.null; - // expect(relationship.tokenId.toString()).to.be.equal(token.toString()); - // expect(relationship.balance.toInt()).to.be.equal(0); - // expect(relationship.isKycGranted).to.be.false; - // expect(relationship.isFrozen).to.be.true; - // }); + it("should be executable", async function () { + this.timeout(120000); + + const operatorId = env.operatorId; + const operatorKey = env.operatorKey.publicKey; + const key = PrivateKey.generateED25519(); + + const response = await new AccountCreateTransaction() + .setKey(key) + .setInitialBalance(new Hbar(2)) + .execute(env.client); + + const account = (await response.getReceipt(env.client)).accountId; + + const token = ( + await ( + await new TokenCreateTransaction() + .setTokenName("ffff") + .setTokenSymbol("F") + .setDecimals(3) + .setInitialSupply(1000000) + .setTreasuryAccountId(operatorId) + .setAdminKey(operatorKey) + .setKycKey(operatorKey) + .setFreezeKey(operatorKey) + .setWipeKey(operatorKey) + .setSupplyKey(operatorKey) + .setFreezeDefault(false) + .execute(env.client) + ).getReceipt(env.client) + ).tokenId; + + await ( + await ( + await new TokenAssociateTransaction() + .setTokenIds([token]) + .setAccountId(account) + .freezeWith(env.client) + .sign(key) + ).execute(env.client) + ).getReceipt(env.client); + + await ( + await ( + await new TokenFreezeTransaction() + .setTokenId(token) + .setAccountId(account) + .freezeWith(env.client) + .sign(key) + ).execute(env.client) + ).getReceipt(env.client); + + const info = await new AccountInfoQuery() + .setTimeout(1000) + .setAccountId(account) + .execute(env.client); + + const relationship = info.tokenRelationships.get(token); + + expect(relationship).to.be.not.null; + expect(relationship.tokenId.toString()).to.be.equal(token.toString()); + expect(relationship.balance.toInt()).to.be.equal(0); + expect(relationship.isKycGranted).to.be.false; + expect(relationship.isFrozen).to.be.true; + }); it("should be executable with no tokens set", async function () { this.timeout(120000); diff --git a/test/integration/TokenGrantKycIntegrationTest.js b/test/integration/TokenGrantKycIntegrationTest.js index 2fa40851b..5000cee76 100644 --- a/test/integration/TokenGrantKycIntegrationTest.js +++ b/test/integration/TokenGrantKycIntegrationTest.js @@ -1,10 +1,10 @@ import { AccountCreateTransaction, - // AccountInfoQuery, + AccountInfoQuery, Hbar, PrivateKey, Status, - // TokenAssociateTransaction, + TokenAssociateTransaction, TokenCreateTransaction, TokenGrantKycTransaction, } from "../../src/exports.js"; @@ -17,75 +17,71 @@ describe("TokenGrantKyc", function () { env = await IntegrationTestEnv.new(); }); - /** - * - * @description The test is temporarily commented because AccountInfoQuery does a query to the consensus node which was deprecated. - * @todo Uncomment a test when the new query to the mirror node is implemented as it described here https://github.com/hashgraph/hedera-sdk-reference/issues/144 - */ - // it("should be executable", async function () { - // this.timeout(120000); - - // const operatorId = env.operatorId; - // const operatorKey = env.operatorKey.publicKey; - // const key = PrivateKey.generateED25519(); - - // const response = await new AccountCreateTransaction() - // .setKey(key) - // .setInitialBalance(new Hbar(2)) - // .execute(env.client); - - // const account = (await response.getReceipt(env.client)).accountId; - - // const token = ( - // await ( - // await new TokenCreateTransaction() - // .setTokenName("ffff") - // .setTokenSymbol("F") - // .setDecimals(3) - // .setInitialSupply(1000000) - // .setTreasuryAccountId(operatorId) - // .setAdminKey(operatorKey) - // .setKycKey(operatorKey) - // .setFreezeKey(operatorKey) - // .setWipeKey(operatorKey) - // .setSupplyKey(operatorKey) - // .setFreezeDefault(false) - // .execute(env.client) - // ).getReceipt(env.client) - // ).tokenId; - - // await ( - // await ( - // await new TokenAssociateTransaction() - // .setTokenIds([token]) - // .setAccountId(account) - // .freezeWith(env.client) - // .sign(key) - // ).execute(env.client) - // ).getReceipt(env.client); - - // await ( - // await ( - // await new TokenGrantKycTransaction() - // .setTokenId(token) - // .setAccountId(account) - // .freezeWith(env.client) - // .sign(key) - // ).execute(env.client) - // ).getReceipt(env.client); - - // const info = await new AccountInfoQuery() - // .setAccountId(account) - // .execute(env.client); - - // const relationship = info.tokenRelationships.get(token); - - // expect(relationship).to.be.not.null; - // expect(relationship.tokenId.toString()).to.be.equal(token.toString()); - // expect(relationship.balance.toInt()).to.be.equal(0); - // expect(relationship.isKycGranted).to.be.true; - // expect(relationship.isFrozen).to.be.false; - // }); + it("should be executable", async function () { + this.timeout(120000); + + const operatorId = env.operatorId; + const operatorKey = env.operatorKey.publicKey; + const key = PrivateKey.generateED25519(); + + const response = await new AccountCreateTransaction() + .setKey(key) + .setInitialBalance(new Hbar(2)) + .execute(env.client); + + const account = (await response.getReceipt(env.client)).accountId; + + const token = ( + await ( + await new TokenCreateTransaction() + .setTokenName("ffff") + .setTokenSymbol("F") + .setDecimals(3) + .setInitialSupply(1000000) + .setTreasuryAccountId(operatorId) + .setAdminKey(operatorKey) + .setKycKey(operatorKey) + .setFreezeKey(operatorKey) + .setWipeKey(operatorKey) + .setSupplyKey(operatorKey) + .setFreezeDefault(false) + .execute(env.client) + ).getReceipt(env.client) + ).tokenId; + + await ( + await ( + await new TokenAssociateTransaction() + .setTokenIds([token]) + .setAccountId(account) + .freezeWith(env.client) + .sign(key) + ).execute(env.client) + ).getReceipt(env.client); + + await ( + await ( + await new TokenGrantKycTransaction() + .setTokenId(token) + .setAccountId(account) + .freezeWith(env.client) + .sign(key) + ).execute(env.client) + ).getReceipt(env.client); + + const info = await new AccountInfoQuery() + .setTimeout(1000) + .setAccountId(account) + .execute(env.client); + + const relationship = info.tokenRelationships.get(token); + + expect(relationship).to.be.not.null; + expect(relationship.tokenId.toString()).to.be.equal(token.toString()); + expect(relationship.balance.toInt()).to.be.equal(0); + expect(relationship.isKycGranted).to.be.true; + expect(relationship.isFrozen).to.be.false; + }); it("should be executable even when no token IDs are set", async function () { this.timeout(120000); diff --git a/test/integration/TokenRevokeKycIntegrationTest.js b/test/integration/TokenRevokeKycIntegrationTest.js index d1023d9fa..bb00867bc 100644 --- a/test/integration/TokenRevokeKycIntegrationTest.js +++ b/test/integration/TokenRevokeKycIntegrationTest.js @@ -1,12 +1,12 @@ import { AccountCreateTransaction, - // AccountInfoQuery, + AccountInfoQuery, Hbar, PrivateKey, Status, - // TokenAssociateTransaction, + TokenAssociateTransaction, TokenCreateTransaction, - // TokenGrantKycTransaction, + TokenGrantKycTransaction, TokenRevokeKycTransaction, } from "../../src/exports.js"; import IntegrationTestEnv from "./client/NodeIntegrationTestEnv.js"; @@ -18,97 +18,94 @@ describe("TokenRevokeKyc", function () { env = await IntegrationTestEnv.new(); }); - /** - * - * @description The test is temporarily commented because AccountInfoQuery does a query to the consensus node which was deprecated. - * @todo Uncomment a test when the new query to the mirror node is implemented as it described here https://github.com/hashgraph/hedera-sdk-reference/issues/144 - */ - // it("should be executable", async function () { - // this.timeout(120000); - - // const operatorId = env.operatorId; - // const operatorKey = env.operatorKey.publicKey; - // const key = PrivateKey.generateED25519(); - - // const response = await new AccountCreateTransaction() - // .setKey(key) - // .setInitialBalance(new Hbar(2)) - // .execute(env.client); - - // const account = (await response.getReceipt(env.client)).accountId; - - // const token = ( - // await ( - // await new TokenCreateTransaction() - // .setTokenName("ffff") - // .setTokenSymbol("F") - // .setDecimals(3) - // .setInitialSupply(1000000) - // .setTreasuryAccountId(operatorId) - // .setAdminKey(operatorKey) - // .setKycKey(operatorKey) - // .setFreezeKey(operatorKey) - // .setWipeKey(operatorKey) - // .setSupplyKey(operatorKey) - // .setFreezeDefault(false) - // .execute(env.client) - // ).getReceipt(env.client) - // ).tokenId; - - // await ( - // await ( - // await new TokenAssociateTransaction() - // .setTokenIds([token]) - // .setAccountId(account) - // .freezeWith(env.client) - // .sign(key) - // ).execute(env.client) - // ).getReceipt(env.client); - - // await ( - // await ( - // await new TokenGrantKycTransaction() - // .setTokenId(token) - // .setAccountId(account) - // .freezeWith(env.client) - // .sign(key) - // ).execute(env.client) - // ).getReceipt(env.client); - - // let info = await new AccountInfoQuery() - // .setAccountId(account) - // .execute(env.client); - - // let relationship = info.tokenRelationships.get(token); - - // expect(relationship).to.be.not.null; - // expect(relationship.tokenId.toString()).to.be.equal(token.toString()); - // expect(relationship.balance.toInt()).to.be.equal(0); - // expect(relationship.isKycGranted).to.be.true; - // expect(relationship.isFrozen).to.be.false; - - // await ( - // await ( - // await new TokenRevokeKycTransaction() - // .setTokenId(token) - // .setAccountId(account) - // .freezeWith(env.client) - // .sign(key) - // ).execute(env.client) - // ).getReceipt(env.client); - - // info = await new AccountInfoQuery() - // .setAccountId(account) - // .execute(env.client); - - // relationship = info.tokenRelationships.get(token); - - // expect(relationship).to.be.not.null; - // expect(relationship.tokenId.toString()).to.be.equal(token.toString()); - // expect(relationship.balance.toInt()).to.be.equal(0); - // expect(relationship.isKycGranted).to.be.false; - // expect(relationship.isFrozen).to.be.false; - // }); + it("should be executable", async function () { + this.timeout(120000); + + const operatorId = env.operatorId; + const operatorKey = env.operatorKey.publicKey; + const key = PrivateKey.generateED25519(); + + const response = await new AccountCreateTransaction() + .setKey(key) + .setInitialBalance(new Hbar(2)) + .execute(env.client); + + const account = (await response.getReceipt(env.client)).accountId; + + const token = ( + await ( + await new TokenCreateTransaction() + .setTokenName("ffff") + .setTokenSymbol("F") + .setDecimals(3) + .setInitialSupply(1000000) + .setTreasuryAccountId(operatorId) + .setAdminKey(operatorKey) + .setKycKey(operatorKey) + .setFreezeKey(operatorKey) + .setWipeKey(operatorKey) + .setSupplyKey(operatorKey) + .setFreezeDefault(false) + .execute(env.client) + ).getReceipt(env.client) + ).tokenId; + + await ( + await ( + await new TokenAssociateTransaction() + .setTokenIds([token]) + .setAccountId(account) + .freezeWith(env.client) + .sign(key) + ).execute(env.client) + ).getReceipt(env.client); + + await ( + await ( + await new TokenGrantKycTransaction() + .setTokenId(token) + .setAccountId(account) + .freezeWith(env.client) + .sign(key) + ).execute(env.client) + ).getReceipt(env.client); + + let info = await new AccountInfoQuery() + .setTimeout(2000) + .setAccountId(account) + .execute(env.client); + + let relationship = info.tokenRelationships.get(token); + + expect(relationship).to.be.not.null; + expect(relationship.tokenId.toString()).to.be.equal(token.toString()); + expect(relationship.balance.toInt()).to.be.equal(0); + expect(relationship.isKycGranted).to.be.true; + expect(relationship.isFrozen).to.be.false; + + await ( + await ( + await new TokenRevokeKycTransaction() + .setTokenId(token) + .setAccountId(account) + .freezeWith(env.client) + .sign(key) + ).execute(env.client) + ).getReceipt(env.client); + + info = await new AccountInfoQuery() + .setTimeout(2000) + .setAccountId(account) + .execute(env.client); + + relationship = info.tokenRelationships.get(token); + + expect(relationship).to.be.not.null; + expect(relationship.tokenId.toString()).to.be.equal(token.toString()); + expect(relationship.balance.toInt()).to.be.equal(0); + expect(relationship.isKycGranted).to.be.false; + expect(relationship.isFrozen).to.be.false; + }); it("should be executable even when no token IDs are set", async function () { this.timeout(120000); diff --git a/test/integration/TokenTransferIntegrationTest.js b/test/integration/TokenTransferIntegrationTest.js index 4ee2605ba..0d059fc7c 100644 --- a/test/integration/TokenTransferIntegrationTest.js +++ b/test/integration/TokenTransferIntegrationTest.js @@ -340,6 +340,7 @@ describe("TokenTransfer", function () { const account = receipt.accountId; let info = await new AccountInfoQuery() + .setTimeout(1000) .setAccountId(account) .execute(env.client); @@ -356,6 +357,7 @@ describe("TokenTransfer", function () { ).getReceipt(env.client); info = await new AccountInfoQuery() + .setTimeout(1000) .setAccountId(account) .execute(env.client); diff --git a/test/integration/TokenUnfreezeIntegrationTest.js b/test/integration/TokenUnfreezeIntegrationTest.js index ec4390e8f..e6fa72bef 100644 --- a/test/integration/TokenUnfreezeIntegrationTest.js +++ b/test/integration/TokenUnfreezeIntegrationTest.js @@ -1,12 +1,12 @@ import { AccountCreateTransaction, - // AccountInfoQuery, + AccountInfoQuery, Hbar, PrivateKey, Status, - // TokenAssociateTransaction, + TokenAssociateTransaction, TokenCreateTransaction, - // TokenFreezeTransaction, + TokenFreezeTransaction, TokenUnfreezeTransaction, } from "../../src/exports.js"; import IntegrationTestEnv from "./client/NodeIntegrationTestEnv.js"; @@ -18,97 +18,94 @@ describe("TokenUnfreeze", function () { env = await IntegrationTestEnv.new(); }); - /** - * - * @description The test is temporarily commented because AccountInfoQuery does a query to the consensus node which was deprecated. - * @todo Uncomment a test when the new query to the mirror node is implemented as it described here https://github.com/hashgraph/hedera-sdk-reference/issues/144 - */ - // it("should be executable", async function () { - // this.timeout(120000); - - // const operatorId = env.operatorId; - // const operatorKey = env.operatorKey.publicKey; - // const key = PrivateKey.generateED25519(); - - // const response = await new AccountCreateTransaction() - // .setKey(key) - // .setInitialBalance(new Hbar(2)) - // .execute(env.client); - - // const account = (await response.getReceipt(env.client)).accountId; - - // const token = ( - // await ( - // await new TokenCreateTransaction() - // .setTokenName("ffff") - // .setTokenSymbol("F") - // .setDecimals(3) - // .setInitialSupply(1000000) - // .setTreasuryAccountId(operatorId) - // .setAdminKey(operatorKey) - // .setKycKey(operatorKey) - // .setFreezeKey(operatorKey) - // .setWipeKey(operatorKey) - // .setSupplyKey(operatorKey) - // .setFreezeDefault(false) - // .execute(env.client) - // ).getReceipt(env.client) - // ).tokenId; - - // await ( - // await ( - // await new TokenAssociateTransaction() - // .setTokenIds([token]) - // .setAccountId(account) - // .freezeWith(env.client) - // .sign(key) - // ).execute(env.client) - // ).getReceipt(env.client); - - // await ( - // await ( - // await new TokenFreezeTransaction() - // .setTokenId(token) - // .setAccountId(account) - // .freezeWith(env.client) - // .sign(key) - // ).execute(env.client) - // ).getReceipt(env.client); - - // let info = await new AccountInfoQuery() - // .setAccountId(account) - // .execute(env.client); - - // let relationship = info.tokenRelationships.get(token); - - // expect(relationship).to.be.not.null; - // expect(relationship.tokenId.toString()).to.be.equal(token.toString()); - // expect(relationship.balance.toInt()).to.be.equal(0); - // expect(relationship.isKycGranted).to.be.false; - // expect(relationship.isFrozen).to.be.true; - - // await ( - // await ( - // await new TokenUnfreezeTransaction() - // .setTokenId(token) - // .setAccountId(account) - // .freezeWith(env.client) - // .sign(key) - // ).execute(env.client) - // ).getReceipt(env.client); - - // info = await new AccountInfoQuery() - // .setAccountId(account) - // .execute(env.client); - - // relationship = info.tokenRelationships.get(token); - - // expect(relationship).to.be.not.null; - // expect(relationship.tokenId.toString()).to.be.equal(token.toString()); - // expect(relationship.balance.toInt()).to.be.equal(0); - // expect(relationship.isKycGranted).to.be.false; - // expect(relationship.isFrozen).to.be.false; - // }); + it("should be executable", async function () { + this.timeout(120000); + + const operatorId = env.operatorId; + const operatorKey = env.operatorKey.publicKey; + const key = PrivateKey.generateED25519(); + + const response = await new AccountCreateTransaction() + .setKey(key) + .setInitialBalance(new Hbar(2)) + .execute(env.client); + + const account = (await response.getReceipt(env.client)).accountId; + + const token = ( + await ( + await new TokenCreateTransaction() + .setTokenName("ffff") + .setTokenSymbol("F") + .setDecimals(3) + .setInitialSupply(1000000) + .setTreasuryAccountId(operatorId) + .setAdminKey(operatorKey) + .setKycKey(operatorKey) + .setFreezeKey(operatorKey) + .setWipeKey(operatorKey) + .setSupplyKey(operatorKey) + .setFreezeDefault(false) + .execute(env.client) + ).getReceipt(env.client) + ).tokenId; + + await ( + await ( + await new TokenAssociateTransaction() + .setTokenIds([token]) + .setAccountId(account) + .freezeWith(env.client) + .sign(key) + ).execute(env.client) + ).getReceipt(env.client); + + await ( + await ( + await new TokenFreezeTransaction() + .setTokenId(token) + .setAccountId(account) + .freezeWith(env.client) + .sign(key) + ).execute(env.client) + ).getReceipt(env.client); + + let info = await new AccountInfoQuery() + .setTimeout(2000) + .setAccountId(account) + .execute(env.client); + + let relationship = info.tokenRelationships.get(token); + + expect(relationship).to.be.not.null; + expect(relationship.tokenId.toString()).to.be.equal(token.toString()); + expect(relationship.balance.toInt()).to.be.equal(0); + expect(relationship.isKycGranted).to.be.false; + expect(relationship.isFrozen).to.be.true; + + await ( + await ( + await new TokenUnfreezeTransaction() + .setTokenId(token) + .setAccountId(account) + .freezeWith(env.client) + .sign(key) + ).execute(env.client) + ).getReceipt(env.client); + + info = await new AccountInfoQuery() + .setTimeout(2000) + .setAccountId(account) + .execute(env.client); + + relationship = info.tokenRelationships.get(token); + + expect(relationship).to.be.not.null; + expect(relationship.tokenId.toString()).to.be.equal(token.toString()); + expect(relationship.balance.toInt()).to.be.equal(0); + expect(relationship.isKycGranted).to.be.false; + expect(relationship.isFrozen).to.be.false; + }); it("should be executable even when no token IDs are set", async function () { this.timeout(120000); diff --git a/test/integration/TokenWipeIntegrationTest.js b/test/integration/TokenWipeIntegrationTest.js index f31d05bc7..4871ebbf8 100644 --- a/test/integration/TokenWipeIntegrationTest.js +++ b/test/integration/TokenWipeIntegrationTest.js @@ -1,6 +1,6 @@ import { AccountCreateTransaction, - // AccountInfoQuery, + AccountInfoQuery, Hbar, PrivateKey, Status, @@ -8,7 +8,7 @@ import { TokenCreateTransaction, TokenGrantKycTransaction, TokenWipeTransaction, - // TransferTransaction, + TransferTransaction, Transaction, } from "../../src/exports.js"; import IntegrationTestEnv from "./client/NodeIntegrationTestEnv.js"; @@ -21,102 +21,99 @@ describe("TokenWipe", function () { env = await IntegrationTestEnv.new(); }); - /** - * - * @description The test is temporarily commented because AccountInfoQuery does a query to the consensus node which was deprecated. - * @todo Uncomment a test when the new query to the mirror node is implemented as it described here https://github.com/hashgraph/hedera-sdk-reference/issues/144 - */ - // it("should be executable", async function () { - // this.timeout(120000); - - // const operatorId = env.operatorId; - // const operatorKey = env.operatorKey.publicKey; - // const key = PrivateKey.generateED25519(); - - // const response = await new AccountCreateTransaction() - // .setKey(key) - // .setInitialBalance(new Hbar(2)) - // .execute(env.client); - - // const account = (await response.getReceipt(env.client)).accountId; - - // const token = ( - // await ( - // await new TokenCreateTransaction() - // .setTokenName("ffff") - // .setTokenSymbol("F") - // .setDecimals(3) - // .setInitialSupply(1000000) - // .setTreasuryAccountId(operatorId) - // .setAdminKey(operatorKey) - // .setKycKey(operatorKey) - // .setFreezeKey(operatorKey) - // .setWipeKey(operatorKey) - // .setSupplyKey(operatorKey) - // .setFreezeDefault(false) - // .execute(env.client) - // ).getReceipt(env.client) - // ).tokenId; - - // await ( - // await ( - // await new TokenAssociateTransaction() - // .setTokenIds([token]) - // .setAccountId(account) - // .freezeWith(env.client) - // .sign(key) - // ).execute(env.client) - // ).getReceipt(env.client); - - // await ( - // await ( - // await new TokenGrantKycTransaction() - // .setTokenId(token) - // .setAccountId(account) - // .freezeWith(env.client) - // .sign(key) - // ).execute(env.client) - // ).getReceipt(env.client); - - // await ( - // await new TransferTransaction() - // .addTokenTransfer(token, account, 10) - // .addTokenTransfer(token, env.operatorId, -10) - // .execute(env.client) - // ).getReceipt(env.client); - - // let info = await new AccountInfoQuery() - // .setAccountId(account) - // .execute(env.client); - - // let relationship = info.tokenRelationships.get(token); - - // expect(relationship).to.be.not.null; - // expect(relationship.tokenId.toString()).to.be.equal(token.toString()); - // expect(relationship.balance.toInt()).to.be.equal(10); - // expect(relationship.isKycGranted).to.be.true; - // expect(relationship.isFrozen).to.be.false; - - // await ( - // await new TokenWipeTransaction() - // .setTokenId(token) - // .setAccountId(account) - // .setAmount(10) - // .execute(env.client) - // ).getReceipt(env.client); - - // info = await new AccountInfoQuery() - // .setAccountId(account) - // .execute(env.client); - - // relationship = info.tokenRelationships.get(token); - - // expect(relationship).to.be.not.null; - // expect(relationship.tokenId.toString()).to.be.equal(token.toString()); - // expect(relationship.balance.toInt()).to.be.equal(0); - // expect(relationship.isKycGranted).to.be.true; - // expect(relationship.isFrozen).to.be.false; - // }); + it("should be executable", async function () { + this.timeout(120000); + + const operatorId = env.operatorId; + const operatorKey = env.operatorKey.publicKey; + const key = PrivateKey.generateED25519(); + + const response = await new AccountCreateTransaction() + .setKey(key) + .setInitialBalance(new Hbar(2)) + .execute(env.client); + + const account = (await response.getReceipt(env.client)).accountId; + + const token = ( + await ( + await new TokenCreateTransaction() + .setTokenName("ffff") + .setTokenSymbol("F") + .setDecimals(3) + .setInitialSupply(1000000) + .setTreasuryAccountId(operatorId) + .setAdminKey(operatorKey) + .setKycKey(operatorKey) + .setFreezeKey(operatorKey) + .setWipeKey(operatorKey) + .setSupplyKey(operatorKey) + .setFreezeDefault(false) + .execute(env.client) + ).getReceipt(env.client) + ).tokenId; + + await ( + await ( + await new TokenAssociateTransaction() + .setTokenIds([token]) + .setAccountId(account) + .freezeWith(env.client) + .sign(key) + ).execute(env.client) + ).getReceipt(env.client); + + await ( + await ( + await new TokenGrantKycTransaction() + .setTokenId(token) + .setAccountId(account) + .freezeWith(env.client) + .sign(key) + ).execute(env.client) + ).getReceipt(env.client); + + await ( + await new TransferTransaction() + .addTokenTransfer(token, account, 10) + .addTokenTransfer(token, env.operatorId, -10) + .execute(env.client) + ).getReceipt(env.client); + + let info = await new AccountInfoQuery() + .setTimeout(1000) + .setAccountId(account) + .execute(env.client); + + let relationship = info.tokenRelationships.get(token); + + expect(relationship).to.be.not.null; + expect(relationship.tokenId.toString()).to.be.equal(token.toString()); + expect(relationship.balance.toInt()).to.be.equal(10); + expect(relationship.isKycGranted).to.be.true; + expect(relationship.isFrozen).to.be.false; + + await ( + await new TokenWipeTransaction() + .setTokenId(token) + .setAccountId(account) + .setAmount(10) + .execute(env.client) + ).getReceipt(env.client); + + info = await new AccountInfoQuery() + .setTimeout(1000) + .setAccountId(account) + .execute(env.client); + + relationship = info.tokenRelationships.get(token); + + expect(relationship).to.be.not.null; + expect(relationship.tokenId.toString()).to.be.equal(token.toString()); + expect(relationship.balance.toInt()).to.be.equal(0); + expect(relationship.isKycGranted).to.be.true; + expect(relationship.isFrozen).to.be.false; + }); it("should error when token ID is not set", async function () { this.timeout(120000); From a1bfa7eee927876359f2f3388259317b69a75f7b Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Mon, 27 May 2024 14:12:33 +0300 Subject: [PATCH 06/49] remove logs Signed-off-by: svetoslav-nikol0v --- src/client/ManagedNetwork.js | 1 - .../AccountBalanceIntegrationTest.js | 30 +++++++++--------- .../AccountCreateIntegrationTest.js | 18 +++++------ .../AccountDeleteIntegrationTest.js | 2 +- .../integration/AccountInfoIntegrationTest.js | 4 +-- .../AccountUpdateIntegrationTest.js | 2 +- test/integration/ClientIntegrationTest.js | 16 ++++++---- .../ContractCreateIntegrationTest.js | 2 +- ...ntractFunctionParametersIntegrationTest.js | 21 ++----------- .../ContractInfoIntegrationTest.js | 5 +-- .../ContractUpdateIntegrationTest.js | 4 +-- test/integration/CustomFeesIntegrationTest.js | 1 - test/integration/GetCostIntegrationTest.js | 10 +++--- .../ScheduleCreateIntegrationTest.js | 4 +-- .../TokenAllowancesIntegrationTest.js | 31 +++---------------- .../TokenAssociateIntegrationTest.js | 2 +- test/integration/TokenBurnIntegrationTest.js | 2 +- .../TokenDissociateIntegrationTest.js | 8 ++--- .../integration/TokenFreezeIntegrationTest.js | 2 +- .../TokenGrantKycIntegrationTest.js | 2 +- .../TokenRevokeKycIntegrationTest.js | 4 +-- .../TokenTransferIntegrationTest.js | 4 +-- .../TokenUnfreezeIntegrationTest.js | 4 +-- test/integration/TokenWipeIntegrationTest.js | 4 +-- .../TopicMessageIntegrationTest.js | 21 +++++++------ test/integration/TopicMessageQueryTest.js | 23 ++++++++------ .../TransactionRecordIntegrationTest.js | 7 +---- test/unit/TransactionReceipt.js | 1 - test/unit/TransactionRecord.js | 2 -- test/unit/TransactionResponse.js | 2 -- 30 files changed, 100 insertions(+), 139 deletions(-) diff --git a/src/client/ManagedNetwork.js b/src/client/ManagedNetwork.js index ab795846e..7a310353f 100644 --- a/src/client/ManagedNetwork.js +++ b/src/client/ManagedNetwork.js @@ -329,7 +329,6 @@ export default class ManagedNetwork { this._nodes = newNodes; this._healthyNodes = newHealthyNodes; this._network = newNetwork; - this._ledgerId = null; return this; } diff --git a/test/integration/AccountBalanceIntegrationTest.js b/test/integration/AccountBalanceIntegrationTest.js index af8f4b7d9..a97d22d9f 100644 --- a/test/integration/AccountBalanceIntegrationTest.js +++ b/test/integration/AccountBalanceIntegrationTest.js @@ -29,10 +29,8 @@ describe("AccountBalanceQuery", function () { expect(balance.hbars.toTinybars().compare(0)).to.be.equal(1); }); - // TODO(2023-11-01 NK) - test is consistently failing and should be enabled once fixed. - // eslint-disable-next-line mocha/no-skipped-tests - xit("can connect to previewnet with TLS", async function () { - this.timeout(30000); + it("can connect to previewnet with TLS", async function () { + this.timeout(120000); if (skipTestDueToNodeJsVersion(16)) { return; } @@ -42,16 +40,18 @@ describe("AccountBalanceQuery", function () { )) { expect(address.endsWith(":50212")).to.be.true; - await new AccountBalanceQuery() - .setTimeout(1000) + const balance = await new AccountBalanceQuery() + .setTimeout(3000) .setAccountId(nodeAccountId) .setMaxAttempts(10) .execute(clientPreviewNet); + + expect(balance.hbars).to.not.be.null; } }); it("can connect to testnet with TLS", async function () { - this.timeout(30000); + this.timeout(120000); if (skipTestDueToNodeJsVersion(16)) { return; @@ -62,11 +62,13 @@ describe("AccountBalanceQuery", function () { )) { expect(address.endsWith(":50212")).to.be.true; - await new AccountBalanceQuery() - .setTimeout(1000) - .setAccountId(nodeAccountId) - .setMaxAttempts(10) - .execute(clientTestnet); + const balance = await new AccountBalanceQuery() + .setTimeout(3000) + .setAccountId(nodeAccountId) + .setMaxAttempts(10) + .execute(clientTestnet); + + expect(balance.hbars).to.not.be.null; } }); @@ -89,7 +91,7 @@ describe("AccountBalanceQuery", function () { }); it("should reflect token with no keys", async function () { - this.timeout(120000); + this.timeout(30000); const operatorId = env.operatorId; @@ -104,7 +106,7 @@ describe("AccountBalanceQuery", function () { ).tokenId; const balances = await new AccountBalanceQuery() - .setTimeout(2000) + .setTimeout(3000) .setAccountId(env.operatorId) .execute(env.client); diff --git a/test/integration/AccountCreateIntegrationTest.js b/test/integration/AccountCreateIntegrationTest.js index ffb1385a2..4212b000c 100644 --- a/test/integration/AccountCreateIntegrationTest.js +++ b/test/integration/AccountCreateIntegrationTest.js @@ -35,7 +35,7 @@ describe("AccountCreate", function () { const account = receipt.accountId; const info = await new AccountInfoQuery() - .setTimeout(1000) + .setTimeout(3000) .setAccountId(account) .execute(env.client); @@ -77,7 +77,7 @@ describe("AccountCreate", function () { const account = receipt.accountId; const info = await new AccountInfoQuery() - .setTimeout(2000) + .setTimeout(3000) .setNodeAccountIds([response.nodeId]) .setAccountId(account) .execute(env.client); @@ -119,7 +119,7 @@ describe("AccountCreate", function () { const account = receipt.accountId; const info = await new AccountInfoQuery() - .setTimeout(1000) + .setTimeout(3000) .setAccountId(account) .execute(env.client); @@ -176,7 +176,7 @@ describe("AccountCreate", function () { const account = receipt.accountId; const info = await new AccountInfoQuery() - .setTimeout(1000) + .setTimeout(3000) .setNodeAccountIds([response.nodeId]) .setAccountId(account) .execute(env.client); @@ -222,7 +222,7 @@ describe("AccountCreate", function () { expect(accountId).to.not.be.null; const info = await new AccountInfoQuery() - .setTimeout(1000) + .setTimeout(3000) .setNodeAccountIds([txAccountCreate.nodeId]) .setAccountId(accountId) .execute(env.client); @@ -260,7 +260,7 @@ describe("AccountCreate", function () { expect(accountId).to.not.be.null; const info = await new AccountInfoQuery() - .setTimeout(2000) + .setTimeout(3000) .setAccountId(accountId) .execute(env.client); @@ -302,7 +302,7 @@ describe("AccountCreate", function () { expect(accountId).to.not.be.null; const info = await new AccountInfoQuery() - .setTimeout(1000) + .setTimeout(3000) .setAccountId(accountId) .execute(env.client); @@ -376,7 +376,7 @@ describe("AccountCreate", function () { expect(accountId).to.not.be.null; const info = await new AccountInfoQuery() - .setTimeout(1000) + .setTimeout(3000) .setAccountId(accountId) .execute(env.client); @@ -455,7 +455,7 @@ describe("AccountCreate", function () { expect(accountId).to.not.be.null; const info = await new AccountInfoQuery() - .setTimeout(1000) + .setTimeout(3000) .setAccountId(accountId) .execute(env.client); diff --git a/test/integration/AccountDeleteIntegrationTest.js b/test/integration/AccountDeleteIntegrationTest.js index 9fd932bae..dde84807f 100644 --- a/test/integration/AccountDeleteIntegrationTest.js +++ b/test/integration/AccountDeleteIntegrationTest.js @@ -33,7 +33,7 @@ describe("AccountDelete", function () { const account = receipt.accountId; const info = await new AccountInfoQuery() - .setTimeout(1000) + .setTimeout(3000) .setAccountId(account) .execute(env.client); diff --git a/test/integration/AccountInfoIntegrationTest.js b/test/integration/AccountInfoIntegrationTest.js index 267b316b7..34f455117 100644 --- a/test/integration/AccountInfoIntegrationTest.js +++ b/test/integration/AccountInfoIntegrationTest.js @@ -86,7 +86,7 @@ describe("AccountInfo", function () { const account = receipt.accountId; const info = await new AccountInfoQuery() - .setTimeout(1000) + .setTimeout(3000) .setAccountId(account) .execute(env.client); @@ -171,7 +171,7 @@ describe("AccountInfo", function () { ).tokenId; const info = await new AccountInfoQuery() - .setTimeout(1000) + .setTimeout(3000) .setAccountId(operatorId) .execute(env.client); diff --git a/test/integration/AccountUpdateIntegrationTest.js b/test/integration/AccountUpdateIntegrationTest.js index ee421deb4..cc987ae17 100644 --- a/test/integration/AccountUpdateIntegrationTest.js +++ b/test/integration/AccountUpdateIntegrationTest.js @@ -39,7 +39,7 @@ describe("AccountUpdate", function () { const account = receipt.accountId; let info = await new AccountInfoQuery() - .setTimeout(1000) + .setTimeout(3000) .setAccountId(account) .execute(env.client); diff --git a/test/integration/ClientIntegrationTest.js b/test/integration/ClientIntegrationTest.js index eba0cd99f..d650d483c 100644 --- a/test/integration/ClientIntegrationTest.js +++ b/test/integration/ClientIntegrationTest.js @@ -30,16 +30,18 @@ describe("ClientIntegration", function () { let err = false; - let network; switch (env.client.ledgerId.toString()) { case "mainnet": - network = "testnet"; + env.client.setLedgerId(LedgerId.TESTNET); break; case "testnet": - network = "previewnet"; + env.client.setLedgerId(LedgerId.PREVIEWNET); break; case "previewnet": - network = "mainnet"; + env.client.setLedgerId(LedgerId.LOCAL_NODE); + break; + case "local-node": + env.client.setLedgerId(LedgerId.MAINNET); break; default: throw new Error( @@ -47,10 +49,11 @@ describe("ClientIntegration", function () { ); } - const accountId = AccountId.withNetwork(3, network); + const accountId = new AccountId(3); try { await new AccountInfoQuery() + .setTimeout(3000) .setAccountId(accountId) .execute(env.client); } catch (error) { @@ -81,10 +84,11 @@ describe("ClientIntegration", function () { const account = receipt.accountId; const info = await new AccountInfoQuery() - .setTimeout(1000) + .setTimeout(3000) .setAccountId(account) .execute(env.client); + expect(info).to.not.be.null; expect(info.accountId.toString()).to.be.equal(account.toString()); expect(info.isDeleted).to.be.false; expect(info.key.toString()).to.be.equal(key.publicKey.toString()); diff --git a/test/integration/ContractCreateIntegrationTest.js b/test/integration/ContractCreateIntegrationTest.js index b2089138e..627a364f2 100644 --- a/test/integration/ContractCreateIntegrationTest.js +++ b/test/integration/ContractCreateIntegrationTest.js @@ -58,7 +58,7 @@ describe("ContractCreate", function () { let contract = receipt.contractId; let info = await new ContractInfoQuery() - .setTimeout(1000) + .setTimeout(3000) .setContractId(contract) .setQueryPayment(new Hbar(1)) .execute(env.client); diff --git a/test/integration/ContractFunctionParametersIntegrationTest.js b/test/integration/ContractFunctionParametersIntegrationTest.js index 990919d2a..b7ca08978 100644 --- a/test/integration/ContractFunctionParametersIntegrationTest.js +++ b/test/integration/ContractFunctionParametersIntegrationTest.js @@ -132,7 +132,6 @@ describe("ContractFunctionParameters", function () { const fileCreateSubmit = await fileCreateSign.execute(env.client); const fileCreateRx = await fileCreateSubmit.getReceipt(env.client); const bytecodeFileId = fileCreateRx.fileId; - console.log(`- The bytecode file ID is: ${bytecodeFileId} \n`); //Append contents to the file const fileAppendTx = new FileAppendTransaction() @@ -142,11 +141,7 @@ describe("ContractFunctionParameters", function () { .freezeWith(env.client); const fileAppendSign = await fileAppendTx.sign(env.operatorKey); const fileAppendSubmit = await fileAppendSign.execute(env.client); - const fileAppendRx = await fileAppendSubmit.getReceipt(env.client); - console.log( - "Status of file append is", - fileAppendRx.status.toString(10), - ); + await fileAppendSubmit.getReceipt(env.client); // Instantiate the contract instance const contractTx = new ContractCreateTransaction() @@ -165,9 +160,6 @@ describe("ContractFunctionParameters", function () { //Get the smart contract ID newContractId = contractReceipt.contractId; - - //Log the smart contract ID - console.log("The smart contract ID is " + newContractId); }); bitSizes.forEach((bitSize) => { @@ -1018,7 +1010,6 @@ describe("ContractFunctionParameters", function () { const contractCreateRecord = await contractCreate.getRecord(env.client); const nonces = contractCreateRecord.contractFunctionResult.contractNonces; - console.log(`contractNonces: ${JSON.stringify(nonces)}`); const contractId = contractCreateRecord.receipt.contractId; const contractAnonce = nonces.find( @@ -1038,19 +1029,13 @@ describe("ContractFunctionParameters", function () { .setContractId(contractId) .execute(env.client); - const contractDeleteResult = await contractDeleteTx.getReceipt( - env.client, - ); - console.log( - `contractDelete status: ${contractDeleteResult.status.toString()}`, - ); + await contractDeleteTx.getReceipt(env.client); const fileDeleteTx = await new FileDeleteTransaction() .setFileId(fileId) .execute(env.client); - const fileDeleteResult = await fileDeleteTx.getReceipt(env.client); - console.log(`fileDelete status: ${fileDeleteResult.status.toString()}`); + await fileDeleteTx.getReceipt(env.client); }); after(async function () { diff --git a/test/integration/ContractInfoIntegrationTest.js b/test/integration/ContractInfoIntegrationTest.js index 4760068ed..4af8e4ef0 100644 --- a/test/integration/ContractInfoIntegrationTest.js +++ b/test/integration/ContractInfoIntegrationTest.js @@ -19,6 +19,7 @@ describe("ContractInfo", function () { before(async function () { env = await IntegrationTestEnv.new(); }); + it("should be executable", async function () { this.timeout(120000); @@ -57,7 +58,7 @@ describe("ContractInfo", function () { let contract = receipt.contractId; let info = await new ContractInfoQuery() - .setTimeout(1000) + .setTimeout(3000) .setContractId(contract) .setQueryPayment(new Hbar(1)) .execute(env.client); @@ -127,7 +128,7 @@ describe("ContractInfo", function () { let contract = receipt.contractId; let info = await new ContractInfoQuery() - .setTimeout(1000) + .setTimeout(3000) .setContractId(contract) .setQueryPayment(new Hbar(1)) .execute(env.client); diff --git a/test/integration/ContractUpdateIntegrationTest.js b/test/integration/ContractUpdateIntegrationTest.js index aa4ff9e9f..323fa6a5b 100644 --- a/test/integration/ContractUpdateIntegrationTest.js +++ b/test/integration/ContractUpdateIntegrationTest.js @@ -59,7 +59,7 @@ describe("ContractUpdate", function () { let contract = receipt.contractId; let info = await new ContractInfoQuery() - .setTimeout(1000) + .setTimeout(3000) .setContractId(contract) .setQueryPayment(new Hbar(1)) .execute(env.client); @@ -86,7 +86,7 @@ describe("ContractUpdate", function () { ).getReceipt(env.client); info = await new ContractInfoQuery() - .setTimeout(1000) + .setTimeout(3000) .setContractId(contract) .setQueryPayment(new Hbar(5)) .execute(env.client); diff --git a/test/integration/CustomFeesIntegrationTest.js b/test/integration/CustomFeesIntegrationTest.js index 46f7eae79..65456c3ca 100644 --- a/test/integration/CustomFeesIntegrationTest.js +++ b/test/integration/CustomFeesIntegrationTest.js @@ -1397,7 +1397,6 @@ describe("CustomFees", function () { .execute(env.client) ).getReceipt(env.client); } catch (error) { - console.log(error); err = error .toString() .includes(Status.CustomFeeChargingExceededMaxAccountAmounts); diff --git a/test/integration/GetCostIntegrationTest.js b/test/integration/GetCostIntegrationTest.js index b560a64d1..92af3913b 100644 --- a/test/integration/GetCostIntegrationTest.js +++ b/test/integration/GetCostIntegrationTest.js @@ -22,7 +22,7 @@ describe("GetCost", function () { .getCost(env.client); await new AccountInfoQuery() - .setTimeout(1000) + .setTimeout(3000) .setAccountId(operatorId) .setQueryPayment(cost) .execute(env.client); @@ -40,7 +40,7 @@ describe("GetCost", function () { .getCost(env.client); await new AccountInfoQuery() - .setTimeout(1000) + .setTimeout(3000) .setAccountId(operatorId) .setQueryPayment(cost) .execute(env.client); @@ -58,7 +58,7 @@ describe("GetCost", function () { .getCost(env.client); await new AccountInfoQuery() - .setTimeout(1000) + .setTimeout(3000) .setAccountId(operatorId) .setQueryPayment(cost) .execute(env.client); @@ -75,7 +75,7 @@ describe("GetCost", function () { .execute(env.client); await new AccountBalanceQuery() - .setTimeout(1000) + .setTimeout(3000) .setAccountId(operatorId) .setQueryPayment(new Hbar(0)) .execute(env.client); @@ -92,7 +92,7 @@ describe("GetCost", function () { .execute(env.client); await new AccountBalanceQuery() - .setTimeout(1000) + .setTimeout(3000) .setAccountId(operatorId) .setQueryPayment(new Hbar(0)) .execute(env.client); diff --git a/test/integration/ScheduleCreateIntegrationTest.js b/test/integration/ScheduleCreateIntegrationTest.js index a1c4e3cc6..55ee83bfa 100644 --- a/test/integration/ScheduleCreateIntegrationTest.js +++ b/test/integration/ScheduleCreateIntegrationTest.js @@ -123,12 +123,10 @@ describe("ScheduleCreate", function () { key3.publicKey, ); - const balance = await new AccountBalanceQuery() + await new AccountBalanceQuery() .setAccountId(operatorId) .execute(env.client); - console.log(`Balances of the new account: ${balance.toString()}`); - const response = await new AccountCreateTransaction() .setInitialBalance(new Hbar(10)) .setKey(keyList) diff --git a/test/integration/TokenAllowancesIntegrationTest.js b/test/integration/TokenAllowancesIntegrationTest.js index c5474e41a..de53ee9e9 100644 --- a/test/integration/TokenAllowancesIntegrationTest.js +++ b/test/integration/TokenAllowancesIntegrationTest.js @@ -156,10 +156,7 @@ describe("TokenAllowances", function () { const approveRx = await receiverApproveTx.execute(env.client); - const approveReceipt = await approveRx.getReceipt(env.client); - console.log( - `Approve spender allowance - status: ${approveReceipt.status}`, - ); + await approveRx.getReceipt(env.client); let err = false; const onBehalfOfTransactionId = @@ -227,8 +224,7 @@ describe("TokenAllowances", function () { .freezeWith(env.client); const fileAppendSign = await fileAppendTx.sign(env.operatorKey); const fileAppendSubmit = await fileAppendSign.execute(env.client); - const fileAppendRx = await fileAppendSubmit.getReceipt(env.client); - console.log("Status of file append is", fileAppendRx.status.toString()); + await fileAppendSubmit.getReceipt(env.client); // Instantiate the contract instance const contractTx = await new ContractCreateTransaction() @@ -249,8 +245,6 @@ describe("TokenAllowances", function () { //Get the smart contract ID const contractId = contractReceipt.contractId; - console.log("Contract ID is:", contractId.toString()); - //Associate Token with Contract const tokenAssociateTransactionWithContract = await new TokenAssociateTransaction() @@ -262,12 +256,7 @@ describe("TokenAllowances", function () { await tokenAssociateTransactionWithContract.sign(env.operatorKey); const txResponseAssociatedTokenWithContract = await signedTxForAssociateTokenWithContract.execute(env.client); - const txReceipt2 = - await txResponseAssociatedTokenWithContract.getReceipt(env.client); - console.log( - "The associate token to contract transaction consensus is", - txReceipt2.status.toString(), - ); + await txResponseAssociatedTokenWithContract.getReceipt(env.client); //Associate Token with Receiver const tokenAssociateTransactionWithContract1 = @@ -280,12 +269,7 @@ describe("TokenAllowances", function () { await tokenAssociateTransactionWithContract1.sign(receiverKey); const txResponseAssociatedTokenWithContract1 = await signedTxForAssociateTokenWithContract1.execute(env.client); - const txReceipt21 = - await txResponseAssociatedTokenWithContract1.getReceipt(env.client); - console.log( - "The associate token to receiver transaction consensus is", - txReceipt21.status.toString(), - ); + await txResponseAssociatedTokenWithContract1.getReceipt(env.client); // Give `spender` allowance for Token const receiverApproveTx = @@ -298,10 +282,7 @@ describe("TokenAllowances", function () { const approveRx = await receiverApproveTx.execute(env.client); - const approveReceipt = await approveRx.getReceipt(env.client); - console.log( - `Approve spender allowance - status: ${approveReceipt.status}`, - ); + await approveRx.getReceipt(env.client); // Get Allowances const checkAllowance = new ContractExecuteTransaction() @@ -324,8 +305,6 @@ describe("TokenAllowances", function () { .execute(env.client); const allowanceSize = recQuery.contractFunctionResult.getUint256(0); - console.log(`Contract has an allowance of ${allowanceSize}`); - expect(allowanceSize.toNumber()).to.equal(100); }); diff --git a/test/integration/TokenAssociateIntegrationTest.js b/test/integration/TokenAssociateIntegrationTest.js index c2c12ad33..98c0948e4 100644 --- a/test/integration/TokenAssociateIntegrationTest.js +++ b/test/integration/TokenAssociateIntegrationTest.js @@ -60,7 +60,7 @@ describe("TokenAssociate", function () { ).getReceipt(env.client); const balances = await new AccountBalanceQuery() - .setTimeout(2000) + .setTimeout(3000) .setAccountId(account) .execute(env.client); diff --git a/test/integration/TokenBurnIntegrationTest.js b/test/integration/TokenBurnIntegrationTest.js index 0efaeb0c6..ca8b4749a 100644 --- a/test/integration/TokenBurnIntegrationTest.js +++ b/test/integration/TokenBurnIntegrationTest.js @@ -100,7 +100,7 @@ describe("TokenBurn", function () { } const accountBalance = await new AccountBalanceQuery() - .setTimeout(1000) + .setTimeout(3000) .setAccountId(operatorId) .execute(env.client); diff --git a/test/integration/TokenDissociateIntegrationTest.js b/test/integration/TokenDissociateIntegrationTest.js index 5757a670f..4d68f7141 100644 --- a/test/integration/TokenDissociateIntegrationTest.js +++ b/test/integration/TokenDissociateIntegrationTest.js @@ -66,14 +66,14 @@ describe("TokenDissociate", function () { ).getReceipt(env.client); let balances = await new AccountBalanceQuery() - .setTimeout(2000) + .setTimeout(3000) .setAccountId(account) .execute(env.client); expect(balances.tokens.get(token).toInt()).to.be.equal(0); let info = await new AccountInfoQuery() - .setTimeout(1000) + .setTimeout(3000) .setAccountId(account) .execute(env.client); @@ -96,14 +96,14 @@ describe("TokenDissociate", function () { ).getReceipt(env.client); balances = await new AccountBalanceQuery() - .setTimeout(1000) + .setTimeout(3000) .setAccountId(account) .execute(env.client); expect(balances.tokens.get(token)).to.be.null; info = await new AccountInfoQuery() - .setTimeout(1000) + .setTimeout(3000) .setAccountId(account) .execute(env.client); diff --git a/test/integration/TokenFreezeIntegrationTest.js b/test/integration/TokenFreezeIntegrationTest.js index a42f0af6a..e629eb14e 100644 --- a/test/integration/TokenFreezeIntegrationTest.js +++ b/test/integration/TokenFreezeIntegrationTest.js @@ -70,7 +70,7 @@ describe("TokenFreeze", function () { ).getReceipt(env.client); const info = await new AccountInfoQuery() - .setTimeout(1000) + .setTimeout(3000) .setAccountId(account) .execute(env.client); diff --git a/test/integration/TokenGrantKycIntegrationTest.js b/test/integration/TokenGrantKycIntegrationTest.js index 5000cee76..3157eb7c4 100644 --- a/test/integration/TokenGrantKycIntegrationTest.js +++ b/test/integration/TokenGrantKycIntegrationTest.js @@ -70,7 +70,7 @@ describe("TokenGrantKyc", function () { ).getReceipt(env.client); const info = await new AccountInfoQuery() - .setTimeout(1000) + .setTimeout(3000) .setAccountId(account) .execute(env.client); diff --git a/test/integration/TokenRevokeKycIntegrationTest.js b/test/integration/TokenRevokeKycIntegrationTest.js index bb00867bc..92cb0eb1d 100644 --- a/test/integration/TokenRevokeKycIntegrationTest.js +++ b/test/integration/TokenRevokeKycIntegrationTest.js @@ -71,7 +71,7 @@ describe("TokenRevokeKyc", function () { ).getReceipt(env.client); let info = await new AccountInfoQuery() - .setTimeout(2000) + .setTimeout(3000) .setAccountId(account) .execute(env.client); @@ -94,7 +94,7 @@ describe("TokenRevokeKyc", function () { ).getReceipt(env.client); info = await new AccountInfoQuery() - .setTimeout(2000) + .setTimeout(3000) .setAccountId(account) .execute(env.client); diff --git a/test/integration/TokenTransferIntegrationTest.js b/test/integration/TokenTransferIntegrationTest.js index 0d059fc7c..ebb424130 100644 --- a/test/integration/TokenTransferIntegrationTest.js +++ b/test/integration/TokenTransferIntegrationTest.js @@ -340,7 +340,7 @@ describe("TokenTransfer", function () { const account = receipt.accountId; let info = await new AccountInfoQuery() - .setTimeout(1000) + .setTimeout(3000) .setAccountId(account) .execute(env.client); @@ -357,7 +357,7 @@ describe("TokenTransfer", function () { ).getReceipt(env.client); info = await new AccountInfoQuery() - .setTimeout(1000) + .setTimeout(3000) .setAccountId(account) .execute(env.client); diff --git a/test/integration/TokenUnfreezeIntegrationTest.js b/test/integration/TokenUnfreezeIntegrationTest.js index e6fa72bef..f1d94f9fa 100644 --- a/test/integration/TokenUnfreezeIntegrationTest.js +++ b/test/integration/TokenUnfreezeIntegrationTest.js @@ -71,7 +71,7 @@ describe("TokenUnfreeze", function () { ).getReceipt(env.client); let info = await new AccountInfoQuery() - .setTimeout(2000) + .setTimeout(3000) .setAccountId(account) .execute(env.client); @@ -94,7 +94,7 @@ describe("TokenUnfreeze", function () { ).getReceipt(env.client); info = await new AccountInfoQuery() - .setTimeout(2000) + .setTimeout(3000) .setAccountId(account) .execute(env.client); diff --git a/test/integration/TokenWipeIntegrationTest.js b/test/integration/TokenWipeIntegrationTest.js index 4871ebbf8..6f4945157 100644 --- a/test/integration/TokenWipeIntegrationTest.js +++ b/test/integration/TokenWipeIntegrationTest.js @@ -81,7 +81,7 @@ describe("TokenWipe", function () { ).getReceipt(env.client); let info = await new AccountInfoQuery() - .setTimeout(1000) + .setTimeout(3000) .setAccountId(account) .execute(env.client); @@ -102,7 +102,7 @@ describe("TokenWipe", function () { ).getReceipt(env.client); info = await new AccountInfoQuery() - .setTimeout(1000) + .setTimeout(3000) .setAccountId(account) .execute(env.client); diff --git a/test/integration/TopicMessageIntegrationTest.js b/test/integration/TopicMessageIntegrationTest.js index 4090da658..8767e26a6 100644 --- a/test/integration/TopicMessageIntegrationTest.js +++ b/test/integration/TopicMessageIntegrationTest.js @@ -7,6 +7,7 @@ import { } from "../../src/exports.js"; import { bigContents } from "./contents.js"; import IntegrationTestEnv from "./client/NodeIntegrationTestEnv.js"; +import { wait } from "../../src/util.js"; describe("TopicMessage", function () { let env; @@ -22,7 +23,7 @@ describe("TopicMessage", function () { const operatorKey = env.operatorKey.publicKey; // Skip this test if we do not have a mirror network - if (env.client.mirrorNetwork.length == 0) { + if (env.client && env.client.mirrorNetwork.length == 0) { return; } @@ -37,19 +38,19 @@ describe("TopicMessage", function () { let finished = false; const contents = "Hello from Hedera SDK JS"; + await wait(3000); + const handle = new TopicMessageQuery() .setTopicId(topic) .setStartTime(0) - .setLimit(1) - .setCompletionHandler(() => { - finished = true; - }) + .setEndTime(Date.now()) + .setCompletionHandler() // eslint-disable-next-line no-unused-vars - .subscribe(env.client, (_) => { - // Do nothing + .subscribe(env.client, null, () => { + finished = true; }); - const startTime = Date.now(); + let endTime = Date.now() + 5000; await ( await new TopicMessageSubmitTransaction() @@ -58,9 +59,9 @@ describe("TopicMessage", function () { .execute(env.client) ).getReceipt(env.client); - while (!finished && Date.now() < startTime + 45000) { + while (!finished && Date.now() < endTime) { //NOSONAR - await new Promise((resolved) => setTimeout(resolved, 2000)); + await new Promise((resolved) => setTimeout(resolved, 5000)); } await ( diff --git a/test/integration/TopicMessageQueryTest.js b/test/integration/TopicMessageQueryTest.js index 83153d0b2..70bf0b534 100644 --- a/test/integration/TopicMessageQueryTest.js +++ b/test/integration/TopicMessageQueryTest.js @@ -3,6 +3,7 @@ import { TopicCreateTransaction, TopicMessageSubmitTransaction, } from "../../src/exports.js"; +import { wait } from "../../src/util.js"; import IntegrationTestEnv from "./client/NodeIntegrationTestEnv.js"; describe("TopicMessageQuery", function () { @@ -42,26 +43,28 @@ describe("TopicMessageQuery", function () { .execute(env.client) ).getReceipt(env.client); - let finished = false; + let listener; let endTime = Date.now() + 50000; + await wait(3000); + new TopicMessageQuery() .setTopicId(topic) - // .setStartTime(0) - // .setLimit(1) - // eslint-disable-next-line no-unused-vars - .subscribe(env, (_) => { - finished = true; + .setStartTime(0) + .setEndTime(Date.now()) + .subscribe(env.client, null, (res) => { + listener = res; }); - while (!finished && Date.now() < endTime) { + while (!listener && Date.now() < endTime) { //NOSONAR await new Promise((resolved) => setTimeout(resolved, 5000)); } - if (!finished) { - throw new Error("Did not receive message from query"); - } + expect(listener).to.not.be.null; + expect(Buffer.from(listener.contents).toString("utf8")).to.be.eql( + contents, + ); }); after(async function () { diff --git a/test/integration/TransactionRecordIntegrationTest.js b/test/integration/TransactionRecordIntegrationTest.js index a33eb0fdf..567d61ea4 100644 --- a/test/integration/TransactionRecordIntegrationTest.js +++ b/test/integration/TransactionRecordIntegrationTest.js @@ -29,7 +29,6 @@ describe("TransactionRecord", function () { const fileCreateSubmit = await fileCreateSign.execute(env.client); const fileCreateRx = await fileCreateSubmit.getReceipt(env.client); const bytecodeFileId = fileCreateRx.fileId; - console.log(`- The bytecode file ID is: ${bytecodeFileId} \n`); //Append contents to the file const fileAppendTx = new FileAppendTransaction() @@ -39,8 +38,7 @@ describe("TransactionRecord", function () { .freezeWith(env.client); const fileAppendSign = await fileAppendTx.sign(privateKey); const fileAppendSubmit = await fileAppendSign.execute(env.client); - const fileAppendRx = await fileAppendSubmit.getReceipt(env.client); - console.log("Status of file append is", fileAppendRx.status.toString()); + await fileAppendSubmit.getReceipt(env.client); // Instantiate the contract instance const contractTx = await new ContractCreateTransaction() @@ -60,9 +58,6 @@ describe("TransactionRecord", function () { //Get the smart contract ID const newContractId = contractReceipt.contractId; - //Log the smart contract ID - console.log("The smart contract ID is " + newContractId); - const contractExecuteTx = new ContractExecuteTransaction() .setContractId(newContractId) .setGas(750000) diff --git a/test/unit/TransactionReceipt.js b/test/unit/TransactionReceipt.js index 35507c1bc..733f50a88 100644 --- a/test/unit/TransactionReceipt.js +++ b/test/unit/TransactionReceipt.js @@ -152,7 +152,6 @@ describe("TransactionReceipt", function () { const receipt = new TransactionReceipt({ status, }); - console.log(JSON.stringify(receipt)); const expectedJSON = `{"status":"OK","accountId":null,"filedId":null,"contractId":null,"topicId":null,"tokenId":null,"scheduleId":null,"exchangeRate":null,"topicSequenceNumber":null,"topicRunningHash":null,"totalSupply":null,"scheduledTransactionId":null,"serials":[],"duplicates":[],"children":[]}`; const expectedJSONParsed = JSON.parse(expectedJSON); diff --git a/test/unit/TransactionRecord.js b/test/unit/TransactionRecord.js index 8db5cf2ca..f448a3404 100644 --- a/test/unit/TransactionRecord.js +++ b/test/unit/TransactionRecord.js @@ -77,8 +77,6 @@ describe("TransactionRecord", function () { tokenTransfersList: [tokenTransfer], }); - console.log(JSON.stringify(newRecord)); - const expectedJSON = JSON.parse( `{"receipt":{"status":"SUCCESS","accountId":"0.0.1246","filedId":null,"contractId":null,"topicId":null,"tokenId":null,"scheduleId":null,"exchangeRate":{"hbars":1,"cents":12,"expirationTime":"1963-11-25T17:31:44.000Z","exchangeRateInCents":12},"topicSequenceNumber":"0","topicRunningHash":"","totalSupply":"0","scheduledTransactionId":null,"serials":[],"duplicates":[],"children":[]},"transactionHash":"cac44f2db045ba441f3fbc295217f2eb0f956293d28b3401578f6160e66f4e47ea87952d91c4b1cb5bda6447823b979a","consensusTimestamp":"2022-06-18T02:54:43.839Z","transactionId":"0.0.1157@1655520872.507983896","transactionMemo":"test","transactionFee":"41694270","transfers":[{"accountId":"0.0.5","amount":"1071080","isApproved":false},{"accountId":"0.0.98","amount":"32498552","isApproved":false},{"accountId":"0.0.800","amount":"4062319","isApproved":false},{"accountId":"0.0.801","amount":"4062319","isApproved":false},{"accountId":"0.0.1157","amount":"-1041694270","isApproved":false},{"accountId":"0.0.1246","amount":"1000000000","isApproved":false}],"tokenTransfers":{"0.0.123":{"0.0.1246":"789"}},"tokenTransfersList":[{"tokenId":"0.0.123","accountId":"0.0.1246","amount":"789"}],"scheduleRef":"0.0.123","assessedCustomFees":[{"feeCollectorAccountId":"0.0.1246","tokenId":"0.0.123","amount":"789","payerAccountIds":["0.0.1246"]}],"nftTransfers":{"0.0.123":[{"sender":"0.0.1246","recipient":"0.0.1246","serial":123,"isApproved":true}]},"automaticTokenAssociations":[{"accountId":"0.0.1246","tokenId":"0.0.123"}],"parentConsensusTimestamp":"2022-06-18T02:54:43.839Z","aliasKey":"302a300506032b6570032100d7366c45e4d2f1a6c1d9af054f5ef8edc0b8d3875ba5d08a7f2e81ee8876e9e8","duplicates":[],"children":[],"ethereumHash":"01020304","paidStakingRewards":[{"accountId":"0.0.5","amount":"1071080","isApproved":false},{"accountId":"0.0.98","amount":"32498552","isApproved":false},{"accountId":"0.0.800","amount":"4062319","isApproved":false},{"accountId":"0.0.801","amount":"4062319","isApproved":false},{"accountId":"0.0.1157","amount":"-1041694270","isApproved":false},{"accountId":"0.0.1246","amount":"1000000000","isApproved":false}],"prngBytes":"01020304","prngNumber":123,"evmAddress":"deadbeef"}`, ); diff --git a/test/unit/TransactionResponse.js b/test/unit/TransactionResponse.js index 3f4b2cb05..9ea90c1b3 100644 --- a/test/unit/TransactionResponse.js +++ b/test/unit/TransactionResponse.js @@ -14,8 +14,6 @@ describe("TransactionResponse", function () { transactionId: TransactionId.fromString("0.0.12@13.000000014"), }); - console.log(JSON.stringify(response)); - const expectedJSON = `{"nodeId":"0.0.3","transactionHash":"010203","transactionId":"0.0.12@13.000000014"}`; const expectedJSONParsed = JSON.parse(expectedJSON); From 7ea713fd908ecf981143ab1f55997ce74328615b Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Tue, 28 May 2024 09:49:07 +0300 Subject: [PATCH 07/49] update: test Signed-off-by: svetoslav-nikol0v --- test/integration/TopicMessageIntegrationTest.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/TopicMessageIntegrationTest.js b/test/integration/TopicMessageIntegrationTest.js index 8767e26a6..2c64da8b1 100644 --- a/test/integration/TopicMessageIntegrationTest.js +++ b/test/integration/TopicMessageIntegrationTest.js @@ -50,7 +50,7 @@ describe("TopicMessage", function () { finished = true; }); - let endTime = Date.now() + 5000; + let endTime = Date.now() + 50000; await ( await new TopicMessageSubmitTransaction() From 716c200a79c21c5c128ed5196f46d8843cba41f5 Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Tue, 28 May 2024 11:11:30 +0300 Subject: [PATCH 08/49] fix: reorder tests in the suite Signed-off-by: svetoslav-nikol0v --- test/integration/ClientIntegrationTest.js | 120 +++++++++++----------- 1 file changed, 59 insertions(+), 61 deletions(-) diff --git a/test/integration/ClientIntegrationTest.js b/test/integration/ClientIntegrationTest.js index d650d483c..7cb3ec9a2 100644 --- a/test/integration/ClientIntegrationTest.js +++ b/test/integration/ClientIntegrationTest.js @@ -21,50 +21,6 @@ describe("ClientIntegration", function () { clientPreviewNet = Client.forPreviewnet(); }); - it("should error when invalid network on entity ID", async function () { - this.timeout(120000); - - if (env.client.ledgerId == null) { - return; - } - - let err = false; - - switch (env.client.ledgerId.toString()) { - case "mainnet": - env.client.setLedgerId(LedgerId.TESTNET); - break; - case "testnet": - env.client.setLedgerId(LedgerId.PREVIEWNET); - break; - case "previewnet": - env.client.setLedgerId(LedgerId.LOCAL_NODE); - break; - case "local-node": - env.client.setLedgerId(LedgerId.MAINNET); - break; - default: - throw new Error( - `(BUG) operator network is unrecognized value: ${env.client.ledgerId.toString()}`, - ); - } - - const accountId = new AccountId(3); - - try { - await new AccountInfoQuery() - .setTimeout(3000) - .setAccountId(accountId) - .execute(env.client); - } catch (error) { - err = true; - } - - if (!err) { - throw new Error("query did not error"); - } - }); - it("can execute with sign on demand", async function () { this.timeout(120000); @@ -127,7 +83,7 @@ describe("ClientIntegration", function () { }); it("can pingAll", async function () { - this.timeout(120000); + this.timeout(300000); await env.client.pingAll(); }); @@ -144,22 +100,6 @@ describe("ClientIntegration", function () { expect(error).to.be.an("Error"); }); - // TODO(2023-11-01 NK) - test is consistently failing and should be enabled once fixed. - // eslint-disable-next-line mocha/no-skipped-tests - xit("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); - - await clientTestnet.setNetwork(clientPreviewNet.network); - - expect(clientTestnet.ledgerId).to.be.null; - - clientTestnet.setLedgerId("previewnet"); - - expect(clientTestnet.ledgerId).to.be.equal(LedgerId.PREVIEWNET); - }); - it("can use same proxies of one node", async function () { this.timeout(300000); let nodes = { @@ -196,6 +136,64 @@ describe("ClientIntegration", function () { expect(env.client.defaultMaxQueryPayment).to.be.equal(value); }); + /** + * @summary + * The last two tests must be in the exact order as + * they are now and always be the last tests in the suite. + * The client is initialized once before all the tests in the suite + * and when we manipulate the ledger id of the network + * this will affect the other tests. + */ + + it("should error when invalid network on entity ID", async function () { + this.timeout(120000); + + if (env.client.ledgerId == null) { + return; + } + + switch (env.client.ledgerId.toString()) { + case "mainnet": + env.client.setLedgerId(LedgerId.TESTNET); + break; + case "testnet": + env.client.setLedgerId(LedgerId.PREVIEWNET); + break; + case "previewnet": + env.client.setLedgerId(LedgerId.LOCAL_NODE); + break; + case "local-node": + env.client.setLedgerId(LedgerId.MAINNET); + break; + default: + throw new Error( + `(BUG) operator network is unrecognized value: ${env.client.ledgerId.toString()}`, + ); + } + + const accountId = new AccountId(3); + let err; + + try { + await new AccountInfoQuery() + .setTimeout(3000) + .setAccountId(accountId) + .execute(env.client); + } catch (error) { + err = error; + } + + expect(err).to.not.be.null; + }); + + it("can set network name on custom network", async function () { + this.timeout(120000); + + env.client.setLedgerId("previewnet"); + + expect(env.client.ledgerId).to.be.equal(LedgerId.PREVIEWNET); + }); + after(async function () { await env.close(); clientTestnet.close(); From a360bbf9135e424091a10f4ffe61cefb21c05634 Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Tue, 28 May 2024 11:20:46 +0300 Subject: [PATCH 09/49] fix: reliability issue Signed-off-by: svetoslav-nikol0v --- test/integration/TopicMessageQueryTest.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/integration/TopicMessageQueryTest.js b/test/integration/TopicMessageQueryTest.js index 70bf0b534..a359745b3 100644 --- a/test/integration/TopicMessageQueryTest.js +++ b/test/integration/TopicMessageQueryTest.js @@ -43,7 +43,8 @@ describe("TopicMessageQuery", function () { .execute(env.client) ).getReceipt(env.client); - let listener; + let finished = false; + let listener = null; let endTime = Date.now() + 50000; await wait(3000); @@ -53,10 +54,11 @@ describe("TopicMessageQuery", function () { .setStartTime(0) .setEndTime(Date.now()) .subscribe(env.client, null, (res) => { + finished = true; listener = res; }); - while (!listener && Date.now() < endTime) { + while (!finished && Date.now() < endTime) { //NOSONAR await new Promise((resolved) => setTimeout(resolved, 5000)); } From cea4dc676f98c5961813808af29657e72b17f342 Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Tue, 28 May 2024 11:27:27 +0300 Subject: [PATCH 10/49] fix: reliability issue Signed-off-by: svetoslav-nikol0v --- test/integration/TopicMessageIntegrationTest.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/test/integration/TopicMessageIntegrationTest.js b/test/integration/TopicMessageIntegrationTest.js index 2c64da8b1..bf3b8a81d 100644 --- a/test/integration/TopicMessageIntegrationTest.js +++ b/test/integration/TopicMessageIntegrationTest.js @@ -36,6 +36,7 @@ describe("TopicMessage", function () { const topic = (await response.getReceipt(env.client)).topicId; let finished = false; + let listener = null; const contents = "Hello from Hedera SDK JS"; await wait(3000); @@ -46,8 +47,9 @@ describe("TopicMessage", function () { .setEndTime(Date.now()) .setCompletionHandler() // eslint-disable-next-line no-unused-vars - .subscribe(env.client, null, () => { + .subscribe(env.client, null, (res) => { finished = true; + listener = res; }); let endTime = Date.now() + 50000; @@ -72,9 +74,10 @@ describe("TopicMessage", function () { handle.unsubscribe(); - if (!finished) { - throw new Error("Failed to receive message in 30s"); - } + expect(listener).to.not.be.null; + expect(Buffer.from(listener.contents).toString("utf8")).to.be.eql( + contents, + ); }); it("should be executable with large message", async function () { From c602b447db71d562a6552a4992b621db2c4cc398 Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Tue, 28 May 2024 11:38:52 +0300 Subject: [PATCH 11/49] fix: integration test Signed-off-by: svetoslav-nikol0v --- .../TopicMessageIntegrationTest.js | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/test/integration/TopicMessageIntegrationTest.js b/test/integration/TopicMessageIntegrationTest.js index bf3b8a81d..6e63fed13 100644 --- a/test/integration/TopicMessageIntegrationTest.js +++ b/test/integration/TopicMessageIntegrationTest.js @@ -16,7 +16,7 @@ describe("TopicMessage", function () { env = await IntegrationTestEnv.new({ throwaway: true }); }); - it("should be executable", async function () { + it.only("should be executable", async function () { this.timeout(120000); const operatorId = env.operatorId; @@ -34,10 +34,18 @@ describe("TopicMessage", function () { .execute(env.client); const topic = (await response.getReceipt(env.client)).topicId; + const contents = "Hello from Hedera SDK JS"; + + await ( + await new TopicMessageSubmitTransaction() + .setTopicId(topic) + .setMessage(contents) + .execute(env.client) + ).getReceipt(env.client); let finished = false; let listener = null; - const contents = "Hello from Hedera SDK JS"; + let endTime = Date.now() + 50000; await wait(3000); @@ -45,22 +53,11 @@ describe("TopicMessage", function () { .setTopicId(topic) .setStartTime(0) .setEndTime(Date.now()) - .setCompletionHandler() - // eslint-disable-next-line no-unused-vars .subscribe(env.client, null, (res) => { finished = true; listener = res; }); - let endTime = Date.now() + 50000; - - await ( - await new TopicMessageSubmitTransaction() - .setTopicId(topic) - .setMessage(contents) - .execute(env.client) - ).getReceipt(env.client); - while (!finished && Date.now() < endTime) { //NOSONAR await new Promise((resolved) => setTimeout(resolved, 5000)); From b4a2a4942f7c21cc3a1f4a454f1ddb5fc695922c Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Tue, 28 May 2024 17:06:27 +0300 Subject: [PATCH 12/49] update: reorder steps in the pipeline Signed-off-by: svetoslav-nikol0v --- .github/workflows/build.yml | 76 +++++++-------------------------- src/network/MirrorNodeRouter.js | 4 +- test/unit/Mocker.js | 2 +- 3 files changed, 19 insertions(+), 63 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ea5e71022..63447af4e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,9 +19,6 @@ defaults: permissions: contents: read -env: - CG_EXEC: export R_UID=$(id -u); CGROUP_LOGLEVEL=DEBUG cgexec -g cpu,memory:user.slice/user-${R_UID}.slice/user@${R_UID}.service/e2e-${{ github.run_id }} --sticky ionice -c 2 -n 2 nice -n 19 - jobs: build: name: Build using Node ${{ matrix.node }} @@ -47,7 +44,7 @@ jobs: version: 3.35.1 - name: Install PNPM - uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0 + uses: pnpm/action-setup@a3252b78c470c02df07e9d59298aecedc3ccdd6d # v3.0.0 with: version: 8.15.4 @@ -68,47 +65,6 @@ jobs: node: [ "16" ] steps: - - name: Setup Control Groups - run: | - echo "::group::Get System Configuration" - USR_ID="$(id -un)" - GRP_ID="$(id -gn)" - E2E_MEM_LIMIT="30064771072" - AGENT_MEM_LIMIT="2147483648" - USER_SLICE="user.slice/user-$(id -u).slice" - USER_SERVICE="${USER_SLICE}/user@$(id -u).service" - E2E_GROUP_NAME="${USER_SERVICE}/e2e-${{ github.run_id }}" - AGENT_GROUP_NAME="${USER_SERVICE}/agent-${{ github.run_id }}" - echo "::endgroup::" - - echo "::group::Install Control Group Tools" - if ! command -v cgcreate >/dev/null 2>&1; then - sudo apt-get update - sudo apt-get install -y cgroup-tools - fi - echo "::endgroup::" - - echo "::group::Create Control Groups" - sudo cgcreate -g cpu,memory:${USER_SLICE} -a ${USR_ID}:${GRP_ID} -t ${USR_ID}:${GRP_ID} - sudo cgcreate -g cpu,memory:${USER_SERVICE} -a ${USR_ID}:${GRP_ID} -t ${USR_ID}:${GRP_ID} - sudo cgcreate -g cpu,memory:${E2E_GROUP_NAME} -a ${USR_ID}:${GRP_ID} -t ${USR_ID}:${GRP_ID} - sudo cgcreate -g cpu,memory:${AGENT_GROUP_NAME} -a ${USR_ID}:${GRP_ID} -t ${USR_ID}:${GRP_ID} - echo "::endgroup::" - - echo "::group::Set Control Group Limits" - cgset -r cpu.weight=768 ${E2E_GROUP_NAME} - cgset -r cpu.weight=500 ${AGENT_GROUP_NAME} - cgset -r memory.max=${E2E_MEM_LIMIT} ${E2E_GROUP_NAME} - cgset -r memory.max=${AGENT_MEM_LIMIT} ${AGENT_GROUP_NAME} - cgset -r memory.swap.max=${E2E_MEM_LIMIT} ${E2E_GROUP_NAME} - cgset -r memory.swap.max=${AGENT_MEM_LIMIT} ${AGENT_GROUP_NAME} - echo "::endgroup::" - - echo "::group::Move Runner Processes to Control Groups" - sudo cgclassify --sticky -g cpu,memory:${AGENT_GROUP_NAME} $(pgrep 'Runner.Listener' | tr '\n' ' ') - sudo cgclassify -g cpu,memory:${AGENT_GROUP_NAME} $(pgrep 'Runner.Worker' | tr '\n' ' ') - echo "::endgroup::" - - name: Harden Runner uses: step-security/harden-runner@f086349bfa2bd1361f7909c78558e816508cdc10 # v2.8.0 with: @@ -133,7 +89,7 @@ jobs: cat .env - name: Install PNPM - uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0 + uses: pnpm/action-setup@a3252b78c470c02df07e9d59298aecedc3ccdd6d # v3.0.0 with: version: 8.15.4 @@ -156,38 +112,38 @@ jobs: id: start-local-node if: ${{ steps.build-sdk.conclusion == 'success' && !cancelled() && always() }} run: | - ${{ env.CG_EXEC }} npx @hashgraph/hedera-local start -d --network-tag=0.49.7 --balance=100000 + npx @hashgraph/hedera-local start -d --network-tag=0.49.7 --balance=100000 # Wait for the network to fully start sleep 30 - name: Run Hedera SDK Integration Tests Codecov if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} - run: ${{ env.CG_EXEC }} task test:integration:codecov + run: task test:integration:codecov + + - name: Unit Test @hashgraph/sdk + if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && steps.playwright-deps.conclusion == 'success' && !cancelled() && always() }} + run: task test:unit + + - name: Codecov @hashgraph/sdk + if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && !cancelled() && always() }} + run: task test:unit:codecov - name: Stop the local node id: stop-local-node if: ${{ steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} - run: ${{ env.CG_EXEC }} npx @hashgraph/hedera-local stop + run: npx @hashgraph/hedera-local stop - name: Build @hashgraph/cryptography working-directory: packages/cryptography if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && !cancelled() && always() }} - run: ${{ env.CG_EXEC }} task build + run: task build - name: Unit Test @hashgraph/cryptography working-directory: packages/cryptography if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && !cancelled() && always() }} - run: ${{ env.CG_EXEC }} task test:unit + run: task test:unit - name: Codecov @hashgraph/cryptography working-directory: packages/cryptography if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && !cancelled() && always() }} - run: ${{ env.CG_EXEC }} task test:unit:codecov - - - name: Unit Test @hashgraph/sdk - if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && steps.playwright-deps.conclusion == 'success' && !cancelled() && always() }} - run: ${{ env.CG_EXEC }} task test:unit - - - name: Codecov @hashgraph/sdk - if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && !cancelled() && always() }} - run: ${{ env.CG_EXEC }} task test:unit:codecov + run: task test:unit:codecov diff --git a/src/network/MirrorNodeRouter.js b/src/network/MirrorNodeRouter.js index 296a1e7a3..3870e2fb4 100644 --- a/src/network/MirrorNodeRouter.js +++ b/src/network/MirrorNodeRouter.js @@ -49,13 +49,13 @@ export default class MirrorNodeRouter { mirrorNodeAddress = mirrorNetwork.map((a) => a.substring(0, a.indexOf(":")), - ); + )[0]; if (mirrorNodeAddress.length == 0) { throw new Error("Mirror address not found!"); } - if (ledgerId != null && !ledgerId.isLocalNode()) { + if (ledgerId != null) { path = HTTPS + mirrorNodeAddress.toString(); } else { // local node case diff --git a/test/unit/Mocker.js b/test/unit/Mocker.js index 1b97d504f..283c4558a 100644 --- a/test/unit/Mocker.js +++ b/test/unit/Mocker.js @@ -424,7 +424,7 @@ class GrpcServers { * @returns {this} */ addServer(responses) { - const address = `0.0.0.0:${50213 + this._index}`; + const address = `127.0.0.1:${50213 + this._index}`; const nodeAccountId = `0.0.${3 + this._index}`; const server = new GrpcServer(PROTOS).addResponses(responses); From f70337f699df2b80e3c6cc3eaabd32dfeff13e7c Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Tue, 28 May 2024 17:10:33 +0300 Subject: [PATCH 13/49] update: update build workflow Signed-off-by: svetoslav-nikol0v --- .github/workflows/build.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 63447af4e..157623445 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -124,10 +124,6 @@ jobs: if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && steps.playwright-deps.conclusion == 'success' && !cancelled() && always() }} run: task test:unit - - name: Codecov @hashgraph/sdk - if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && !cancelled() && always() }} - run: task test:unit:codecov - - name: Stop the local node id: stop-local-node if: ${{ steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} @@ -147,3 +143,7 @@ jobs: working-directory: packages/cryptography if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && !cancelled() && always() }} run: task test:unit:codecov + + - name: Codecov @hashgraph/sdk + if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && !cancelled() && always() }} + run: task test:unit:codecov From db6ee8c5c92099a19de8e0943193204272e8be98 Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Tue, 28 May 2024 17:48:54 +0300 Subject: [PATCH 14/49] update: reorder steps in build workflow Signed-off-by: svetoslav-nikol0v --- .github/workflows/build.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 157623445..63447af4e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -124,6 +124,10 @@ jobs: if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && steps.playwright-deps.conclusion == 'success' && !cancelled() && always() }} run: task test:unit + - name: Codecov @hashgraph/sdk + if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && !cancelled() && always() }} + run: task test:unit:codecov + - name: Stop the local node id: stop-local-node if: ${{ steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} @@ -143,7 +147,3 @@ jobs: working-directory: packages/cryptography if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && !cancelled() && always() }} run: task test:unit:codecov - - - name: Codecov @hashgraph/sdk - if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && !cancelled() && always() }} - run: task test:unit:codecov From 8d564281d0d7c41cbd1af6537056f5d19b4c463c Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Wed, 29 May 2024 09:38:37 +0300 Subject: [PATCH 15/49] chore: remove log Signed-off-by: svetoslav-nikol0v --- src/client/ManagedNetwork.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/client/ManagedNetwork.js b/src/client/ManagedNetwork.js index 7a310353f..31cd9e2d0 100644 --- a/src/client/ManagedNetwork.js +++ b/src/client/ManagedNetwork.js @@ -325,7 +325,6 @@ export default class ManagedNetwork { newNetwork.set(node.getKey(), newNetworkNodes); } - // console.log(JSON.stringify(newNodes, null, 2)); this._nodes = newNodes; this._healthyNodes = newHealthyNodes; this._network = newNetwork; From 2be6ead0f1649236506a144516ba4c1a79ce4a43 Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Wed, 29 May 2024 10:38:42 +0300 Subject: [PATCH 16/49] chore: adjustment Signed-off-by: svetoslav-nikol0v --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 63447af4e..663796ba0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -121,11 +121,11 @@ jobs: run: task test:integration:codecov - name: Unit Test @hashgraph/sdk - if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && steps.playwright-deps.conclusion == 'success' && !cancelled() && always() }} + if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && steps.playwright-deps.conclusion == 'success' && !cancelled() && always() }} run: task test:unit - name: Codecov @hashgraph/sdk - if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && !cancelled() && always() }} + if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} run: task test:unit:codecov - name: Stop the local node From 987953d8f6e45f17603cd1c182ed56f7c83f84cf Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Wed, 29 May 2024 10:56:40 +0300 Subject: [PATCH 17/49] fix Signed-off-by: svetoslav-nikol0v --- src/client/NodeClient.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/client/NodeClient.js b/src/client/NodeClient.js index e28577b5a..4685e929c 100644 --- a/src/client/NodeClient.js +++ b/src/client/NodeClient.js @@ -107,6 +107,10 @@ export default class NodeClient extends Client { this.setMirrorNetwork(MirrorNetwork.PREVIEWNET); break; + case "local-node": + this.setMirrorNetwork(MirrorNetwork.LOCAL_NODE); + break; + default: this.setMirrorNetwork([props.mirrorNetwork]); break; From 3da90e424bdd65cf72ecaf6684fa0175c2213a36 Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Wed, 29 May 2024 11:50:22 +0300 Subject: [PATCH 18/49] update: unit test Signed-off-by: svetoslav-nikol0v --- test/unit/TransactionReceiptMocking.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/TransactionReceiptMocking.js b/test/unit/TransactionReceiptMocking.js index 26c9cfd95..496535a81 100644 --- a/test/unit/TransactionReceiptMocking.js +++ b/test/unit/TransactionReceiptMocking.js @@ -38,7 +38,7 @@ describe("TransactionReceiptMocking", function () { let client; let servers; - afterEach(function () { + afterAll(function () { client.close(); servers.close(); }); From bfacf9c3bcab780c948ffa556c379f2fa45c96ab Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Wed, 29 May 2024 12:31:25 +0300 Subject: [PATCH 19/49] fix: unit test Signed-off-by: svetoslav-nikol0v --- test/unit/TopicMessageMocking.js | 9 +++++++-- test/unit/TransactionReceiptMocking.js | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/test/unit/TopicMessageMocking.js b/test/unit/TopicMessageMocking.js index 4bf6b101f..a7b17c0c8 100644 --- a/test/unit/TopicMessageMocking.js +++ b/test/unit/TopicMessageMocking.js @@ -28,8 +28,13 @@ describe("TopicMessageMocking", function () { let handle; afterEach(function () { - client.close(); - servers.close(); + if (client != null) { + client.close(); + } + + if (servers != null) { + servers.close(); + } if (handle != null) { handle.unsubscribe(); diff --git a/test/unit/TransactionReceiptMocking.js b/test/unit/TransactionReceiptMocking.js index 496535a81..26c9cfd95 100644 --- a/test/unit/TransactionReceiptMocking.js +++ b/test/unit/TransactionReceiptMocking.js @@ -38,7 +38,7 @@ describe("TransactionReceiptMocking", function () { let client; let servers; - afterAll(function () { + afterEach(function () { client.close(); servers.close(); }); From 6c9fb6c3e2dd1aa85709e5dc6193f70cc8a47be9 Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Wed, 29 May 2024 12:49:21 +0300 Subject: [PATCH 20/49] update: unit tests Signed-off-by: svetoslav-nikol0v --- test/unit/AccountInfoMocking.js | 9 +++++++-- test/unit/ContractCreateFlowMocking.js | 9 +++++++-- test/unit/EthereumFlowMocking.js | 9 +++++++-- test/unit/TopicMessageMocking.js | 2 +- test/unit/TransactionReceiptMocking.js | 9 +++++++-- 5 files changed, 29 insertions(+), 9 deletions(-) diff --git a/test/unit/AccountInfoMocking.js b/test/unit/AccountInfoMocking.js index 6366938f3..cde177b1a 100644 --- a/test/unit/AccountInfoMocking.js +++ b/test/unit/AccountInfoMocking.js @@ -49,8 +49,13 @@ describe("AccountInfoMocking", function () { let servers; afterEach(function () { - client.close(); - servers.close(); + if (client != null) { + client.close(); + } + + if (servers != null) { + servers.close(); + } }); it("payment transaction is correctly constructed", async function () { diff --git a/test/unit/ContractCreateFlowMocking.js b/test/unit/ContractCreateFlowMocking.js index 77ecec5f3..4bf9ebebe 100644 --- a/test/unit/ContractCreateFlowMocking.js +++ b/test/unit/ContractCreateFlowMocking.js @@ -14,8 +14,13 @@ describe("ContractCreateFlowMocking", function () { let wallet; afterEach(function () { - client.close(); - servers.close(); + if (client != null) { + client.close(); + } + + if (servers != null) { + servers.close(); + } }); it("signs all transactions", async function () { diff --git a/test/unit/EthereumFlowMocking.js b/test/unit/EthereumFlowMocking.js index 04591319d..44badc66a 100644 --- a/test/unit/EthereumFlowMocking.js +++ b/test/unit/EthereumFlowMocking.js @@ -32,8 +32,13 @@ describe("EthereumFlowMocking", function () { let servers; afterEach(function () { - client.close(); - servers.close(); + if (client != null) { + client.close(); + } + + if (servers != null) { + servers.close(); + } }); it("doesn't truncate ethereum data if it's not long enough", async function () { diff --git a/test/unit/TopicMessageMocking.js b/test/unit/TopicMessageMocking.js index a7b17c0c8..8da95bef9 100644 --- a/test/unit/TopicMessageMocking.js +++ b/test/unit/TopicMessageMocking.js @@ -31,7 +31,7 @@ describe("TopicMessageMocking", function () { if (client != null) { client.close(); } - + if (servers != null) { servers.close(); } diff --git a/test/unit/TransactionReceiptMocking.js b/test/unit/TransactionReceiptMocking.js index 26c9cfd95..fc79bb760 100644 --- a/test/unit/TransactionReceiptMocking.js +++ b/test/unit/TransactionReceiptMocking.js @@ -39,8 +39,13 @@ describe("TransactionReceiptMocking", function () { let servers; afterEach(function () { - client.close(); - servers.close(); + if (client != null) { + client.close(); + } + + if (servers != null) { + servers.close(); + } }); it("should error with max attempts", async function () { From 3b08ef0851faddeee460ac184f250968af944e7e Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Wed, 29 May 2024 13:45:02 +0300 Subject: [PATCH 21/49] update: revert workflow Signed-off-by: svetoslav-nikol0v --- .github/workflows/build.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 663796ba0..318be433f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -120,14 +120,6 @@ jobs: if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} run: task test:integration:codecov - - name: Unit Test @hashgraph/sdk - if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && steps.playwright-deps.conclusion == 'success' && !cancelled() && always() }} - run: task test:unit - - - name: Codecov @hashgraph/sdk - if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} - run: task test:unit:codecov - - name: Stop the local node id: stop-local-node if: ${{ steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} @@ -147,3 +139,11 @@ jobs: working-directory: packages/cryptography if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && !cancelled() && always() }} run: task test:unit:codecov + + - name: Unit Test @hashgraph/sdk + if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && steps.playwright-deps.conclusion == 'success' && !cancelled() && always() }} + run: task test:unit + + - name: Codecov @hashgraph/sdk + if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && !cancelled() && always() }} + run: task test:unit:codecov \ No newline at end of file From 7602f57729c836c7e1c0930bab190b2e114c1a83 Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Wed, 29 May 2024 14:06:10 +0300 Subject: [PATCH 22/49] update workflow Signed-off-by: svetoslav-nikol0v --- .github/workflows/build.yml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 318be433f..38bca4c0c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -120,30 +120,30 @@ jobs: if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} run: task test:integration:codecov - - name: Stop the local node - id: stop-local-node - if: ${{ steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} - run: npx @hashgraph/hedera-local stop - - name: Build @hashgraph/cryptography working-directory: packages/cryptography - if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && !cancelled() && always() }} + if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} run: task build - name: Unit Test @hashgraph/cryptography working-directory: packages/cryptography - if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && !cancelled() && always() }} + if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} run: task test:unit - name: Codecov @hashgraph/cryptography working-directory: packages/cryptography - if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && !cancelled() && always() }} + if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} run: task test:unit:codecov - name: Unit Test @hashgraph/sdk - if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && steps.playwright-deps.conclusion == 'success' && !cancelled() && always() }} + if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && steps.playwright-deps.conclusion == 'success' && !cancelled() && always() }} run: task test:unit - name: Codecov @hashgraph/sdk - if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && !cancelled() && always() }} - run: task test:unit:codecov \ No newline at end of file + if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} + run: task test:unit:codecov + + - name: Stop the local node + id: stop-local-node + if: ${{ steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} + run: npx @hashgraph/hedera-local stop \ No newline at end of file From a967f1ee1e3a563ac26be1887567a39877f2465d Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Wed, 29 May 2024 14:24:23 +0300 Subject: [PATCH 23/49] update: workflow Signed-off-by: svetoslav-nikol0v --- .github/workflows/build.yml | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 38bca4c0c..b34f67f9c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -120,6 +120,15 @@ jobs: if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} run: task test:integration:codecov + - name: Codecov @hashgraph/sdk + if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} + run: task test:unit:codecov + + - name: Stop the local node + id: stop-local-node + if: ${{ steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} + run: npx @hashgraph/hedera-local stop + - name: Build @hashgraph/cryptography working-directory: packages/cryptography if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} @@ -133,17 +142,4 @@ jobs: - name: Codecov @hashgraph/cryptography working-directory: packages/cryptography if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} - run: task test:unit:codecov - - - name: Unit Test @hashgraph/sdk - if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && steps.playwright-deps.conclusion == 'success' && !cancelled() && always() }} - run: task test:unit - - - name: Codecov @hashgraph/sdk - if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} - run: task test:unit:codecov - - - name: Stop the local node - id: stop-local-node - if: ${{ steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} - run: npx @hashgraph/hedera-local stop \ No newline at end of file + run: task test:unit:codecov \ No newline at end of file From c785296defece2a5133ec5b8ea99f61a2c2169ae Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Wed, 29 May 2024 14:26:44 +0300 Subject: [PATCH 24/49] update workflow Signed-off-by: svetoslav-nikol0v --- .github/workflows/build.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b34f67f9c..466e65572 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -131,15 +131,15 @@ jobs: - name: Build @hashgraph/cryptography working-directory: packages/cryptography - if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} + if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && !cancelled() && always() }} run: task build - name: Unit Test @hashgraph/cryptography working-directory: packages/cryptography - if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} + if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && !cancelled() && always() }} run: task test:unit - name: Codecov @hashgraph/cryptography working-directory: packages/cryptography - if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} + if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && !cancelled() && always() }} run: task test:unit:codecov \ No newline at end of file From 970b7acdb1163686147010fa06d08a419ffbcdf6 Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Wed, 29 May 2024 14:35:36 +0300 Subject: [PATCH 25/49] update: workflow Signed-off-by: svetoslav-nikol0v --- .github/workflows/build.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 466e65572..0aca041c5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -120,10 +120,6 @@ jobs: if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} run: task test:integration:codecov - - name: Codecov @hashgraph/sdk - if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} - run: task test:unit:codecov - - name: Stop the local node id: stop-local-node if: ${{ steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} @@ -141,5 +137,9 @@ jobs: - name: Codecov @hashgraph/cryptography working-directory: packages/cryptography + if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && !cancelled() && always() }} + run: task test:unit:codecov + + - name: Run Hedera SDK Unit Tests Codecov if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && !cancelled() && always() }} run: task test:unit:codecov \ No newline at end of file From 2205131c642bc276752c1db5fadc878a082a206c Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Wed, 29 May 2024 14:45:56 +0300 Subject: [PATCH 26/49] update: workflow Signed-off-by: svetoslav-nikol0v --- .github/workflows/build.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0aca041c5..549e25003 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -120,6 +120,10 @@ jobs: if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} run: task test:integration:codecov + - name: Run Hedera SDK Unit Tests Codecov + if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} + run: task test:unit:codecov + - name: Stop the local node id: stop-local-node if: ${{ steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} @@ -137,9 +141,5 @@ jobs: - name: Codecov @hashgraph/cryptography working-directory: packages/cryptography - if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && !cancelled() && always() }} - run: task test:unit:codecov - - - name: Run Hedera SDK Unit Tests Codecov if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && !cancelled() && always() }} run: task test:unit:codecov \ No newline at end of file From 0b7bcfd7cf9fae92c9d2fc31222eb8e41bf1d71a Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Wed, 29 May 2024 15:50:35 +0300 Subject: [PATCH 27/49] add logs Signed-off-by: svetoslav-nikol0v --- src/account/AccountInfoQuery.js | 3 +++ src/network/MirrorNodeGateway.js | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/account/AccountInfoQuery.js b/src/account/AccountInfoQuery.js index 20cbd1512..9859a7d1a 100644 --- a/src/account/AccountInfoQuery.js +++ b/src/account/AccountInfoQuery.js @@ -183,6 +183,9 @@ export default class AccountInfoQuery extends Query { this._mirrorNetwork, this._ledgerId, ); + + console.log('mirrorNetwork', this._mirrorNetwork); + console.log('ledgerId', this._ledgerId); const mirrorNodeService = new MirrorNodeService(mirrorNodeGateway); const info = diff --git a/src/network/MirrorNodeGateway.js b/src/network/MirrorNodeGateway.js index c9ca694ab..8ee92220c 100644 --- a/src/network/MirrorNodeGateway.js +++ b/src/network/MirrorNodeGateway.js @@ -90,7 +90,10 @@ export default class MirrorNodeGateway { axios .get(url) .then((response) => resolve(response)) - .catch((error) => reject(error)); + .catch((error) => { + console.log('ERROR', error); + reject(error) + }); }); } From 404bac08266619edd0ec9e518b7b316f19d17fe0 Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Wed, 29 May 2024 16:23:29 +0300 Subject: [PATCH 28/49] update Signed-off-by: svetoslav-nikol0v --- .github/workflows/build.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 549e25003..5a9ec783a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -120,7 +120,11 @@ jobs: if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} run: task test:integration:codecov - - name: Run Hedera SDK Unit Tests Codecov + - name: Unit Test @hashgraph/sdk + if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && steps.playwright-deps.conclusion == 'success' && !cancelled() && always() }} + run: task test:unit:node + + - name: Codecov @hashgraph/sdk if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} run: task test:unit:codecov From 91289cfb200d2c0b9157cc0b0ffd1425e33070ce Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Wed, 29 May 2024 16:32:56 +0300 Subject: [PATCH 29/49] .. Signed-off-by: svetoslav-nikol0v --- .github/workflows/build.yml | 2 +- src/network/MirrorNodeRouter.js | 2 +- test/unit/AccountInfoMocking.js | 2 ++ test/unit/Mocker.js | 2 ++ 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5a9ec783a..0f6f805bf 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -122,7 +122,7 @@ jobs: - name: Unit Test @hashgraph/sdk if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && steps.playwright-deps.conclusion == 'success' && !cancelled() && always() }} - run: task test:unit:node + run: task test:unit - name: Codecov @hashgraph/sdk if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} diff --git a/src/network/MirrorNodeRouter.js b/src/network/MirrorNodeRouter.js index 3870e2fb4..4c4ba1875 100644 --- a/src/network/MirrorNodeRouter.js +++ b/src/network/MirrorNodeRouter.js @@ -55,7 +55,7 @@ export default class MirrorNodeRouter { throw new Error("Mirror address not found!"); } - if (ledgerId != null) { + if (ledgerId != null && !ledgerId.isLocalNode()) { path = HTTPS + mirrorNodeAddress.toString(); } else { // local node case diff --git a/test/unit/AccountInfoMocking.js b/test/unit/AccountInfoMocking.js index cde177b1a..eca2b8587 100644 --- a/test/unit/AccountInfoMocking.js +++ b/test/unit/AccountInfoMocking.js @@ -142,6 +142,8 @@ describe("AccountInfoMocking", function () { errorName = error.name; } + console.log(errorName); + expect(errorName).to.be.eql("MaxQueryPaymentExceededError"); }); diff --git a/test/unit/Mocker.js b/test/unit/Mocker.js index 283c4558a..25d92b0d6 100644 --- a/test/unit/Mocker.js +++ b/test/unit/Mocker.js @@ -5,6 +5,7 @@ import { Client, Wallet, LocalProvider, + LedgerId, } from "../../src/index.js"; import * as grpc from "@grpc/grpc-js"; import * as loader from "@grpc/proto-loader"; @@ -453,6 +454,7 @@ class GrpcServers { return new Client({ network, scheduleNetworkUpdate: false }) .setMirrorNetwork(Object.keys(network)) + .setLedgerId(LedgerId.LOCAL_NODE) .setNodeMinBackoff(0) .setNodeMaxBackoff(0) .setNodeMinReadmitPeriod(0) From abef8df6bbc671a582f68b91c1f713cc6581edb6 Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Wed, 29 May 2024 16:55:07 +0300 Subject: [PATCH 30/49] workflow Signed-off-by: svetoslav-nikol0v --- .github/workflows/build.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0f6f805bf..318be433f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -120,14 +120,6 @@ jobs: if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} run: task test:integration:codecov - - name: Unit Test @hashgraph/sdk - if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && steps.playwright-deps.conclusion == 'success' && !cancelled() && always() }} - run: task test:unit - - - name: Codecov @hashgraph/sdk - if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} - run: task test:unit:codecov - - name: Stop the local node id: stop-local-node if: ${{ steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} @@ -145,5 +137,13 @@ jobs: - name: Codecov @hashgraph/cryptography working-directory: packages/cryptography + if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && !cancelled() && always() }} + run: task test:unit:codecov + + - name: Unit Test @hashgraph/sdk + if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && steps.playwright-deps.conclusion == 'success' && !cancelled() && always() }} + run: task test:unit + + - name: Codecov @hashgraph/sdk if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && !cancelled() && always() }} run: task test:unit:codecov \ No newline at end of file From 439cbc11ba5eecd008a94261f0c0ab78c3e2ee90 Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Wed, 29 May 2024 16:56:41 +0300 Subject: [PATCH 31/49] log Signed-off-by: svetoslav-nikol0v --- test/unit/Mocker.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/unit/Mocker.js b/test/unit/Mocker.js index 25d92b0d6..e778e950f 100644 --- a/test/unit/Mocker.js +++ b/test/unit/Mocker.js @@ -452,13 +452,17 @@ class GrpcServers { await server.listen(address); } - return new Client({ network, scheduleNetworkUpdate: false }) + const client = new Client({ network, scheduleNetworkUpdate: false }) .setMirrorNetwork(Object.keys(network)) .setLedgerId(LedgerId.LOCAL_NODE) .setNodeMinBackoff(0) .setNodeMaxBackoff(0) .setNodeMinReadmitPeriod(0) .setNodeMaxReadmitPeriod(0); + + + console.log(client); + return client } close() { From 665001931806f4ffa1b556993d9ffd1bba3271c0 Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Thu, 30 May 2024 09:20:39 +0300 Subject: [PATCH 32/49] update Signed-off-by: svetoslav-nikol0v --- .github/workflows/build.yml | 18 +++++++++--------- src/account/AccountInfoQuery.js | 2 -- src/network/MirrorNodeGateway.js | 5 +---- test/unit/Mocker.js | 6 +----- 4 files changed, 11 insertions(+), 20 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 318be433f..f425510e6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -114,12 +114,20 @@ jobs: run: | npx @hashgraph/hedera-local start -d --network-tag=0.49.7 --balance=100000 # Wait for the network to fully start - sleep 30 + sleep 60 - name: Run Hedera SDK Integration Tests Codecov if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} run: task test:integration:codecov + - name: Unit Test @hashgraph/sdk + if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && steps.playwright-deps.conclusion == 'success' && !cancelled() && always() }} + run: task test:unit + + - name: Codecov @hashgraph/sdk + if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} + run: task test:unit:codecov + - name: Stop the local node id: stop-local-node if: ${{ steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} @@ -137,13 +145,5 @@ jobs: - name: Codecov @hashgraph/cryptography working-directory: packages/cryptography - if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && !cancelled() && always() }} - run: task test:unit:codecov - - - name: Unit Test @hashgraph/sdk - if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && steps.playwright-deps.conclusion == 'success' && !cancelled() && always() }} - run: task test:unit - - - name: Codecov @hashgraph/sdk if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && !cancelled() && always() }} run: task test:unit:codecov \ No newline at end of file diff --git a/src/account/AccountInfoQuery.js b/src/account/AccountInfoQuery.js index 9859a7d1a..b4bf9d24c 100644 --- a/src/account/AccountInfoQuery.js +++ b/src/account/AccountInfoQuery.js @@ -184,8 +184,6 @@ export default class AccountInfoQuery extends Query { this._ledgerId, ); - console.log('mirrorNetwork', this._mirrorNetwork); - console.log('ledgerId', this._ledgerId); const mirrorNodeService = new MirrorNodeService(mirrorNodeGateway); const info = diff --git a/src/network/MirrorNodeGateway.js b/src/network/MirrorNodeGateway.js index 8ee92220c..c9ca694ab 100644 --- a/src/network/MirrorNodeGateway.js +++ b/src/network/MirrorNodeGateway.js @@ -90,10 +90,7 @@ export default class MirrorNodeGateway { axios .get(url) .then((response) => resolve(response)) - .catch((error) => { - console.log('ERROR', error); - reject(error) - }); + .catch((error) => reject(error)); }); } diff --git a/test/unit/Mocker.js b/test/unit/Mocker.js index e778e950f..25d92b0d6 100644 --- a/test/unit/Mocker.js +++ b/test/unit/Mocker.js @@ -452,17 +452,13 @@ class GrpcServers { await server.listen(address); } - const client = new Client({ network, scheduleNetworkUpdate: false }) + return new Client({ network, scheduleNetworkUpdate: false }) .setMirrorNetwork(Object.keys(network)) .setLedgerId(LedgerId.LOCAL_NODE) .setNodeMinBackoff(0) .setNodeMaxBackoff(0) .setNodeMinReadmitPeriod(0) .setNodeMaxReadmitPeriod(0); - - - console.log(client); - return client } close() { From e119fa9729d84c45fabc078cb1fd98b9ad0c62d9 Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Thu, 30 May 2024 10:19:29 +0300 Subject: [PATCH 33/49] update: workflow Signed-off-by: svetoslav-nikol0v --- .github/workflows/build.yml | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f425510e6..12c4003c4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -120,30 +120,30 @@ jobs: if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} run: task test:integration:codecov - - name: Unit Test @hashgraph/sdk - if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && steps.playwright-deps.conclusion == 'success' && !cancelled() && always() }} - run: task test:unit - - - name: Codecov @hashgraph/sdk - if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} - run: task test:unit:codecov - - - name: Stop the local node - id: stop-local-node - if: ${{ steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} - run: npx @hashgraph/hedera-local stop - - name: Build @hashgraph/cryptography working-directory: packages/cryptography - if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && !cancelled() && always() }} + if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} run: task build - name: Unit Test @hashgraph/cryptography working-directory: packages/cryptography - if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && !cancelled() && always() }} + if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} run: task test:unit - name: Codecov @hashgraph/cryptography working-directory: packages/cryptography - if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && !cancelled() && always() }} - run: task test:unit:codecov \ No newline at end of file + if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} + run: task test:unit:codecov + + - name: Unit Test @hashgraph/sdk + if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && steps.playwright-deps.conclusion == 'success' && !cancelled() && always() }} + run: task test:unit + + - name: Codecov @hashgraph/sdk + if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} + run: task test:unit:codecov + + - name: Stop the local node + id: stop-local-node + if: ${{ steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} + run: npx @hashgraph/hedera-local stop \ No newline at end of file From bae37ba0d4fbf4d6271165fdaa5f464d76e0f00f Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Thu, 30 May 2024 11:38:44 +0300 Subject: [PATCH 34/49] update Signed-off-by: svetoslav-nikol0v --- .github/workflows/build.yml | 2 +- src/network/MirrorNodeService.js | 15 +++--- src/token/TokenFreezeStatus.js | 87 -------------------------------- src/token/TokenKycStatus.js | 87 -------------------------------- test/unit/Mocker.js | 2 +- 5 files changed, 9 insertions(+), 184 deletions(-) delete mode 100644 src/token/TokenFreezeStatus.js delete mode 100644 src/token/TokenKycStatus.js diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 12c4003c4..c887d7f0b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -114,7 +114,7 @@ jobs: run: | npx @hashgraph/hedera-local start -d --network-tag=0.49.7 --balance=100000 # Wait for the network to fully start - sleep 60 + sleep 30 - name: Run Hedera SDK Integration Tests Codecov if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} diff --git a/src/network/MirrorNodeService.js b/src/network/MirrorNodeService.js index a8a41d29a..3c2e2b593 100644 --- a/src/network/MirrorNodeService.js +++ b/src/network/MirrorNodeService.js @@ -26,8 +26,7 @@ */ import TokenId from "../token/TokenId.js"; import Long from "long"; -import TokenKycStatus from "../token/TokenKycStatus.js"; -import TokenFreezeStatus from "../token/TokenFreezeStatus.js"; +import hashgraph from "@hashgraph/proto/lib/proto.js"; /** * @typedef MirrorNodeTokenResponse @@ -148,11 +147,11 @@ export default class MirrorNodeService { getTokenKycStatusFrom(status) { switch (status) { case "NOT_APPLICABLE": - return TokenKycStatus.KycNotApplicable.valueOf(); + return hashgraph.proto.TokenKycStatus.KycNotApplicable; case "GRANTED": - return TokenKycStatus.Granted.valueOf(); + return hashgraph.proto.TokenKycStatus.Granted; case "REVOKED": - return TokenKycStatus.Revoked.valueOf(); + return hashgraph.proto.TokenKycStatus.Revoked; default: throw new Error(`Invalid token KYC status: ${status}`); } @@ -166,11 +165,11 @@ export default class MirrorNodeService { getTokenFreezeStatusFrom(status) { switch (status) { case "NOT_APPLICABLE": - return TokenFreezeStatus.FreezeNotApplicable.valueOf(); + return hashgraph.proto.TokenFreezeStatus.FreezeNotApplicable; case "FROZEN": - return TokenFreezeStatus.Frozen.valueOf(); + return hashgraph.proto.TokenFreezeStatus.Frozen; case "UNFROZEN": - return TokenFreezeStatus.Unfrozen.valueOf(); + return hashgraph.proto.TokenFreezeStatus.Unfrozen; default: throw new Error(`Invalid token freeze status: ${status}`); } diff --git a/src/token/TokenFreezeStatus.js b/src/token/TokenFreezeStatus.js deleted file mode 100644 index 13b06c8cd..000000000 --- a/src/token/TokenFreezeStatus.js +++ /dev/null @@ -1,87 +0,0 @@ -/*- - * ‌ - * Hedera JavaScript SDK - * ​ - * Copyright (C) 2020 - 2023 Hedera Hashgraph, LLC - * ​ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ‍ - */ - -/** - * @namespace proto - * @typedef {import("@hashgraph/proto").proto.TokenFreezeStatus} HashgraphProto.proto.TokenFreezeStatus - */ - -export default class TokenFreezeStatus { - /** - * @hideconstructor - * @internal - * @param {number} code - */ - constructor(code) { - /** @readonly */ - this._code = code; - - Object.freeze(this); - } - - /** - * @returns {string} - */ - toString() { - switch (this) { - case TokenFreezeStatus.FreezeNotApplicable: - return "NOT_APPLICABLE"; - case TokenFreezeStatus.Frozen: - return "GRANTED"; - case TokenFreezeStatus.Unfrozen: - return "REVOKED"; - default: - return `UNKNOWN (${this._code})`; - } - } - - /** - * @internal - * @param {number} code - * @returns {TokenFreezeStatus} - */ - static _fromCode(code) { - switch (code) { - case 0: - return TokenFreezeStatus.FreezeNotApplicable; - case 1: - return TokenFreezeStatus.Frozen; - case 2: - return TokenFreezeStatus.Unfrozen; - } - - throw new Error( - `(BUG) TokenFreezeStatus.fromCode() does not handle code: ${code}`, - ); - } - - /** - * @returns {HashgraphProto.proto.TokenFreezeStatus} - */ - valueOf() { - return this._code; - } -} - -TokenFreezeStatus.FreezeNotApplicable = new TokenFreezeStatus(0); - -TokenFreezeStatus.Frozen = new TokenFreezeStatus(1); - -TokenFreezeStatus.Unfrozen = new TokenFreezeStatus(2); diff --git a/src/token/TokenKycStatus.js b/src/token/TokenKycStatus.js deleted file mode 100644 index 53d0ad496..000000000 --- a/src/token/TokenKycStatus.js +++ /dev/null @@ -1,87 +0,0 @@ -/*- - * ‌ - * Hedera JavaScript SDK - * ​ - * Copyright (C) 2020 - 2023 Hedera Hashgraph, LLC - * ​ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ‍ - */ - -/** - * @namespace proto - * @typedef {import("@hashgraph/proto").proto.TokenKycStatus} HashgraphProto.proto.TokenKycStatus - */ - -export default class TokenKycStatus { - /** - * @hideconstructor - * @internal - * @param {number} code - */ - constructor(code) { - /** @readonly */ - this._code = code; - - Object.freeze(this); - } - - /** - * @returns {string} - */ - toString() { - switch (this) { - case TokenKycStatus.KycNotApplicable: - return "NOT_APPLICABLE"; - case TokenKycStatus.Granted: - return "GRANTED"; - case TokenKycStatus.Revoked: - return "REVOKED"; - default: - return `UNKNOWN (${this._code})`; - } - } - - /** - * @internal - * @param {number} code - * @returns {TokenKycStatus} - */ - static _fromCode(code) { - switch (code) { - case 0: - return TokenKycStatus.KycNotApplicable; - case 1: - return TokenKycStatus.Granted; - case 2: - return TokenKycStatus.Revoked; - } - - throw new Error( - `(BUG) TokenKycStatus.fromCode() does not handle code: ${code}`, - ); - } - - /** - * @returns {HashgraphProto.proto.TokenKycStatus} - */ - valueOf() { - return this._code; - } -} - -TokenKycStatus.KycNotApplicable = new TokenKycStatus(0); - -TokenKycStatus.Granted = new TokenKycStatus(1); - -TokenKycStatus.Revoked = new TokenKycStatus(2); diff --git a/test/unit/Mocker.js b/test/unit/Mocker.js index 25d92b0d6..0d20c183f 100644 --- a/test/unit/Mocker.js +++ b/test/unit/Mocker.js @@ -425,7 +425,7 @@ class GrpcServers { * @returns {this} */ addServer(responses) { - const address = `127.0.0.1:${50213 + this._index}`; + const address = `127.0.0.1:${1111 + this._index}`; const nodeAccountId = `0.0.${3 + this._index}`; const server = new GrpcServer(PROTOS).addResponses(responses); From ccb63b291009b4f3fb85abccbfb942f5de74167b Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Thu, 30 May 2024 11:41:42 +0300 Subject: [PATCH 35/49] update: workflow Signed-off-by: svetoslav-nikol0v --- .github/workflows/build.yml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c887d7f0b..318be433f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -120,30 +120,30 @@ jobs: if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} run: task test:integration:codecov + - name: Stop the local node + id: stop-local-node + if: ${{ steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} + run: npx @hashgraph/hedera-local stop + - name: Build @hashgraph/cryptography working-directory: packages/cryptography - if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} + if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && !cancelled() && always() }} run: task build - name: Unit Test @hashgraph/cryptography working-directory: packages/cryptography - if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} + if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && !cancelled() && always() }} run: task test:unit - name: Codecov @hashgraph/cryptography working-directory: packages/cryptography - if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} + if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && !cancelled() && always() }} run: task test:unit:codecov - - name: Unit Test @hashgraph/sdk - if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && steps.playwright-deps.conclusion == 'success' && !cancelled() && always() }} + - name: Unit Test @hashgraph/sdk + if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && steps.playwright-deps.conclusion == 'success' && !cancelled() && always() }} run: task test:unit - name: Codecov @hashgraph/sdk - if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} - run: task test:unit:codecov - - - name: Stop the local node - id: stop-local-node - if: ${{ steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} - run: npx @hashgraph/hedera-local stop \ No newline at end of file + if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && !cancelled() && always() }} + run: task test:unit:codecov \ No newline at end of file From b09ce7873a839f8223da6247eb747ef1b0ebf308 Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Thu, 30 May 2024 11:50:04 +0300 Subject: [PATCH 36/49] chore: formatting Signed-off-by: svetoslav-nikol0v --- src/network/MirrorNodeService.js | 14 +++++++------- test/integration/TopicMessageIntegrationTest.js | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/network/MirrorNodeService.js b/src/network/MirrorNodeService.js index 3c2e2b593..5e71b7a9e 100644 --- a/src/network/MirrorNodeService.js +++ b/src/network/MirrorNodeService.js @@ -26,7 +26,7 @@ */ import TokenId from "../token/TokenId.js"; import Long from "long"; -import hashgraph from "@hashgraph/proto/lib/proto.js"; +import * as HashgraphProto from "@hashgraph/proto"; /** * @typedef MirrorNodeTokenResponse @@ -147,11 +147,11 @@ export default class MirrorNodeService { getTokenKycStatusFrom(status) { switch (status) { case "NOT_APPLICABLE": - return hashgraph.proto.TokenKycStatus.KycNotApplicable; + return HashgraphProto.proto.TokenKycStatus.KycNotApplicable; case "GRANTED": - return hashgraph.proto.TokenKycStatus.Granted; + return HashgraphProto.proto.TokenKycStatus.Granted; case "REVOKED": - return hashgraph.proto.TokenKycStatus.Revoked; + return HashgraphProto.proto.TokenKycStatus.Revoked; default: throw new Error(`Invalid token KYC status: ${status}`); } @@ -165,11 +165,11 @@ export default class MirrorNodeService { getTokenFreezeStatusFrom(status) { switch (status) { case "NOT_APPLICABLE": - return hashgraph.proto.TokenFreezeStatus.FreezeNotApplicable; + return HashgraphProto.proto.TokenFreezeStatus.FreezeNotApplicable; case "FROZEN": - return hashgraph.proto.TokenFreezeStatus.Frozen; + return HashgraphProto.proto.TokenFreezeStatus.Frozen; case "UNFROZEN": - return hashgraph.proto.TokenFreezeStatus.Unfrozen; + return HashgraphProto.proto.TokenFreezeStatus.Unfrozen; default: throw new Error(`Invalid token freeze status: ${status}`); } diff --git a/test/integration/TopicMessageIntegrationTest.js b/test/integration/TopicMessageIntegrationTest.js index 6e63fed13..1ba1b352d 100644 --- a/test/integration/TopicMessageIntegrationTest.js +++ b/test/integration/TopicMessageIntegrationTest.js @@ -16,7 +16,7 @@ describe("TopicMessage", function () { env = await IntegrationTestEnv.new({ throwaway: true }); }); - it.only("should be executable", async function () { + it("should be executable", async function () { this.timeout(120000); const operatorId = env.operatorId; From 93f25f2bf9f1ea2a3d16f9e097ca72e3abfe008d Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Thu, 30 May 2024 11:53:30 +0300 Subject: [PATCH 37/49] update Signed-off-by: svetoslav-nikol0v --- src/network/MirrorNodeService.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/network/MirrorNodeService.js b/src/network/MirrorNodeService.js index 5e71b7a9e..0350cb092 100644 --- a/src/network/MirrorNodeService.js +++ b/src/network/MirrorNodeService.js @@ -26,7 +26,7 @@ */ import TokenId from "../token/TokenId.js"; import Long from "long"; -import * as HashgraphProto from "@hashgraph/proto"; +import * as hashgraphProto from "@hashgraph/proto"; /** * @typedef MirrorNodeTokenResponse @@ -147,11 +147,11 @@ export default class MirrorNodeService { getTokenKycStatusFrom(status) { switch (status) { case "NOT_APPLICABLE": - return HashgraphProto.proto.TokenKycStatus.KycNotApplicable; + return hashgraphProto.proto.TokenKycStatus.KycNotApplicable; case "GRANTED": - return HashgraphProto.proto.TokenKycStatus.Granted; + return hashgraphProto.proto.TokenKycStatus.Granted; case "REVOKED": - return HashgraphProto.proto.TokenKycStatus.Revoked; + return hashgraphProto.proto.TokenKycStatus.Revoked; default: throw new Error(`Invalid token KYC status: ${status}`); } @@ -165,11 +165,11 @@ export default class MirrorNodeService { getTokenFreezeStatusFrom(status) { switch (status) { case "NOT_APPLICABLE": - return HashgraphProto.proto.TokenFreezeStatus.FreezeNotApplicable; + return hashgraphProto.proto.TokenFreezeStatus.FreezeNotApplicable; case "FROZEN": - return HashgraphProto.proto.TokenFreezeStatus.Frozen; + return hashgraphProto.proto.TokenFreezeStatus.Frozen; case "UNFROZEN": - return HashgraphProto.proto.TokenFreezeStatus.Unfrozen; + return hashgraphProto.proto.TokenFreezeStatus.Unfrozen; default: throw new Error(`Invalid token freeze status: ${status}`); } From 43a71fa07c26e6f154851cd6a0c051c9c24a0adf Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Thu, 30 May 2024 12:28:32 +0300 Subject: [PATCH 38/49] update: workflow Signed-off-by: svetoslav-nikol0v --- .github/workflows/build.yml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 318be433f..38bca4c0c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -120,30 +120,30 @@ jobs: if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} run: task test:integration:codecov - - name: Stop the local node - id: stop-local-node - if: ${{ steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} - run: npx @hashgraph/hedera-local stop - - name: Build @hashgraph/cryptography working-directory: packages/cryptography - if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && !cancelled() && always() }} + if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} run: task build - name: Unit Test @hashgraph/cryptography working-directory: packages/cryptography - if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && !cancelled() && always() }} + if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} run: task test:unit - name: Codecov @hashgraph/cryptography working-directory: packages/cryptography - if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && !cancelled() && always() }} + if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} run: task test:unit:codecov - name: Unit Test @hashgraph/sdk - if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && steps.playwright-deps.conclusion == 'success' && !cancelled() && always() }} + if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && steps.playwright-deps.conclusion == 'success' && !cancelled() && always() }} run: task test:unit - name: Codecov @hashgraph/sdk - if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && !cancelled() && always() }} - run: task test:unit:codecov \ No newline at end of file + if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} + run: task test:unit:codecov + + - name: Stop the local node + id: stop-local-node + if: ${{ steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} + run: npx @hashgraph/hedera-local stop \ No newline at end of file From cdc252ac1426d529bc993c152f4465d0e4d3eb66 Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Thu, 30 May 2024 17:09:23 +0300 Subject: [PATCH 39/49] add: tests Signed-off-by: svetoslav-nikol0v --- src/network/MirrorNodeService.js | 32 ++++++++++++++++++----- test/unit/MirrorNodeService.js | 44 ++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 7 deletions(-) create mode 100644 test/unit/MirrorNodeService.js diff --git a/src/network/MirrorNodeService.js b/src/network/MirrorNodeService.js index 0350cb092..74e4a27f0 100644 --- a/src/network/MirrorNodeService.js +++ b/src/network/MirrorNodeService.js @@ -43,6 +43,23 @@ import * as hashgraphProto from "@hashgraph/proto"; * @typedef {import("./MirrorNodeGateway.js").default} MirrorNodeGateway */ +/** + * @enum {string} + */ +export const TokenFreezeStatusEnum = { + NOT_APPLICABLE: "NOT_APPLICABLE", + FROZEN: "FROZEN", + UNFROZEN: "UNFROZEN", +}; +/** + * @enum {string} + */ +export const TokenKeyStatusEnum = { + NOT_APPLICABLE: "NOT_APPLICABLE", + GRANTED: "GRANTED", + REVOKED: "REVOKED", +}; + export default class MirrorNodeService { /** * @param {MirrorNodeGateway} mirrorNodeGateway @@ -146,11 +163,11 @@ export default class MirrorNodeService { */ getTokenKycStatusFrom(status) { switch (status) { - case "NOT_APPLICABLE": + case TokenKeyStatusEnum.NOT_APPLICABLE: return hashgraphProto.proto.TokenKycStatus.KycNotApplicable; - case "GRANTED": + case TokenKeyStatusEnum.GRANTED: return hashgraphProto.proto.TokenKycStatus.Granted; - case "REVOKED": + case TokenKeyStatusEnum.REVOKED: return hashgraphProto.proto.TokenKycStatus.Revoked; default: throw new Error(`Invalid token KYC status: ${status}`); @@ -164,11 +181,12 @@ export default class MirrorNodeService { */ getTokenFreezeStatusFrom(status) { switch (status) { - case "NOT_APPLICABLE": - return hashgraphProto.proto.TokenFreezeStatus.FreezeNotApplicable; - case "FROZEN": + case TokenFreezeStatusEnum.NOT_APPLICABLE: + return hashgraphProto.proto.TokenFreezeStatus + .FreezeNotApplicable; + case TokenFreezeStatusEnum.FROZEN: return hashgraphProto.proto.TokenFreezeStatus.Frozen; - case "UNFROZEN": + case TokenFreezeStatusEnum.UNFROZEN: return hashgraphProto.proto.TokenFreezeStatus.Unfrozen; default: throw new Error(`Invalid token freeze status: ${status}`); diff --git a/test/unit/MirrorNodeService.js b/test/unit/MirrorNodeService.js new file mode 100644 index 000000000..beb898ae5 --- /dev/null +++ b/test/unit/MirrorNodeService.js @@ -0,0 +1,44 @@ +import { log } from "util"; +import MirrorNodeService, { + TokenKeyStatusEnum, + TokenFreezeStatusEnum, +} from "../../src/network/MirrorNodeService.js"; +import * as HashgraphProto from "@hashgraph/proto"; +import { expect } from "chai"; + +describe("MirrorNodeService", function () { + let mirrorNodeService; + + before(function () { + mirrorNodeService = new MirrorNodeService(); + }); + + it("should return the set timeout value", async function () { + mirrorNodeService.setTimeout(1000); + expect(mirrorNodeService._timeout).to.be.eql(1000); + }); + + it("getTokenFreezeStatusFrom helper function", async function () { + const statuses = Object.values(TokenFreezeStatusEnum); + + for (let i; i < statuses.length; i++) { + const freezeStatus = mirrorNodeService.getTokenFreezeStatusFrom( + statuses[i], + ); + expect(freezeStatus).to.be.eql( + HashgraphProto.proto.TokenFreezeStatus[i], + ); + } + }); + + it("getTokenKycStatusFrom helper function", async function () { + const statuses = Object.values(TokenKeyStatusEnum); + + for (let i; i < statuses.length; i++) { + const kycStatus = mirrorNodeService.getTokenKycStatusFrom( + statuses[i], + ); + expect(kycStatus).to.be.eql(HashgraphProto.proto.TokenKycStatus[i]); + } + }); +}); From f6eb0d13afb48a990c809d87e9cb8640957ceecc Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Thu, 30 May 2024 17:15:08 +0300 Subject: [PATCH 40/49] chore: formatting Signed-off-by: svetoslav-nikol0v --- test/unit/MirrorNodeService.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/unit/MirrorNodeService.js b/test/unit/MirrorNodeService.js index beb898ae5..4e10066c4 100644 --- a/test/unit/MirrorNodeService.js +++ b/test/unit/MirrorNodeService.js @@ -1,4 +1,3 @@ -import { log } from "util"; import MirrorNodeService, { TokenKeyStatusEnum, TokenFreezeStatusEnum, From 34ffbeaa2e62e1e74cfa2bb762bb72f8f576222a Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Fri, 31 May 2024 09:45:48 +0300 Subject: [PATCH 41/49] deprecate symbol Signed-off-by: svetoslav-nikol0v --- src/account/AccountBalance.js | 10 ---------- src/account/TokenRelationship.js | 20 ++++++++++++++++--- .../TokenAssociateIntegrationTest.js | 5 ++++- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/account/AccountBalance.js b/src/account/AccountBalance.js index 3a7ae31a2..4fe031fac 100644 --- a/src/account/AccountBalance.js +++ b/src/account/AccountBalance.js @@ -54,18 +54,8 @@ export default class AccountBalance { */ this.hbars = props.hbars; - /** - * @deprecated - Use the mirror node API https://docs.hedera.com/guides/docs/mirror-node-api/rest-api#api-v1-accounts instead - * @readonly - */ - // eslint-disable-next-line deprecation/deprecation this.tokens = props.tokens; - /** - * @deprecated - Use the mirror node API https://docs.hedera.com/guides/docs/mirror-node-api/rest-api#api-v1-accounts instead - * @readonly - */ - // eslint-disable-next-line deprecation/deprecation this.tokenDecimals = props.tokenDecimals; Object.freeze(this); diff --git a/src/account/TokenRelationship.js b/src/account/TokenRelationship.js index 095205710..7e8d65b97 100644 --- a/src/account/TokenRelationship.js +++ b/src/account/TokenRelationship.js @@ -41,6 +41,7 @@ export default class TokenRelationship { * @param {boolean | null} props.isKycGranted * @param {boolean | null} props.isFrozen * @param {boolean | null} props.automaticAssociation + * @param {number | null} props.decimals */ constructor(props) { /** @@ -53,8 +54,11 @@ export default class TokenRelationship { /** * The Symbol of the token * - * @readonly + * @deprecated - Not supported by consensus nodes (from hedera-services tag v0.50.x). + * Although the Mirror Node REST APIs still contain this feature, there is no straightforward way of integration, + * leading to this field being deprecated. */ + // eslint-disable-next-line deprecation/deprecation this.symbol = props.symbol; /** @@ -73,13 +77,19 @@ export default class TokenRelationship { this.isKycGranted = props.isKycGranted; /** - * The Freeze status of the account (FreezeNotApplicable, Frozen or Unfrozen). If the token - * does not have Freeze key, FreezeNotApplicable is returned + * Tokens divide into 10^decimals pieces * * @readonly */ this.isFrozen = props.isFrozen; + /** + Tokens divide into 10^decimals pieces + * + * @readonly + */ + this.decimals = props.decimals; + /** * Specifies if the relationship is created implicitly. False : explicitly associated, True : * implicitly associated. @@ -119,6 +129,8 @@ export default class TokenRelationship { : Long.ZERO, isKycGranted, isFrozen, + decimals: + relationship.decimals != null ? relationship.decimals : null, automaticAssociation: relationship.automaticAssociation != null ? relationship.automaticAssociation @@ -132,12 +144,14 @@ export default class TokenRelationship { _toProtobuf() { return { tokenId: this.tokenId._toProtobuf(), + // eslint-disable-next-line deprecation/deprecation symbol: this.symbol, balance: this.balance, kycStatus: this.isKycGranted == null ? 0 : this.isKycGranted ? 1 : 2, freezeStatus: this.isFrozen == null ? 0 : this.isFrozen ? 1 : 2, automaticAssociation: this.automaticAssociation, + decimals: this.decimals, }; } } diff --git a/test/integration/TokenAssociateIntegrationTest.js b/test/integration/TokenAssociateIntegrationTest.js index 98c0948e4..8a4323397 100644 --- a/test/integration/TokenAssociateIntegrationTest.js +++ b/test/integration/TokenAssociateIntegrationTest.js @@ -30,13 +30,14 @@ describe("TokenAssociate", function () { .execute(env.client); const account = (await response.getReceipt(env.client)).accountId; + const tokenDecimal = 3; const token = ( await ( await new TokenCreateTransaction() .setTokenName("ffff") .setTokenSymbol("F") - .setDecimals(3) + .setDecimals(tokenDecimal) .setInitialSupply(1000000) .setTreasuryAccountId(operatorId) .setAdminKey(operatorKey) @@ -67,11 +68,13 @@ describe("TokenAssociate", function () { expect(balances.tokens.get(token).toInt()).to.be.equal(0); const info = await new AccountInfoQuery() + .setTimeout(3000) .setAccountId(account) .execute(env.client); const relationship = info.tokenRelationships.get(token); + expect(relationship.decimals).to.be.equal(tokenDecimal); expect(relationship).to.be.not.null; expect(relationship.tokenId.toString()).to.be.equal(token.toString()); expect(relationship.balance.toInt()).to.be.equal(0); From 1d599001ee9636ef6560f5ce2982838bacbc708e Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Tue, 4 Jun 2024 10:18:30 +0300 Subject: [PATCH 42/49] update: review changes Signed-off-by: svetoslav-nikol0v --- common_js_test/src/test.js | 2 +- src/Executable.js | 1 + src/account/AccountBalanceQuery.js | 26 ++++++++++---------------- src/account/AccountInfoQuery.js | 29 +++++++++++++++-------------- src/account/TokenRelationship.js | 1 + src/contract/ContractInfoQuery.js | 17 +++++++---------- 6 files changed, 35 insertions(+), 41 deletions(-) diff --git a/common_js_test/src/test.js b/common_js_test/src/test.js index a8b5f0050..25296d198 100644 --- a/common_js_test/src/test.js +++ b/common_js_test/src/test.js @@ -2,7 +2,7 @@ const { Client, AccountBalanceQuery } = require("@hashgraph/sdk"); describe("CommonJS", function () { it("it should query each node's balance", async function () { - this.timeout(30000); + this.timeout(15000); const client = Client.forTestnet(); diff --git a/src/Executable.js b/src/Executable.js index c9da1140b..2cc9862fc 100644 --- a/src/Executable.js +++ b/src/Executable.js @@ -529,6 +529,7 @@ export default class Executable { // Set list of mirror network nodes with // which execution will be attempted this._mirrorNetwork = client.mirrorNetwork; + // Set current LedgerId of the network with // which execution will be attempted this._ledgerId = client.ledgerId; diff --git a/src/account/AccountBalanceQuery.js b/src/account/AccountBalanceQuery.js index 729ff5665..1a152bafb 100644 --- a/src/account/AccountBalanceQuery.js +++ b/src/account/AccountBalanceQuery.js @@ -237,14 +237,14 @@ export default class AccountBalanceQuery extends Query { ); const mirrorNodeService = new MirrorNodeService(mirrorNodeGateway); - const cryptogetAccountBalance = + const cryptogetAccountBalanceFromConsensusNode = /** @type {HashgraphProto.proto.ICryptoGetAccountBalanceResponse} */ ( response.cryptogetAccountBalance ); - if (cryptogetAccountBalance.accountID) { + if (cryptogetAccountBalanceFromConsensusNode.accountID) { const accountIdFromConsensusNode = AccountId._fromProtobuf( - cryptogetAccountBalance.accountID, + cryptogetAccountBalanceFromConsensusNode.accountID, ); mirrorNodeService @@ -257,25 +257,19 @@ export default class AccountBalanceQuery extends Query { /** @type {HashgraphProto.proto.ITokenBalance[]} */ tokenBalances, ) => { if ( - cryptogetAccountBalance && - cryptogetAccountBalance.tokenBalances && + cryptogetAccountBalanceFromConsensusNode?.tokenBalances && tokenBalances ) { - cryptogetAccountBalance.tokenBalances.splice( - 0, - cryptogetAccountBalance.tokenBalances - .length, + // Reset the array to avoid duplicates + cryptogetAccountBalanceFromConsensusNode.tokenBalances.length = 0; + // Add the token balances from the mirror node to the response fromn the consensus node + cryptogetAccountBalanceFromConsensusNode.tokenBalances.push( + ...tokenBalances, ); - for (const tokenBalance of tokenBalances) { - cryptogetAccountBalance.tokenBalances.push( - tokenBalance, - ); - } - resolve( AccountBalance._fromProtobuf( - cryptogetAccountBalance, + cryptogetAccountBalanceFromConsensusNode, ), ); } diff --git a/src/account/AccountInfoQuery.js b/src/account/AccountInfoQuery.js index b4bf9d24c..263b47677 100644 --- a/src/account/AccountInfoQuery.js +++ b/src/account/AccountInfoQuery.js @@ -186,14 +186,17 @@ export default class AccountInfoQuery extends Query { const mirrorNodeService = new MirrorNodeService(mirrorNodeGateway); - const info = + const accountInfoFromConsensusNode = /** @type {HashgraphProto.proto.ICryptoGetInfoResponse} */ ( response.cryptoGetInfo ); - if (info.accountInfo && info.accountInfo.accountID) { + if ( + accountInfoFromConsensusNode.accountInfo && + accountInfoFromConsensusNode.accountInfo.accountID + ) { const accountIdFromConsensusNode = AccountId._fromProtobuf( - info.accountInfo.accountID, + accountInfoFromConsensusNode.accountInfo.accountID, ); mirrorNodeService @@ -203,25 +206,23 @@ export default class AccountInfoQuery extends Query { ) .then((tokensRelationships) => { if ( - info.accountInfo && - info.accountInfo.tokenRelationships && + accountInfoFromConsensusNode.accountInfo + ?.tokenRelationships && tokensRelationships ) { - info.accountInfo.tokenRelationships.splice( - 0, - info.accountInfo.tokenRelationships.length, + // Reset the array to avoid duplicates + accountInfoFromConsensusNode.accountInfo.tokenRelationships.length = 0; + + // Add the token relationships from the mirror node to the response fromn the consensus node + accountInfoFromConsensusNode.accountInfo.tokenRelationships.push( + ...tokensRelationships, ); - for (const tokenRelationship of tokensRelationships) { - info.accountInfo.tokenRelationships.push( - tokenRelationship, - ); - } } resolve( AccountInfo._fromProtobuf( /** @type {HashgraphProto.proto.CryptoGetInfoResponse.IAccountInfo} */ ( - info.accountInfo + accountInfoFromConsensusNode.accountInfo ), ), ); diff --git a/src/account/TokenRelationship.js b/src/account/TokenRelationship.js index 7e8d65b97..3c69ac820 100644 --- a/src/account/TokenRelationship.js +++ b/src/account/TokenRelationship.js @@ -57,6 +57,7 @@ export default class TokenRelationship { * @deprecated - Not supported by consensus nodes (from hedera-services tag v0.50.x). * Although the Mirror Node REST APIs still contain this feature, there is no straightforward way of integration, * leading to this field being deprecated. + * Can be extracted from TokenInfo class. */ // eslint-disable-next-line deprecation/deprecation this.symbol = props.symbol; diff --git a/src/contract/ContractInfoQuery.js b/src/contract/ContractInfoQuery.js index 773f0979b..34a6fb09d 100644 --- a/src/contract/ContractInfoQuery.js +++ b/src/contract/ContractInfoQuery.js @@ -201,19 +201,16 @@ export default class ContractInfoQuery extends Query { ) .then((tokensRelationships) => { if ( - info.contractInfo && - info.contractInfo.tokenRelationships && + info.contractInfo?.tokenRelationships && tokensRelationships ) { - info.contractInfo.tokenRelationships.splice( - 0, - info.contractInfo.tokenRelationships.length, + // Reset the array to avoid duplicates + info.contractInfo.tokenRelationships.length = 0; + + // Add the token relationships from the mirror node to the response fromn the consensus node + info.contractInfo.tokenRelationships.push( + ...tokensRelationships, ); - for (const tokenRelationship of tokensRelationships) { - info.contractInfo.tokenRelationships.push( - tokenRelationship, - ); - } } resolve( From bbb9299700d1f4a64056035864ad69aab6a5e84c Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Tue, 4 Jun 2024 13:52:55 +0300 Subject: [PATCH 43/49] update: added missing statuses Signed-off-by: svetoslav-nikol0v --- src/Status.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/Status.js b/src/Status.js index c9f3dae99..d0314bd36 100644 --- a/src/Status.js +++ b/src/Status.js @@ -651,6 +651,16 @@ export default class Status { return "INVALID_GRPC_CERTIFICATE"; case Status.InvalidMaxAutoAssociations: return "INVALID_MAX_AUTO_ASSOCIATIONS"; + case Status.MaxNodeHaveBeenCreated: + return "MAX_NODE_HAVE_BEEN_CREATED"; + case Status.IpFqdnCannotBeSetForSameEndpoint: + return "IP_FQDN_CANNOT_BE_SET_FOR_SAME_ENDPOINT"; + case Status.GossipEndpointCannotHaveFqdn: + return "GOSSIP_ENDPOINT_CANNOT_HAVE_FQDN"; + case Status.FqdnSizeTooLarge: + return "FQDN_SIZE_TOO_LARGE"; + case Status.InvalidEndpoint: + return "INVALID_ENDPOINT"; default: return `UNKNOWN (${this._code})`; } @@ -1273,6 +1283,16 @@ export default class Status { return Status.InvalidGrpcCertificate; case 346: return Status.InvalidMaxAutoAssociations; + case 347: + return Status.MaxNodeHaveBeenCreated; + case 348: + return Status.IpFqdnCannotBeSetForSameEndpoint; + case 349: + return Status.GossipEndpointCannotHaveFqdn; + case 350: + return Status.FqdnSizeTooLarge; + case 351: + return Status.InvalidEndpoint; default: throw new Error( `(BUG) Status.fromCode() does not handle code: ${code}`, @@ -2855,3 +2875,29 @@ Status.InvalidGrpcCertificate = new Status(345); * The most common cause for this error is a value less than `-1`. */ Status.InvalidMaxAutoAssociations = new Status(346); + +/** + * The maximum number of nodes allowed in the address book have been created. + */ +Status.MaxNodeHaveBeenCreated = new Status(347); + +/** + * In ServiceEndpoint, domain_name and ipAddressV4 are mutually exclusive + */ +Status.IpFqdnCannotBeSetForSameEndpoint = new Status(348); + + +/** + * Fully qualified domain name is not allowed in gossip_endpoint + */ +Status.GossipEndpointCannotHaveFqdn = new Status(349); + +/** + * In ServiceEndpoint, domain_name size too large + */ +Status.FqdnSizeTooLarge = new Status(350); + +/** + * ServiceEndpoint is invalid + */ +Status.InvalidEndpoint = new Status(351); \ No newline at end of file From 7c3d1a2591d9084a6904e2b85bb27627fe7a9530 Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Tue, 4 Jun 2024 14:00:01 +0300 Subject: [PATCH 44/49] chore: renaming Signed-off-by: svetoslav-nikol0v --- src/network/MirrorNodeGateway.js | 6 +++--- src/network/MirrorNodeRouter.js | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/network/MirrorNodeGateway.js b/src/network/MirrorNodeGateway.js index c9ca694ab..db6f056b0 100644 --- a/src/network/MirrorNodeGateway.js +++ b/src/network/MirrorNodeGateway.js @@ -67,13 +67,13 @@ export default class MirrorNodeGateway { } /** - * @param {string[]} mirrorNetwork + * @param {string[]} mirrorNetworkNodes * @param {?LedgerId} ledgerId * @returns {MirrorNodeGateway} */ - static forNetwork(mirrorNetwork, ledgerId) { + static forNetwork(mirrorNetworkNodes, ledgerId) { const mirrorNodeUrl = MirrorNodeRouter.getMirrorNodeUrl( - mirrorNetwork, + mirrorNetworkNodes, ledgerId, ); diff --git a/src/network/MirrorNodeRouter.js b/src/network/MirrorNodeRouter.js index 4c4ba1875..4347c024f 100644 --- a/src/network/MirrorNodeRouter.js +++ b/src/network/MirrorNodeRouter.js @@ -39,15 +39,15 @@ const LOCAL_NODE_PORT = "5551"; export default class MirrorNodeRouter { /** * Set mirror node url - * @param {string[]} mirrorNetwork + * @param {string[]} mirrorNetworkNodes * @param {LedgerId | null} ledgerId * @returns {string} */ - static getMirrorNodeUrl(mirrorNetwork, ledgerId) { + static getMirrorNodeUrl(mirrorNetworkNodes, ledgerId) { let path; let mirrorNodeAddress; - mirrorNodeAddress = mirrorNetwork.map((a) => + mirrorNodeAddress = mirrorNetworkNodes.map((a) => a.substring(0, a.indexOf(":")), )[0]; From e68c0c0fd242b4dbe9f1339b97daa7c08bf0372e Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Tue, 4 Jun 2024 14:17:58 +0300 Subject: [PATCH 45/49] chore: naming Signed-off-by: svetoslav-nikol0v --- src/Executable.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Executable.js b/src/Executable.js index 2cc9862fc..419445597 100644 --- a/src/Executable.js +++ b/src/Executable.js @@ -141,7 +141,7 @@ export default class Executable { * @protected * @type {string[]} */ - this._mirrorNetwork = []; + this._mirrorNetworkNodes = []; /** * Current LedgerId of the network with which execution will be attempted. @@ -528,7 +528,7 @@ export default class Executable { async execute(client, requestTimeout) { // Set list of mirror network nodes with // which execution will be attempted - this._mirrorNetwork = client.mirrorNetwork; + this._mirrorNetworkNodes = client.mirrorNetwork; // Set current LedgerId of the network with // which execution will be attempted From afca2d48e9200e8daa5c147feb865f3c876bbd4e Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Tue, 4 Jun 2024 14:24:44 +0300 Subject: [PATCH 46/49] chore: formatting Signed-off-by: svetoslav-nikol0v --- src/Status.js | 3 +-- src/account/AccountBalanceQuery.js | 2 +- src/account/AccountInfoQuery.js | 2 +- src/contract/ContractInfoQuery.js | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Status.js b/src/Status.js index d0314bd36..2bd178b86 100644 --- a/src/Status.js +++ b/src/Status.js @@ -2886,7 +2886,6 @@ Status.MaxNodeHaveBeenCreated = new Status(347); */ Status.IpFqdnCannotBeSetForSameEndpoint = new Status(348); - /** * Fully qualified domain name is not allowed in gossip_endpoint */ @@ -2900,4 +2899,4 @@ Status.FqdnSizeTooLarge = new Status(350); /** * ServiceEndpoint is invalid */ -Status.InvalidEndpoint = new Status(351); \ No newline at end of file +Status.InvalidEndpoint = new Status(351); diff --git a/src/account/AccountBalanceQuery.js b/src/account/AccountBalanceQuery.js index 1a152bafb..37c785a20 100644 --- a/src/account/AccountBalanceQuery.js +++ b/src/account/AccountBalanceQuery.js @@ -232,7 +232,7 @@ export default class AccountBalanceQuery extends Query { _mapResponse(response, nodeAccountId, request) { return new Promise((resolve, reject) => { const mirrorNodeGateway = MirrorNodeGateway.forNetwork( - this._mirrorNetwork, + this._mirrorNetworkNodes, this._ledgerId, ); const mirrorNodeService = new MirrorNodeService(mirrorNodeGateway); diff --git a/src/account/AccountInfoQuery.js b/src/account/AccountInfoQuery.js index 263b47677..6743b9dc6 100644 --- a/src/account/AccountInfoQuery.js +++ b/src/account/AccountInfoQuery.js @@ -180,7 +180,7 @@ export default class AccountInfoQuery extends Query { _mapResponse(response, nodeAccountId, request) { return new Promise((resolve, reject) => { const mirrorNodeGateway = MirrorNodeGateway.forNetwork( - this._mirrorNetwork, + this._mirrorNetworkNodes, this._ledgerId, ); diff --git a/src/contract/ContractInfoQuery.js b/src/contract/ContractInfoQuery.js index 34a6fb09d..f6de77b01 100644 --- a/src/contract/ContractInfoQuery.js +++ b/src/contract/ContractInfoQuery.js @@ -179,7 +179,7 @@ export default class ContractInfoQuery extends Query { _mapResponse(response, nodeAccountId, request) { return new Promise((resolve, reject) => { const mirrorNodeGateway = MirrorNodeGateway.forNetwork( - this._mirrorNetwork, + this._mirrorNetworkNodes, this._ledgerId, ); const mirrorNodeService = new MirrorNodeService(mirrorNodeGateway); From 6881780fcd4430dae27c565b76c4be6af5ecf937 Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Thu, 6 Jun 2024 09:17:39 +0300 Subject: [PATCH 47/49] fix: typo Signed-off-by: svetoslav-nikol0v --- src/account/AccountBalanceQuery.js | 2 +- src/account/AccountInfoQuery.js | 2 +- src/contract/ContractInfoQuery.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/account/AccountBalanceQuery.js b/src/account/AccountBalanceQuery.js index 37c785a20..467162da7 100644 --- a/src/account/AccountBalanceQuery.js +++ b/src/account/AccountBalanceQuery.js @@ -262,7 +262,7 @@ export default class AccountBalanceQuery extends Query { ) { // Reset the array to avoid duplicates cryptogetAccountBalanceFromConsensusNode.tokenBalances.length = 0; - // Add the token balances from the mirror node to the response fromn the consensus node + // Add the token balances from the mirror node to the response from the consensus node cryptogetAccountBalanceFromConsensusNode.tokenBalances.push( ...tokenBalances, ); diff --git a/src/account/AccountInfoQuery.js b/src/account/AccountInfoQuery.js index 6743b9dc6..595c9dfcd 100644 --- a/src/account/AccountInfoQuery.js +++ b/src/account/AccountInfoQuery.js @@ -213,7 +213,7 @@ export default class AccountInfoQuery extends Query { // Reset the array to avoid duplicates accountInfoFromConsensusNode.accountInfo.tokenRelationships.length = 0; - // Add the token relationships from the mirror node to the response fromn the consensus node + // Add the token relationships from the mirror node to the response from the consensus node accountInfoFromConsensusNode.accountInfo.tokenRelationships.push( ...tokensRelationships, ); diff --git a/src/contract/ContractInfoQuery.js b/src/contract/ContractInfoQuery.js index f6de77b01..c7dcfb311 100644 --- a/src/contract/ContractInfoQuery.js +++ b/src/contract/ContractInfoQuery.js @@ -207,7 +207,7 @@ export default class ContractInfoQuery extends Query { // Reset the array to avoid duplicates info.contractInfo.tokenRelationships.length = 0; - // Add the token relationships from the mirror node to the response fromn the consensus node + // Add the token relationships from the mirror node to the response from the consensus node info.contractInfo.tokenRelationships.push( ...tokensRelationships, ); From 20fd9f09ea737a32c84b69a805f611b3236e65ac Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Thu, 6 Jun 2024 10:37:03 +0300 Subject: [PATCH 48/49] update: add new response code Signed-off-by: svetoslav-nikol0v --- src/Status.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Status.js b/src/Status.js index 2bd178b86..0febc8673 100644 --- a/src/Status.js +++ b/src/Status.js @@ -651,8 +651,8 @@ export default class Status { return "INVALID_GRPC_CERTIFICATE"; case Status.InvalidMaxAutoAssociations: return "INVALID_MAX_AUTO_ASSOCIATIONS"; - case Status.MaxNodeHaveBeenCreated: - return "MAX_NODE_HAVE_BEEN_CREATED"; + case Status.MaxNodesCreated: + return "MAX_NODES_CREATED"; case Status.IpFqdnCannotBeSetForSameEndpoint: return "IP_FQDN_CANNOT_BE_SET_FOR_SAME_ENDPOINT"; case Status.GossipEndpointCannotHaveFqdn: @@ -661,6 +661,8 @@ export default class Status { return "FQDN_SIZE_TOO_LARGE"; case Status.InvalidEndpoint: return "INVALID_ENDPOINT"; + case Status.GossipEndpointsExceededLimit: + return "GOSSIP_ENDPOINTS_EXCEEDED_LIMIT"; default: return `UNKNOWN (${this._code})`; } @@ -1284,7 +1286,7 @@ export default class Status { case 346: return Status.InvalidMaxAutoAssociations; case 347: - return Status.MaxNodeHaveBeenCreated; + return Status.MaxNodesCreated; case 348: return Status.IpFqdnCannotBeSetForSameEndpoint; case 349: @@ -1293,6 +1295,8 @@ export default class Status { return Status.FqdnSizeTooLarge; case 351: return Status.InvalidEndpoint; + case 352: + return Status.GossipEndpointsExceededLimit; default: throw new Error( `(BUG) Status.fromCode() does not handle code: ${code}`, @@ -2879,7 +2883,7 @@ Status.InvalidMaxAutoAssociations = new Status(346); /** * The maximum number of nodes allowed in the address book have been created. */ -Status.MaxNodeHaveBeenCreated = new Status(347); +Status.MaxNodesCreated = new Status(347); /** * In ServiceEndpoint, domain_name and ipAddressV4 are mutually exclusive @@ -2900,3 +2904,8 @@ Status.FqdnSizeTooLarge = new Status(350); * ServiceEndpoint is invalid */ Status.InvalidEndpoint = new Status(351); + +/** + * The number of gossip endpoints exceeds the limit + */ +Status.GossipEndpointsExceededLimit = new Status(352); \ No newline at end of file From 495d2ed6fe5a44e0b761ddc00027b9392027397a Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Thu, 6 Jun 2024 11:40:18 +0300 Subject: [PATCH 49/49] update: build workflow Signed-off-by: svetoslav-nikol0v --- .github/workflows/build.yml | 64 +++++++++++++++++++++++++++++++------ 1 file changed, 54 insertions(+), 10 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 38bca4c0c..082c9a78d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,6 +19,9 @@ defaults: permissions: contents: read +env: + CG_EXEC: export R_UID=$(id -u); CGROUP_LOGLEVEL=DEBUG cgexec -g cpu,memory:user.slice/user-${R_UID}.slice/user@${R_UID}.service/e2e-${{ github.run_id }} --sticky ionice -c 2 -n 2 nice -n 19 + jobs: build: name: Build using Node ${{ matrix.node }} @@ -44,7 +47,7 @@ jobs: version: 3.35.1 - name: Install PNPM - uses: pnpm/action-setup@a3252b78c470c02df07e9d59298aecedc3ccdd6d # v3.0.0 + uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0 with: version: 8.15.4 @@ -65,6 +68,47 @@ jobs: node: [ "16" ] steps: + - name: Setup Control Groups + run: | + echo "::group::Get System Configuration" + USR_ID="$(id -un)" + GRP_ID="$(id -gn)" + E2E_MEM_LIMIT="30064771072" + AGENT_MEM_LIMIT="2147483648" + USER_SLICE="user.slice/user-$(id -u).slice" + USER_SERVICE="${USER_SLICE}/user@$(id -u).service" + E2E_GROUP_NAME="${USER_SERVICE}/e2e-${{ github.run_id }}" + AGENT_GROUP_NAME="${USER_SERVICE}/agent-${{ github.run_id }}" + echo "::endgroup::" + + echo "::group::Install Control Group Tools" + if ! command -v cgcreate >/dev/null 2>&1; then + sudo apt-get update + sudo apt-get install -y cgroup-tools + fi + echo "::endgroup::" + + echo "::group::Create Control Groups" + sudo cgcreate -g cpu,memory:${USER_SLICE} -a ${USR_ID}:${GRP_ID} -t ${USR_ID}:${GRP_ID} + sudo cgcreate -g cpu,memory:${USER_SERVICE} -a ${USR_ID}:${GRP_ID} -t ${USR_ID}:${GRP_ID} + sudo cgcreate -g cpu,memory:${E2E_GROUP_NAME} -a ${USR_ID}:${GRP_ID} -t ${USR_ID}:${GRP_ID} + sudo cgcreate -g cpu,memory:${AGENT_GROUP_NAME} -a ${USR_ID}:${GRP_ID} -t ${USR_ID}:${GRP_ID} + echo "::endgroup::" + + echo "::group::Set Control Group Limits" + cgset -r cpu.weight=768 ${E2E_GROUP_NAME} + cgset -r cpu.weight=500 ${AGENT_GROUP_NAME} + cgset -r memory.max=${E2E_MEM_LIMIT} ${E2E_GROUP_NAME} + cgset -r memory.max=${AGENT_MEM_LIMIT} ${AGENT_GROUP_NAME} + cgset -r memory.swap.max=${E2E_MEM_LIMIT} ${E2E_GROUP_NAME} + cgset -r memory.swap.max=${AGENT_MEM_LIMIT} ${AGENT_GROUP_NAME} + echo "::endgroup::" + + echo "::group::Move Runner Processes to Control Groups" + sudo cgclassify --sticky -g cpu,memory:${AGENT_GROUP_NAME} $(pgrep 'Runner.Listener' | tr '\n' ' ') + sudo cgclassify -g cpu,memory:${AGENT_GROUP_NAME} $(pgrep 'Runner.Worker' | tr '\n' ' ') + echo "::endgroup::" + - name: Harden Runner uses: step-security/harden-runner@f086349bfa2bd1361f7909c78558e816508cdc10 # v2.8.0 with: @@ -89,7 +133,7 @@ jobs: cat .env - name: Install PNPM - uses: pnpm/action-setup@a3252b78c470c02df07e9d59298aecedc3ccdd6d # v3.0.0 + uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0 with: version: 8.15.4 @@ -112,38 +156,38 @@ jobs: id: start-local-node if: ${{ steps.build-sdk.conclusion == 'success' && !cancelled() && always() }} run: | - npx @hashgraph/hedera-local start -d --network-tag=0.49.7 --balance=100000 + ${{ env.CG_EXEC }} npx @hashgraph/hedera-local start -d --network-tag=0.49.7 --balance=100000 # Wait for the network to fully start sleep 30 - name: Run Hedera SDK Integration Tests Codecov if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} - run: task test:integration:codecov + run: ${{ env.CG_EXEC }} task test:integration:codecov - name: Build @hashgraph/cryptography working-directory: packages/cryptography if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} - run: task build + run: ${{ env.CG_EXEC }} task build - name: Unit Test @hashgraph/cryptography working-directory: packages/cryptography if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} - run: task test:unit + run: ${{ env.CG_EXEC }} task test:unit - name: Codecov @hashgraph/cryptography working-directory: packages/cryptography if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} - run: task test:unit:codecov + run: ${{ env.CG_EXEC }} task test:unit:codecov - name: Unit Test @hashgraph/sdk if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && steps.playwright-deps.conclusion == 'success' && !cancelled() && always() }} - run: task test:unit + run: ${{ env.CG_EXEC }} task test:unit - name: Codecov @hashgraph/sdk if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} - run: task test:unit:codecov + run: ${{ env.CG_EXEC }} task test:unit:codecov - name: Stop the local node id: stop-local-node if: ${{ steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} - run: npx @hashgraph/hedera-local stop \ No newline at end of file + run: ${{ env.CG_EXEC }} npx @hashgraph/hedera-local stop \ No newline at end of file