Skip to content

Various fixes, part 5#963

Merged
quietbits merged 26 commits intotypescript-migrationfrom
some-fixes-5
Apr 2, 2026
Merged

Various fixes, part 5#963
quietbits merged 26 commits intotypescript-migrationfrom
some-fixes-5

Conversation

@quietbits
Copy link
Copy Markdown
Contributor

@quietbits quietbits commented Apr 2, 2026

Medium items 6-10 from the doc.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 2, 2026

Size Change: +4.36 kB (+0.25%)

Total Size: 1.76 MB

📦 View Changed
Filename Size Change
dist/stellar-base.cjs.js 699 kB +1.68 kB (+0.24%)
dist/stellar-base.js 718 kB +1.73 kB (+0.24%)
dist/stellar-base.min.js 346 kB +951 B (+0.28%)

compressed-size-action

Comment on lines -272 to -276
console.log("minAccountSequenceAge", tx.minAccountSequenceAge);
console.log(
"builderOpts.minAccountSequenceAge",
builderOpts.minAccountSequenceAge,
);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I removed these console.log. We can put them back if needed.

Copy link
Copy Markdown

Copilot AI left a 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 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 timebounds and ledgerbounds in TransactionBuilder (and corresponding unit tests).
  • Improve Operation.manageData and Operation.changeTrust round-tripping through fromXDRObject by accepting shapes produced by parsing XDR (and add tests).
  • Adjust ScInt type 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.

Comment on lines 23 to 37
@@ -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;
}
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

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).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Comment on lines +31 to 44
// 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");
}
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

@quietbits quietbits requested a review from Ryang-21 April 2, 2026 15:44

// parsed has `line` (not `asset`); changeTrust accepts both
const rebuilt = Operation.changeTrust(parsed);
expect(rebuilt).toBeInstanceOf(xdr.Operation);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ditto here we should check that they are the same operation

Base automatically changed from some-fixes-4 to typescript-migration April 2, 2026 20:16
@quietbits quietbits merged commit 44288b1 into typescript-migration Apr 2, 2026
7 checks passed
@quietbits quietbits deleted the some-fixes-5 branch April 2, 2026 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants