Skip to content

Conversation

@cce
Copy link
Contributor

@cce cce commented Nov 14, 2025

This pull request refactors and improves the ledger test utilities and error checking in transaction validation tests. The main changes introduce clearer separation between validated and intentionally invalid transaction paths, enhance error assertions to check specific error messages, and update block creation for deterministic test behavior. These improvements help make the tests more robust and easier to understand and maintain.

Test utility refactoring and improvements:

  • Added new helper methods in ledger/ledger_test.go to allow explicit construction and addition of intentionally invalid transactions and blocks, such as appendInvalidTx, appendInvalidSignedTx, and addBlockTxnsInvalid. These bypass normal validation to facilitate negative test cases. [1] [2] [3]
  • Refactored block creation in tests to ensure deterministic timestamps by incrementing from the previous block, improving reproducibility.
  • Updated addEmptyValidatedBlock to use the new block evaluator pattern for consistency and clarity in block addition.

Test assertion improvements:

  • Replaced generic error assertions with ErrorContains to check for specific error messages, making tests more precise and easier to debug. This applies to transaction validity checks throughout TestLedgerSingleTx and testLedgerSingleTxApplyData. [1] [2] [3] [4] [5]

Compatibility and maintenance:

  • Updated imports in ledger/ledger_test.go to include the committee package, supporting new block proposer logic in the refactored test helpers.

Minor compatibility fix:

  • In ledger/applications_test.go, updated a call from appendUnvalidatedTx to appendInvalidTx to use the new helper for constructing invalid application call transactions.

@codecov
Copy link

codecov bot commented Nov 14, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 47.69%. Comparing base (99c6b19) to head (48c0b4e).
⚠️ Report is 3 commits behind head on master.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6499      +/-   ##
==========================================
+ Coverage   47.60%   47.69%   +0.08%     
==========================================
  Files         666      657       -9     
  Lines       88508    87909     -599     
==========================================
- Hits        42135    41926     -209     
+ Misses      43609    43210     -399     
- Partials     2764     2773       +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@cce cce changed the title tests: use more realistic BlockEvaluator ledger/ledger_test.go tests: use more realistic BlockEvaluator in ledger/ledger_test.go Nov 14, 2025
@cce cce marked this pull request as ready for review November 24, 2025 15:53
jannotti
jannotti previously approved these changes Dec 1, 2025
Copy link
Contributor

@jannotti jannotti left a comment

Choose a reason for hiding this comment

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

I can live with it as is. I had two thoughts.

return l.evaluatorToBlock(t, eval)
}

func (l *Ledger) addBlockTxns(t *testing.T, accounts map[basics.Address]basics.AccountData, stxns []transactions.SignedTxn, ad transactions.ApplyData) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add comment that this isn't for groups. The stxns seem like they could be.

badTx = correctPay
badTx.GenesisID = "invalid"
a.Error(l.appendUnvalidatedTx(t, initAccounts, initSecrets, badTx, ad), "added tx with invalid genesis ID")
a.ErrorContains(l.appendUnvalidatedTx(t, initAccounts, initSecrets, badTx, ad), "tx.GenesisID <invalid> does not match expected", "added tx with invalid genesis ID")
Copy link
Contributor

Choose a reason for hiding this comment

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

I find the "message" argument on this (and below) to be kind of pointless, and even a little confusing. I think they made sense when the call was a.Error() to explain, but now the text of the error is pretty descriptive!

Copy link
Contributor

@algorandskiy algorandskiy left a comment

Choose a reason for hiding this comment

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

LGTM, couple minor comments below

}

func (l *Ledger) appendUnvalidatedSignedTx(t *testing.T, initAccounts map[basics.Address]basics.AccountData, stx transactions.SignedTxn, ad transactions.ApplyData) error {
// appendInvalidSignedTx adds an invalid transaction using the old fake block method that bypasses BlockEvaluator.
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure I understand the "old fake block" portion. appendUnvalidated -> evaluatorToBlock calls ledger.Validate

return l.evaluatorToBlock(t, eval)
}

func (l *Ledger) addBlockTxns(t *testing.T, accounts map[basics.Address]basics.AccountData, stxns []transactions.SignedTxn, ad transactions.ApplyData) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

is there any difference in add vs append methods? a bit confusing naming

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants