Skip to content

test: add property-based tests for XDR transaction builder - #796

Merged
Nanle-code merged 1 commit into
Nanle-code:masterfrom
jaymoneymanxl:test/property-based-xdr-amount
Jul 29, 2026
Merged

test: add property-based tests for XDR transaction builder#796
Nanle-code merged 1 commit into
Nanle-code:masterfrom
jaymoneymanxl:test/property-based-xdr-amount

Conversation

@jaymoneymanxl

@jaymoneymanxl jaymoneymanxl commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Closes #785

Problem

The TransactionBuilder and related XDR serialisation modules lacked property-based (fuzz) testing. Unit tests cover specific known cases, but they don't explore the vast space of valid and invalid inputs that real-world usage can produce, such as:

  • Edge-case amounts (0, 1, u64::MAX, extreme decimals).
  • Malformed memo payloads (oversized text, wrong hash length, invalid enum discriminants).
  • Time bounds with maxTime < minTime.
  • Mixed operation sets with varying types and boundaries.

Without property-based tests, regressions in XDR round-trip encoding/decoding or input validation can slip through.

Changes

src/lib/__tests__/transactionBuilder.property.test.ts (new)

Install fast-check as a devDependency and add the following property tests, each running 50–200 random iterations:

1. XDR Round-Trips (xdrRoundtrip)

  • Generates a random Transaction with 1–10 operations, each of type payment, createAccount, or changeTrust.
  • Encodes the transaction to XDR, then decodes it back.
  • Property: The decoded fields (source account, operations, memo, time bounds, fee) are deeply equal to the original.

2. Amount Boundary Rejection (amountBoundaries)

  • Generates invalid amount inputs: 0, negative numbers, Infinity, -Infinity, NaN, extreme floats (> u64::MAX), non-integer decimals.
  • Property: TransactionBuilder.isValidAmount() returns false for every invalid input.
  • Also generates valid amounts (1 … u64::MAX) and verifies they return true.

3. Memo Boundary Handling (memoBoundaries)

  • Generates valid text memos (1–28 chars, printable ASCII), ID memos (u64 range), hash memos (exactly 32 bytes), and return hash memos.
  • Property: Each valid memo round-trips through Memo.toXDR() / Memo.fromXDR() without error.
  • Generates invalid memos: text > 28 bytes, hash with wrong length (≠ 32), empty text, null/undefined.
  • Property: Each invalid input throws or returns a validation error.

4. Time Bounds Round-Trip (timeBoundsRoundtrip)

  • Generates random minTime/maxTime pairs where minTime <= maxTime.
  • Property: Serialising and deserialising through XDR preserves both values exactly.
  • Also verifies that minTime > maxTime pairs are rejected.

5. Operation Set Boundaries (operationSetBoundaries)

  • Generates transactions with varying operation counts (0, 1, 5, 10, 20, 50) and mixed types.
  • Property: Transactions with 0 operations raise a validation error.
  • Property: Transactions with 1–10 valid operations are accepted and round-trip correctly.
  • Property: Each operation in the decoded set retains its original type and parameters.

package.json

  • Added fast-check: ^3.x devDependency.

Verification

  • Run npx vitest run src/lib/__tests__/transactionBuilder.property.test.ts → all 5 property suites pass.
  • Each suite runs 50–200 random iterations, covering a combinatorial space far larger than hand-written unit tests.
  • Add a deliberate regression (e.g., remove XDR encoding) → at least one property test fails, preventing the regression.

…t boundaries

- Add fast-check as a devDependency for property-based testing
- Create transactionBuilder.property.test.ts with property-based tests:
  * XDR round-trips: payment, createAccount, changeTrust transactions
  * Amount boundary rejection: zero, negative, infinity, NaN, extreme values
  * Memo boundary handling: valid text/id/hash/return memos and invalid
    oversized/hash-length-mismatch rejection
  * Time bounds round-trip through XDR serialization
  * Operation set boundaries: 1-10 operations, mixed operation types
- Each property test runs 50-200 random iterations with fast-check
  generators for public keys, amounts, memos, and time bounds

Closes Nanle-code#785
@vercel

vercel Bot commented Jul 29, 2026

Copy link
Copy Markdown

@jaymoneymanxl is attempting to deploy a commit to the nanle-code's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Jul 29, 2026

Copy link
Copy Markdown

@jaymoneymanxl Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Nanle-code
Nanle-code merged commit 13cbc62 into Nanle-code:master Jul 29, 2026
1 check failed
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.

[2026 Testing] Add property-based tests for XDR and amount boundaries

2 participants