Skip to content

Conversation

@wanwiset25
Copy link
Collaborator

Proposed changes

Add tests for getTCEpochInfo() to catch bug during refactors.

Types of changes

What types of changes does your code introduce to XDC network?
Put an in the boxes that apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices apply)
  • Regular KTLO or any of the maintaince work. e.g code style
  • CICD Improvement

Impacted Components

Which part of the codebase this PR will touch base on,

Put an in the boxes that apply

  • Consensus
  • Account
  • Network
  • Geth
  • Smart Contract
  • External components
  • Not sure (Please specify below)

Checklist

Put an in the boxes once you have confirmed below actions (or provide reasons on not doing so) that

  • This PR has sufficient test coverage (unit/integration test) OR I have provided reason in the PR description for not having test coverage
  • Provide an end-to-end test plan in the PR description on how to manually test it on the devnet/testnet.
  • Tested the backwards compatibility.
  • Tested with XDC nodes running this version co-exist with those running the previous version.
  • Relevant documentation has been updated as part of this PR
  • N/A

Copilot AI review requested due to automatic review settings February 10, 2026 11:06
@coderabbitai
Copy link

coderabbitai bot commented Feb 10, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch getTCEpochInfo-tests

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

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

Adds unit coverage for getTCEpochInfo() in the v2 consensus engine to help catch regressions during refactors, by asserting expected epoch-switch block/round behavior across key timeout rounds.

Changes:

  • Added TestGetTCEpochInfo covering invalid, boundary, and “far future” timeout rounds.
  • Added a new GetTCEpochInfoFaker test hook on XDPoS_v2 to expose the internal getTCEpochInfo logic to the external test package.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
consensus/tests/engine_v2_tests/timeout_test.go Adds a dedicated test validating epoch-switch info returned for various timeout rounds.
consensus/XDPoS/engines/engine_v2/testing_utils.go Adds an exported *Faker helper to call the internal getTCEpochInfo from tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


func TestGetTCEpochInfo(t *testing.T) {
// First epoch, round 1, switch block 901
// Second epoch, round 901, block 1800
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

The comment describing the second epoch is inaccurate: with SwitchBlock=900 and Epoch=900, the epoch switch happens at round 900 (block 1800), not round 901. Please update the comment to match the assertions below to avoid confusion during future refactors.

Suggested change
// Second epoch, round 901, block 1800
// Second epoch, round 900, block 1800

Copilot uses AI. Check for mistakes.
Comment on lines +385 to +389
epochInfo, err = engineV2.GetTCEpochInfoFaker(blockchain, types.Round(1))
assert.Nil(t, err)
assert.NotNil(t, epochInfo)
assert.Equal(t, big.NewInt(901), epochInfo.EpochSwitchBlockInfo.Number)
assert.Equal(t, types.Round(1), epochInfo.EpochSwitchBlockInfo.Round)
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

These assertions don't stop the test on failure, but the code dereferences epochInfo immediately afterward. If err != nil or epochInfo == nil, the test can panic and mask the real failure. Consider using require assertions or guarding with if !assert.NoError(...) { return } / if !assert.NotNil(...) { return } before accessing fields on epochInfo.

Copilot uses AI. Check for mistakes.
func (x *XDPoS_v2) GetForensicsFaker() *Forensics {
return x.ForensicsProcessor
}

Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

This is an exported method added specifically to expose an internal helper for tests. For consistency with the rest of this file (several methods are explicitly marked as test-only), add a short "for test only" / "WARN: testing purpose only" comment so it’s harder to accidentally use in production code paths.

Suggested change
// WARN: This function is designed for testing purpose only!

Copilot uses AI. Check for mistakes.
@gzliudan gzliudan changed the title consensus: add tests for getTCEpochInfo() test(consensus): add tests for getTCEpochInfo() Feb 11, 2026
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