From bc026d0a201f5a70dbe2e11be5fb52ef3ae13074 Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Wed, 28 Feb 2024 13:22:10 +0200 Subject: [PATCH 1/3] update: add execute method Signed-off-by: svetoslav-nikol0v --- src/system/FreezeTransaction.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/system/FreezeTransaction.js b/src/system/FreezeTransaction.js index 035b4102f..28ac8830e 100644 --- a/src/system/FreezeTransaction.js +++ b/src/system/FreezeTransaction.js @@ -382,6 +382,17 @@ export default class FreezeTransaction extends Transaction { ); return `FreezeTransaction:${timestamp.toString()}`; } + + /** + * @override + * @internal + * @param {Channel} channel + * @param {HashgraphProto.proto.ITransaction} request + * @returns {Promise} + */ + _execute(channel, request) { + return channel.freeze.freeze(request); + } } // eslint-disable-next-line @typescript-eslint/unbound-method From dfaa28c47bbb5da6e360ae324a9382fabf9f675d Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Wed, 28 Feb 2024 13:22:26 +0200 Subject: [PATCH 2/3] update: export FreezeType Signed-off-by: svetoslav-nikol0v --- src/exports.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/exports.js b/src/exports.js index 8223aad40..290940718 100644 --- a/src/exports.js +++ b/src/exports.js @@ -174,6 +174,7 @@ export { default as Logger } from "./logger/Logger.js"; export { default as LogLevel } from "./logger/LogLevel.js"; export { EntityIdHelper }; export { default as Long } from "long"; +export { default as FreezeType } from "./FreezeType.js"; export { default as StatusError } from "./StatusError.js"; export { default as PrecheckStatusError } from "./PrecheckStatusError.js"; From feda4c68301025b83b8c0d5b8ac213cfb1415a94 Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Wed, 28 Feb 2024 14:19:37 +0200 Subject: [PATCH 3/3] chore: integration and unit test added Signed-off-by: svetoslav-nikol0v --- .../FreezeTransactionIntegrationTest.js | 49 +++++++++++++++++++ test/unit/FreezeTransaction.js | 22 +++++++++ 2 files changed, 71 insertions(+) create mode 100644 test/integration/FreezeTransactionIntegrationTest.js create mode 100644 test/unit/FreezeTransaction.js diff --git a/test/integration/FreezeTransactionIntegrationTest.js b/test/integration/FreezeTransactionIntegrationTest.js new file mode 100644 index 000000000..20c15c52f --- /dev/null +++ b/test/integration/FreezeTransactionIntegrationTest.js @@ -0,0 +1,49 @@ +import { + Timestamp, + FreezeTransaction, + FreezeType, + // TransactionResponse, + // TransactionReceipt, + Status, +} from "../../src/exports.js"; +import IntegrationTestEnv from "./client/NodeIntegrationTestEnv.js"; + +describe("FreezeTransaction", function () { + let client; + + before(async function () { + const env = await IntegrationTestEnv.new(); + client = env.client; + }); + + it("should be executable but not supported", async function () { + this.timeout(120000); + const seconds = Math.round(Date.now() / 1000); + const validStart = new Timestamp(seconds, 0); + + const transaction = new FreezeTransaction() + .setStartTimestamp(validStart) + .setFreezeType(new FreezeType(1)) + .freezeWith(client); + expect(transaction.startTimestamp).to.be.equal(validStart); + expect(transaction.freezeType).to.be.instanceof(FreezeType); + + try { + await transaction.execute(client); + } catch (error) { + expect(error.status).to.be.equal(Status.NotSupported); + } + + // At the moment the API is not supported that's why the following lines are commented out. + // Once supported the try/catch block above should be removed. + // The status from execution of the transaction is code 13 which means NOT_SUPPORTED. + + // const response = await transaction.execute(client) + // expect(response).to.be.instanceof(TransactionResponse) + // const receipt = await response.getReceipt(client) + // expect(receipt).to.be.instanceof(TransactionReceipt) + // expect(receipt.status.toString).to.be.instanceof(Status.Success) + + client.close(); + }); +}); diff --git a/test/unit/FreezeTransaction.js b/test/unit/FreezeTransaction.js new file mode 100644 index 000000000..7f3a77cfd --- /dev/null +++ b/test/unit/FreezeTransaction.js @@ -0,0 +1,22 @@ +import { expect } from "chai"; + +import { FreezeTransaction, Timestamp, FreezeType } from "../../src/index.js"; + +describe("FreezeTransaction", function () { + it("create transaction and set ", function () { + const seconds = Math.round(Date.now() / 1000); + const validStart = new Timestamp(seconds, 0); + const freezeType = new FreezeType(1); + + const transaction = new FreezeTransaction() + .setStartTimestamp(validStart) + .setFreezeType(freezeType); + + expect(transaction).to.be.instanceof(FreezeTransaction); + expect(transaction.startTimestamp).to.be.equal(validStart); + expect(transaction.freezeType).to.be.instanceof(FreezeType); + expect(transaction.freezeType.toString()).to.be.equal( + freezeType.toString(), + ); + }); +});