Skip to content

test: add setupDashClient unit tests and mnemonic validation#61

Merged
thephez merged 9 commits intomainfrom
test/setupdashclient-test
Mar 14, 2026
Merged

test: add setupDashClient unit tests and mnemonic validation#61
thephez merged 9 commits intomainfrom
test/setupdashclient-test

Conversation

@thephez
Copy link
Collaborator

@thephez thephez commented Mar 14, 2026

Summary

  • Add comprehensive unit tests for setupDashClient covering client creation, key derivation, DIP-13 path logic, identity handling, and error paths (~920 lines, 138 assertions)
  • Validate mnemonic in setupDashClient before key derivation, throwing a clear error for invalid BIP39 mnemonics
  • Add test:setup script for running setupDashClient tests via Mocha
  • Add Chai and Mocha dev dependencies; pin existing devDependencies to exact versions

Summary by CodeRabbit

Release Notes

  • Chores

    • Updated development dependencies including testing libraries and version pinning for better stability.
  • Bug Fixes

    • Added validation for wallet mnemonics with helpful error guidance when invalid input is detected.
  • Tests

    • Expanded test coverage for identity and key management workflows across various scenarios and network configurations.

thephez and others added 7 commits March 13, 2026 16:12
Replace hardcoded DIP-13 path construction in deriveKeysFromMnemonic with
the exported dip13KeyPath() helper, ensuring a single source of truth for
path derivation. Add test cases for missing setupDashClient() permutations
including undefined manager guards, requireIdentity flag, and identityIndex
forwarding.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Catch invalid BIP39 mnemonics early with a clear error message instead
of letting them propagate to the WASM SDK as opaque WasmSdkError objects.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Verify key-role correctness (keyId per getSigner method), signer depth
(keyCount for getMaster/getFullSigner), createClient success branches
(testnet/mainnet isConnected), findNextIndex loop logic with stubbed
occupied indices, createForNewIdentity nonzero auto-index, and
AddressKeyManager getInfo/getInfoAt with stubbed SDK. Fix stale comment
and remove weak clientConfig direct-usage tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Don't run setup in test:all
@coderabbitai
Copy link

coderabbitai bot commented Mar 14, 2026

Warning

Rate limit exceeded

@thephez has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 20 minutes and 18 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5ad8cc4f-c76b-498b-9161-8f8e541f22ec

📥 Commits

Reviewing files that changed from the base of the PR and between 68cae9f and 394f94f.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (2)
  • package.json
  • test/read-only.test.mjs
📝 Walkthrough

Walkthrough

This PR adds runtime validation for mnemonic inputs in setupDashClient and introduces a comprehensive test suite for identity and address key management operations, with supporting dependency updates to enable the new testing infrastructure.

Changes

Cohort / File(s) Summary
Configuration & Dependencies
package.json
Added test:setup script; updated dotenv to 17.3.1 with explicit versioning; added chai 6.2.2 and mocha 11.7.5 dev dependencies; updated eslint to 8.45.0.
Validation Logic
setupDashClient.mjs
Added runtime validation for mnemonics; throws error with helpful message if provided mnemonic fails wallet.validateMnemonic check.
Test Suite
test/setupDashClient.test.mjs
Comprehensive test suite for identity and address key management covering: DIP-9 key derivation from mnemonics, IdentityKeyManager and AddressKeyManager scenarios, signer creation (IdentitySigner, PlatformAddressSigner), identity resolution and auto-indexing, network-specific DIP-13 path construction, error paths for invalid inputs, and various client setup flows.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 A mnemonic springs to life, validated with care,
Keys dance through DIP-9, signers everywhere!
From testnet to mainnet, our tests lay them bare,
✨ Identity and address—a well-managed pair!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the two main changes: adding setupDashClient unit tests and implementing mnemonic validation.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch test/setupdashclient-test
📝 Coding Plan
  • Generate coding plan for human review comments

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (1)
package.json (1)

