Skip to content

Fix flaky genTinySurplusTx by computing surplus dynamically#1157

Merged
Jimbo4350 merged 1 commit into
masterfrom
jordan/fix-flaky-tiny-surplus-test
Mar 30, 2026
Merged

Fix flaky genTinySurplusTx by computing surplus dynamically#1157
Jimbo4350 merged 1 commit into
masterfrom
jordan/fix-flaky-tiny-surplus-test

Conversation

@Jimbo4350
Copy link
Copy Markdown
Contributor

@Jimbo4350 Jimbo4350 commented Mar 25, 2026

Changelog

- description: |
    Fix flaky genTinySurplusTx test by computing surplus relative to actual fee
  type:
   - test
  projects:
   - cardano-api

Context

The genTinySurplusTx generator used a hardcoded surplus range (237–250), assuming the 1-output fee (F1) was always ~236. This was flaky because F1 varies with the randomly generated address structure (different credential types and staking references produce different CBOR serialization sizes). A surplus of 237 was observed to balance successfully on Windows GHC 9.12 CI (failure on PR #1156).

The fix computes F1 per-test via calcMinFeeTx on the generated tx and sets surplus to [F1+4, F1+10] — always in the danger zone regardless of address size.

Also:

  • Removes duplicate genTinySurplusTx and property test from Experimental.hs (now lives only in Fee.hs)
  • Adds exampleProtocolParamsEra :: Era era -> PParams (LedgerEra era) to keep the generator polymorphic

How to trust this PR

cabal test cardano-api-test --test-option='--pattern=Tiny surplus' --test-option='--hedgehog-tests=5000'

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • New tests are added if needed and existing tests are updated
  • Self-reviewed the diff

Copilot AI review requested due to automatic review settings March 25, 2026 15:58
Copy link
Copy Markdown
Contributor

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

Tightens the genTinySurplusTx test generator’s surplus range to avoid values near the F2 fee threshold and eliminate flakiness in fee-related tests.

Changes:

  • Reduce the generated surplus upper bound from 250 to 246 to stay clearly below F2.
  • Update generator comments to document the F1/F2 relationship and boundary-case rationale.

@Jimbo4350 Jimbo4350 force-pushed the jordan/fix-flaky-tiny-surplus-test branch 8 times, most recently from f0a316a to 1567a40 Compare March 26, 2026 15:14
The hardcoded surplus range assumed a fixed F1 for all inputs, but
the fee varies with generated address structure (credential types,
staking references). Compute F1 per-test via calcMinFeeTx and set
surplus to [F1+4, F1+10].

Also deduplicates genTinySurplusTx — it now lives only in Fee.hs —
and adds a deterministic fee gap invariant test.
@Jimbo4350 Jimbo4350 force-pushed the jordan/fix-flaky-tiny-surplus-test branch from 1567a40 to 3faaf89 Compare March 26, 2026 15:19
@Jimbo4350 Jimbo4350 changed the title Fix flaky genTinySurplusTx test by tightening surplus range Fix flaky genTinySurplusTx by computing surplus dynamically Mar 26, 2026
@Jimbo4350 Jimbo4350 added this pull request to the merge queue Mar 30, 2026
Merged via the queue into master with commit 78fb9c5 Mar 30, 2026
34 checks passed
@Jimbo4350 Jimbo4350 deleted the jordan/fix-flaky-tiny-surplus-test branch March 30, 2026 16:53
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