Skip to content

agreement: use specific error assertions in tests#6542

Open
cce wants to merge 4 commits intoalgorand:masterfrom
cce:errorcontains-agreement
Open

agreement: use specific error assertions in tests#6542
cce wants to merge 4 commits intoalgorand:masterfrom
cce:errorcontains-agreement

Conversation

@cce
Copy link
Copy Markdown
Contributor

@cce cce commented Feb 3, 2026

Summary

Replace bare require.Error/assert.Error calls with ErrorContains in agreement tests. This ensures tests verify the actual error message, not just that some error occurred.

Also adds a forbidigo lint rule to prevent require.Error/assert.Error in agreement/ going forward. Split off from #6512 to make review easier.

Test Plan

Existing tests should pass with the new, more precise error assertions.

@cce cce added the Enhancement label Feb 3, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Feb 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 47.75%. Comparing base (5ae5c5a) to head (ae3f3ab).
⚠️ Report is 24 commits behind head on master.
✅ All tests successful. No failed tests found.

❗ There is a different number of reports uploaded between BASE (5ae5c5a) and HEAD (ae3f3ab). Click for more details.

HEAD has 4 uploads less than BASE
Flag BASE (5ae5c5a) HEAD (ae3f3ab)
full_coverage 4 0
Additional details and impacted files
@@             Coverage Diff             @@
##           master    #6542       +/-   ##
===========================================
- Coverage   61.80%   47.75%   -14.05%     
===========================================
  Files         484      645      +161     
  Lines       67520    87792    +20272     
===========================================
+ Hits        41730    41925      +195     
- Misses      22224    43117    +20893     
+ Partials     3566     2750      -816     
Flag Coverage Δ
full_coverage ?

Flags with carried forward coverage won't be shown. Click here to find out more.

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

Replace bare require.Error/assert.Error calls with more specific
assertions (ErrorContains, ErrorIs) that verify the actual error
message content. This improves test quality by ensuring tests
fail for the right reasons.
@cce cce force-pushed the errorcontains-agreement branch from e26b601 to 6358672 Compare February 3, 2026 19:52
cce added 3 commits February 3, 2026 16:52
Convert ErrorContains to ErrorIs where the error message matches
a known sentinel error variable.
Use require.ErrorAs with *proposalManager.errProposalManagerPVNotFound
where runtime captures showed a typed error rather than a plain string.
Copy link
Copy Markdown
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.

This one I'm much less able to figure out from context whether the string is correct. Willing to approve, just want to mention that I'm relying on others more for that aspect.

Comment on lines +80 to +81
var errProposalSeekerNotLess errProposalSeekerNotLess
assert.ErrorAs(t, err, &errProposalSeekerNotLess)
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.

Are these wrapped, so you can't use ErrorIs?

Comment thread agreement/bundle_test.go
@@ -89,8 +89,9 @@ func TestBundleCreationWithZeroVotes(t *testing.T) {
var ub unauthenticatedBundle
makeBundlePanicWrapper(t, "makeBundle: no votes present in bundle (len(equivocationVotes) =", proposal, votes, nil)
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.

Look at makeBundlePanicWrapper below - it does not use message, seems uncompleted - nullWriter vs string buf writer and message check

Comment thread agreement/bundle_test.go
var ub unauthenticatedBundle
makeBundlePanicWrapper(t, "makeBundle: no votes present in bundle (len(equivocationVotes) =", proposal, votes, nil)

ub.Step = step(s)
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.

Without this change all errors are the same for all 5 tested steps that does not make much sense (s not used).
The change looks correct.
I also suggest to test the error it raises with ub.Step=0 as before the modification, outside of the for loop.

	if b.Step == propose {
		return termFmtErrorFn("unauthenticatedBundle.verify: b.Step = %v", propose)
	}

Comment thread agreement/bundle_test.go
require.Error(t, err)
require.ErrorContains(t, err, `bundle: did not see enough votes: 0`)

bundles = append(bundles, bundle)
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.

bundles are not used, the line below _ = bundles[0].u() is useless, it should probably assert that all bundles are empty

@algorandskiy
Copy link
Copy Markdown
Contributor

Btw, the test failure (race) is fixed in #6546

@cce cce force-pushed the errorcontains-agreement branch from e882a3f to ae3f3ab Compare February 13, 2026 18:33
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