12-13: test:all doesn’t include the new setup suite.

If your CI treats test:all as the full gate, test/setupDashClient.test.mjs won’t run. Consider chaining test:setup (or renaming test:all to reflect current scope).

♻️ Suggested script update
-    "test:all": "node --test --test-timeout=300000 --test-concurrency=1 test/read-only.test.mjs test/read-write.test.mjs",
+    "test:all": "node --test --test-timeout=300000 --test-concurrency=1 test/read-only.test.mjs test/read-write.test.mjs && npm run test:setup",
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@package.json` around lines 12 - 13, The test:all npm script currently runs
only read-only and read-write suites and omits the setup suite (script names
"test:all" and "test:setup"), so update package.json to include the setup test
in the test:all command or rename test:all to reflect scope; specifically,
modify the "test:all" script to also invoke test/setupDashClient.test.mjs (or
chain the "test:setup" script within it) so CI runs the setup suite as part of
the full test gate.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@test/setupDashClient.test.mjs`:
- Around line 77-84: The test suite bootstraps a real SDK client in the before
hook (createClient, network) which couples the IdentityKeyManager tests to live
network calls; refactor tests to stub or mock network interactions for unit
tests by replacing createClient/network-dependent calls with a mocked client or
injected fake implementation (e.g., a mocked SDK exposing the same methods used
by IdentityKeyManager), and move the real createClient usage behind an explicit
integration flag or separate describe block named "integration" so live-network
tests run only when opted-in.
- Around line 450-461: The test uses a real SDK and a mutable TEST_MNEMONIC to
assert "no on-chain identity", which is flaky; replace the dependency with a
deterministic fake/stub SDK that returns null for identity lookups (e.g.,
implement a minimal sdk mock where byPublicKeyHash or the identity resolution
method returns null) and pass that mock into IdentityKeyManager.create({ sdk,
mnemonic: TEST_MNEMONIC }) so the failure path is deterministic; apply the same
change to the similar test at lines 513-516 to stub the identity resolver rather
than relying on chain state.
- Around line 744-772: The test is skipped but documents a real crash when
clientConfig.mnemonic is null; fix by adding an explicit guard in
setupDashClient() that throws a clear Error when mnemonic is missing and ensure
returned objects (keyManager, addressKeyManager) are either valid helpers or
replaced with stubs that throw a clear Error for getAuth()/getSigner; update
setupDashClient() to check clientConfig.mnemonic early and throw a descriptive
Error (e.g., "mnemonic required to create keyManager") so the test can be
unskipped and assertions on keyManager.getAuth and addressKeyManager.getSigner
will receive an instanceOf Error with no raw TypeError.

---

Nitpick comments:
In `@package.json`:
- Around line 12-13: The test:all npm script currently runs only read-only and
read-write suites and omits the setup suite (script names "test:all" and
"test:setup"), so update package.json to include the setup test in the test:all
command or rename test:all to reflect scope; specifically, modify the "test:all"
script to also invoke test/setupDashClient.test.mjs (or chain the "test:setup"
script within it) so CI runs the setup suite as part of the full test gate.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 21c0f9e0-0aee-4413-a8f7-4933a3d4afe0

📥 Commits

Reviewing files that changed from the base of the PR and between 9115cda and 68cae9f.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (3)
  • package.json
  • setupDashClient.mjs
  • test/setupDashClient.test.mjs

thephez and others added 2 commits March 14, 2026 13:09
Tutorials depend on dotenv to load .env files, so it should be a
regular dependency to ensure it is available after `npm install`.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Fork PRs don't have access to repository secrets, so identity-retrieve
fails in CI. Skip tests marked with requiresMnemonic when the env var
is absent.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@thephez thephez merged commit 1996f90 into main Mar 14, 2026
6 of 7 checks passed
@thephez thephez deleted the test/setupdashclient-test branch March 14, 2026 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant