-
Notifications
You must be signed in to change notification settings - Fork 550
fix: improve Batch inner transaction typing #3035
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation<
8000
/h2>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Walkthrough
The changes refactor batch transaction validation logic by introducing a dedicated helper function, update type usage for inner batch transactions, and add new type guard utilities. Test cases are streamlined for clarity and reusability, and the changelog is updated for accuracy and formatting.
Changes
Files/Paths
Change Summary
packages/xrpl/src/models/transactions/batch.ts
Refactored validation logic for batch inner transactions; removed BatchInnerTransaction
type; now uses SubmittableTransaction
; added validateBatchInnerTransaction
helper.
packages/xrpl/src/models/transactions/common.ts
Added isNull
and isValue
type guard utility functions.
packages/xrpl/test/integration/transactions/batch.test.ts
Refactored tests for clarity and DRYness; reused explicit Payment
objects; updated imports.
packages/xrpl/test/models/batch.test.ts
Updated sequence number in batch transaction test.
packages/xrpl/test/utils/hashes.test.ts
Replaced BatchInnerTransaction
type with Payment
in test annotations.
packages/xrpl/test/wallet/batchSigner.test.ts
Adjusted imports and type annotations to remove BatchInnerTransaction
usage.
packages/xrpl/src/sugar/autofill.ts
Removed ESLint disable comments related to unnecessary condition checks in autofillBatchTxn
.
packages/xrpl/src/models/transactions/delegateSet.ts
Removed and re-added NON_DELEGATABLE_TRANSACTIONS
constant with whitespace-only change.
packages/xrpl/HISTORY.md
Updated changelog with improved typing note and corrected date formatting.
Possibly related PRs
- feat: add support for Batch amendment #2801: Adds initial support for the
Batch
amendment including models, signing helpers, autofill, and tests; related to batch transactions but does not modify the same validation logic or types.
Suggested reviewers
- khancode
- achowdhry-ripple
Poem
A batch of changes, neat and bright,
With helpers new to check what's right.
Type guards join the bunny dance,
While tests now prance in elegance.
The changelog hops in tidy rows—
🐇 Onward, code, as progress grows!
📜 Recent review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/xrpl/HISTORY.md
(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- packages/xrpl/HISTORY.md
⏰ 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). (9)
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: generate-documentation (22.x)
- GitHub Check: integration (22.x)
- GitHub Check: integration (20.x)
- GitHub Check: browser (22.x)
- GitHub Check: unit (22.x)
- GitHub Check: unit (20.x)
- GitHub Check: build-and-lint (22.x)
- GitHub Check: Analyze (javascript)
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.
🪧 Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
I pushed a fix in commit <commit_id>, please review it.
Explain this complex logic.
Open a follow-up GitHub issue for this discussion.
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitai
in a new review comment at the desired location with your query. Examples:
@coderabbitai explain this code block.
@coderabbitai modularize this function.
- PR comments: Tag
@coderabbitai
in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
@coderabbitai read src/utils.ts and explain its main purpose.
@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
@coderabbitai help me debug CodeRabbit configuration file.
Support
Need help? Create a ticket on our support page for assistance with any issues or questions.
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.
CodeRabbit Commands (Invoked using PR comments)
@coderabbitai pause
to pause the reviews on a PR.
@coderabbitai resume
to resume the paused reviews.
@coderabbitai review
to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
@coderabbitai full review
to do a full review from scratch and review all the files again.
@coderabbitai summary
to regenerate the summary of the PR.
@coderabbitai generate docstrings
to generate docstrings for this PR.
@coderabbitai generate sequence diagram
to generate a sequence diagram of the changes in this PR.
@coderabbitai resolve
resolve all the CodeRabbit review comments.
@coderabbitai configuration
to show the current CodeRabbit configuration for the repository.
@coderabbitai help
to
8000
get help.
Other keywords and placeholders
- Add
@coderabbitai ignore
anywhere in the PR description to prevent this PR from being reviewed.
- Add
@coderabbitai summary
to generate the high-level summary at a specific location in the PR description.
- Add
@coderabbitai
anywhere in the PR title to generate the title automatically.
Documentation and Community
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
packages/xrpl/HISTORY.md
(1 hunks)
packages/xrpl/src/models/transactions/batch.ts
(3 hunks)
packages/xrpl/src/models/transactions/common.ts
(1 hunks)
packages/xrpl/test/integration/transactions/batch.test.ts
(3 hunks)
🧰 Additional context used
🧠 Learnings (5)
📓 Common learnings
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/clawback.test.ts:165-178
Timestamp: 2024-12-06T19:27:11.147Z
Learning: In the integration tests for `clawback.test.ts`, it's acceptable to use `@ts-expect-error` to bypass type checking when verifying ledger entries, and no additional type safety improvements are needed.
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/mptokenAuthorize.test.ts:29-118
Timestamp: 2024-12-06T19:25:15.376Z
Learning: In the XRPLF/xrpl.js TypeScript client library, when writing tests (e.g., in `packages/xrpl/test/integration/transactions/`), we generally do not need to test rippled server behaviors, because those behaviors are covered by rippled's own integration and unit tests.
Learnt from: achowdhry-ripple
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts:69-102
Timestamp: 2024-12-05T16:48:12.951Z
Learning: When adding validation in `validate*` functions in `packages/xrpl/src/models/transactions/`, utilize existing helper functions (e.g., `validateOptionalField`, `validateType`, `isNumber`, `isInteger`) for type checking and validation where appropriate.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2801
File: packages/xrpl/src/Wallet/batchSigner.ts:0-0
Timestamp: 2025-04-16T15:55:50.121Z
Learning: When using `encodeForSigningBatch` for Batch transactions in the XRPL.js library, the field names should use camelCase (`flags`, `txIDs`) even though the transaction object properties themselves use PascalCase (`Flags`, `TxIDs`).
packages/xrpl/test/integration/transactions/batch.test.ts (10)
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/mptokenAuthorize.test.ts:29-118
Timestamp: 2024-12-06T19:25:15.376Z
Learning: In the XRPLF/xrpl.js TypeScript client library, when writing tests (e.g., in `packages/xrpl/test/integration/transactions/`), we generally do not need to test rippled server behaviors, because those behaviors are covered by rippled's own integration and unit tests.
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/clawback.test.ts:165-178
Timestamp: 2024-12-06T19:27:11.147Z
Learning: In the integration tests for `clawback.test.ts`, it's acceptable to use `@ts-expect-error` to bypass type checking when verifying ledger entries, and no additional type safety improvements are needed.
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/models/MPTokenAuthorize.test.ts:60-71
Timestamp: 2024-12-06T18:44:55.095Z
Learning: In the XRPL.js library's TypeScript test file `packages/xrpl/test/models/MPTokenAuthorize.test.ts`, negative test cases for invalid `Account` address format, invalid `Holder` address format, invalid `MPTokenIssuanceID` format, and invalid flag combinations are not necessary.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2801
File: packages/xrpl/src/Wallet/batchSigner.ts:0-0
Timestamp: 2025-04-16T15:55:50.121Z
Learning: When using `encodeForSigningBatch` for Batch transactions in the XRPL.js library, the field names should use camelCase (`flags`, `txIDs`) even though the transaction object properties themselves use PascalCase (`Flags`, `TxIDs`).
Learnt from: ckeshava
PR: XRPLF/xrpl.js#2873
File: packages/xrpl/test/integration/transactions/trustSet.test.ts:0-0
Timestamp: 2025-01-31T17:46:25.375Z
Learning: For the XRPL implementation, extensive test cases for deep freeze behavior (high/low side interactions, clearing flags, etc.) are maintained in the C++ implementation and don't need to be duplicated in the JavaScript implementation.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2801
File: packages/xrpl/test/models/Batch.test.ts:0-0
Timestamp: 2025-04-16T15:22:45.633Z
Learning: Using `as any` type assertions is acceptable in test files for the XRPL.js project, as strict typing is not required for test code.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2690
File: packages/xrpl/tools/generateModels.js:52-52
Timestamp: 2024-10-08T16:29:11.194Z
Learning: In `generateModels.js`, the regex used to match `SubmittableTransaction` in `transaction.ts` is expected to always succeed because the pattern is present in the source code. If it fails, the code needs to be updated.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2690
File: packages/xrpl/tools/generateModels.js:52-52
Timestamp: 2024-10-02T15:47:02.491Z
Learning: In `generateModels.js`, the regex used to match `SubmittableTransaction` in `transaction.ts` is expected to always succeed because the pattern is present in the source code. If it fails, the code needs to be updated.
Learnt from: achowdhry-ripple
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts:69-102
Timestamp: 2024-12-05T16:48:12.951Z
Learning: When adding validation in `validate*` functions in `packages/xrpl/src/models/transactions/`, utilize existing helper functions (e.g., `validateOptionalField`, `validateType`, `isNumber`, `isInteger`) for type checking and validation where appropriate.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2895
File: package
8000
s/xrpl/test/models/DIDDelete.test.ts:28-31
Timestamp: 2025-02-12T23:30:40.622Z
Learning: In JavaScript/TypeScript transaction validation tests, object key validation can be performed using:
1. Object.keys() comparison with expected set
2. TypeScript interfaces with strict object literal checks
3. Object sanitization by filtering to allowed keys only
packages/xrpl/HISTORY.md (2)
Learnt from: mvadari
PR: XRPLF/xrpl.js#2779
File: packages/xrpl/HISTORY.md:10-14
Timestamp: 2024-10-11T18:48:28.561Z
Learning: Ensure to reference the correct version numbers when commenting on changes to `HISTORY.md` to avoid confusion.
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/mptokenAuthorize.test.ts:29-118
Timestamp: 2024-12-06T19:25:15.376Z
Learning: In the XRPLF/xrpl.js TypeScript client library, when writing tests (e.g., in `packages/xrpl/test/integration/transactions/`), we generally do not need to test rippled server behaviors, because those behaviors are covered by rippled's own integration and unit tests.
packages/xrpl/src/models/transactions/common.ts (8)
Learnt from: achowdhry-ripple
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts:69-102
Timestamp: 2024-12-05T16:48:12.951Z
Learning: When adding validation in `validate*` functions in `packages/xrpl/src/models/transactions/`, utilize existing helper functions (e.g., `validateOptionalField`, `validateType`, `isNumber`, `isInteger`) for type checking and validation where appropriate.
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/clawback.test.ts:165-178
Timestamp: 2024-12-06T19:27:11.147Z
Learning: In the integration tests for `clawback.test.ts`, it's acceptable to use `@ts-expect-error` to bypass type checking when verifying ledger entries, and no additional type safety improvements are needed.
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/mptokenAuthorize.test.ts:29-118
Timestamp: 2024-12-06T19:25:15.376Z
Learning: In the XRPLF/xrpl.js TypeScript client library, when writing tests (e.g., in `packages/xrpl/test/integration/transactions/`), we generally do not need to test rippled server behaviors, because those behaviors are covered by rippled's own integration and unit tests.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2801
File: packages/xrpl/test/models/Batch.test.ts:0-0
Timestamp: 2025-04-16T15:22:45.633Z
Learning: Using `as any` type assertions is acceptable in test files for the XRPL.js project, as strict typing is not required for test code.
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/models/MPTokenAuthorize.test.ts:60-71
Timestamp: 2024-12-06T18:44:55.095Z
Learning: In the XRPL.js library's TypeScript test file `packages/xrpl/test/models/MPTokenAuthorize.test.ts`, negative test cases for invalid `Account` address format, invalid `Holder` address format, invalid `MPTokenIssuanceID` format, and invalid flag combinations are not necessary.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2895
File: packages/xrpl/test/models/DIDDelete.test.ts:28-31
Timestamp: 2025-02-12T23:30:40.622Z
Learning: In JavaScript/TypeScript transaction validation tests, object key validation can be performed using:
1. Object.keys() comparison with expected set
2. TypeScript interfaces with strict object literal checks
3. Object sanitization by filtering to allowed keys only
Learnt from: mvadari
PR: XRPLF/xrpl.js#2690
File: packages/xrpl/tools/generateModels.js:52-52
Timestamp: 2024-10-02T15:47:02.491Z
Learning: In `generateModels.js`, the regex used to match `SubmittableTransaction` in `transaction.ts` is expected to always succeed because the pattern is present in the source code. If it fails, the code needs to be updated.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2690
File: packages/xrpl/tools/generateModels.js:52-52
Timestamp: 2024-10-08T16:29:11.194Z
Learning: In `generateModels.js`, the regex used to match `SubmittableTransaction` in `transaction.ts` is expected to always succeed because the pattern is present in the source code. If it fails, the code needs to be updated.
packages/xrpl/src/models/transactions/batch.ts (8)
Learnt from: mvadari
PR: XRPLF/xrpl.js#2801
File: packages/xrpl/src/Wallet/batchSigner.ts:0-0
Timestamp: 2025-04-16T15:55:50.121Z
Learning: When using `encodeForSigningBatch` for Batch transactions in the XRPL.js library, the field names should use camelCase (`flags`, `txIDs`) even though the transaction object properties themselves use PascalCase (`Flags`, `TxIDs`).
Learnt from: achowdhry-ripple
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts:69-102
Timestamp: 2024-12-05T16:48:12.951Z
Learning: When adding validation in `validate*` functions in `packages/xrpl/src/models/transactions/`, utilize existing helper functions (e.g., `validateOptionalField`, `validateType`, `isNumber`, `isInteger`) for type checking and validation where appropriate.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2690
File: packages/xrpl/tools/generateModels.js:52-52
Timestamp: 2024-10-02T15:47:02.491Z
Learning: In `generateModels.js`, the regex used to match `SubmittableTransaction` in `transaction.ts` is expected to always succeed because the pattern is present in the source code. If it fails, the code needs to be updated.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2690
File: packages/xrpl/tools/generateModels.js:52-52
Timestamp: 2024-10-08T16:29:11.194Z
Learning: In `generateModels.js`, the regex used to match `SubmittableTransaction` in `transaction.ts` is expected to always succeed because the pattern is present in the source code. If it fails, the code needs to be updated.
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/clawback.test.ts:165-178
Timestamp: 2024-12-06T19:27:11.147Z
Learning: In the integration tests for `clawback.test.ts`, it's acceptable to use `@ts-expect-error` to bypass type checking when verifying ledger entries, and no additional type safety improvements are needed.
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/mptokenAuthorize.test.ts:29-118
Timestamp: 2024-12-06T19:25:15.376Z
Learning: In the XRPLF/xrpl.js TypeScript client library, when writing tests (e.g., in `packages/xrpl/test/integration/transactions/`), we generally do not need to test rippled server behaviors, because those behaviors are covered by rippled's own integration and unit tests.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2895
File: packages/xrpl/test/models/DIDDelete.test.ts:28-31
Timestamp: 2025-02-12T23:30:40.622Z
Learning: In JavaScript/TypeScript transaction validation tests, object key validation can be performed using:
1. Object.keys() comparison with expected set
2. TypeScript interfaces with strict object literal checks
3. Object sanitization by filtering to allowed keys only
Learnt from: mvadari
PR: XRPLF/xrpl.js#2895
File: packages/xrpl/test/models/clawback.test.ts:0-0
Timestamp: 2025-02-12T23:28:55.377Z
Learning: The `validate` function in xrpl.js is synchronous and should be tested using `assert.doesNotThrow` rather than async assertions.
🧬 Code Graph Analysis (1)
packages/xrpl/src/models/transactions/batch.ts (5)
packages/xrpl/src/models/transactions/index.ts (1)
SubmittableTransaction
(5-5)
packages/xrpl/src/models/transactions/transaction.ts (1)
SubmittableTransaction
(135-197)
packages/xrpl/src/errors.ts (1)
ValidationError
(156-156)
packages/xrpl/src/models/utils/index.ts (1)
hasFlag
(40-52)
packages/xrpl/src/models/transactions/common.ts (3)
validateOptionalField
(375-395)
isValue
(134-138)
isNull
(120-122)
⏰ 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). (3)
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: browser (22.x)
- GitHub Check: unit (20.x)
🔇 Additional comments (9)
packages/xrpl/HISTORY.md (2)
17-17
: LGTM! Changelog entry accurately reflects the changes.
The new entry correctly documents the improvement to Batch inner transaction typing that was implemented in this PR.
19-19
: Good catch on the date format fix.
Standardizing the date format with zero-padding (2025-06-09) improves consistency and readability.
packages/xrpl/test/integration/transactions/batch.test.ts (3)
1-1
: Good addition of Payment import.
Adding the Payment type import supports the refactored test structure and improves type safety.
52-65
: Excellent refactoring to improve code reusability.
Creating an explicit payment
object and reusing it with .map()
reduces duplication and makes the test more maintainable while preserving the same test logic.
76-91
: Good implementation of DRY principle.
The explicit creation of payment
and payment2
objects followed by mapping them into the RawTransactions array eliminates redundancy and improves test readability.
packages/xrpl/src/models/transactions/batch.ts (4)
10-10
: Good addition of type guard imports.
The isNull
and isValue
helper functions are appropriately imported and used in the new validation logic.
Also applies to: 13-13
66-66
: Excellent type generalization.
Changing from BatchInnerTransaction
to SubmittableTransaction
makes the typing more flexible while maintaining type safety. This aligns with the PR objective to improve Batch inner transaction typing.
70-106
: Well-designed validation helper function.
The validateBatchInnerTransaction
function properly encapsulates validation logic with comprehensive checks:
- Prevents nested Batch transactions (lines 74-78)
- Enforces required
tfInnerBatchTxn
flag (lines 81-85)
- Validates optional fields with appropriate constraints using the imported type guards
- Provides clear, specific error messages with proper indexing
The use of validateOptionalField
with isValue(0)
, isValue('')
, and isNull
follows established patterns in the codebase.
132-132
: Good refactoring to use the new helper.
Replacing inline validation with the dedicated validateBatchInnerTransaction
function improves code organization and maintainability.
Comment on lines
+114
to
+122
/**
* Verify the form and type of a null value at runtime.
*
* @param inp - The value to check the form and type of.
* @returns Whether the value is properly formed.
*/
export function isNull(inp: unknown): inp is null {
return inp == null
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⚠️ Potential issue
Fix function name and return type to match actual behavior.
The isNull
function uses loose equality (==
) which returns true for both null
and undefined
, but the function name implies it only checks for null. The return type inp is null
is also misleading.
Consider one of these approaches:
Option 1: Rename to match behavior
-export function isNull(inp: unknown): inp is null {
+export function isNullish(inp: unknown): inp is null | undefined {
return inp == null
}
Option 2: Change implementation to match name
export function isNull(inp: unknown): inp is null {
- return inp == null
+ return inp === null
}
🤖 Prompt for AI Agents
In packages/xrpl/src/models/transactions/common.ts around lines 114 to 122, the
function named isNull uses loose equality which returns true for both null and
undefined, but its name and return type imply it only checks for null. To fix
this, either rename the function to reflect that it checks for both null and
undefined (e.g., isNullOrUndefined) or change the implementation to use strict
equality (inp === null) so it only returns true for null values, and update the
return type accordingly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want it to check for both null
and undefined
- is there a better name to call this function in that case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mvadari Yes, isNullish
would be the best name for this function! It's a widely recognized term in the TypeScript/JavaScript community that specifically refers to values that are either null
or undefined
.
Here's the corrected function:
/**
* Verify the form and type of a nullish value (null or undefined) at runtime.
*
* @param inp - The value to check the form and type of.
* @returns Whether the value is null or undefined.
*/
export function isNullish(inp: unknown): inp is null | undefined {
return inp == null
}
The name isNullish
is perfect because:
- It aligns with the nullish coalescing operator (
??
) terminology
- It's concise and widely understood in the JavaScript/TypeScript community
- It clearly indicates that the function checks for both
null
and undefined
- The return type
inp is null | undefined
accurately reflects the behavior
🧠 Learnings used
Learnt from: achowdhry-ripple
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts:69-102
Timestamp: 2024-12-05T16:48:12.951Z
Learning: When adding validation in `validate*` functions in `packages/xrpl/src/models/transactions/`, utilize existing helper functions (e.g., `validateOptionalField`, `validateType`, `isNumber`, `isInteger`) for type checking and validation where appropriate.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2801
File: packages/xrpl/test/models/Batch.test.ts:0-0
Timestamp: 2025-04-16T15:22:45.633Z
Learning: Using `as any` type assertions is acceptable in test files for the XRPL.js project, as strict typing is not required for test code.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2895
File: packages/xrpl/test/models/DIDDelete.test.ts:28-31
Timestamp: 2025-02-12T23:30:40.622Z
Learning: In JavaScript/TypeScript transaction validation tests, object key validation can be performed using:
1. Object.keys() comparison with expected set
2. TypeScript interfaces with strict object literal checks
3. Object sanitization by filtering to allowed keys only
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/mptokenAuthorize.test.ts:29-118
Timestamp: 2024-12-06T19:25:15.376Z
Learning: In the XRPLF/xrpl.js TypeScript client library, when writing tests (e.g., in `packages/xrpl/test/integration/transactions/`), we generally do not need to test rippled server behaviors, because those behaviors are covered by rippled's own integration and unit tests.
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/models/MPTokenAuthorize.test.ts:60-71
Timestamp: 2024-12-06T18:44:55.095Z
Learning: In the XRPL.js library's TypeScript test file `packages/xrpl/test/models/MPTokenAuthorize.test.ts`, negative test cases for invalid `Account` address format, invalid `Holder` address format, invalid `MPTokenIssuanceID` format, and invalid flag combinations are not necessary.
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/clawback.test.ts:165-178
Timestamp: 2024-12-06T19:27:11.147Z
Learning: In the integration tests for `clawback.test.ts`, it's acceptable to use `@ts-expect-error` to bypass type checking when verifying ledger entries, and no additional type safety improvements are needed.
Learnt from: ckeshava
PR: XRPLF/xrpl.js#2874
File: packages/xrpl/test/models/permissionedDomainDelete.test.ts:15-20
Timestamp: 2025-01-08T02:11:21.997Z
Learning: In validation test cases for XRPL transactions, using generic JSON input (e.g., `as any`) is preferred over strict typing as it better represents real-world scenarios where the `validate` method needs to handle arbitrary JSON/map/dictionary input from users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR replaces the removed BatchInnerTransaction
compile‐time type with runtime validation for inner batch transactions, improving TypeScript ergonomics and enforcing correct flags/fields at runtime.
- Remove
BatchInnerTransaction
and add validateBatchInnerTransaction
to check flags (tfInnerBatchTxn
) and enforce inner‐txn fields (Fee
, SigningPubKey
, etc.).
- Update unit and integration tests to use
SubmittableTransaction
or specific tx types (e.g., Payment
) instead of the old type.
- Introduce
isNull
and isValue
helpers in common utilities and clean up ESLint comments in batch autofill logic.
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
File
Description
packages/xrpl/src/models/transactions/batch.ts
Extract inner‐txn validation into validateBatchInnerTransaction
and drop static type
packages/xrpl/src/models/transactions/common.ts
Add isNull
and isValue
runtime type guards
packages/xrpl/test/wallet/batchSigner.test.ts
Adjust tests to use SubmittableTransaction
instead of BatchInnerTransaction
packages/xrpl/test/utils/hashes.test.ts
Update hash tests to use Payment
type
packages/xrpl/test/models/batch.test.ts
Update expected Sequence
value in batch model test
packages/xrpl/test/integration/transactions/batch.test.ts
Refactor integration examples to map raw transactions array
packages/xrpl/src/sugar/autofill.ts
Remove unnecessary ESLint disables around batch autofill checks
Comments suppressed due to low confidence (1)
packages/xrpl/src/models/transactions/batch.ts:70
- New validation logic in
validateBatchInnerTransaction
covers nesting, flags, and field constraints—there are no unit tests targeting each failure case. Please add tests for missing tfInnerBatchTxn
, nested Batch txns, and invalid field values.
function validateBatchInnerTransaction(
* @returns Whether the value is properly formed.
*/
export function isNull(inp: unknown): inp is null {
return inp == null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The isNull
guard uses inp == null
, which treats both null
and undefined
as valid. To strictly detect only null
, change this to inp === null
.
Suggested change
return inp == null
return inp === null
Copilot uses AI. Check for mistakes.
Positive FeedbackNegative Feedback
)
}
validateOptionalField(tx, 'Fee', isValue('0'), {
paramName: `RawTransactions[${index}].Fee`,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error paramName
for the inner transaction Fee
omits the RawTransaction
layer, unlike the others. Consider using RawTransactions[${index}].RawTransaction.Fee
for consistency in error messages.
Suggested change
paramName: `RawTransactions[${index}].Fee`,
paramName: `RawTransactions[${index}].RawTransaction.Fee`,
Copilot uses AI. Check for mistakes.
Positive FeedbackNegative Feedback
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
WalkthroughThe changes refactor batch transaction validation logic by introducing a dedicated helper function, update type usage for inner batch transactions, and add new type guard utilities. Test cases are streamlined for clarity and reusability, and the changelog is updated for accuracy and formatting. Changes
Possibly related PRs
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
⏰ 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). (9)
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
packages/xrpl/HISTORY.md
(1 hunks)packages/xrpl/src/models/transactions/batch.ts
(3 hunks)packages/xrpl/src/models/transactions/common.ts
(1 hunks)packages/xrpl/test/integration/transactions/batch.test.ts
(3 hunks)
🧰 Additional context used
🧠 Learnings (5)
📓 Common learnings
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/clawback.test.ts:165-178
Timestamp: 2024-12-06T19:27:11.147Z
Learning: In the integration tests for `clawback.test.ts`, it's acceptable to use `@ts-expect-error` to bypass type checking when verifying ledger entries, and no additional type safety improvements are needed.
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/mptokenAuthorize.test.ts:29-118
Timestamp: 2024-12-06T19:25:15.376Z
Learning: In the XRPLF/xrpl.js TypeScript client library, when writing tests (e.g., in `packages/xrpl/test/integration/transactions/`), we generally do not need to test rippled server behaviors, because those behaviors are covered by rippled's own integration and unit tests.
Learnt from: achowdhry-ripple
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts:69-102
Timestamp: 2024-12-05T16:48:12.951Z
Learning: When adding validation in `validate*` functions in `packages/xrpl/src/models/transactions/`, utilize existing helper functions (e.g., `validateOptionalField`, `validateType`, `isNumber`, `isInteger`) for type checking and validation where appropriate.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2801
File: packages/xrpl/src/Wallet/batchSigner.ts:0-0
Timestamp: 2025-04-16T15:55:50.121Z
Learning: When using `encodeForSigningBatch` for Batch transactions in the XRPL.js library, the field names should use camelCase (`flags`, `txIDs`) even though the transaction object properties themselves use PascalCase (`Flags`, `TxIDs`).
packages/xrpl/test/integration/transactions/batch.test.ts (10)
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/mptokenAuthorize.test.ts:29-118
Timestamp: 2024-12-06T19:25:15.376Z
Learning: In the XRPLF/xrpl.js TypeScript client library, when writing tests (e.g., in `packages/xrpl/test/integration/transactions/`), we generally do not need to test rippled server behaviors, because those behaviors are covered by rippled's own integration and unit tests.
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/clawback.test.ts:165-178
Timestamp: 2024-12-06T19:27:11.147Z
Learning: In the integration tests for `clawback.test.ts`, it's acceptable to use `@ts-expect-error` to bypass type checking when verifying ledger entries, and no additional type safety improvements are needed.
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/models/MPTokenAuthorize.test.ts:60-71
Timestamp: 2024-12-06T18:44:55.095Z
Learning: In the XRPL.js library's TypeScript test file `packages/xrpl/test/models/MPTokenAuthorize.test.ts`, negative test cases for invalid `Account` address format, invalid `Holder` address format, invalid `MPTokenIssuanceID` format, and invalid flag combinations are not necessary.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2801
File: packages/xrpl/src/Wallet/batchSigner.ts:0-0
Timestamp: 2025-04-16T15:55:50.121Z
Learning: When using `encodeForSigningBatch` for Batch transactions in the XRPL.js library, the field names should use camelCase (`flags`, `txIDs`) even though the transaction object properties themselves use PascalCase (`Flags`, `TxIDs`).
Learnt from: ckeshava
PR: XRPLF/xrpl.js#2873
File: packages/xrpl/test/integration/transactions/trustSet.test.ts:0-0
Timestamp: 2025-01-31T17:46:25.375Z
Learning: For the XRPL implementation, extensive test cases for deep freeze behavior (high/low side interactions, clearing flags, etc.) are maintained in the C++ implementation and don't need to be duplicated in the JavaScript implementation.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2801
File: packages/xrpl/test/models/Batch.test.ts:0-0
Timestamp: 2025-04-16T15:22:45.633Z
Learning: Using `as any` type assertions is acceptable in test files for the XRPL.js project, as strict typing is not required for test code.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2690
File: packages/xrpl/tools/generateModels.js:52-52
Timestamp: 2024-10-08T16:29:11.194Z
Learning: In `generateModels.js`, the regex used to match `SubmittableTransaction` in `transaction.ts` is expected to always succeed because the pattern is present in the source code. If it fails, the code needs to be updated.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2690
File: packages/xrpl/tools/generateModels.js:52-52
Timestamp: 2024-10-02T15:47:02.491Z
Learning: In `generateModels.js`, the regex used to match `SubmittableTransaction` in `transaction.ts` is expected to always succeed because the pattern is present in the source code. If it fails, the code needs to be updated.
Learnt from: achowdhry-ripple
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts:69-102
Timestamp: 2024-12-05T16:48:12.951Z
Learning: When adding validation in `validate*` functions in `packages/xrpl/src/models/transactions/`, utilize existing helper functions (e.g., `validateOptionalField`, `validateType`, `isNumber`, `isInteger`) for type checking and validation where appropriate.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2895
File: package
8000
s/xrpl/test/models/DIDDelete.test.ts:28-31
Timestamp: 2025-02-12T23:30:40.622Z
Learning: In JavaScript/TypeScript transaction validation tests, object key validation can be performed using:
1. Object.keys() comparison with expected set
2. TypeScript interfaces with strict object literal checks
3. Object sanitization by filtering to allowed keys only
packages/xrpl/HISTORY.md (2)
Learnt from: mvadari
PR: XRPLF/xrpl.js#2779
File: packages/xrpl/HISTORY.md:10-14
Timestamp: 2024-10-11T18:48:28.561Z
Learning: Ensure to reference the correct version numbers when commenting on changes to `HISTORY.md` to avoid confusion.
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/mptokenAuthorize.test.ts:29-118
Timestamp: 2024-12-06T19:25:15.376Z
Learning: In the XRPLF/xrpl.js TypeScript client library, when writing tests (e.g., in `packages/xrpl/test/integration/transactions/`), we generally do not need to test rippled server behaviors, because those behaviors are covered by rippled's own integration and unit tests.
packages/xrpl/src/models/transactions/common.ts (8)
Learnt from: achowdhry-ripple
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts:69-102
Timestamp: 2024-12-05T16:48:12.951Z
Learning: When adding validation in `validate*` functions in `packages/xrpl/src/models/transactions/`, utilize existing helper functions (e.g., `validateOptionalField`, `validateType`, `isNumber`, `isInteger`) for type checking and validation where appropriate.
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/clawback.test.ts:165-178
Timestamp: 2024-12-06T19:27:11.147Z
Learning: In the integration tests for `clawback.test.ts`, it's acceptable to use `@ts-expect-error` to bypass type checking when verifying ledger entries, and no additional type safety improvements are needed.
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/mptokenAuthorize.test.ts:29-118
Timestamp: 2024-12-06T19:25:15.376Z
Learning: In the XRPLF/xrpl.js TypeScript client library, when writing tests (e.g., in `packages/xrpl/test/integration/transactions/`), we generally do not need to test rippled server behaviors, because those behaviors are covered by rippled's own integration and unit tests.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2801
File: packages/xrpl/test/models/Batch.test.ts:0-0
Timestamp: 2025-04-16T15:22:45.633Z
Learning: Using `as any` type assertions is acceptable in test files for the XRPL.js project, as strict typing is not required for test code.
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/models/MPTokenAuthorize.test.ts:60-71
Timestamp: 2024-12-06T18:44:55.095Z
Learning: In the XRPL.js library's TypeScript test file `packages/xrpl/test/models/MPTokenAuthorize.test.ts`, negative test cases for invalid `Account` address format, invalid `Holder` address format, invalid `MPTokenIssuanceID` format, and invalid flag combinations are not necessary.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2895
File: packages/xrpl/test/models/DIDDelete.test.ts:28-31
Timestamp: 2025-02-12T23:30:40.622Z
Learning: In JavaScript/TypeScript transaction validation tests, object key validation can be performed using:
1. Object.keys() comparison with expected set
2. TypeScript interfaces with strict object literal checks
3. Object sanitization by filtering to allowed keys only
Learnt from: mvadari
PR: XRPLF/xrpl.js#2690
File: packages/xrpl/tools/generateModels.js:52-52
Timestamp: 2024-10-02T15:47:02.491Z
Learning: In `generateModels.js`, the regex used to match `SubmittableTransaction` in `transaction.ts` is expected to always succeed because the pattern is present in the source code. If it fails, the code needs to be updated.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2690
File: packages/xrpl/tools/generateModels.js:52-52
Timestamp: 2024-10-08T16:29:11.194Z
Learning: In `generateModels.js`, the regex used to match `SubmittableTransaction` in `transaction.ts` is expected to always succeed because the pattern is present in the source code. If it fails, the code needs to be updated.
packages/xrpl/src/models/transactions/batch.ts (8)
Learnt from: mvadari
PR: XRPLF/xrpl.js#2801
File: packages/xrpl/src/Wallet/batchSigner.ts:0-0
Timestamp: 2025-04-16T15:55:50.121Z
Learning: When using `encodeForSigningBatch` for Batch transactions in the XRPL.js library, the field names should use camelCase (`flags`, `txIDs`) even though the transaction object properties themselves use PascalCase (`Flags`, `TxIDs`).
Learnt from: achowdhry-ripple
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts:69-102
Timestamp: 2024-12-05T16:48:12.951Z
Learning: When adding validation in `validate*` functions in `packages/xrpl/src/models/transactions/`, utilize existing helper functions (e.g., `validateOptionalField`, `validateType`, `isNumber`, `isInteger`) for type checking and validation where appropriate.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2690
File: packages/xrpl/tools/generateModels.js:52-52
Timestamp: 2024-10-02T15:47:02.491Z
Learning: In `generateModels.js`, the regex used to match `SubmittableTransaction` in `transaction.ts` is expected to always succeed because the pattern is present in the source code. If it fails, the code needs to be updated.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2690
File: packages/xrpl/tools/generateModels.js:52-52
Timestamp: 2024-10-08T16:29:11.194Z
Learning: In `generateModels.js`, the regex used to match `SubmittableTransaction` in `transaction.ts` is expected to always succeed because the pattern is present in the source code. If it fails, the code needs to be updated.
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/clawback.test.ts:165-178
Timestamp: 2024-12-06T19:27:11.147Z
Learning: In the integration tests for `clawback.test.ts`, it's acceptable to use `@ts-expect-error` to bypass type checking when verifying ledger entries, and no additional type safety improvements are needed.
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/mptokenAuthorize.test.ts:29-118
Timestamp: 2024-12-06T19:25:15.376Z
Learning: In the XRPLF/xrpl.js TypeScript client library, when writing tests (e.g., in `packages/xrpl/test/integration/transactions/`), we generally do not need to test rippled server behaviors, because those behaviors are covered by rippled's own integration and unit tests.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2895
File: packages/xrpl/test/models/DIDDelete.test.ts:28-31
Timestamp: 2025-02-12T23:30:40.622Z
Learning: In JavaScript/TypeScript transaction validation tests, object key validation can be performed using:
1. Object.keys() comparison with expected set
2. TypeScript interfaces with strict object literal checks
3. Object sanitization by filtering to allowed keys only
Learnt from: mvadari
PR: XRPLF/xrpl.js#2895
File: packages/xrpl/test/models/clawback.test.ts:0-0
Timestamp: 2025-02-12T23:28:55.377Z
Learning: The `validate` function in xrpl.js is synchronous and should be tested using `assert.doesNotThrow` rather than async assertions.
🧬 Code Graph Analysis (1)
packages/xrpl/src/models/transactions/batch.ts (5)
packages/xrpl/src/models/transactions/index.ts (1)
SubmittableTransaction
(5-5)packages/xrpl/src/models/transactions/transaction.ts (1)
SubmittableTransaction
(135-197)packages/xrpl/src/errors.ts (1)
ValidationError
(156-156)packages/xrpl/src/models/utils/index.ts (1)
hasFlag
(40-52)packages/xrpl/src/models/transactions/common.ts (3)
validateOptionalField
(375-395)isValue
(134-138)isNull
(120-122)
⏰ 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). (3)
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: browser (22.x)
- GitHub Check: unit (20.x)
🔇 Additional comments (9)
packages/xrpl/HISTORY.md (2)
17-17
: LGTM! Changelog entry accurately reflects the changes.The new entry correctly documents the improvement to Batch inner transaction typing that was implemented in this PR.
19-19
: Good catch on the date format fix.Standardizing the date format with zero-padding (2025-06-09) improves consistency and readability.
packages/xrpl/test/integration/transactions/batch.test.ts (3)
1-1
: Good addition of Payment import.Adding the Payment type import supports the refactored test structure and improves type safety.
52-65
: Excellent refactoring to improve code reusability.Creating an explicit
payment
object and reusing it with.map()
reduces duplication and makes the test more maintainable while preserving the same test logic.
76-91
: Good implementation of DRY principle.The explicit creation of
payment
andpayment2
objects followed by mapping them into the RawTransactions array eliminates redundancy and improves test readability.packages/xrpl/src/models/transactions/batch.ts (4)
10-10
: Good addition of type guard imports.The
isNull
andisValue
helper functions are appropriately imported and used in the new validation logic.Also applies to: 13-13
66-66
: Excellent type generalization.Changing from
BatchInnerTransaction
toSubmittableTransaction
makes the typing more flexible while maintaining type safety. This aligns with the PR objective to improve Batch inner transaction typing.
70-106
: Well-designed validation helper function.The
validateBatchInnerTransaction
function properly encapsulates validation logic with comprehensive checks:
- Prevents nested Batch transactions (lines 74-78)
- Enforces required
tfInnerBatchTxn
flag (lines 81-85)- Validates optional fields with appropriate constraints using the imported type guards
- Provides clear, specific error messages with proper indexing
The use of
validateOptionalField
withisValue(0)
,isValue('')
, andisNull
follows established patterns in the codebase.
132-132
: Good refactoring to use the new helper.Replacing inline validation with the dedicated
validateBatchInnerTransaction
function improves code organization and maintainability.
/** | ||
* Verify the form and type of a null value at runtime. | ||
* | ||
* @param inp - The value to check the form and type of. | ||
* @returns Whether the value is properly formed. | ||
*/ | ||
export function isNull(inp: unknown): inp is null { | ||
return inp == null | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix function name and return type to match actual behavior.
The isNull
function uses loose equality (==
) which returns true for both null
and undefined
, but the function name implies it only checks for null. The return type inp is null
is also misleading.
Consider one of these approaches:
Option 1: Rename to match behavior
-export function isNull(inp: unknown): inp is null {
+export function isNullish(inp: unknown): inp is null | undefined {
return inp == null
}
Option 2: Change implementation to match name
export function isNull(inp: unknown): inp is null {
- return inp == null
+ return inp === null
}
🤖 Prompt for AI Agents
In packages/xrpl/src/models/transactions/common.ts around lines 114 to 122, the
function named isNull uses loose equality which returns true for both null and
undefined, but its name and return type imply it only checks for null. To fix
this, either rename the function to reflect that it checks for both null and
undefined (e.g., isNullOrUndefined) or change the implementation to use strict
equality (inp === null) so it only returns true for null values, and update the
return type accordingly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want it to check for both null
and undefined
- is there a better name to call this function in that case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mvadari Yes, isNullish
would be the best name for this function! It's a widely recognized term in the TypeScript/JavaScript community that specifically refers to values that are either null
or undefined
.
Here's the corrected function:
/**
* Verify the form and type of a nullish value (null or undefined) at runtime.
*
* @param inp - The value to check the form and type of.
* @returns Whether the value is null or undefined.
*/
export function isNullish(inp: unknown): inp is null | undefined {
return inp == null
}
The name isNullish
is perfect because:
- It aligns with the nullish coalescing operator (
??
) terminology - It's concise and widely understood in the JavaScript/TypeScript community
- It clearly indicates that the function checks for both
null
andundefined
- The return type
inp is null | undefined
accurately reflects the behavior
🧠 Learnings used
Learnt from: achowdhry-ripple
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts:69-102
Timestamp: 2024-12-05T16:48:12.951Z
Learning: When adding validation in `validate*` functions in `packages/xrpl/src/models/transactions/`, utilize existing helper functions (e.g., `validateOptionalField`, `validateType`, `isNumber`, `isInteger`) for type checking and validation where appropriate.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2801
File: packages/xrpl/test/models/Batch.test.ts:0-0
Timestamp: 2025-04-16T15:22:45.633Z
Learning: Using `as any` type assertions is acceptable in test files for the XRPL.js project, as strict typing is not required for test code.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2895
File: packages/xrpl/test/models/DIDDelete.test.ts:28-31
Timestamp: 2025-02-12T23:30:40.622Z
Learning: In JavaScript/TypeScript transaction validation tests, object key validation can be performed using:
1. Object.keys() comparison with expected set
2. TypeScript interfaces with strict object literal checks
3. Object sanitization by filtering to allowed keys only
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/mptokenAuthorize.test.ts:29-118
Timestamp: 2024-12-06T19:25:15.376Z
Learning: In the XRPLF/xrpl.js TypeScript client library, when writing tests (e.g., in `packages/xrpl/test/integration/transactions/`), we generally do not need to test rippled server behaviors, because those behaviors are covered by rippled's own integration and unit tests.
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/models/MPTokenAuthorize.test.ts:60-71
Timestamp: 2024-12-06T18:44:55.095Z
Learning: In the XRPL.js library's TypeScript test file `packages/xrpl/test/models/MPTokenAuthorize.test.ts`, negative test cases for invalid `Account` address format, invalid `Holder` address format, invalid `MPTokenIssuanceID` format, and invalid flag combinations are not necessary.
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/clawback.test.ts:165-178
Timestamp: 2024-12-06T19:27:11.147Z
Learning: In the integration tests for `clawback.test.ts`, it's acceptable to use `@ts-expect-error` to bypass type checking when verifying ledger entries, and no additional type safety improvements are needed.
Learnt from: ckeshava
PR: XRPLF/xrpl.js#2874
File: packages/xrpl/test/models/permissionedDomainDelete.test.ts:15-20
Timestamp: 2025-01-08T02:11:21.997Z
Learning: In validation test cases for XRPL transactions, using generic JSON input (e.g., `as any`) is preferred over strict typing as it better represents real-world scenarios where the `validate` method needs to handle arbitrary JSON/map/dictionary input from users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR replaces the removed BatchInnerTransaction
compile‐time type with runtime validation for inner batch transactions, improving TypeScript ergonomics and enforcing correct flags/fields at runtime.
- Remove
BatchInnerTransaction
and addvalidateBatchInnerTransaction
to check flags (tfInnerBatchTxn
) and enforce inner‐txn fields (Fee
,SigningPubKey
, etc.). - Update unit and integration tests to use
SubmittableTransaction
or specific tx types (e.g.,Payment
) instead of the old type. - Introduce
isNull
andisValue
helpers in common utilities and clean up ESLint comments in batch autofill logic.
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
packages/xrpl/src/models/transactions/batch.ts | Extract inner‐txn validation into validateBatchInnerTransaction and drop static type |
packages/xrpl/src/models/transactions/common.ts | Add isNull and isValue runtime type guards |
packages/xrpl/test/wallet/batchSigner.test.ts | Adjust tests to use SubmittableTransaction instead of BatchInnerTransaction |
packages/xrpl/test/utils/hashes.test.ts | Update hash tests to use Payment type |
packages/xrpl/test/models/batch.test.ts | Update expected Sequence value in batch model test |
packages/xrpl/test/integration/transactions/batch.test.ts | Refactor integration examples to map raw transactions array |
packages/xrpl/src/sugar/autofill.ts | Remove unnecessary ESLint disables around batch autofill checks |
Comments suppressed due to low confidence (1)
packages/xrpl/src/models/transactions/batch.ts:70
- New validation logic in
validateBatchInnerTransaction
covers nesting, flags, and field constraints—there are no unit tests targeting each failure case. Please add tests for missingtfInnerBatchTxn
, nested Batch txns, and invalid field values.
function validateBatchInnerTransaction(
* @returns Whether the value is properly formed. | ||
*/ | ||
export function isNull(inp: unknown): inp is null { | ||
return inp == null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The isNull
guard uses inp == null
, which treats both null
and undefined
as valid. To strictly detect only null
, change this to inp === null
.
return inp == null | |
return inp === null |
Copilot uses AI. Check for mistakes.
) | ||
} | ||
validateOptionalField(tx, 'Fee', isValue('0'), { | ||
paramName: `RawTransactions[${index}].Fee`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error paramName
for the inner transaction Fee
omits the RawTransaction
layer, unlike the others. Consider using RawTransactions[${index}].RawTransaction.Fee
for consistency in error messages.
paramName: `RawTransactions[${index}].Fee`, | |
paramName: `RawTransactions[${index}].RawTransaction.Fee`, |
Copilot uses AI. Check for mistakes.
High Level Overview of Change
This PR swaps out the use of
BatchInnerTransaction
for runtime checking instead, allowing for better TS usage with Batch inner transactions.Note: while this is technically a breaking change (since
BatchInnerTransaction
is being removed), it doesn't change any top-level exports.Context of Change
Feedback from Batch users suggested that this would be a better, more usable setup
Type of Change
Did you update HISTORY.md?
Test Plan
Adjusted integration tests to check that it works correctly