Skip to content

test: Increase test coverage#2367

Merged
tac0turtle merged 1 commit into
mainfrom
manav/increase_coverage
Jun 11, 2025
Merged

test: Increase test coverage#2367
tac0turtle merged 1 commit into
mainfrom
manav/increase_coverage

Conversation

@Manav-Aggarwal

@Manav-Aggarwal Manav-Aggarwal commented Jun 11, 2025

Copy link
Copy Markdown
Member

Overview

Summary by CodeRabbit

  • Tests
    • Added new tests covering notification handling, validation methods, configuration defaults, and error scenarios.
    • Expanded coverage on concurrency safety, cache management, and utility function edge cases.
    • Improved test organization by replacing a single complex test with multiple focused and granular tests.

@coderabbitai

coderabbitai Bot commented Jun 11, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The changes remove a single, complex test function and its helper, replacing them with several new, focused test functions. These new tests independently verify getter methods, cache behavior, utility functions, error handling, and state management, including concurrency aspects, for the Manager component. Commented-out legacy tests are also deleted. Additionally, the Manager struct initialization now includes a buffered transaction notification channel and a default signature payload provider.

Changes

File Change Summary
block/manager_test.go Updated getManager to initialize new fields (txNotifyCh, signaturePayloadProvider). Removed old comprehensive test and helper. Added multiple new focused tests covering getters, caches, utilities, error handling, state management, concurrency, notification system, validation, and configuration defaults. Extensive use of mocks and concurrency tests included.

Suggested reviewers

  • pthmas

Poem

In the warren of code, we swept the old,
Many small tests now, precise and bold.
Getters and caches, concurrency too,
Each with a purpose, each with a view.
The garden is tidy, the carrots aligned,
Bugs beware—these tests are designed! 🥕

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (1.64.8)

Error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2
Failed executing command with error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions

github-actions Bot commented Jun 11, 2025

Copy link
Copy Markdown
Contributor

