Skip to content

Commit

Permalink
Merge branch 'main' into 2239-fix-failing-integration-test-in-modular…
Browse files Browse the repository at this point in the history
…ised-version

Signed-off-by: svetoslav-nikol0v <[email protected]>
  • Loading branch information
svetoslav-nikol0v authored Apr 19, 2024
2 parents f62f5de + 65a2323 commit c15c168
Show file tree
Hide file tree
Showing 12 changed files with 226 additions and 79 deletions.
44 changes: 42 additions & 2 deletions .github/workflows/publish_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,32 @@ jobs:
- name: Install Playwright Dependencies
run: sudo npx playwright install-deps

- name: Check Proto Subpackage Publish Status
id: proto
working-directory: packages/proto
run: |
PACKAGE_VERSION="$(node -p "require('./package.json').version")"
PUBLISH_REQUIRED="false"
if ! curl -sSLf "https://registry.npmjs.org/@hashgraph/proto/${PACKAGE_VERSION}" >/dev/null 2>&1; then
PUBLISH_REQUIRED="true"
fi
echo "version=${PACKAGE_VERSION}" >>"${GITHUB_OUTPUT}"
echo "publish-required=${PUBLISH_REQUIRED}" >>"${GITHUB_OUTPUT}"
- name: Check Cryptography Subpackage Publish Status
id: cryptography
working-directory: packages/cryptography
run: |
PACKAGE_VERSION="$(node -p "require('./package.json').version")"
PUBLISH_REQUIRED="false"
if ! curl -sSLf "https://registry.npmjs.org/@hashgraph/cryptography/${PACKAGE_VERSION}" >/dev/null 2>&1; then
PUBLISH_REQUIRED="true"
fi
echo "version=${PACKAGE_VERSION}" >>"${GITHUB_OUTPUT}"
echo "publish-required=${PUBLISH_REQUIRED}" >>"${GITHUB_OUTPUT}"
- name: Calculate Publish Arguments
id: publish
run: |
Expand All @@ -188,14 +214,28 @@ jobs:
# Add the registry authentication stanza with variable substitution to the .npmrc configuration file.
echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}' >>".npmrc"
- name: Publish Release
- name: Publish Proto Release
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
working-directory: packages/proto
if: ${{ steps.proto.outputs.publish-required == 'true' && !cancelled() && !failure() }}
run: task publish -- ${{ steps.publish.outputs.args }}

- name: Publish Cryptography Release
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
working-directory: packages/cryptography
if: ${{ steps.cryptography.outputs.publish-required == 'true' && !cancelled() && !failure() }}
run: task publish -- ${{ steps.publish.outputs.args }}

- name: Publish SDK Release
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: task publish -- ${{ steps.publish.outputs.args }}

- name: Generate Github Release
uses: ncipollo/release-action@2c591bcc8ecdcd2db72b97d6147f871fcd833ba5 # v1.14.0
if: ${{ github.event.inputs.dry-run-enabled != 'true' }}
if: ${{ github.event.inputs.dry-run-enabled != 'true' && !cancelled() && !failure() }}
with:
tag: ${{ steps.validate-release.outputs.tag }}
prerelease: ${{ needs.validate-release.outputs.prerelease == 'true' }}
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## v2.44.0

## What's Changed

* fix: set correct autoRenrewAccountId by @svetoslav-nikol0v in https://github.com/hashgraph/hedera-sdk-js/pull/2217
* update: add a new getter to the TransferTransaction class by @svetoslav-nikol0v in https://github.com/hashgraph/hedera-sdk-js/pull/2214
* fix: integer overflow isuue for defaultMaxQueryPayment field by @svetoslav-nikol0v in https://github.com/hashgraph/hedera-sdk-js/pull/2213
* chore(ci): update the publish workflow to release the cryptography and proto artifacts if needed by @nathanklick in https://github.com/hashgraph/hedera-sdk-js/pull/2198

## v2.43.0

## What's Changed
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hashgraph/sdk",
"version": "2.43.0",
"version": "2.44.0",
"description": "Hedera™ Hashgraph SDK",
"types": "./lib/index.d.ts",
"main": "./lib/index.cjs",
Expand Down
7 changes: 7 additions & 0 deletions src/account/TransferTransaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,13 @@ export default class TransferTransaction extends Transaction {
return map;
}

/**
* @returns {Transfer[]}
*/
get hbarTransfersList() {
return this._hbarTransfers;
}

