From fe0fbe94fd41c8adc19751a1fd393b3ba26dc868 Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v <136077184+svetoslav-nikol0v@users.noreply.github.com> Date: Fri, 17 Nov 2023 11:09:33 +0200 Subject: [PATCH] Method fromEvmAddress() fails to return the contract id from long zero address (#2018) * contract id from long zero address Signed-off-by: svetoslav-nikol0v * test description Signed-off-by: svetoslav-nikol0v --------- Signed-off-by: svetoslav-nikol0v --- src/contract/ContractId.js | 2 +- test/unit/ContractId.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/contract/ContractId.js b/src/contract/ContractId.js index e5c4718f1..1ef0085b7 100644 --- a/src/contract/ContractId.js +++ b/src/contract/ContractId.js @@ -72,7 +72,7 @@ export default class ContractId extends Key { static fromEvmAddress(shard, realm, evmAddress) { // eslint-disable-next-line @typescript-eslint/no-unsafe-call if (isLongZeroAddress(hex.decode(evmAddress))) { - return this.fromEvmAddress(0, 0, evmAddress); + return new ContractId(...entity_id.fromSolidityAddress(evmAddress)); } else { return new ContractId(shard, realm, 0, hex.decode(evmAddress)); } diff --git a/test/unit/ContractId.js b/test/unit/ContractId.js index 6a02d9a03..ea6a6fcac 100644 --- a/test/unit/ContractId.js +++ b/test/unit/ContractId.js @@ -51,4 +51,23 @@ describe("ContractId", function () { evmAddress: null, }); }); + + it("should return the contract id from long zero address", function () { + const shard = 0, + realm = 0, + num = 5; + const ADDRESS_LENGTH = 42; + const contractId = new ContractId(shard, realm, num); + const longZeroAddress = contractId + .toSolidityAddress() + .padStart(ADDRESS_LENGTH, "0x"); + + const contractIdFromAddress = ContractId.fromEvmAddress( + shard, + realm, + longZeroAddress + ); + + expect(contractId).to.deep.equal(contractIdFromAddress); + }); });