feat: harden StarkNet client typing and add production client tests (#58)#79
feat: harden StarkNet client typing and add production client tests (#58)#79daveades wants to merge 2 commits into
Conversation
Replace broad any casts in receipt/execution handling with narrow local types (StarknetEvent, StarknetReceipt, ExecuteResult, StarknetDeps). Add optional dep injection on createStarknetCampaignClient to enable testing without live RPC, then cover missing env vars, tx-hash extraction, event campaign-ID parsing, fallback behavior, and retry logic in 14 new focused tests.
|
@daveades Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
📝 WalkthroughWalkthroughAdds typed StarkNet receipt and execution helpers, optional dependency injection for the campaign client, and tests for env validation, transaction-hash extraction, event-based campaign ID parsing, and retry behavior. ChangesStarkNet Client Hardening
Sequence Diagram(s)Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration. 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.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/services/cairo/campaignFactory.starknet.ts`:
- Around line 93-96: The submission path in create_campaign is incorrectly
wrapped in withRetry around account.execute, which can resubmit a state-changing
transaction after transient RPC errors; update the campaignFactory.starknet.ts
flow so retries remain only around read-only validation steps, and in the create
campaign submission path call account.execute directly or make any resubmission
logic explicitly nonce-aware. Use the existing create_campaign invocation and
logger.info context to locate the submit step, and ensure the retry helper is
not applied to the final transaction send.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 79c82866-d16b-4b73-97e9-7b51d0eb8867
📒 Files selected for processing (2)
src/__tests__/cairo.client.starknet.test.tssrc/services/cairo/campaignFactory.starknet.ts
|
Hi @daveades Thank you for your awesome contribution, however after analyzing your implementation, there are some minor fixes to be done. Kindly fix them to merge your PR asap. Also do not forget to use fundable.finance to offramp. |
Wrapping account.execute in withRetry could resubmit a create_campaign transaction after a transient RPC error, duplicating the on-chain call. Move the logger.info outside the retry block and call execute directly. Read-only getClassHashAt and waitForTransaction calls are unaffected. Update two tests: replace the execute-retry assertions with tests that verify execute is called exactly once and errors propagate immediately.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/services/cairo/campaignFactory.starknet.ts (1)
54-68: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDefer env validation until the fallback path actually needs it.
createStarknetCampaignClient(deps)still readsCAIRO_RPC_URL,CAIRO_ACCOUNT_ADDRESS, andCAIRO_PRIVATE_KEYbefore it consults the injectedprovider/account, so the new DI hook remains coupled to process env. Lazily resolve those vars only when_depsdoes not supply the dependency, and consider injectingfactoryAddresstoo if you want this constructor to be fully testable without env scaffolding.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/services/cairo/campaignFactory.starknet.ts` around lines 54 - 68, The `createStarknetCampaignClient` constructor still eagerly calls `getRequiredEnv` for `CAIRO_RPC_URL`, `CAIRO_ACCOUNT_ADDRESS`, and `CAIRO_PRIVATE_KEY` before checking `_deps`, so the injected `provider` and `account` are not actually decoupled from process env. Move those env reads behind the fallback branches in `createStarknetCampaignClient`, only resolving them when `_deps.provider` or `_deps.account` is missing, and consider applying the same pattern to `factoryAddress` if you want the client setup to be fully testable without env scaffolding.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/services/cairo/campaignFactory.starknet.ts`:
- Around line 54-68: The `createStarknetCampaignClient` constructor still
eagerly calls `getRequiredEnv` for `CAIRO_RPC_URL`, `CAIRO_ACCOUNT_ADDRESS`, and
`CAIRO_PRIVATE_KEY` before checking `_deps`, so the injected `provider` and
`account` are not actually decoupled from process env. Move those env reads
behind the fallback branches in `createStarknetCampaignClient`, only resolving
them when `_deps.provider` or `_deps.account` is missing, and consider applying
the same pattern to `factoryAddress` if you want the client setup to be fully
testable without env scaffolding.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 45421c38-ce9b-4f87-8f86-d837772ad440
📒 Files selected for processing (2)
src/__tests__/cairo.client.starknet.test.tssrc/services/cairo/campaignFactory.starknet.ts
|
@pragmaticAweds I have now implemented the fixes |
Summary
anycasts incampaignFactory.starknet.tswith narrow local types:StarknetEvent,StarknetReceipt,ExecuteResult, andStarknetDeps_depsinjection parameter tocreateStarknetCampaignClient(exportedStarknetDepstype) enabling test-time mocking without live RPC accesscairo.client.starknet.test.tscovering: all 4 missing required env vars, missing transaction hash, bothtransaction_hash/transactionHashfield name fallbacks, event campaign-ID extraction, case-insensitive event key matching, empty-data fallback, and retry success/exhaustion behaviorTest plan
bun run type-checkpasses (noanytype errors)tsx --testeslintreports no errors on changed filescairo.client.mock.test.ts) unaffectedCloses #58
Summary by CodeRabbit
Bug Fixes
Tests