/**
* @internal
* @param {AccountId | string} accountId
Expand Down
5 changes: 4 additions & 1 deletion src/client/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import LedgerId from "../LedgerId.js";
import FileId from "../file/FileId.js";
import CACHE from "../Cache.js";
import Logger from "../logger/Logger.js"; // eslint-disable-line
import { convertToNumber } from "../util.js";

/**
* @typedef {import("../channel/Channel.js").default} Channel
Expand Down Expand Up @@ -449,7 +450,9 @@ export default class Client {
* @returns {Client<ChannelT, MirrorChannelT>}
*/
setDefaultMaxQueryPayment(defaultMaxQueryPayment) {
if (defaultMaxQueryPayment.toTinybars().toInt() < 0) {
const isMaxQueryPaymentNegative =
convertToNumber(defaultMaxQueryPayment.toTinybars()) < 0;
if (isMaxQueryPaymentNegative) {
throw new Error("defaultMaxQueryPayment must be non-negative");
}
this._defaultMaxQueryPayment = defaultMaxQueryPayment;
Expand Down
32 changes: 6 additions & 26 deletions src/token/TokenCreateTransaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,12 @@ export default class TokenCreateTransaction extends Transaction {
* @private
* @type {?Timestamp}
*/
this._expirationTime = null;
this._expirationTime = new Timestamp(
Math.floor(
Date.now() / 1000 + DEFAULT_AUTO_RENEW_PERIOD.toNumber(),
),
0,
);

/**
* @private
Expand Down Expand Up @@ -657,7 +662,6 @@ export default class TokenCreateTransaction extends Transaction {
*/
setExpirationTime(time) {
this._requireNotFrozen();
this._autoRenewPeriod = null;
this._expirationTime =
time instanceof Timestamp ? time : Timestamp.fromDate(time);

Expand Down Expand Up @@ -791,30 +795,6 @@ export default class TokenCreateTransaction extends Transaction {
return this;
}

/**
* @override
* @param {AccountId} accountId
*/
_freezeWithAccountId(accountId) {
super._freezeWithAccountId(accountId);

if (this._autoRenewPeriod != null && accountId != null) {
this._autoRenewAccountId = accountId;
}
}

/**
* @param {?import("../client/Client.js").default<Channel, *>} client
* @returns {this}
*/
freezeWith(client) {
if (client != null && client.operatorAccountId != null) {
this._freezeWithAccountId(client.operatorAccountId);
}

return super.freezeWith(client);
}

/**
* @param {Client} client
*/
Expand Down
18 changes: 18 additions & 0 deletions test/integration/ClientIntegrationTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,24 @@ describe("ClientIntegration", function () {
expect(clientTestnet.isTransportSecurity()).to.be.an("boolean");
});

it("should return the following error message `defaultMaxQueryPayment must be non-negative` when the user tries to set a negative value to the defaultMaxQueryPayment field", async function () {
this.timeout(120000);
try {
env.client.setDefaultMaxQueryPayment(new Hbar(1).negated());
} catch (error) {
expect(error.message).to.be.equal(
"defaultMaxQueryPayment must be non-negative",
);
}
});

it("should set defaultMaxQueryPayment field", async function () {
this.timeout(120000);
const value = new Hbar(100);
env.client.setDefaultMaxQueryPayment(value);
expect(env.client.defaultMaxQueryPayment).to.be.equal(value);
});

after(async function () {
await env.close();
clientTestnet.close();
Expand Down
106 changes: 94 additions & 12 deletions test/integration/TokenCreateIntegrationTest.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
PrivateKey,
Status,
Timestamp,
TokenCreateTransaction,
TokenDeleteTransaction,
TokenInfoQuery,
Expand Down Expand Up @@ -59,12 +60,8 @@ describe("TokenCreate", function () {
expect(info.defaultFreezeStatus).to.be.false;
expect(info.defaultKycStatus).to.be.false;
expect(info.isDeleted).to.be.false;
expect(info.autoRenewAccountId).to.be.not.null;
expect(info.autoRenewAccountId.toString()).to.be.eql(
operatorId.toString(),
);
expect(info.autoRenewPeriod).to.be.not.null;
expect(info.autoRenewPeriod.seconds.toInt()).to.be.eql(7776000);
expect(info.autoRenewAccountId).to.be.null;
expect(info.autoRenewPeriod).to.be.null;
expect(info.expirationTime).to.be.not.null;
});

Expand Down Expand Up @@ -101,12 +98,8 @@ describe("TokenCreate", function () {
expect(info.defaultFreezeStatus).to.be.null;
expect(info.defaultKycStatus).to.be.null;
expect(info.isDeleted).to.be.false;
expect(info.autoRenewAccountId).to.be.not.null;
expect(info.autoRenewAccountId.toString()).to.be.eql(
operatorId.toString(),
);
expect(info.autoRenewPeriod).to.be.not.null;
expect(info.autoRenewPeriod.seconds.toInt()).to.be.eql(7776000);
expect(info.autoRenewAccountId).to.be.null;
expect(info.autoRenewPeriod).to.be.null;
expect(info.expirationTime).to.be.not.null;

let err = false;
Expand All @@ -126,6 +119,95 @@ describe("TokenCreate", function () {
}
});

it("when autoRenewAccountId is set", async function () {
this.timeout(120000);

const operatorId = env.operatorId;

const response = await new TokenCreateTransaction()
.setTokenName("ffff")
.setTokenSymbol("F")
.setTreasuryAccountId(operatorId)
.setAutoRenewAccountId(operatorId)
.execute(env.client);

const tokenId = (await response.getReceipt(env.client)).tokenId;

const info = await new TokenInfoQuery()
.setTokenId(tokenId)
.execute(env.client);

expect(info.autoRenewAccountId).to.be.not.null;
expect(info.autoRenewAccountId.toString()).to.be.eql(
operatorId.toString(),
);
});

it("when expirationTime is set", async function () {
this.timeout(120000);

const operatorId = env.operatorId;
const DAYS_45_IN_SECONDS = 3888000;
const expirationTime = new Timestamp(
Math.floor(Date.now() / 1000 + DAYS_45_IN_SECONDS),
0,
);

const response = await new TokenCreateTransaction()
.setTokenName("ffff")
.setTokenSymbol("F")
.setTreasuryAccountId(operatorId)
.setExpirationTime(expirationTime)
.execute(env.client);

const tokenId = (await response.getReceipt(env.client)).tokenId;

const info = await new TokenInfoQuery()
.setTokenId(tokenId)
.execute(env.client);

expect(info.expirationTime).to.be.not.null;
expect(info.expirationTime.toString()).to.be.eql(
expirationTime.toString(),
);
});

it("when autoRenewAccountId and expirationTime are set", async function () {
this.timeout(120000);

const operatorId = env.operatorId;
const DAYS_90_IN_SECONDS = 7776000;
const expirationTime = new Timestamp(
Math.floor(Date.now() / 1000 + DAYS_90_IN_SECONDS),
0,
);

const response = await new TokenCreateTransaction()
.setTokenName("ffff")
.setTokenSymbol("F")
.setTreasuryAccountId(operatorId)
.setExpirationTime(expirationTime)
.setAutoRenewAccountId(operatorId)
.execute(env.client);

const tokenId = (await response.getReceipt(env.client)).tokenId;

const info = await new TokenInfoQuery()
.setTokenId(tokenId)
.execute(env.client);

expect(info.autoRenewAccountId).to.be.not.null;
expect(info.autoRenewAccountId.toString()).to.be.eql(
operatorId.toString(),
);
expect(info.autoRenewPeriod).to.be.not.null;
expect(info.autoRenewPeriod.seconds.toInt()).to.be.eql(7776000);
expect(info.expirationTime).to.be.not.null;
expect(info.expirationTime.toString()).to.be.eql(
expirationTime.toString(),
);
});

it("should error when token name is not set", async function () {
this.timeout(120000);

Expand Down
16 changes: 4 additions & 12 deletions test/integration/TokenInfoIntegrationTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,8 @@ describe("TokenInfo", function () {
expect(info.defaultFreezeStatus).to.be.false;
expect(info.defaultKycStatus).to.be.false;
expect(info.isDeleted).to.be.false;
expect(info.autoRenewAccountId).to.be.not.null;
expect(info.autoRenewAccountId.toString()).to.be.eql(
operatorId.toString(),
);
expect(info.autoRenewPeriod).to.be.not.null;
expect(info.autoRenewPeriod.seconds.toInt()).to.be.eql(7776000);
expect(info.autoRenewAccountId).to.be.null;
expect(info.autoRenewPeriod).to.be.null;
expect(info.expirationTime).to.be.not.null;
});

Expand Down Expand Up @@ -101,12 +97,8 @@ describe("TokenInfo", function () {
expect(info.defaultFreezeStatus).to.be.null;
expect(info.defaultKycStatus).to.be.null;
expect(info.isDeleted).to.be.false;
expect(info.autoRenewAccountId).to.be.not.null;
expect(info.autoRenewAccountId.toString()).to.be.eql(
operatorId.toString(),
);
expect(info.autoRenewPeriod).to.be.not.null;
expect(info.autoRenewPeriod.seconds.toInt()).to.be.eql(7776000);
expect(info.autoRenewAccountId).to.be.null;
expect(info.autoRenewPeriod).to.be.null;
expect(info.expirationTime).to.be.not.null;
});

Expand Down
Loading

0 comments on commit c15c168

Please sign in to comment.