Conversation
|
Size Change: +4.36 kB (+0.25%) Total Size: 1.76 MB 📦 View Changed
|
src/transaction_builder.ts
Outdated
| console.log("minAccountSequenceAge", tx.minAccountSequenceAge); | ||
| console.log( | ||
| "builderOpts.minAccountSequenceAge", | ||
| builderOpts.minAccountSequenceAge, | ||
| ); |
There was a problem hiding this comment.
I removed these console.log. We can put them back if needed.
There was a problem hiding this comment.
Pull request overview
This PR adds more runtime validation and round-trip robustness across transaction building and operation helpers, plus improves integer auto-sizing edge cases for Soroban ScInt.
Changes:
- Add constructor-time validation for
timeboundsandledgerboundsinTransactionBuilder(and corresponding unit tests). - Improve
Operation.manageDataandOperation.changeTrustround-tripping throughfromXDRObjectby accepting shapes produced by parsing XDR (and add tests). - Adjust
ScInttype auto-selection logic for negative boundary values and add boundary-focused tests.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| test/unit/transaction_builder.test.ts | Adds tests for constructor validation of timebounds/ledgerbounds. |
| test/unit/operations/manage_data.test.ts | Adds round-trip test for delete (null/missing) manageData value. |
| test/unit/operations/change_trust.test.ts | Adds round-trip tests for Asset and LiquidityPoolAsset changeTrust parsing/rebuild. |
| test/unit/numbers/sc_int.test.ts | Adds tests for exact signed minimum boundaries for i64/i128/i256. |
| src/transaction_builder.ts | Implements constructor-time validation and introduces toEpochSeconds helper. |
| src/operations/manage_data.ts | Accepts undefined as delete semantics (treated as null). |
| src/operations/change_trust.ts | Accepts line as an alias for asset for round-trip compatibility. |
| src/numbers/sc_int.ts | Changes negative bit-length sizing logic for ScInt auto-selection. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -32,7 +33,7 @@ export function manageData( | |||
| if (typeof opts.value === "string") { | |||
| dataValue = Buffer.from(opts.value); | |||
| } else { | |||
| dataValue = opts.value; | |||
| dataValue = opts.value ?? null; | |||
| } | |||
There was a problem hiding this comment.
This change makes manageData treat value: undefined as a delete (null), which helps round-tripping Operation.fromXDRObject results (where value is optional). However, the thrown message still says "string, Buffer or null" and the public ManageDataOpts type currently requires value: Buffer | string | null (no undefined). Consider updating the error text and aligning the TypeScript types/docs with the new accepted input (e.g. make value optional or include undefined).
There was a problem hiding this comment.
This is intentional — undefined is only accepted as an internal tolerance for XDR round-trips (fromXDRObject returns undefined for absent optional fields). The public API contract remains null for delete-entry, so the error message and ManageDataOpts type are kept as-is to avoid confusing users with an implementation detail they shouldn't need to know about.
| // Accept `line` as an alias for `asset` so that the output of | ||
| // fromXDRObject (which uses `line`) can round-trip back through here. | ||
| const asset = | ||
| opts.asset ?? | ||
| (opts as unknown as { line?: Asset | LiquidityPoolAsset }).line; | ||
| let line: xdr.ChangeTrustAsset; | ||
|
|
||
| if (opts.asset instanceof Asset) { | ||
| line = opts.asset.toChangeTrustXDRObject(); | ||
| } else if (opts.asset instanceof LiquidityPoolAsset) { | ||
| line = opts.asset.toXDRObject(); | ||
| if (asset instanceof Asset) { | ||
| line = asset.toChangeTrustXDRObject(); | ||
| } else if (asset instanceof LiquidityPoolAsset) { | ||
| line = asset.toXDRObject(); | ||
| } else { | ||
| throw new TypeError("asset must be Asset or LiquidityPoolAsset"); | ||
| } |
There was a problem hiding this comment.
changeTrust now accepts line as an alias for asset to support round-tripping fromXDRObject results, but the public ChangeTrustOpts type still requires asset and does not include line. Consider updating the exported typings (and optionally docs) to reflect that callers may pass line (or change the record shape) so the round-trip pattern is supported without casts.
There was a problem hiding this comment.
Same approach as the manageData case — line is only produced internally by fromXDRObject. The public API contract remains asset. Changing ChangeTrustOpts to expose line would either make asset optional (breaking) or require a union type that adds complexity for an internal concern. The cast is intentional and the comment explains why.
|
|
||
| // parsed has `line` (not `asset`); changeTrust accepts both | ||
| const rebuilt = Operation.changeTrust(parsed); | ||
| expect(rebuilt).toBeInstanceOf(xdr.Operation); |
There was a problem hiding this comment.
we should check that the rebuilt and the original op are the same. An easy way to do this would be string comparing the xdr strings of the two
| name: parsed.name, | ||
| value: parsed.value, | ||
| }); | ||
| expect(rebuilt).toBeInstanceOf(xdr.Operation); |
There was a problem hiding this comment.
ditto here we should check that they are the same operation
Medium items 6-10 from the doc.