The latest Buf updates on your PR. Results from workflow CI and Release / buf-check (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed⏩ skipped✅ passed✅ passedJun 11, 2025, 5:18 PM

@Manav-Aggarwal Manav-Aggarwal self-assigned this Jun 11, 2025
@Manav-Aggarwal
Manav-Aggarwal force-pushed the manav/increase_coverage branch from 8c7a52e to d25f75f Compare June 11, 2025 07:16
@Manav-Aggarwal
Manav-Aggarwal marked this pull request as ready for review June 11, 2025 07:16
@codecov

codecov Bot commented Jun 11, 2025

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.44%. Comparing base (b4668a0) to head (cbd3ec4).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2367      +/-   ##
==========================================
+ Coverage   69.79%   70.44%   +0.65%     
==========================================
  Files          64       64              
  Lines        6267     6267              
==========================================
+ Hits         4374     4415      +41     
+ Misses       1501     1465      -36     
+ Partials      392      387       -5     
Flag Coverage Δ
combined 70.44% <ø> (+0.65%) ⬆️

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.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tac0turtle
tac0turtle added this pull request to the merge queue Jun 11, 2025
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Jun 11, 2025
@tac0turtle
tac0turtle enabled auto-merge June 11, 2025 12:05

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🔭 Outside diff range comments (1)
block/manager_test.go (1)

180-201: ⚠️ Potential issue

Fix inconsistent IsDAIncluded signature across tests

TestIsDAIncluded treats IsDAIncluded as returning a single bool, whereas the newer tests expect (bool, error).
The mixed usage will fail to compile whichever signature you actually expose.

Apply the patch below (or update the later tests in the opposite way) so all call-sites consistently expect the (bool, error) form:

@@
-	// IsDAIncluded should return false for unseen hash
-	require.False(m.IsDAIncluded(ctx, height))
+	// IsDAIncluded should return false for unseen hash
+	ok, err := m.IsDAIncluded(ctx, height)
+	require.NoError(err)
+	require.False(ok)
@@
-	m.headerCache.SetDAIncluded(header.Hash().String())
-	require.False(m.IsDAIncluded(ctx, height))
+	m.headerCache.SetDAIncluded(header.Hash().String())
+	ok, err = m.IsDAIncluded(ctx, height)
+	require.NoError(err)
+	require.False(ok)
@@
-	m.dataCache.SetDAIncluded(data.DACommitment().String())
-	require.True(m.IsDAIncluded(ctx, height))
+	m.dataCache.SetDAIncluded(data.DACommitment().String())
+	ok, err = m.IsDAIncluded(ctx, height)
+	require.NoError(err)
+	require.True(ok)

Without this alignment the file will not type-check.

Also applies to: 695-705

🧹 Nitpick comments (2)
block/manager_test.go (2)

525-531: Redundant assertions on PendingHeaders

require.Nil(result)
require.Equal(m.pendingHeaders, result)

Equal is superfluous after asserting Nil; both conditions reduce to the
same check. Dropping the second line will streamline the test.


553-556: Local variable shadows imported package name

cache := m.HeaderCache() hides the cache package imported at the top.
Renaming the variable (e.g., hdrCache) avoids shadowing and improves
readability.

- cache := m.HeaderCache()
- require.NotNil(cache)
- require.Equal(m.headerCache, cache)
+ hdrCache := m.HeaderCache()
+ require.NotNil(hdrCache)
+ require.Equal(m.headerCache, hdrCache)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d95da86 and 35ec474.

📒 Files selected for processing (1)
  • block/manager_test.go (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: test / Run EVM Execution Tests
  • GitHub Check: test / Run E2E System Tests
  • GitHub Check: test / Run Unit Tests
  • GitHub Check: test / Build All Rollkit Binaries
  • GitHub Check: Analyze (go)
  • GitHub Check: Summary
🔇 Additional comments (1)
block/manager_test.go (1)

611-625: Guard against nil config when patching block-time

m.config is left at its zero value by getManager.
Writing to m.config.DA.BlockTime.Duration without ensuring that
m.config (or the nested structs) are initialised will panic
if the real type uses pointers.

Either initialise a minimal config in getManager, or do it here:

if m.config.DA == nil { // or the relevant zero check for your type
    m.config = defaultConfig() // helper returning a fully-formed config
}
m.config.DA.BlockTime.Duration = 10 * time.Second

This keeps the test resilient to future refactors of Manager.

Comment thread block/manager_test.go
@Manav-Aggarwal
Manav-Aggarwal force-pushed the manav/increase_coverage branch from a7b522a to dd23696 Compare June 11, 2025 17:13

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 0

♻️ Duplicate comments (1)
block/manager_test.go (1)

775-839: ⚠️ Potential issue

Use errors.Is for error comparisons to handle wrapped errors.

The error assertions use direct equality which will fail if the errors are wrapped in production code.

Apply this diff to make error assertions more robust:

-		require.Equal(expectedErr, err)
+		require.True(errors.Is(err, expectedErr))

This change should be applied to lines 784, 796, 819, and 837.

🧹 Nitpick comments (1)
block/manager_test.go (1)

1014-1018: Consider clarifying the test comment for better understanding.

The test correctly validates that backoff is capped at 0 when block time is 0, but the comment could be more descriptive about the capping behavior.

-		require.Equal(0*time.Millisecond, result) // Capped at 0
+		require.Equal(0*time.Millisecond, result) // Capped at block time (0ms), not doubled
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 35ec474 and dd23696.

📒 Files selected for processing (1)
  • block/manager_test.go (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: test / Build Docker Image
  • GitHub Check: test / Run Unit Tests
  • GitHub Check: test / Build All Rollkit Binaries
  • GitHub Check: Analyze (go)
  • GitHub Check: Summary
🔇 Additional comments (7)
block/manager_test.go (7)

45-55: LGTM! Proper initialization of new Manager fields.

The addition of the buffered txNotifyCh channel (size 1) and signaturePayloadProvider is correctly implemented. The buffered channel prevents blocking in the notification system, which is a good design choice.


596-638: Well-structured getter method tests!

Good coverage of all getter methods with clear, focused test cases.


640-670: Comprehensive cache method testing!

Excellent coverage of cache functionality including state transitions.


672-773: Excellent utility function test coverage!

Thorough testing of edge cases, error conditions, and proper header validation logic.


841-915: Excellent thread safety testing!

Comprehensive concurrency tests for state management with proper synchronization.


917-955: Well-designed notification system tests!

Good coverage of both blocking and non-blocking scenarios. The timing assertion for non-blocking behavior is reasonable.


957-1006: Solid validation method tests!

Good coverage of success and failure scenarios with proper configuration testing.

@Manav-Aggarwal
Manav-Aggarwal force-pushed the manav/increase_coverage branch from dd23696 to cbd3ec4 Compare June 11, 2025 17:17

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🧹 Nitpick comments (3)
block/manager_test.go (3)

54-55: Channel capacity of txNotifyCh might be too restrictive

A capacity of 1 is fine when NotifyNewTransactions intentionally drops subsequent events while one is pending, but if the production consumer does not drain the channel promptly (e.g. under load, long GC pause, or bug) the notification path silently stops signalling new transactions. Consider documenting the intentional drop-behaviour or increasing the buffer (e.g. 16) so that short bursts are not lost.

- txNotifyCh:               make(chan struct{}, 1),
+ // small buffer to survive short bursts without losing events
+ txNotifyCh:               make(chan struct{}, 16),

617-623: Redundant assertion in “PendingHeaders” sub-test

require.Nil(result) already establishes that the value is nil; the subsequent equality check against the same nil pointer adds no extra safety and can be dropped for clarity.

- require.Nil(result)
- require.Equal(m.pendingHeaders, result)
+ require.Nil(result)

920-930: Drain txNotifyCh after burst to avoid leaking goroutines

After issuing 11 notifications only one value is read from the buffered channel, leaving 10 unread.
In a long-lived test suite this can block other goroutines that try to drain or close the channel.
Consider draining the channel (or replacing it with a local one) once the assertion is done.

for len(m.txNotifyCh) > 0 {
    <-m.txNotifyCh
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dd23696 and cbd3ec4.

📒 Files selected for processing (1)
  • block/manager_test.go (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: lint / markdown-lint
  • GitHub Check: test / Run Integration Tests
  • GitHub Check: test / Run Unit Tests
  • GitHub Check: test / Build All Rollkit Binaries
  • GitHub Check: test / Build Docker Image
  • GitHub Check: Analyze (actions)
  • GitHub Check: Analyze (go)
  • GitHub Check: Summary
🔇 Additional comments (1)
block/manager_test.go (1)

1015-1018: Zero block-time cap semantics need clarification

The test expects that when m.config.DA.BlockTime.Duration == 0, the back-off is forcibly clamped to zero.
Most back-off implementations treat “0” as “no cap”, returning the doubled value instead.
Please confirm that the production exponentialBackoff intentionally clamps to 0, otherwise this assertion will fail and mask real regressions.

Comment thread block/manager_test.go
Comment on lines +940 to +954
t.Run("NotifyNewTransactions_NonBlocking", func(t *testing.T) {
require := require.New(t)
m, _ := getManager(t, mocks.NewDA(t), -1, -1)

// Fill the channel to test non-blocking behavior
m.txNotifyCh <- struct{}{}

// This should not block even though channel is full
start := time.Now()
m.NotifyNewTransactions()
duration := time.Since(start)

// Should complete quickly (non-blocking)
require.Less(duration, 10*time.Millisecond)
})

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.

🛠️ Refactor suggestion

Tight 10 ms wall-clock assertion risks flakiness in CI

require.Less(duration, 10*time.Millisecond) can intermittently fail on loaded CI runners or slow virtualised environments.
Either relax the bound (e.g. 100 ms) or use assert.Eventually / assert.Never with a context to express non-blocking semantics without relying on wall-clock precision.

- require.Less(duration, 10*time.Millisecond)
+ require.Less(duration, 100*time.Millisecond) // avoid test flakiness on slow machines
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
t.Run("NotifyNewTransactions_NonBlocking", func(t *testing.T) {
require := require.New(t)
m, _ := getManager(t, mocks.NewDA(t), -1, -1)
// Fill the channel to test non-blocking behavior
m.txNotifyCh <- struct{}{}
// This should not block even though channel is full
start := time.Now()
m.NotifyNewTransactions()
duration := time.Since(start)
// Should complete quickly (non-blocking)
require.Less(duration, 10*time.Millisecond)
})
t.Run("NotifyNewTransactions_NonBlocking", func(t *testing.T) {
require := require.New(t)
m, _ := getManager(t, mocks.NewDA(t), -1, -1)
// Fill the channel to test non-blocking behavior
m.txNotifyCh <- struct{}{}
// This should not block even though channel is full
start := time.Now()
m.NotifyNewTransactions()
duration := time.Since(start)
// Should complete quickly (non-blocking)
require.Less(duration, 100*time.Millisecond) // avoid test flakiness on slow machines
})
🤖 Prompt for AI Agents
In block/manager_test.go around lines 940 to 954, the test uses a strict 10
millisecond duration check to assert non-blocking behavior, which can cause
flaky failures in CI environments. To fix this, relax the timing bound to a
higher value like 100 milliseconds or replace the direct duration check with
assert.Eventually or assert.Never combined with a context to more reliably
verify non-blocking behavior without depending on precise timing.

@tac0turtle
tac0turtle added this pull request to the merge queue Jun 11, 2025
Merged via the queue into main with commit 5aeef52 Jun 11, 2025
27 checks passed
@tac0turtle
tac0turtle deleted the manav/increase_coverage branch June 11, 2025 17:30
@github-project-automation github-project-automation Bot moved this to Done in Evolve Jun 11, 2025
@tac0turtle tac0turtle removed this from Evolve Aug 25, 2025
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.

2 participants