From d84ec34e9d9d8227ace1d7975023d76915f826c2 Mon Sep 17 00:00:00 2001 From: Svetoslav Borislavov Date: Wed, 20 Nov 2024 12:48:18 +0200 Subject: [PATCH 01/12] feat: add unit tests for optional properties when deserializing NodeUpdateTransaction Signed-off-by: Svetoslav Borislavov --- test/unit/NodeUpdateTransaction.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/unit/NodeUpdateTransaction.js b/test/unit/NodeUpdateTransaction.js index 0eaf0aec1..dc525986d 100644 --- a/test/unit/NodeUpdateTransaction.js +++ b/test/unit/NodeUpdateTransaction.js @@ -277,4 +277,24 @@ describe("NodeUpdateTransaction", function () { expect(err).to.be.true; }); }); + + describe("deserialization of optional parameters", function () { + it("should deserialize with gossipCaCertificate, grpcCertificateHash being null", function () { + const tx = new NodeUpdateTransaction(); + const tx2 = NodeUpdateTransaction.fromBytes(tx.toBytes()); + + expect(tx.gossipCaCertificate).to.be.null; + expect(tx.certificateHash).to.be.null; + expect(tx2.gossipCaCertificate).to.be.null; + expect(tx2.certificateHash).to.be.null; + }); + + it("should deserialize with description being null", function () { + const tx = new NodeUpdateTransaction(); + const tx2 = NodeUpdateTransaction.fromBytes(tx.toBytes()); + + expect(tx.description).to.be.null; + expect(tx2.description).to.be.null; + }); + }); }); From 35d9e3032832c4014c92bcdb5cd67ab6220c5adc Mon Sep 17 00:00:00 2001 From: Svetoslav Borislavov Date: Wed, 20 Nov 2024 13:12:19 +0200 Subject: [PATCH 02/12] fix: NodeUpdateTransaction _fromProtobuf Signed-off-by: Svetoslav Borislavov --- src/node/NodeUpdateTransaction.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/node/NodeUpdateTransaction.js b/src/node/NodeUpdateTransaction.js index 3a9d9bd37..0ea77d3c0 100644 --- a/src/node/NodeUpdateTransaction.js +++ b/src/node/NodeUpdateTransaction.js @@ -60,8 +60,8 @@ export default class NodeUpdateTransaction extends Transaction { * @param {?string} [props.description] * @param {Array} [props.gossipEndpoints] * @param {?Array} [props.serviceEndpoints] - * @param {Uint8Array} [props.gossipCaCertificate] - * @param {Uint8Array} [props.grpcCertificateHash] + * @param {?Uint8Array} [props.gossipCaCertificate] + * @param {?Uint8Array} [props.grpcCertificateHash] * @param {Key} [props.adminKey] */ constructor(props) { @@ -164,7 +164,7 @@ export default class NodeUpdateTransaction extends Transaction { : undefined, description: nodeUpdate.description != null - ? nodeUpdate.description.value != null + ? Object.hasOwn(nodeUpdate.description, "value") ? nodeUpdate.description.value : undefined : undefined, @@ -182,13 +182,13 @@ export default class NodeUpdateTransaction extends Transaction { : undefined, gossipCaCertificate: nodeUpdate.gossipCaCertificate != null - ? nodeUpdate.gossipCaCertificate.value != null + ? Object.hasOwn(nodeUpdate.gossipCaCertificate, "value") ? nodeUpdate.gossipCaCertificate.value : undefined : undefined, grpcCertificateHash: nodeUpdate.grpcCertificateHash != null - ? nodeUpdate.grpcCertificateHash.value != null + ? Object.hasOwn(nodeUpdate.grpcCertificateHash, "value") ? nodeUpdate.grpcCertificateHash.value : undefined : undefined, From 8a9b6339cb44484ed6b0659ddf8228737211d1f7 Mon Sep 17 00:00:00 2001 From: Svetoslav Borislavov Date: Wed, 20 Nov 2024 13:18:33 +0200 Subject: [PATCH 03/12] fix: AccountUpdateTransaction _fromProtobuf Signed-off-by: Svetoslav Borislavov --- src/account/AccountUpdateTransaction.js | 18 ++++++++------ test/unit/AccountUpdateTransaction.js | 31 +++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 test/unit/AccountUpdateTransaction.js diff --git a/src/account/AccountUpdateTransaction.js b/src/account/AccountUpdateTransaction.js index c8a747e0c..a4746bf18 100644 --- a/src/account/AccountUpdateTransaction.js +++ b/src/account/AccountUpdateTransaction.js @@ -52,16 +52,16 @@ export default class AccountUpdateTransaction extends Transaction { * @param {object} props * @param {AccountId} [props.accountId] * @param {Key} [props.key] - * @param {boolean} [props.receiverSignatureRequired] + * @param {?boolean} [props.receiverSignatureRequired] * @param {AccountId} [props.proxyAccountId] * @param {Duration | Long | number} [props.autoRenewPeriod] * @param {Timestamp | Date} [props.expirationTime] - * @param {string} [props.accountMemo] + * @param {?string} [props.accountMemo] * @param {Long | number} [props.maxAutomaticTokenAssociations] * @param {Key} [props.aliasKey] * @param {AccountId | string} [props.stakedAccountId] * @param {Long | number} [props.stakedNodeId] - * @param {boolean} [props.declineStakingReward] + * @param {?boolean} [props.declineStakingReward] */ constructor(props = {}) { super(); @@ -224,7 +224,10 @@ export default class AccountUpdateTransaction extends Transaction { : undefined, receiverSignatureRequired: update.receiverSigRequiredWrapper != null - ? update.receiverSigRequiredWrapper.value != null + ? Object.hasOwn( + update.receiverSigRequiredWrapper, + "value", + ) ? update.receiverSigRequiredWrapper.value : undefined : undefined, @@ -248,13 +251,14 @@ export default class AccountUpdateTransaction extends Transaction { : undefined, accountMemo: update.memo != null - ? update.memo.value != null + ? Object.hasOwn(update.memo, "value") ? update.memo.value : undefined : undefined, maxAutomaticTokenAssociations: update.maxAutomaticTokenAssociations != null && - update.maxAutomaticTokenAssociations.value != null + update.maxAutomaticTokenAssociations.value != null && + Object.hasOwn(update.maxAutomaticTokenAssociations, "value") ? Long.fromNumber( update.maxAutomaticTokenAssociations.value, ) @@ -269,7 +273,7 @@ export default class AccountUpdateTransaction extends Transaction { : undefined, declineStakingReward: update.declineReward != null - ? update.declineReward.value != null + ? Object.hasOwn(update.declineReward, "value") ? update.declineReward.value : undefined : undefined, diff --git a/test/unit/AccountUpdateTransaction.js b/test/unit/AccountUpdateTransaction.js new file mode 100644 index 000000000..cdd65c097 --- /dev/null +++ b/test/unit/AccountUpdateTransaction.js @@ -0,0 +1,31 @@ +import { AccountUpdateTransaction } from "../../src/index.js"; + +describe("AccountUpdateTransaction", function () { + describe("deserialization of optional parameters", function () { + let tx, txBytes, tx2; + + before(function () { + tx = new AccountUpdateTransaction(); + txBytes = tx.toBytes(); + tx2 = AccountUpdateTransaction.fromBytes(txBytes); + }); + + it("should deserialize with accountMemo being null", function () { + expect(tx.accountMemo).to.be.null; + expect(tx2.accountMemo).to.be.null; + }); + + it("should deserialize with declineReward, receiverSignatureRequired being null", function () { + expect(tx.declineStakingRewards).to.be.null; + expect(tx2.declineStakingRewards).to.be.null; + + expect(tx.receiverSignatureRequired).to.be.null; + expect(tx2.receiverSignatureRequired).to.be.null; + }); + + it("should deserialize with maxAutomaticTokenAssociations being null", function () { + expect(tx.maxAutomaticTokenAssociations).to.be.null; + expect(tx2.maxAutomaticTokenAssociations).to.be.null; + }); + }); +}); From 609ae49b6be6970d6de8c0bbfce99c2e55285330 Mon Sep 17 00:00:00 2001 From: Svetoslav Borislavov Date: Wed, 20 Nov 2024 13:30:51 +0200 Subject: [PATCH 04/12] fix: ContractFunctionResult _fromProtobuf Signed-off-by: Svetoslav Borislavov --- src/contract/ContractFunctionResult.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/contract/ContractFunctionResult.js b/src/contract/ContractFunctionResult.js index dc0776553..77476bb19 100644 --- a/src/contract/ContractFunctionResult.js +++ b/src/contract/ContractFunctionResult.js @@ -213,8 +213,8 @@ export default class ContractFunctionResult { ), signerNonce: result.signerNonce != null - ? result.signerNonce.value - ? result.signerNonce.value + ? Object.hasOwn(result.signerNonce, "value") + ? result.signerNonce.value || null : null : null, }); From fb112c093923f8a17622e688c861cc078e8a3be6 Mon Sep 17 00:00:00 2001 From: Svetoslav Borislavov Date: Wed, 20 Nov 2024 13:52:37 +0200 Subject: [PATCH 05/12] fix: TokenTransfer _fromProtobuf Signed-off-by: Svetoslav Borislavov --- src/token/TokenTransfer.js | 8 ++++---- test/unit/TokenTransfer.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 test/unit/TokenTransfer.js diff --git a/src/token/TokenTransfer.js b/src/token/TokenTransfer.js index 1e292e6cb..1303875c4 100644 --- a/src/token/TokenTransfer.js +++ b/src/token/TokenTransfer.js @@ -98,9 +98,9 @@ export default class TokenTransfer { ); const expectedDecimals = tokenTransfer.expectedDecimals != null - ? /** @type {number | null } */ ( - tokenTransfer.expectedDecimals.value - ) + ? Object.hasOwn(tokenTransfer.expectedDecimals, "value") + ? tokenTransfer.expectedDecimals.value + : null : null; for (const transfer of tokenTransfer.transfers != null @@ -114,7 +114,7 @@ export default class TokenTransfer { transfer.accountID ), ), - expectedDecimals, + expectedDecimals: expectedDecimals || null, amount: transfer.amount != null ? transfer.amount diff --git a/test/unit/TokenTransfer.js b/test/unit/TokenTransfer.js new file mode 100644 index 000000000..249a9a1a1 --- /dev/null +++ b/test/unit/TokenTransfer.js @@ -0,0 +1,28 @@ +import TokenTransfer from "../../src/token/TokenTransfer.js"; + +describe("TokenTransfer", function () { + describe("_fromProtobuf with optional parameters", function () { + it("should deserialize with expectedDecimals being null", function () { + const transfer = new TokenTransfer({ + tokenId: "0.0.123", + accountId: "0.0.456", + amount: 100, + expectedDecimals: null, + isApproved: true, + }); + + const transfersProtobuf = [ + { + token: transfer.tokenId._toProtobuf(), + expectedDecimals: {}, + transfers: [transfer._toProtobuf()], + }, + ]; + + const [transferFromProtobuf] = + TokenTransfer._fromProtobuf(transfersProtobuf); + + expect(transferFromProtobuf.expectedDecimals).to.be.null; + }); + }); +}); From a95bbb6f67c6bf2366685b7e7b568ad220177d78 Mon Sep 17 00:00:00 2001 From: Svetoslav Borislavov Date: Wed, 20 Nov 2024 14:03:04 +0200 Subject: [PATCH 06/12] fix: ContractUpdateTransaction _fromProtobuf Signed-off-by: Svetoslav Borislavov --- src/contract/ContractUpdateTransaction.js | 6 +++++- test/unit/ContractUpdateTransaction.js | 13 +++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 test/unit/ContractUpdateTransaction.js diff --git a/src/contract/ContractUpdateTransaction.js b/src/contract/ContractUpdateTransaction.js index 858eba95d..a8052734d 100644 --- a/src/contract/ContractUpdateTransaction.js +++ b/src/contract/ContractUpdateTransaction.js @@ -221,7 +221,11 @@ export default class ContractUpdateTransaction extends Transaction { } let contractMemo = undefined; - if (update.memoWrapper != null && update.memoWrapper.value != null) { + if ( + update.memoWrapper != null && + Object.hasOwn(update.memoWrapper, "value") && + update.memoWrapper.value != null + ) { contractMemo = update.memoWrapper.value; } diff --git a/test/unit/ContractUpdateTransaction.js b/test/unit/ContractUpdateTransaction.js new file mode 100644 index 000000000..93bd78bf0 --- /dev/null +++ b/test/unit/ContractUpdateTransaction.js @@ -0,0 +1,13 @@ +import { ContractUpdateTransaction } from "../../src/index.js"; + +describe("ContractUpdateTransaction", function () { + describe("deserialization of optional parameters", function () { + it("should deserialize with contractMemo being null", function () { + const tx = new ContractUpdateTransaction(); + const tx2 = ContractUpdateTransaction.fromBytes(tx.toBytes()); + + expect(tx.contractMemo).to.be.null; + expect(tx2.contractMemo).to.be.null; + }); + }); +}); From 382871962af3983e7a1b3a2eada7860325ed2070 Mon Sep 17 00:00:00 2001 From: Svetoslav Borislavov Date: Wed, 20 Nov 2024 14:03:43 +0200 Subject: [PATCH 07/12] fix: FileUpdateTransaction _fromProtobuf Signed-off-by: Svetoslav Borislavov --- src/file/FileUpdateTransaction.js | 4 ++-- test/unit/FileUpdateTransaction.js | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 test/unit/FileUpdateTransaction.js diff --git a/src/file/FileUpdateTransaction.js b/src/file/FileUpdateTransaction.js index 981584e8e..f31513b3a 100644 --- a/src/file/FileUpdateTransaction.js +++ b/src/file/FileUpdateTransaction.js @@ -54,7 +54,7 @@ export default class FileUpdateTransaction extends Transaction { * @param {Key[] | KeyList} [props.keys] * @param {Timestamp | Date} [props.expirationTime] * @param {Uint8Array | string} [props.contents] - * @param {string} [props.fileMemo] + * @param {?string} [props.fileMemo] */ constructor(props = {}) { super(); @@ -153,7 +153,7 @@ export default class FileUpdateTransaction extends Transaction { contents: update.contents != null ? update.contents : undefined, fileMemo: update.memo != null - ? update.memo.value != null + ? Object.hasOwn(update.memo, "value") ? update.memo.value : undefined : undefined, diff --git a/test/unit/FileUpdateTransaction.js b/test/unit/FileUpdateTransaction.js new file mode 100644 index 000000000..2c5385d45 --- /dev/null +++ b/test/unit/FileUpdateTransaction.js @@ -0,0 +1,13 @@ +import { FileUpdateTransaction } from "../../src/index.js"; + +describe("FileUpdateTransaction", function () { + describe("deserialization of optional parameters", function () { + it("should deserialize with fileMemo being null", function () { + const tx = new FileUpdateTransaction(); + const tx2 = FileUpdateTransaction.fromBytes(tx.toBytes()); + + expect(tx.fileMemo).to.be.null; + expect(tx2.fileMemo).to.be.null; + }); + }); +}); From ea7673dada4c1e9ebc55bb12c6614752ce64a9a4 Mon Sep 17 00:00:00 2001 From: Svetoslav Borislavov Date: Wed, 20 Nov 2024 14:20:05 +0200 Subject: [PATCH 08/12] fix: TokenUpdateTransaction _fromProtobuf Signed-off-by: Svetoslav Borislavov --- src/token/TokenUpdateTransaction.js | 18 +++++++++++------- test/unit/TokenUpdateTransaction.js | 17 +++++++++++++++++ 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/token/TokenUpdateTransaction.js b/src/token/TokenUpdateTransaction.js index bcf2b9f64..9be37c019 100644 --- a/src/token/TokenUpdateTransaction.js +++ b/src/token/TokenUpdateTransaction.js @@ -53,8 +53,8 @@ export default class TokenUpdateTransaction extends Transaction { /** * @param {object} [props] * @param {TokenId | string} [props.tokenId] - * @param {string} [props.tokenName] - * @param {string} [props.tokenSymbol] + * @param {?string} [props.tokenName] + * @param {?string} [props.tokenSymbol] * @param {AccountId | string} [props.treasuryAccountId] * @param {Key} [props.adminKey] * @param {Key} [props.kycKey] @@ -64,7 +64,7 @@ export default class TokenUpdateTransaction extends Transaction { * @param {AccountId | string} [props.autoRenewAccountId] * @param {Timestamp | Date} [props.expirationTime] * @param {Duration | Long | number} [props.autoRenewPeriod] - * @param {string} [props.tokenMemo] + * @param {?string} [props.tokenMemo] * @param {Key} [props.feeScheduleKey] * @param {Key} [props.pauseKey] * @param {Key} [props.metadataKey] @@ -285,8 +285,12 @@ export default class TokenUpdateTransaction extends Transaction { update.token != null ? TokenId._fromProtobuf(update.token) : undefined, - tokenName: update.name != null ? update.name : undefined, - tokenSymbol: update.symbol != null ? update.symbol : undefined, + tokenName: Object.hasOwn(update, "name") + ? update.name + : undefined, + tokenSymbol: Object.hasOwn(update, "symbol") + ? update.symbol + : undefined, treasuryAccountId: update.treasury != null ? AccountId._fromProtobuf(update.treasury) @@ -325,7 +329,7 @@ export default class TokenUpdateTransaction extends Transaction { : undefined, tokenMemo: update.memo != null - ? update.memo.value != null + ? Object.hasOwn(update.memo, "value") ? update.memo.value : undefined : undefined, @@ -763,7 +767,7 @@ export default class TokenUpdateTransaction extends Transaction { _makeTransactionData() { return { token: this._tokenId != null ? this._tokenId._toProtobuf() : null, - name: this.tokenName, + name: this.tokenName != null ? this.tokenName : null, symbol: this.tokenSymbol, treasury: this._treasuryAccountId != null diff --git a/test/unit/TokenUpdateTransaction.js b/test/unit/TokenUpdateTransaction.js index d1b4f145a..0975f08cc 100644 --- a/test/unit/TokenUpdateTransaction.js +++ b/test/unit/TokenUpdateTransaction.js @@ -137,6 +137,7 @@ describe("TokenUpdateTransaction", function () { it("all properties should be equal to their initial values", async function () { const tx = new TokenUpdateTransaction(); + const tx2 = TokenUpdateTransaction.fromBytes(tx.toBytes()); expect(tx.tokenId).to.be.null; expect(tx.tokenName).to.be.null; @@ -153,5 +154,21 @@ describe("TokenUpdateTransaction", function () { expect(tx.tokenMemo).to.be.null; expect(tx.feeScheduleKey).to.be.null; expect(tx.pauseKey).to.be.null; + + expect(tx2.tokenId).to.be.null; + expect(tx2.tokenName).to.be.null; + expect(tx2.tokenSymbol).to.be.null; + expect(tx2.treasuryAccountId).to.be.null; + expect(tx2.adminKey).to.be.null; + expect(tx2.kycKey).to.be.null; + expect(tx2.freezeKey).to.be.null; + expect(tx2.wipeKey).to.be.null; + expect(tx2.supplyKey).to.be.null; + expect(tx2.autoRenewAccountId).to.be.null; + expect(tx2.expirationTime).to.be.null; + expect(tx2.autoRenewPeriod).to.be.null; + expect(tx2.tokenMemo).to.be.null; + expect(tx2.feeScheduleKey).to.be.null; + expect(tx2.pauseKey).to.be.null; }); }); From 6b85f4f79837abc9c7c2b4f47a766803e894f989 Mon Sep 17 00:00:00 2001 From: Svetoslav Borislavov Date: Wed, 20 Nov 2024 14:22:04 +0200 Subject: [PATCH 09/12] fix: TopicUpdateTransaction _fromProtobuf Signed-off-by: Svetoslav Borislavov --- src/topic/TopicUpdateTransaction.js | 4 ++-- test/unit/TopicUpdateTransaction.js | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 test/unit/TopicUpdateTransaction.js diff --git a/src/topic/TopicUpdateTransaction.js b/src/topic/TopicUpdateTransaction.js index dced8e901..ee397587b 100644 --- a/src/topic/TopicUpdateTransaction.js +++ b/src/topic/TopicUpdateTransaction.js @@ -61,7 +61,7 @@ export default class TopicUpdateTransaction extends Transaction { * @param {Key} [props.submitKey] * @param {Duration | Long | number} [props.autoRenewPeriod] * @param {AccountId | string} [props.autoRenewAccountId] - * @param {string} [props.topicMemo] + * @param {?string} [props.topicMemo] * @param {Timestamp | Date} [props.expirationTime] */ constructor(props = {}) { @@ -186,7 +186,7 @@ export default class TopicUpdateTransaction extends Transaction { : undefined, topicMemo: update.memo != null - ? update.memo.value != null + ? Object.hasOwn(update.memo, "value") ? update.memo.value : undefined : undefined, diff --git a/test/unit/TopicUpdateTransaction.js b/test/unit/TopicUpdateTransaction.js new file mode 100644 index 000000000..8dc63ed24 --- /dev/null +++ b/test/unit/TopicUpdateTransaction.js @@ -0,0 +1,13 @@ +import { TopicUpdateTransaction } from "../../src/index.js"; + +describe("TopicUpdateTransaction", function () { + describe("deserialization of optional parameters", function () { + it("should deserialize with topicMemo being null", function () { + const tx = new TopicUpdateTransaction(); + const tx2 = TopicUpdateTransaction.fromBytes(tx.toBytes()); + + expect(tx.topicMemo).to.be.null; + expect(tx2.topicMemo).to.be.null; + }); + }); +}); From 3ceffc0010b62ecac1722892a9b379c6b1a038b1 Mon Sep 17 00:00:00 2001 From: Svetoslav Borislavov Date: Wed, 20 Nov 2024 14:25:50 +0200 Subject: [PATCH 10/12] fix: TokenUpdateTransaction fromProtobuf Signed-off-by: Svetoslav Borislavov --- src/token/TokenUpdateTransaction.js | 4 ++-- test/unit/TokenUpdateTransaction.js | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/token/TokenUpdateTransaction.js b/src/token/TokenUpdateTransaction.js index 9be37c019..c9079605f 100644 --- a/src/token/TokenUpdateTransaction.js +++ b/src/token/TokenUpdateTransaction.js @@ -68,7 +68,7 @@ export default class TokenUpdateTransaction extends Transaction { * @param {Key} [props.feeScheduleKey] * @param {Key} [props.pauseKey] * @param {Key} [props.metadataKey] - * @param {Uint8Array} [props.metadata] + * @param {?Uint8Array} [props.metadata] * @param {TokenKeyValidation} [props.keyVerificationMode] */ constructor(props = {}) { @@ -347,7 +347,7 @@ export default class TokenUpdateTransaction extends Transaction { : undefined, metadata: update.metadata != null - ? update.metadata.value != null + ? Object.hasOwn(update.metadata, "value") ? update.metadata.value : undefined : undefined, diff --git a/test/unit/TokenUpdateTransaction.js b/test/unit/TokenUpdateTransaction.js index 0975f08cc..5078c7688 100644 --- a/test/unit/TokenUpdateTransaction.js +++ b/test/unit/TokenUpdateTransaction.js @@ -154,6 +154,7 @@ describe("TokenUpdateTransaction", function () { expect(tx.tokenMemo).to.be.null; expect(tx.feeScheduleKey).to.be.null; expect(tx.pauseKey).to.be.null; + expect(tx.metadata).to.be.null; expect(tx2.tokenId).to.be.null; expect(tx2.tokenName).to.be.null; @@ -170,5 +171,6 @@ describe("TokenUpdateTransaction", function () { expect(tx2.tokenMemo).to.be.null; expect(tx2.feeScheduleKey).to.be.null; expect(tx2.pauseKey).to.be.null; + expect(tx2.metadata).to.be.null; }); }); From 8d44a859781c43cb1cf747101a3d95db1dcc7746 Mon Sep 17 00:00:00 2001 From: Svetoslav Borislavov Date: Wed, 20 Nov 2024 14:30:54 +0200 Subject: [PATCH 11/12] fix: TokenUpdateNftsTransaction _fromProtobuf Signed-off-by: Svetoslav Borislavov --- src/token/TokenUpdateNftsTransaction.js | 4 ++-- test/unit/TokenUpdateNftsTransaction.js | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/token/TokenUpdateNftsTransaction.js b/src/token/TokenUpdateNftsTransaction.js index 8d5482019..3af1a689f 100644 --- a/src/token/TokenUpdateNftsTransaction.js +++ b/src/token/TokenUpdateNftsTransaction.js @@ -46,7 +46,7 @@ export default class TokenUpdateNftsTransaction extends Transaction { * @param {object} [props] * @param {TokenId | string} [props.tokenId] * @param {Long[]} [props.serialNumbers] - * @param {Uint8Array} [props.metadata] + * @param {?Uint8Array} [props.metadata] */ constructor(props = {}) { super(); @@ -116,7 +116,7 @@ export default class TokenUpdateNftsTransaction extends Transaction { : [], metadata: tokenUpdate.metadata != null - ? tokenUpdate.metadata.value != null + ? Object.hasOwn(tokenUpdate.metadata, "value") ? tokenUpdate.metadata.value : undefined : undefined, diff --git a/test/unit/TokenUpdateNftsTransaction.js b/test/unit/TokenUpdateNftsTransaction.js index 2d6b0e1ec..606e565c7 100644 --- a/test/unit/TokenUpdateNftsTransaction.js +++ b/test/unit/TokenUpdateNftsTransaction.js @@ -37,4 +37,12 @@ describe("TokenUpdateNftsTransaction", function () { expect(transaction._serialNumbers).to.eql(serials); expect(transaction._metadata).to.eql(metadata); }); + + it("should _metadata equal to null", async function () { + const tx = new TokenUpdateNftsTransaction(); + const tx2 = TokenUpdateNftsTransaction.fromBytes(tx.toBytes()); + + expect(tx._metadata).to.be.null; + expect(tx2._metadata).to.be.null; + }); }); From 4cece1411ebde94e735f94080caec825017789ef Mon Sep 17 00:00:00 2001 From: Svetoslav Borislavov Date: Wed, 20 Nov 2024 14:32:32 +0200 Subject: [PATCH 12/12] fix: ContractFunctionResult _fromProtobuf Signed-off-by: Svetoslav Borislavov --- src/contract/ContractFunctionResult.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/contract/ContractFunctionResult.js b/src/contract/ContractFunctionResult.js index 77476bb19..688ce45b6 100644 --- a/src/contract/ContractFunctionResult.js +++ b/src/contract/ContractFunctionResult.js @@ -192,7 +192,9 @@ export default class ContractFunctionResult { : [] ).map((contractId) => ContractId._fromProtobuf(contractId)), evmAddress: - result.evmAddress != null && result.evmAddress.value != null + result.evmAddress != null && + Object.hasOwn(result.evmAddress, "value") && + result.evmAddress.value != null ? result.evmAddress.value : null, stateChanges: [],