Skip to content
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
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"dotenv": "^17.0.0",
"ethers": "^6.13.4",
"fs-extra": "^11.3.0",
"genlayer-js": "^0.21.0",
"genlayer-js": "^0.21.2",
"inquirer": "^12.0.0",
"keytar": "^7.9.0",
"node-fetch": "^3.0.0",
Expand Down
3 changes: 2 additions & 1 deletion src/lib/actions/BaseAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ export class BaseAction extends ConfigFileManager {
}

private getAddress(keystoreData: any): Address {
return keystoreData.address as Address;
const addr = keystoreData.address;
return (addr.startsWith('0x') ? addr : `0x${addr}`) as Address;
}

protected async createKeypairByName(accountName: string, overwrite: boolean, passwordInput?: string): Promise<string> {
Expand Down
21 changes: 20 additions & 1 deletion tests/libs/baseAction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,30 @@ describe("BaseAction", () => {
test("should return address when called with readOnly=true", async () => {
const address = await baseAction["getAccount"](true);

expect(address).toBe(mockKeystoreData.address);
expect(address).toBe(`0x${mockKeystoreData.address}`);
expect(existsSync).toHaveBeenCalledWith("/mocked/home/.genlayer/keystores/default.json");
expect(readFileSync).toHaveBeenCalledWith("/mocked/home/.genlayer/keystores/default.json", "utf-8");
});

test("should return 0x-prefixed address for readOnly even when keystore has no prefix", async () => {
const address = await baseAction["getAccount"](true);

expect(address).toMatch(/^0x/);
expect(address).toBe(`0x${mockKeystoreData.address}`);
});

test("should not double-prefix address that already has 0x", async () => {
const prefixedKeystoreData = {
...mockKeystoreData,
address: "0x1234567890123456789012345678901234567890",
};
vi.mocked(readFileSync).mockReturnValue(JSON.stringify(prefixedKeystoreData));

const address = await baseAction["getAccount"](true);

expect(address).toBe("0x1234567890123456789012345678901234567890");
});

test("should create new keypair when keystore file does not exist", async () => {
vi.mocked(existsSync).mockReturnValue(false);
vi.mocked(inquirer.prompt)
Expand Down
Loading