fix: add 0x prefix to read-only keystore address#283
Conversation
getEpochInfo now returns validatorMinStakeRaw and validatorMinStake, fixing the "Cannot mix BigInt and other types" crash in the staking wizard.
Ethers keystores store addresses without the 0x prefix. When getAddress() returned the bare address, it propagated as a malformed `from` field in gen_call RPC requests, causing the testnet RPC to return an object instead of a hex string. genlayer-js then produced "0x[object Object]" which crashed viem's hexToBytes.
📝 WalkthroughWalkthroughA patch-level dependency bump for genlayer-js combined with address normalization logic. The Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
tests/libs/baseAction.test.ts (2)
2-2: Use path alias for src imports.As per coding guidelines, use
@/*path alias for./src/*imports.Suggested fix
-import {BaseAction} from "../../src/lib/actions/BaseAction"; +import {BaseAction} from "@/lib/actions/BaseAction";🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/libs/baseAction.test.ts` at line 2, The test imports BaseAction using a relative path; update the import to use the project path alias for src (replace "../../src/lib/actions/BaseAction" with the `@/` path e.g. "@/lib/actions/BaseAction") so tests follow the coding guideline; ensure the import in tests/libs/baseAction.test.ts references BaseAction via the alias and, if needed, confirm tsconfig/paths is configured so the alias resolves in the test runner.
288-293: Consider consolidating redundant test cases.This test largely duplicates the test at lines 280-286. Both verify that
getAccount(true)returns a 0x-prefixed address when the keystore address lacks the prefix. The regex check on line 291 adds minimal value over the strict equality check on line 292.Consider merging into the existing test
test("should return address when called with readOnly=true", async () => { const address = await baseAction["getAccount"](true); + expect(address).toMatch(/^0x/); 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}`); -});🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/libs/baseAction.test.ts` around lines 288 - 293, The test is redundant with the earlier case that already asserts getAccount(true) returns a 0x-prefixed address; remove or merge this duplicate by either deleting this test block or adding the regex assertion to the existing test that calls baseAction["getAccount"](true) (keep the strict equality assert expect(address).toBe(`0x${mockKeystoreData.address}`) and, if desired, also include expect(address).toMatch(/^0x/) in that same test) so only one test covers both checks for getAccount and mockKeystoreData.address.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@tests/libs/baseAction.test.ts`:
- Line 2: The test imports BaseAction using a relative path; update the import
to use the project path alias for src (replace
"../../src/lib/actions/BaseAction" with the `@/` path e.g.
"@/lib/actions/BaseAction") so tests follow the coding guideline; ensure the
import in tests/libs/baseAction.test.ts references BaseAction via the alias and,
if needed, confirm tsconfig/paths is configured so the alias resolves in the
test runner.
- Around line 288-293: The test is redundant with the earlier case that already
asserts getAccount(true) returns a 0x-prefixed address; remove or merge this
duplicate by either deleting this test block or adding the regex assertion to
the existing test that calls baseAction["getAccount"](true) (keep the strict
equality assert expect(address).toBe(`0x${mockKeystoreData.address}`) and, if
desired, also include expect(address).toMatch(/^0x/) in that same test) so only
one test covers both checks for getAccount and mockKeystoreData.address.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: b57152c0-d818-403c-bcea-0cf895a5dc03
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (3)
package.jsonsrc/lib/actions/BaseAction.tstests/libs/baseAction.test.ts
Summary
0xprefix.getAddress()returned the bare hex, which propagated as a malformedfromfield ingen_callRPC requests"0x[object Object]"crashing viem'shexToBytes0xprefix ingetAddress()with guard against double-prefixingTest plan
0xprefixSummary by CodeRabbit
Bug Fixes
Tests
Chores