Skip to content

Commit

Permalink
Method fromEvmAddress() fails to return the contract id from long zer…
Browse files Browse the repository at this point in the history
…o address (#2018)

* contract id from long zero address

Signed-off-by: svetoslav-nikol0v <[email protected]>

* test description

Signed-off-by: svetoslav-nikol0v <[email protected]>

---------

Signed-off-by: svetoslav-nikol0v <[email protected]>
  • Loading branch information
svetoslav-nikol0v authored Nov 17, 2023
1 parent e3d2ed3 commit fe0fbe9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/contract/ContractId.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
19 changes: 19 additions & 0 deletions test/unit/ContractId.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit fe0fbe9

Please sign in to comment.