Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method fromEvmAddress() fails to return the contract id from long zero address #2018

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
});