feat(alert): implement wallet balance alerts#2167
Conversation
WalkthroughAdds WALLET_BALANCE alert support: DB enum migration and snapshot; new WalletBalanceAlertsService with unit tests; schema, repository, module/provider, HTTP schema, handler, seeder, and test updates; small utility defensive error handling change. Changes
Sequence Diagram(s)sequenceDiagram
participant BC as BlockCreated
participant CEH as ChainEventsHandler
participant DBAS as DeploymentBalanceAlertsService
participant WBAS as WalletBalanceAlertsService
participant BR as AlertRepository
participant BHS as BalanceHttpService
participant AMS as AlertMessageService
participant MC as MessageCallback
BC->>CEH: blockCreated(block)
par Concurrent checks
CEH->>DBAS: evaluateDeploymentBalanceAlertsOnBlock(block)
CEH->>WBAS: evaluateWalletBalanceAlertsOnBlock(block)
end
opt Wallet flow details
WBAS->>BR: paginate WALLET_BALANCE alerts
loop per alert
WBAS->>BHS: fetchBalance(owner, denom)
alt fetch success & condition matches
WBAS->>BR: update status -> TRIGGERED and minBlockHeight
WBAS->>AMS: build message
WBAS->>MC: emit onMessage
else fetch success & no match
WBAS->>BR: update status -> OK and minBlockHeight
else fetch error
WBAS->>WBAS: log ALERT_FAILURE (block, alert, error)
end
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25–30 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (3)
apps/notifications/src/modules/alert/providers/http-sdk.provider.ts (1)
2-2: LGTM! BalanceHttpService provider correctly configured.The
BalanceHttpServiceprovider is properly set up with the required configuration fromConfigService.Note: Unlike
DeploymentHttpServiceandLeaseHttpServicewhich share a commonHttpClientinstance,BalanceHttpServicecreates its own HTTP client. This is due to the different constructor signature in the@akashnetwork/http-sdkpackage and results in separate connection pools.Also applies to: 26-30
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.ts (2)
6-6: Remove unused import.
DeploymentBalanceAlertOutputis imported but the only reference to it on line 64 is incorrect—it should beWalletBalanceAlertOutputinstead. Remove this unused import.-import { AlertRepository, DeploymentBalanceAlertOutput, WalletBalanceAlertOutput } from "@src/modules/alert/repositories/alert/alert.repository"; +import { AlertRepository, WalletBalanceAlertOutput } from "@src/modules/alert/repositories/alert/alert.repository";
54-61: Add block context to error logging.The error log is missing the block height, which would be helpful for correlating failures with specific chain events and debugging.
if (!balance) { this.loggerService.error({ event: "ALERT_FAILURE", + block: block.height, alert, error: new Error("Failed to fetch balance") }); return; }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (16)
apps/notifications/drizzle/0005_left_magus.sql(1 hunks)apps/notifications/drizzle/meta/0005_snapshot.json(1 hunks)apps/notifications/drizzle/meta/_journal.json(1 hunks)apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.ts(2 hunks)apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.ts(1 hunks)apps/notifications/src/interfaces/rest/http-schemas/alert.http-schema.ts(3 hunks)apps/notifications/src/lib/value-backoff/value-backoff.ts(1 hunks)apps/notifications/src/modules/alert/alert.module.ts(3 hunks)apps/notifications/src/modules/alert/model-schemas/alert.schema.ts(1 hunks)apps/notifications/src/modules/alert/providers/http-sdk.provider.ts(2 hunks)apps/notifications/src/modules/alert/repositories/alert/alert-json-fields.schema.ts(4 hunks)apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts(3 hunks)apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts(1 hunks)apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.ts(1 hunks)apps/notifications/test/functional/balance-alert.spec.ts(1 hunks)apps/notifications/test/seeders/wallet-balance-alert.seeder.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.spec.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/no-jest-mock.mdc)
Don't use
jest.mock()to mock dependencies in test files. Instead, usejest-mock-extendedto create mocks and pass mocks as dependencies to the service under test.
**/*.spec.{ts,tsx}: Usesetupfunction instead ofbeforeEachin test files
setupfunction must be at the bottom of the rootdescribeblock in test files
setupfunction creates an object under test and returns it
setupfunction should accept a single parameter with inline type definition
Don't use shared state insetupfunction
Don't specify return type ofsetupfunction
Files:
apps/notifications/test/functional/balance-alert.spec.tsapps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.tsapps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/general.mdc)
Never use type any or cast to type any. Always define the proper TypeScript types.
Files:
apps/notifications/test/functional/balance-alert.spec.tsapps/notifications/src/modules/alert/model-schemas/alert.schema.tsapps/notifications/test/seeders/wallet-balance-alert.seeder.tsapps/notifications/src/modules/alert/alert.module.tsapps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.tsapps/notifications/src/modules/alert/repositories/alert/alert.repository.tsapps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.tsapps/notifications/src/lib/value-backoff/value-backoff.tsapps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.tsapps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.tsapps/notifications/src/modules/alert/providers/http-sdk.provider.tsapps/notifications/src/interfaces/rest/http-schemas/alert.http-schema.tsapps/notifications/src/modules/alert/repositories/alert/alert-json-fields.schema.ts
**/*.{js,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/general.mdc)
**/*.{js,ts,tsx}: Never use deprecated methods from libraries.
Don't add unnecessary comments to the code
Files:
apps/notifications/test/functional/balance-alert.spec.tsapps/notifications/src/modules/alert/model-schemas/alert.schema.tsapps/notifications/test/seeders/wallet-balance-alert.seeder.tsapps/notifications/src/modules/alert/alert.module.tsapps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.tsapps/notifications/src/modules/alert/repositories/alert/alert.repository.tsapps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.tsapps/notifications/src/lib/value-backoff/value-backoff.tsapps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.tsapps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.tsapps/notifications/src/modules/alert/providers/http-sdk.provider.tsapps/notifications/src/interfaces/rest/http-schemas/alert.http-schema.tsapps/notifications/src/modules/alert/repositories/alert/alert-json-fields.schema.ts
🧠 Learnings (5)
📚 Learning: 2025-10-15T16:39:55.348Z
Learnt from: jzsfkzm
Repo: akash-network/console PR: 2039
File: apps/deploy-web/tests/ui/change-wallets.spec.ts:4-10
Timestamp: 2025-10-15T16:39:55.348Z
Learning: In the Akash Console E2E tests using the context-with-extension fixture, the first wallet is automatically created during fixture setup via `importWalletToLeap` in `apps/deploy-web/tests/ui/fixture/wallet-setup.ts`, so tests that call `frontPage.createWallet()` are creating a second wallet to test wallet switching functionality.
Applied to files:
apps/notifications/test/seeders/wallet-balance-alert.seeder.tsapps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.ts
📚 Learning: 2025-07-03T14:40:49.886Z
Learnt from: jzsfkzm
Repo: akash-network/console PR: 1498
File: apps/api/src/services/external/templates/template-fetcher.service.ts:0-0
Timestamp: 2025-07-03T14:40:49.886Z
Learning: In the TemplateFetcherService class in apps/api/src/services/external/templates/template-fetcher.service.ts, the error handling strategy should maintain process resilience by catching all errors and returning null rather than re-throwing critical errors, to avoid breaking the whole template fetching process.
Applied to files:
apps/notifications/src/lib/value-backoff/value-backoff.ts
📚 Learning: 2025-07-21T08:25:07.474Z
Learnt from: CR
Repo: akash-network/console PR: 0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-07-21T08:25:07.474Z
Learning: Applies to **/*.spec.{ts,tsx} : `setup` function creates an object under test and returns it
Applied to files:
apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.ts
📚 Learning: 2025-09-04T04:27:50.638Z
Learnt from: stalniy
Repo: akash-network/console PR: 1868
File: apps/api/src/billing/services/managed-signer/managed-signer.service.ts:1-1
Timestamp: 2025-09-04T04:27:50.638Z
Learning: In the akash-network/console project, importing MsgCreateLease from "akashnetwork/akash-api/v1beta3" instead of v1beta4 is considered non-critical by the maintainers, likely due to backward compatibility or project-specific requirements.
Applied to files:
apps/notifications/src/modules/alert/providers/http-sdk.provider.ts
📚 Learning: 2025-09-25T14:31:44.914Z
Learnt from: baktun14
Repo: akash-network/console PR: 1969
File: apps/deploy-web/src/pages/payment.tsx:179-191
Timestamp: 2025-09-25T14:31:44.914Z
Learning: The payment confirmation endpoint in apps/api/src/billing/http-schemas/stripe.schema.ts uses zod schema validation with `amount: z.number().gte(20, "Amount must be greater or equal to $20")` to ensure all payment requests meet the minimum amount requirement, preventing zero-amount or invalid payments from reaching Stripe.
Applied to files:
apps/notifications/src/modules/alert/repositories/alert/alert-json-fields.schema.ts
🧬 Code graph analysis (9)
apps/notifications/src/modules/alert/model-schemas/alert.schema.ts (1)
apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts (1)
AlertType(34-34)
apps/notifications/test/seeders/wallet-balance-alert.seeder.ts (2)
apps/notifications/test/seeders/akash-address.seeder.ts (1)
mockAkashAddress(3-3)apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts (1)
WalletBalanceAlertOutput(29-29)
apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.ts (3)
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.ts (1)
Injectable(13-100)apps/notifications/src/infrastructure/broker/services/broker/broker.service.ts (1)
Injectable(17-72)apps/notifications/src/common/config/event-key-registry.config.ts (1)
eventKeyRegistry(1-5)
apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts (1)
apps/notifications/src/modules/alert/model-schemas/alert.schema.ts (1)
AlertType(8-8)
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts (8)
apps/notifications/test/seeders/akash-address.seeder.ts (1)
mockAkashAddress(3-3)apps/notifications/test/seeders/wallet-balance-alert.seeder.ts (1)
generateWalletBalanceAlert(7-45)apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts (2)
WalletBalanceAlertOutput(29-29)AlertOutput(32-32)packages/http-sdk/src/types/denom.type.ts (1)
Denom(1-4)apps/notifications/test/seeders/alert-message.seeder.ts (1)
generateAlertMessage(5-17)packages/logging/src/services/logger/logger.service.ts (1)
error(142-144)packages/http-sdk/src/balance/balance-http.service.ts (1)
BalanceHttpService(20-29)apps/notifications/test/mocks/provider.mock.ts (1)
MockProvider(4-6)
apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.ts (2)
apps/notifications/src/common/config/event-key-registry.config.ts (1)
eventKeyRegistry(1-5)apps/notifications/test/mocks/provider.mock.ts (1)
MockProvider(4-6)
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.ts (6)
apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts (3)
WalletBalanceAlertOutput(29-29)Injectable(84-320)DeploymentBalanceAlertOutput(26-26)apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.ts (1)
Injectable(11-45)packages/http-sdk/src/balance/balance-http.service.ts (1)
BalanceHttpService(20-29)apps/notifications/src/modules/alert/types/message-callback.type.ts (1)
MessageCallback(8-8)packages/logging/src/services/logger/logger.service.ts (1)
error(142-144)apps/notifications/src/modules/alert/services/conditions-matcher/conditions-matcher.service.ts (1)
isMatching(22-25)
apps/notifications/src/modules/alert/providers/http-sdk.provider.ts (2)
packages/http-sdk/src/balance/balance-http.service.ts (1)
BalanceHttpService(20-29)apps/notifications/src/modules/alert/config/index.ts (1)
AlertConfig(9-9)
apps/notifications/src/interfaces/rest/http-schemas/alert.http-schema.ts (2)
apps/notifications/src/modules/alert/repositories/alert/alert-json-fields.schema.ts (5)
balanceConditionsSchema(31-31)deploymentBalanceParamsSchema(37-41)walletBalanceTypeSchema(58-58)walletBalanceParamsSchema(43-47)generalAlertConditionsSchema(23-23)packages/http-sdk/src/generated/NotificationSDK.ts (1)
AlertCreateInput(13-93)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: validate / validate-app
- GitHub Check: test-build
🔇 Additional comments (12)
apps/notifications/drizzle/0005_left_magus.sql (1)
1-1: LGTM! SQL migration is correct.The migration correctly extends the
alert_typeenum with the newWALLET_BALANCEvalue using proper PostgreSQL syntax.apps/notifications/drizzle/meta/_journal.json (1)
40-46: LGTM! Migration journal entry is correct.The new journal entry properly tracks the 0005_left_magus migration with appropriate metadata.
apps/notifications/drizzle/meta/0005_snapshot.json (1)
1-444: LGTM! Snapshot reflects the schema after migration.This auto-generated snapshot correctly captures the database schema state including the new
WALLET_BALANCEenum value in thealert_typeenum.apps/notifications/src/modules/alert/alert.module.ts (2)
14-14: LGTM! Service properly registered.The
WalletBalanceAlertsServiceis correctly imported and added to the module's providers array, making it available for dependency injection.Also applies to: 30-30
39-39: LGTM! Service properly exported.Exporting
WalletBalanceAlertsServicemakes it available for injection in other modules, which is necessary for theChainEventsHandlerto use it.apps/notifications/src/modules/alert/model-schemas/alert.schema.ts (1)
8-8: LGTM! Enum extension is correct.The
WALLET_BALANCEvalue has been properly added to theAlertTypeenum, maintaining consistency with the SQL migration and providing type safety for TypeScript code.apps/notifications/test/functional/balance-alert.spec.ts (1)
127-128: LGTM! Method rename improves clarity.The renamed method
evaluateDeploymentBalanceAlertsOnBlockis more descriptive and explicitly indicates that it processes deployment balance alerts, distinguishing it from the new wallet balance alert evaluation pathway.apps/notifications/test/seeders/wallet-balance-alert.seeder.ts (1)
7-45: LGTM! Test seeder is well-implemented.The
generateWalletBalanceAlertfunction follows established patterns in the codebase, provides sensible defaults for all fields, and maintains type safety withWalletBalanceAlertOutput. The default conditions and params are appropriate for wallet balance alert testing scenarios.apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.ts (1)
31-48: Reconsider re-throwing errors in batch processing.The error is re-thrown on line 46, which could cause the entire block processing to fail. Since
processSingleAlertalready has isolated error handling (lines 92-98) that doesn't re-throw, this inconsistency means a pagination-level error (e.g., database timeout) will propagate up and potentially stop all alert processing for the block, while per-alert errors are contained.Consider whether pagination errors should also be isolated to allow other alerts to continue processing, or if failing fast is the intended behavior.
} catch (error) { this.loggerService.error({ event: "ALERT_FAILURE", block, error }); - throw error; }apps/notifications/src/modules/alert/repositories/alert/alert-json-fields.schema.ts (3)
31-31: Good refactoring to share the schema.Renaming
deploymentBalanceConditionsSchematobalanceConditionsSchemaappropriately reflects that the schema is now shared between deployment and wallet balance alerts, eliminating duplication.
43-47: Consider adding validation for address and denomination formats.The
owneranddenomfields accept any string without format validation. Invalid addresses or denominations will only fail at runtime whenBalanceHttpService.getBalance()is called, potentially after the alert is already saved.Verify whether validation should be added here (e.g., Bech32 format for
owner, known denom values fordenom) or if flexibility is preferred for supporting various chain configurations.
72-76: LGTM!The
walletBalanceJsonFieldsSchemaandWalletBalanceJsonFieldstype follow the same pattern as the existing deployment balance schema, maintaining consistency across alert types.Also applies to: 80-80
...notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.ts
Show resolved
Hide resolved
...tions/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
Show resolved
Hide resolved
...ifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.ts
Outdated
Show resolved
Hide resolved
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #2167 +/- ##
==========================================
- Coverage 46.70% 46.43% -0.28%
==========================================
Files 1019 1010 -9
Lines 28929 28641 -288
Branches 7515 7480 -35
==========================================
- Hits 13512 13300 -212
+ Misses 15103 15047 -56
+ Partials 314 294 -20
*This pull request uses carry forward flags. Click here to find out more.
🚀 New features to boost your workflow:
|
ab00336 to
24eeebf
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (1)
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts (1)
235-266: Match setup signature with mandated pattern.The setup function must accept exactly one parameter with an inline type definition and should not declare an explicit return type, per the coding guidelines.
Apply this diff:
- async function setup(): Promise<{ - service: WalletBalanceAlertsService; - loggerService: MockProxy<LoggerService>; - alertRepository: MockProxy<AlertRepository>; - conditionsMatcherService: ConditionsMatcherService; - alertMessageService: MockProxy<AlertMessageService>; - balanceHttpService: MockProxy<BalanceHttpService>; - onMessage: jest.Mock; - }> { + async function setup(opts: Record<string, never> = {}) {As per coding guidelines.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (16)
apps/notifications/drizzle/0005_left_magus.sql(1 hunks)apps/notifications/drizzle/meta/0005_snapshot.json(1 hunks)apps/notifications/drizzle/meta/_journal.json(1 hunks)apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.ts(2 hunks)apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.ts(1 hunks)apps/notifications/src/interfaces/rest/http-schemas/alert.http-schema.ts(3 hunks)apps/notifications/src/lib/value-backoff/value-backoff.ts(1 hunks)apps/notifications/src/modules/alert/alert.module.ts(3 hunks)apps/notifications/src/modules/alert/model-schemas/alert.schema.ts(1 hunks)apps/notifications/src/modules/alert/providers/http-sdk.provider.ts(2 hunks)apps/notifications/src/modules/alert/repositories/alert/alert-json-fields.schema.ts(4 hunks)apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts(3 hunks)apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts(1 hunks)apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.ts(1 hunks)apps/notifications/test/functional/balance-alert.spec.ts(1 hunks)apps/notifications/test/seeders/wallet-balance-alert.seeder.ts(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (7)
- apps/notifications/src/modules/alert/alert.module.ts
- apps/notifications/src/modules/alert/model-schemas/alert.schema.ts
- apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.ts
- apps/notifications/test/functional/balance-alert.spec.ts
- apps/notifications/src/lib/value-backoff/value-backoff.ts
- apps/notifications/test/seeders/wallet-balance-alert.seeder.ts
- apps/notifications/drizzle/0005_left_magus.sql
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/general.mdc)
Never use type any or cast to type any. Always define the proper TypeScript types.
Files:
apps/notifications/src/modules/alert/providers/http-sdk.provider.tsapps/notifications/src/modules/alert/repositories/alert/alert.repository.tsapps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.tsapps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.tsapps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.tsapps/notifications/src/modules/alert/repositories/alert/alert-json-fields.schema.tsapps/notifications/src/interfaces/rest/http-schemas/alert.http-schema.ts
**/*.{js,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/general.mdc)
**/*.{js,ts,tsx}: Never use deprecated methods from libraries.
Don't add unnecessary comments to the code
Files:
apps/notifications/src/modules/alert/providers/http-sdk.provider.tsapps/notifications/src/modules/alert/repositories/alert/alert.repository.tsapps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.tsapps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.tsapps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.tsapps/notifications/src/modules/alert/repositories/alert/alert-json-fields.schema.tsapps/notifications/src/interfaces/rest/http-schemas/alert.http-schema.ts
**/*.spec.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/no-jest-mock.mdc)
Don't use
jest.mock()to mock dependencies in test files. Instead, usejest-mock-extendedto create mocks and pass mocks as dependencies to the service under test.
**/*.spec.{ts,tsx}: Usesetupfunction instead ofbeforeEachin test files
setupfunction must be at the bottom of the rootdescribeblock in test files
setupfunction creates an object under test and returns it
setupfunction should accept a single parameter with inline type definition
Don't use shared state insetupfunction
Don't specify return type ofsetupfunction
Files:
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
🧠 Learnings (11)
📚 Learning: 2025-09-04T04:27:50.638Z
Learnt from: stalniy
Repo: akash-network/console PR: 1868
File: apps/api/src/billing/services/managed-signer/managed-signer.service.ts:1-1
Timestamp: 2025-09-04T04:27:50.638Z
Learning: In the akash-network/console project, importing MsgCreateLease from "akashnetwork/akash-api/v1beta3" instead of v1beta4 is considered non-critical by the maintainers, likely due to backward compatibility or project-specific requirements.
Applied to files:
apps/notifications/src/modules/alert/providers/http-sdk.provider.ts
📚 Learning: 2025-10-15T16:39:55.348Z
Learnt from: jzsfkzm
Repo: akash-network/console PR: 2039
File: apps/deploy-web/tests/ui/change-wallets.spec.ts:4-10
Timestamp: 2025-10-15T16:39:55.348Z
Learning: In the Akash Console E2E tests using the context-with-extension fixture, the first wallet is automatically created during fixture setup via `importWalletToLeap` in `apps/deploy-web/tests/ui/fixture/wallet-setup.ts`, so tests that call `frontPage.createWallet()` are creating a second wallet to test wallet switching functionality.
Applied to files:
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
📚 Learning: 2025-07-21T08:25:07.474Z
Learnt from: CR
Repo: akash-network/console PR: 0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-07-21T08:25:07.474Z
Learning: Applies to **/*.spec.{ts,tsx} : `setup` function should accept a single parameter with inline type definition
Applied to files:
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
📚 Learning: 2025-07-21T08:25:07.474Z
Learnt from: CR
Repo: akash-network/console PR: 0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-07-21T08:25:07.474Z
Learning: Applies to **/*.spec.{ts,tsx} : Don't specify return type of `setup` function
Applied to files:
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
📚 Learning: 2025-07-21T08:25:07.474Z
Learnt from: CR
Repo: akash-network/console PR: 0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-07-21T08:25:07.474Z
Learning: Applies to **/*.spec.{ts,tsx} : Use `setup` function instead of `beforeEach` in test files
Applied to files:
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
📚 Learning: 2025-07-21T08:25:07.474Z
Learnt from: CR
Repo: akash-network/console PR: 0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-07-21T08:25:07.474Z
Learning: Applies to **/*.spec.{ts,tsx} : `setup` function creates an object under test and returns it
Applied to files:
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
📚 Learning: 2025-07-21T08:25:07.474Z
Learnt from: CR
Repo: akash-network/console PR: 0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-07-21T08:25:07.474Z
Learning: Applies to **/*.spec.{ts,tsx} : Don't use shared state in `setup` function
Applied to files:
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
📚 Learning: 2025-07-21T08:25:07.474Z
Learnt from: CR
Repo: akash-network/console PR: 0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-07-21T08:25:07.474Z
Learning: Applies to **/*.spec.{ts,tsx} : `setup` function must be at the bottom of the root `describe` block in test files
Applied to files:
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
📚 Learning: 2025-07-21T08:24:24.269Z
Learnt from: CR
Repo: akash-network/console PR: 0
File: .cursor/rules/no-jest-mock.mdc:0-0
Timestamp: 2025-07-21T08:24:24.269Z
Learning: Applies to **/*.spec.{ts,tsx} : Don't use `jest.mock()` to mock dependencies in test files. Instead, use `jest-mock-extended` to create mocks and pass mocks as dependencies to the service under test.
Applied to files:
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
📚 Learning: 2025-07-03T14:42:10.968Z
Learnt from: jzsfkzm
Repo: akash-network/console PR: 1498
File: apps/api/test/functional/templates.spec.ts:39-110
Timestamp: 2025-07-03T14:42:10.968Z
Learning: Setup function guidelines in test files apply when creating objects under test. For simple environment preparation functions (like file copying), the typical setup function pattern of accepting parameters and returning objects may not be necessary.
Applied to files:
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
📚 Learning: 2025-09-25T14:31:44.914Z
Learnt from: baktun14
Repo: akash-network/console PR: 1969
File: apps/deploy-web/src/pages/payment.tsx:179-191
Timestamp: 2025-09-25T14:31:44.914Z
Learning: The payment confirmation endpoint in apps/api/src/billing/http-schemas/stripe.schema.ts uses zod schema validation with `amount: z.number().gte(20, "Amount must be greater or equal to $20")` to ensure all payment requests meet the minimum amount requirement, preventing zero-amount or invalid payments from reaching Stripe.
Applied to files:
apps/notifications/src/modules/alert/repositories/alert/alert-json-fields.schema.ts
🧬 Code graph analysis (6)
apps/notifications/src/modules/alert/providers/http-sdk.provider.ts (3)
packages/http-sdk/src/balance/balance-http.service.ts (1)
BalanceHttpService(20-29)apps/api/src/core/services/config/config.service.ts (1)
ConfigService(9-22)apps/notifications/src/modules/alert/config/index.ts (1)
AlertConfig(9-9)
apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts (1)
apps/notifications/src/modules/alert/model-schemas/alert.schema.ts (1)
AlertType(8-8)
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts (7)
apps/notifications/test/seeders/akash-address.seeder.ts (1)
mockAkashAddress(3-3)apps/notifications/test/seeders/wallet-balance-alert.seeder.ts (1)
generateWalletBalanceAlert(7-45)apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts (2)
WalletBalanceAlertOutput(29-29)AlertOutput(32-32)packages/http-sdk/src/types/denom.type.ts (1)
Denom(1-4)apps/notifications/test/seeders/alert-message.seeder.ts (1)
generateAlertMessage(5-17)packages/http-sdk/src/balance/balance-http.service.ts (1)
BalanceHttpService(20-29)apps/notifications/test/mocks/provider.mock.ts (1)
MockProvider(4-6)
apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.ts (3)
apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts (1)
Injectable(84-320)apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.ts (1)
Injectable(13-100)apps/notifications/src/infrastructure/broker/services/broker/broker.service.ts (1)
Injectable(17-72)
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.ts (6)
apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts (2)
WalletBalanceAlertOutput(29-29)Injectable(84-320)apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.ts (1)
Injectable(11-45)packages/http-sdk/src/balance/balance-http.service.ts (1)
BalanceHttpService(20-29)apps/notifications/src/modules/alert/types/message-callback.type.ts (1)
MessageCallback(8-8)packages/logging/src/services/logger/logger.service.ts (1)
error(142-144)apps/notifications/src/modules/alert/services/conditions-matcher/conditions-matcher.service.ts (1)
isMatching(22-25)
apps/notifications/src/interfaces/rest/http-schemas/alert.http-schema.ts (2)
apps/notifications/src/modules/alert/repositories/alert/alert-json-fields.schema.ts (5)
balanceConditionsSchema(31-31)deploymentBalanceParamsSchema(37-41)walletBalanceTypeSchema(58-58)walletBalanceParamsSchema(43-47)generalAlertConditionsSchema(23-23)packages/http-sdk/src/generated/NotificationSDK.ts (1)
AlertCreateInput(13-93)
🔇 Additional comments (2)
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.ts (1)
1-100: LGTM!The service implementation correctly orchestrates wallet balance alert processing with proper error handling, status transitions, and message emission logic.
apps/notifications/src/interfaces/rest/http-schemas/alert.http-schema.ts (1)
52-58: LGTM!The wallet balance alert schemas are properly integrated into the discriminated unions for both input and output, with appropriate reuse of
balanceConditionsSchema.Also applies to: 60-65, 106-117
apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.ts
Outdated
Show resolved
Hide resolved
24eeebf to
ba550e4
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (3)
apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.ts (1)
40-46: Keep a singleblockCreatedhandlerRegistering a second
@HandlerforeventKeyRegistry.blockCreatedspins up another worker on the same queue, so one handler steals jobs from the other and wallet/deployment alerts get skipped. We already fan out insideprocessBlock; drop the duplicate handler.- @Handler({ - key: eventKeyRegistry.blockCreated, - dto: ChainBlockCreatedDto - }) - async evaluateWalletBalanceAlertsOnBlock(block: ChainBlockCreatedDto) { - await this.walletBalanceAlertsService.alertFor(block, async message => this.brokerService.publish(eventKeyRegistry.createNotification, message)); - }apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.ts (1)
50-58: Alignsetupsignature with spec guidelinesPer the spec conventions,
setupmust accept a single inline-typed parameter. Please update the helper signature accordingly. As per coding guidelines.- async function setup() { + async function setup({}: Record<string, never> = {}) {apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts (1)
235-266: Adjust setup function signature to match coding guidelines.The setup function currently has no parameter and an explicit return type, which violates the coding guidelines. Per the guidelines and similar to the previous review comment, the function should accept a single parameter with an inline type definition and should not have an explicit return type annotation.
As per coding guidelines. Based on learnings.
Apply this diff:
- async function setup(): Promise<{ - service: WalletBalanceAlertsService; - loggerService: MockProxy<LoggerService>; - alertRepository: MockProxy<AlertRepository>; - conditionsMatcherService: ConditionsMatcherService; - alertMessageService: MockProxy<AlertMessageService>; - balanceHttpService: MockProxy<BalanceHttpService>; - onMessage: jest.Mock; - }> { + async function setup({}: {} = {}) { const module: TestingModule = await Test.createTestingModule({
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (16)
apps/notifications/drizzle/0005_left_magus.sql(1 hunks)apps/notifications/drizzle/meta/0005_snapshot.json(1 hunks)apps/notifications/drizzle/meta/_journal.json(1 hunks)apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.ts(3 hunks)apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.ts(2 hunks)apps/notifications/src/interfaces/rest/http-schemas/alert.http-schema.ts(3 hunks)apps/notifications/src/lib/value-backoff/value-backoff.ts(1 hunks)apps/notifications/src/modules/alert/alert.module.ts(3 hunks)apps/notifications/src/modules/alert/model-schemas/alert.schema.ts(1 hunks)apps/notifications/src/modules/alert/providers/http-sdk.provider.ts(2 hunks)apps/notifications/src/modules/alert/repositories/alert/alert-json-fields.schema.ts(4 hunks)apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts(3 hunks)apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts(1 hunks)apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.ts(1 hunks)apps/notifications/test/functional/balance-alert.spec.ts(1 hunks)apps/notifications/test/seeders/wallet-balance-alert.seeder.ts(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
- apps/notifications/src/modules/alert/alert.module.ts
- apps/notifications/src/modules/alert/providers/http-sdk.provider.ts
- apps/notifications/src/lib/value-backoff/value-backoff.ts
- apps/notifications/drizzle/meta/_journal.json
- apps/notifications/drizzle/0005_left_magus.sql
🧰 Additional context used
📓 Path-based instructions (3)
**/*.spec.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/no-jest-mock.mdc)
Don't use
jest.mock()to mock dependencies in test files. Instead, usejest-mock-extendedto create mocks and pass mocks as dependencies to the service under test.
**/*.spec.{ts,tsx}: Usesetupfunction instead ofbeforeEachin test files
setupfunction must be at the bottom of the rootdescribeblock in test files
setupfunction creates an object under test and returns it
setupfunction should accept a single parameter with inline type definition
Don't use shared state insetupfunction
Don't specify return type ofsetupfunction
Files:
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.tsapps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.tsapps/notifications/test/functional/balance-alert.spec.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/general.mdc)
Never use type any or cast to type any. Always define the proper TypeScript types.
Files:
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.tsapps/notifications/src/modules/alert/model-schemas/alert.schema.tsapps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.tsapps/notifications/src/modules/alert/repositories/alert/alert-json-fields.schema.tsapps/notifications/src/modules/alert/repositories/alert/alert.repository.tsapps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.tsapps/notifications/test/seeders/wallet-balance-alert.seeder.tsapps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.tsapps/notifications/src/interfaces/rest/http-schemas/alert.http-schema.tsapps/notifications/test/functional/balance-alert.spec.ts
**/*.{js,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/general.mdc)
**/*.{js,ts,tsx}: Never use deprecated methods from libraries.
Don't add unnecessary comments to the code
Files:
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.tsapps/notifications/src/modules/alert/model-schemas/alert.schema.tsapps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.tsapps/notifications/src/modules/alert/repositories/alert/alert-json-fields.schema.tsapps/notifications/src/modules/alert/repositories/alert/alert.repository.tsapps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.tsapps/notifications/test/seeders/wallet-balance-alert.seeder.tsapps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.tsapps/notifications/src/interfaces/rest/http-schemas/alert.http-schema.tsapps/notifications/test/functional/balance-alert.spec.ts
🧠 Learnings (11)
📚 Learning: 2025-10-15T16:39:55.348Z
Learnt from: jzsfkzm
Repo: akash-network/console PR: 2039
File: apps/deploy-web/tests/ui/change-wallets.spec.ts:4-10
Timestamp: 2025-10-15T16:39:55.348Z
Learning: In the Akash Console E2E tests using the context-with-extension fixture, the first wallet is automatically created during fixture setup via `importWalletToLeap` in `apps/deploy-web/tests/ui/fixture/wallet-setup.ts`, so tests that call `frontPage.createWallet()` are creating a second wallet to test wallet switching functionality.
Applied to files:
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.tsapps/notifications/test/seeders/wallet-balance-alert.seeder.tsapps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.ts
📚 Learning: 2025-07-21T08:25:07.474Z
Learnt from: CR
Repo: akash-network/console PR: 0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-07-21T08:25:07.474Z
Learning: Applies to **/*.spec.{ts,tsx} : `setup` function should accept a single parameter with inline type definition
Applied to files:
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.tsapps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.ts
📚 Learning: 2025-07-21T08:25:07.474Z
Learnt from: CR
Repo: akash-network/console PR: 0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-07-21T08:25:07.474Z
Learning: Applies to **/*.spec.{ts,tsx} : Don't specify return type of `setup` function
Applied to files:
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.tsapps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.ts
📚 Learning: 2025-07-21T08:25:07.474Z
Learnt from: CR
Repo: akash-network/console PR: 0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-07-21T08:25:07.474Z
Learning: Applies to **/*.spec.{ts,tsx} : Use `setup` function instead of `beforeEach` in test files
Applied to files:
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.tsapps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.ts
📚 Learning: 2025-07-21T08:25:07.474Z
Learnt from: CR
Repo: akash-network/console PR: 0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-07-21T08:25:07.474Z
Learning: Applies to **/*.spec.{ts,tsx} : `setup` function creates an object under test and returns it
Applied to files:
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.tsapps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.ts
📚 Learning: 2025-07-21T08:25:07.474Z
Learnt from: CR
Repo: akash-network/console PR: 0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-07-21T08:25:07.474Z
Learning: Applies to **/*.spec.{ts,tsx} : Don't use shared state in `setup` function
Applied to files:
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.tsapps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.ts
📚 Learning: 2025-07-21T08:25:07.474Z
Learnt from: CR
Repo: akash-network/console PR: 0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-07-21T08:25:07.474Z
Learning: Applies to **/*.spec.{ts,tsx} : `setup` function must be at the bottom of the root `describe` block in test files
Applied to files:
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.tsapps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.ts
📚 Learning: 2025-07-21T08:24:24.269Z
Learnt from: CR
Repo: akash-network/console PR: 0
File: .cursor/rules/no-jest-mock.mdc:0-0
Timestamp: 2025-07-21T08:24:24.269Z
Learning: Applies to **/*.spec.{ts,tsx} : Don't use `jest.mock()` to mock dependencies in test files. Instead, use `jest-mock-extended` to create mocks and pass mocks as dependencies to the service under test.
Applied to files:
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.tsapps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.ts
📚 Learning: 2025-07-03T14:42:10.968Z
Learnt from: jzsfkzm
Repo: akash-network/console PR: 1498
File: apps/api/test/functional/templates.spec.ts:39-110
Timestamp: 2025-07-03T14:42:10.968Z
Learning: Setup function guidelines in test files apply when creating objects under test. For simple environment preparation functions (like file copying), the typical setup function pattern of accepting parameters and returning objects may not be necessary.
Applied to files:
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.tsapps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.ts
📚 Learning: 2025-09-25T14:31:44.914Z
Learnt from: baktun14
Repo: akash-network/console PR: 1969
File: apps/deploy-web/src/pages/payment.tsx:179-191
Timestamp: 2025-09-25T14:31:44.914Z
Learning: The payment confirmation endpoint in apps/api/src/billing/http-schemas/stripe.schema.ts uses zod schema validation with `amount: z.number().gte(20, "Amount must be greater or equal to $20")` to ensure all payment requests meet the minimum amount requirement, preventing zero-amount or invalid payments from reaching Stripe.
Applied to files:
apps/notifications/src/modules/alert/repositories/alert/alert-json-fields.schema.ts
📚 Learning: 2025-07-21T08:24:27.953Z
Learnt from: CR
Repo: akash-network/console PR: 0
File: .cursor/rules/query-by-in-tests.mdc:0-0
Timestamp: 2025-07-21T08:24:27.953Z
Learning: Applies to apps/{deploy-web,provider-console}/**/*.spec.tsx : Use `queryBy` methods instead of `getBy` methods in test expectations in `.spec.tsx` files
Applied to files:
apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.ts
🧬 Code graph analysis (8)
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts (8)
apps/notifications/test/seeders/akash-address.seeder.ts (1)
mockAkashAddress(3-3)apps/notifications/test/seeders/wallet-balance-alert.seeder.ts (1)
generateWalletBalanceAlert(7-45)apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts (2)
WalletBalanceAlertOutput(29-29)AlertOutput(32-32)packages/http-sdk/src/types/denom.type.ts (1)
Denom(1-4)apps/notifications/test/seeders/alert-message.seeder.ts (1)
generateAlertMessage(5-17)packages/logging/src/services/logger/logger.service.ts (1)
error(142-144)packages/http-sdk/src/balance/balance-http.service.ts (1)
BalanceHttpService(20-29)apps/notifications/test/mocks/provider.mock.ts (1)
MockProvider(4-6)
apps/notifications/src/modules/alert/model-schemas/alert.schema.ts (1)
apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts (1)
AlertType(34-34)
apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.ts (6)
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.ts (1)
Injectable(13-100)apps/notifications/src/infrastructure/broker/services/broker/broker.service.ts (1)
Injectable(17-72)apps/notifications/src/modules/alert/services/deployment-balance-alerts/deployment-balance-alerts.service.ts (1)
Injectable(16-133)apps/notifications/src/common/config/event-key-registry.config.ts (1)
eventKeyRegistry(1-5)apps/notifications/src/infrastructure/broker/decorators/handler.decorator.ts (1)
Handler(7-7)apps/notifications/src/modules/alert/dto/chain-block-created.dto.ts (1)
ChainBlockCreatedDto(8-8)
apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts (2)
apps/notifications/src/modules/alert/repositories/alert/alert-json-fields.schema.ts (1)
WalletBalanceJsonFields(80-80)apps/notifications/src/modules/alert/model-schemas/alert.schema.ts (1)
AlertType(8-8)
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.ts (7)
apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts (2)
WalletBalanceAlertOutput(29-29)Injectable(84-320)apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.ts (1)
Injectable(11-57)packages/http-sdk/src/balance/balance-http.service.ts (1)
BalanceHttpService(20-29)apps/notifications/src/modules/alert/dto/chain-block-created.dto.ts (1)
ChainBlockCreatedDto(8-8)apps/notifications/src/modules/alert/types/message-callback.type.ts (1)
MessageCallback(8-8)packages/logging/src/services/logger/logger.service.ts (1)
error(142-144)apps/notifications/src/modules/alert/services/conditions-matcher/conditions-matcher.service.ts (1)
isMatching(22-25)
apps/notifications/test/seeders/wallet-balance-alert.seeder.ts (2)
apps/notifications/test/seeders/akash-address.seeder.ts (1)
mockAkashAddress(3-3)apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts (1)
WalletBalanceAlertOutput(29-29)
apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.ts (2)
apps/notifications/src/common/config/event-key-registry.config.ts (1)
eventKeyRegistry(1-5)apps/notifications/test/mocks/provider.mock.ts (1)
MockProvider(4-6)
apps/notifications/src/interfaces/rest/http-schemas/alert.http-schema.ts (1)
apps/notifications/src/modules/alert/repositories/alert/alert-json-fields.schema.ts (5)
balanceConditionsSchema(31-31)deploymentBalanceParamsSchema(37-41)walletBalanceTypeSchema(58-58)walletBalanceParamsSchema(43-47)generalAlertConditionsSchema(23-23)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: validate / validate-app
- GitHub Check: test-build
🔇 Additional comments (20)
apps/notifications/test/seeders/wallet-balance-alert.seeder.ts (1)
7-45: LGTM!The seeder function is well-structured with appropriate defaults and type safety. The function signature correctly uses
Partial<WalletBalanceAlertOutput>for flexible test data generation, and all fields are properly initialized with sensible faker-generated values or explicit defaults.apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts (4)
14-14: LGTM!The import of
WalletBalanceJsonFieldsis correctly added alongside existing alert type imports.
28-32: LGTM!The type definitions follow the established pattern for alert types.
WalletBalanceAlertInputandWalletBalanceAlertOutputare properly defined using the sameOmitpattern asDeploymentBalanceAlertInput/Output, and they're correctly integrated into the union types.
38-48: LGTM!The type maps are correctly extended to include
WALLET_BALANCEentries, maintaining consistency with the existing alert type registration pattern.
311-316: LGTM!The
WALLET_BALANCEhandling intoOutputcorrectly follows the same pattern asDEPLOYMENT_BALANCE, parsing the schema and returning the typed output.apps/notifications/drizzle/meta/0005_snapshot.json (1)
416-425: LGTM!The database snapshot correctly includes
WALLET_BALANCEin thealert_typeenum alongside existing alert types. This generated file properly reflects the schema changes for wallet balance alerts.apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts (6)
20-69: LGTM!The test comprehensively validates the alert triggering flow, including balance fetching, condition matching, message generation, and repository updates with correct status and minBlockHeight values.
71-122: LGTM!The recovery test correctly validates that a triggered alert transitions back to OK status when the balance condition is no longer met.
124-161: LGTM!This test correctly validates the duplicate trigger guard behavior: when an alert is already triggered and conditions still match, the service skips message generation and emission while still updating the minBlockHeight.
163-191: LGTM!The test properly validates error handling when balance fetch returns null, ensuring the error is logged with the correct event type and alert context without attempting updates.
193-210: LGTM!The test correctly validates that repository failures are logged with event, block, and error details, and the error is propagated to the caller.
212-232: LGTM!The test validates that individual alert processing errors are caught, logged with alert and error context, and don't prevent other alerts from being processed.
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.ts (4)
14-25: LGTM!The service is properly structured with correct dependency injection and the logger context is set appropriately. The throttle constant is well-named and scoped.
27-29: LGTM!Clean delegation pattern that separates concerns between block processing orchestration and per-alert processing logic.
31-48: LGTM!The pagination logic correctly queries WALLET_BALANCE alerts for the given block, processes them concurrently with
Promise.all, and properly handles errors by logging and re-throwing to notify the caller.
50-99: LGTM!The alert processing logic is well-structured:
- Fetches balance and handles missing data gracefully
- Uses conditions matcher to determine if alert should trigger
- Correctly manages status transitions (OK ↔ TRIGGERED) with appropriate throttling
- Sends notifications only when status changes
- Catches and logs individual alert errors without failing the entire batch
apps/notifications/src/interfaces/rest/http-schemas/alert.http-schema.ts (4)
6-15: LGTM!The imports correctly include the new wallet balance schemas and the shared
balanceConditionsSchema, which promotes reuse between deployment and wallet balance alert types.
52-58: LGTM!The
walletBalanceCreateInputSchemacorrectly follows the same pattern asdeploymentBalanceCreateInputSchema, using the sharedbalanceConditionsSchemaand wallet-specific params schema.
60-65: LGTM!The discriminated union correctly includes
walletBalanceCreateInputSchema, enabling type-safe alert creation for wallet balance alerts.
106-117: LGTM!The output schemas correctly mirror the input schema structure, with
walletBalanceOutputSchemaproperly included in the discriminated union for type-safe alert responses.
| await this.deploymentBalanceAlertsService.alertFor(block, message => this.brokerService.publish(eventKeyRegistry.createNotification, message)); | ||
| const results = await Promise.allSettled([ | ||
| this.deploymentBalanceAlertsService.alertFor(block, message => this.brokerService.publish(eventKeyRegistry.createNotification, message)), | ||
| this.walletBalanceAlertsService.alertFor(block, async message => this.brokerService.publish(eventKeyRegistry.createNotification, message)) |
There was a problem hiding this comment.
question: Does that mean we fetch the balance from the api every block for every alerts?
There was a problem hiding this comment.
there is a throttle value similarly to deployment balance alerts.
https://github.com/akash-network/console/pull/2167/files/ba550e4f0ead428a2566ef26d1018ce6483f71ec#diff-84fb62ed999011521b82c17f15f2a14d301ffb7be42f3dd6ff10128965d1dfe4R65
https://github.com/akash-network/console/pull/2167/files/ba550e4f0ead428a2566ef26d1018ce6483f71ec#diff-84fb62ed999011521b82c17f15f2a14d301ffb7be42f3dd6ff10128965d1dfe4R34
However this a dumb initial implementation which is fine for quite a while. By the end of the milestone I have an idea on how to optimise this much nicer: listen to deployment-closed/created events and recalculate that value for owners.
Which besides being another type of supported alerts would serve as auto credit reload. refs #1779
7375956 to
7c56445
Compare
There was a problem hiding this comment.
Actionable comments posted: 0
♻️ Duplicate comments (1)
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts (1)
235-243: Adjust setup signature to match coding guidelines.The
setupfunction violates coding guidelines by having no parameter and an explicit return type. As per coding guidelines.Apply this diff:
- async function setup(): Promise<{ - service: WalletBalanceAlertsService; - loggerService: MockProxy<LoggerService>; - alertRepository: MockProxy<AlertRepository>; - conditionsMatcherService: ConditionsMatcherService; - alertMessageService: MockProxy<AlertMessageService>; - balanceHttpService: MockProxy<BalanceHttpService>; - onMessage: jest.Mock; - }> { + async function setup(opts: {} = {}) {
🧹 Nitpick comments (1)
apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.ts (1)
25-28: Remove unnecessaryasynckeyword for consistency.Line 27 uses
async message =>while line 26 usesmessage =>. SincebrokerService.publishalready returns a Promise, theasynckeyword is redundant and creates an inconsistency.Apply this diff:
- this.walletBalanceAlertsService.alertFor(block, async message => this.brokerService.publish(eventKeyRegistry.createNotification, message)) + this.walletBalanceAlertsService.alertFor(block, message => this.brokerService.publish(eventKeyRegistry.createNotification, message))
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (16)
apps/notifications/drizzle/0005_left_magus.sql(1 hunks)apps/notifications/drizzle/meta/0005_snapshot.json(1 hunks)apps/notifications/drizzle/meta/_journal.json(1 hunks)apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.ts(3 hunks)apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.ts(2 hunks)apps/notifications/src/interfaces/rest/http-schemas/alert.http-schema.ts(3 hunks)apps/notifications/src/lib/value-backoff/value-backoff.ts(1 hunks)apps/notifications/src/modules/alert/alert.module.ts(3 hunks)apps/notifications/src/modules/alert/model-schemas/alert.schema.ts(1 hunks)apps/notifications/src/modules/alert/providers/http-sdk.provider.ts(2 hunks)apps/notifications/src/modules/alert/repositories/alert/alert-json-fields.schema.ts(4 hunks)apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts(3 hunks)apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts(1 hunks)apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.ts(1 hunks)apps/notifications/test/functional/balance-alert.spec.ts(0 hunks)apps/notifications/test/seeders/wallet-balance-alert.seeder.ts(1 hunks)
💤 Files with no reviewable changes (1)
- apps/notifications/test/functional/balance-alert.spec.ts
✅ Files skipped from review due to trivial changes (1)
- apps/notifications/drizzle/0005_left_magus.sql
🚧 Files skipped from review as they are similar to previous changes (9)
- apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.ts
- apps/notifications/src/lib/value-backoff/value-backoff.ts
- apps/notifications/src/interfaces/rest/http-schemas/alert.http-schema.ts
- apps/notifications/test/seeders/wallet-balance-alert.seeder.ts
- apps/notifications/src/modules/alert/repositories/alert/alert-json-fields.schema.ts
- apps/notifications/src/modules/alert/alert.module.ts
- apps/notifications/drizzle/meta/0005_snapshot.json
- apps/notifications/drizzle/meta/_journal.json
- apps/notifications/src/modules/alert/providers/http-sdk.provider.ts
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/general.mdc)
Never use type any or cast to type any. Always define the proper TypeScript types.
Files:
apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.tsapps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.tsapps/notifications/src/modules/alert/model-schemas/alert.schema.tsapps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.tsapps/notifications/src/modules/alert/repositories/alert/alert.repository.ts
**/*.{js,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/general.mdc)
**/*.{js,ts,tsx}: Never use deprecated methods from libraries.
Don't add unnecessary comments to the code
Files:
apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.tsapps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.tsapps/notifications/src/modules/alert/model-schemas/alert.schema.tsapps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.tsapps/notifications/src/modules/alert/repositories/alert/alert.repository.ts
**/*.spec.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/no-jest-mock.mdc)
Don't use
jest.mock()to mock dependencies in test files. Instead, usejest-mock-extendedto create mocks and pass mocks as dependencies to the service under test.
**/*.spec.{ts,tsx}: Usesetupfunction instead ofbeforeEachin test files
setupfunction must be at the bottom of the rootdescribeblock in test files
setupfunction creates an object under test and returns it
setupfunction should accept a single parameter with inline type definition
Don't use shared state insetupfunction
Don't specify return type ofsetupfunction
Files:
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
🧠 Learnings (9)
📚 Learning: 2025-10-15T16:39:55.348Z
Learnt from: jzsfkzm
Repo: akash-network/console PR: 2039
File: apps/deploy-web/tests/ui/change-wallets.spec.ts:4-10
Timestamp: 2025-10-15T16:39:55.348Z
Learning: In the Akash Console E2E tests using the context-with-extension fixture, the first wallet is automatically created during fixture setup via `importWalletToLeap` in `apps/deploy-web/tests/ui/fixture/wallet-setup.ts`, so tests that call `frontPage.createWallet()` are creating a second wallet to test wallet switching functionality.
Applied to files:
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
📚 Learning: 2025-07-21T08:25:07.474Z
Learnt from: CR
Repo: akash-network/console PR: 0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-07-21T08:25:07.474Z
Learning: Applies to **/*.spec.{ts,tsx} : `setup` function should accept a single parameter with inline type definition
Applied to files:
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
📚 Learning: 2025-07-21T08:25:07.474Z
Learnt from: CR
Repo: akash-network/console PR: 0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-07-21T08:25:07.474Z
Learning: Applies to **/*.spec.{ts,tsx} : Don't specify return type of `setup` function
Applied to files:
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
📚 Learning: 2025-07-21T08:25:07.474Z
Learnt from: CR
Repo: akash-network/console PR: 0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-07-21T08:25:07.474Z
Learning: Applies to **/*.spec.{ts,tsx} : Use `setup` function instead of `beforeEach` in test files
Applied to files:
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
📚 Learning: 2025-07-21T08:25:07.474Z
Learnt from: CR
Repo: akash-network/console PR: 0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-07-21T08:25:07.474Z
Learning: Applies to **/*.spec.{ts,tsx} : `setup` function creates an object under test and returns it
Applied to files:
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
📚 Learning: 2025-07-21T08:25:07.474Z
Learnt from: CR
Repo: akash-network/console PR: 0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-07-21T08:25:07.474Z
Learning: Applies to **/*.spec.{ts,tsx} : Don't use shared state in `setup` function
Applied to files:
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
📚 Learning: 2025-07-21T08:25:07.474Z
Learnt from: CR
Repo: akash-network/console PR: 0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-07-21T08:25:07.474Z
Learning: Applies to **/*.spec.{ts,tsx} : `setup` function must be at the bottom of the root `describe` block in test files
Applied to files:
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
📚 Learning: 2025-07-21T08:24:24.269Z
Learnt from: CR
Repo: akash-network/console PR: 0
File: .cursor/rules/no-jest-mock.mdc:0-0
Timestamp: 2025-07-21T08:24:24.269Z
Learning: Applies to **/*.spec.{ts,tsx} : Don't use `jest.mock()` to mock dependencies in test files. Instead, use `jest-mock-extended` to create mocks and pass mocks as dependencies to the service under test.
Applied to files:
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
📚 Learning: 2025-07-03T14:42:10.968Z
Learnt from: jzsfkzm
Repo: akash-network/console PR: 1498
File: apps/api/test/functional/templates.spec.ts:39-110
Timestamp: 2025-07-03T14:42:10.968Z
Learning: Setup function guidelines in test files apply when creating objects under test. For simple environment preparation functions (like file copying), the typical setup function pattern of accepting parameters and returning objects may not be necessary.
Applied to files:
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
🧬 Code graph analysis (5)
apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.ts (4)
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.ts (1)
Injectable(13-100)apps/notifications/src/infrastructure/broker/services/broker/broker.service.ts (1)
Injectable(17-72)apps/notifications/src/modules/alert/services/deployment-balance-alerts/deployment-balance-alerts.service.ts (1)
Injectable(16-133)apps/notifications/src/common/config/event-key-registry.config.ts (1)
eventKeyRegistry(1-5)
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts (7)
apps/notifications/test/seeders/akash-address.seeder.ts (1)
mockAkashAddress(3-3)apps/notifications/test/seeders/wallet-balance-alert.seeder.ts (1)
generateWalletBalanceAlert(7-45)packages/http-sdk/src/types/denom.type.ts (1)
Denom(1-4)apps/notifications/test/seeders/alert-message.seeder.ts (1)
generateAlertMessage(5-17)packages/logging/src/services/logger/logger.service.ts (1)
error(142-144)packages/http-sdk/src/balance/balance-http.service.ts (1)
BalanceHttpService(20-29)apps/notifications/test/mocks/provider.mock.ts (1)
MockProvider(4-6)
apps/notifications/src/modules/alert/model-schemas/alert.schema.ts (1)
apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts (1)
AlertType(34-34)
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.ts (6)
apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts (2)
WalletBalanceAlertOutput(29-29)Injectable(84-320)apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.ts (1)
Injectable(11-49)packages/http-sdk/src/balance/balance-http.service.ts (1)
BalanceHttpService(20-29)apps/notifications/src/modules/alert/types/message-callback.type.ts (1)
MessageCallback(8-8)packages/logging/src/services/logger/logger.service.ts (1)
error(142-144)apps/notifications/src/modules/alert/services/conditions-matcher/conditions-matcher.service.ts (1)
isMatching(22-25)
apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts (1)
apps/notifications/src/modules/alert/model-schemas/alert.schema.ts (1)
AlertType(8-8)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: validate / validate-app
🔇 Additional comments (8)
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.ts (3)
27-29: LGTM!The public API cleanly delegates to the internal pagination logic.
31-48: LGTM!Pagination logic with concurrent batch processing and appropriate error handling matches the established pattern.
50-99: LGTM!The per-alert processing logic is well-structured:
- Defensive balance check with early return
- Correct status transitions (OK ↔ TRIGGERED)
- Message sent only on status change
- Per-alert error handling ensures batch resilience
apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.ts (1)
25-37: Good use of Promise.allSettled for concurrent execution.The refactor to
Promise.allSettledwithAggregateErrorensures both deployment and wallet balance alerts run concurrently while properly collecting and surfacing all failures.apps/notifications/src/modules/alert/model-schemas/alert.schema.ts (1)
8-8: LGTM!The enum extension correctly adds WALLET_BALANCE as a new alert type, aligning with the PR objectives.
apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts (2)
14-14: LGTM!The type system extensions for wallet balance alerts follow the established pattern used by deployment balance alerts, maintaining type safety across the repository layer.
Also applies to: 28-29, 31-32, 38-38, 45-45
311-316: LGTM!The
WALLET_BALANCEcase intoOutputcorrectly parses wallet balance JSON fields using the appropriate schema, consistent with existing alert types.apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts (1)
20-232: Comprehensive test coverage.The test suite thoroughly covers the wallet balance alerting scenarios:
- Alert triggering when condition matches
- Alert recovery when condition no longer matches
- Duplicate trigger prevention
- Missing balance error handling
- Repository failure handling
- Per-alert error isolation
Which besides being another type of supported alerts would serve as auto credit reload.
refs #1779
Summary by CodeRabbit
New Features
API
Database
Tests
Reliability