diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9dbcaf7fd..ee93701c2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -102,7 +102,7 @@ jobs: id: start-local-node if: ${{ steps.build-sdk.conclusion == 'success' && !cancelled() && always() }} run: | - npx @hashgraph/hedera-local start -d --network local --balance=100000 + npx @hashgraph/hedera-local start -d --network-tag=0.48.0 --balance=100000 # Wait for the network to fully start sleep 30 diff --git a/src/token/TokenCreateTransaction.js b/src/token/TokenCreateTransaction.js index 1c335166f..0ea8b030a 100644 --- a/src/token/TokenCreateTransaction.js +++ b/src/token/TokenCreateTransaction.js @@ -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 @@ -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); @@ -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} client - * @returns {this} - */ - freezeWith(client) { - if (client != null && client.operatorAccountId != null) { - this._freezeWithAccountId(client.operatorAccountId); - } - - return super.freezeWith(client); - } - /** * @param {Client} client */ diff --git a/test/integration/TokenCreateIntegrationTest.js b/test/integration/TokenCreateIntegrationTest.js index b4da60200..fd50af46b 100644 --- a/test/integration/TokenCreateIntegrationTest.js +++ b/test/integration/TokenCreateIntegrationTest.js @@ -1,6 +1,7 @@ import { PrivateKey, Status, + Timestamp, TokenCreateTransaction, TokenDeleteTransaction, TokenInfoQuery, @@ -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; }); @@ -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; @@ -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); diff --git a/test/integration/TokenInfoIntegrationTest.js b/test/integration/TokenInfoIntegrationTest.js index ec4001557..389994a2c 100644 --- a/test/integration/TokenInfoIntegrationTest.js +++ b/test/integration/TokenInfoIntegrationTest.js @@ -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; }); @@ -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; }); diff --git a/test/integration/TokenUpdateIntegrationTest.js b/test/integration/TokenUpdateIntegrationTest.js index 7f5d47e3b..e40fb3fe1 100644 --- a/test/integration/TokenUpdateIntegrationTest.js +++ b/test/integration/TokenUpdateIntegrationTest.js @@ -70,12 +70,8 @@ describe("TokenUpdate", 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; await ( @@ -104,12 +100,8 @@ describe("TokenUpdate", 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; }); @@ -171,12 +163,8 @@ describe("TokenUpdate", 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; await ( @@ -219,12 +207,8 @@ describe("TokenUpdate", 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; }); diff --git a/test/unit/TokenCreateTransaction.js b/test/unit/TokenCreateTransaction.js index 7fc942503..90e8150ca 100644 --- a/test/unit/TokenCreateTransaction.js +++ b/test/unit/TokenCreateTransaction.js @@ -7,6 +7,7 @@ import { Timestamp, } from "../../src/index.js"; import Long from "long"; +import { DEFAULT_AUTO_RENEW_PERIOD } from "../../src/transaction/Transaction.js"; describe("TokenCreateTransaction", function () { it("encodes to correct protobuf", function () { @@ -34,6 +35,13 @@ describe("TokenCreateTransaction", function () { const autoRenewAccountId = new AccountId(10); const treasuryAccountId = new AccountId(11); + const expirationTime = new Timestamp( + Math.floor( + Date.now() / 1000 + DEFAULT_AUTO_RENEW_PERIOD.toNumber(), + ), + 0, + ); + const transaction = new TokenCreateTransaction() .setMaxTransactionFee(new Hbar(30)) .setTransactionId( @@ -48,6 +56,7 @@ describe("TokenCreateTransaction", function () { .setDecimals(7) .setTreasuryAccountId(treasuryAccountId) .setAutoRenewAccountId(autoRenewAccountId) + .setExpirationTime(expirationTime) .setAdminKey(key1) .setKycKey(key2) .setFreezeKey(key3) @@ -77,7 +86,7 @@ describe("TokenCreateTransaction", function () { autoRenewPeriod: { seconds: Long.fromValue(7776000), }, - expiry: null, + expiry: expirationTime._toProtobuf(), treasury: treasuryAccountId._toProtobuf(), adminKey: { ed25519: key1.publicKey.toBytesRaw(),