Skip to content
This repository was archived by the owner on May 29, 2026. It is now read-only.

refactor: extract shared BeaconChain test suite - #505

Open
cats2101 wants to merge 1 commit into
Consensys:mainfrom
cats2101:refactor/shared-beacon-chain-test-suite
Open

refactor: extract shared BeaconChain test suite#505
cats2101 wants to merge 1 commit into
Consensys:mainfrom
cats2101:refactor/shared-beacon-chain-test-suite

Conversation

@cats2101

@cats2101 cats2101 commented Apr 5, 2026

Copy link
Copy Markdown

Summary

Factors out common BeaconChain contract tests into an abstract BeaconChainTestSuite in core/src/testFixtures, so both InMemoryBeaconChainTest and KvDatabaseTest inherit from a single shared suite.

  • 12 shared tests cover the BeaconChain interface contract: CRUD for states and blocks, rollback, null lookups, getSealedBeaconBlocks pagination
  • Implementation-specific tests remain in their respective classes:
    • InMemoryBeaconChainTest: uncommitted change visibility, byte-array equality, state lookup by block number
    • KvDatabaseTest: persistence across DB restarts, repeated writes, P2P state

Net result: -84 lines of duplicated test code, and KvDatabase now also runs shared tests it previously lacked (e.g. rollback, null lookups, initial state by hash).

Test plan

  • ./gradlew :core:test — 16 tests pass (12 inherited + 4 specific)
  • ./gradlew :storage:test — 18 tests pass (12 inherited + 6 specific)
  • Zero failures, zero errors

Closes #198


Note

Low Risk
Low risk refactor limited to test code and test-fixture dependencies; production logic is unchanged, with main risk being altered test coverage/assumptions for implementations.

Overview
Refactors duplicated BeaconChain tests into a new shared BeaconChainTestSuite (in core test fixtures) that validates common contract behavior (state/block CRUD, rollback, null lookups, and getSealedBeaconBlocks sequencing).

Updates InMemoryBeaconChainTest and KvDatabaseTest to extend the shared suite and keep only implementation-specific assertions (e.g., uncommitted visibility and byte-array key behavior for in-memory; persistence across restarts for RocksDB). Adds JUnit/AssertJ dependencies to core’s testFixtures so the suite can be reused across modules.

Reviewed by Cursor Bugbot for commit eaf8aea. Bugbot is set up for automated code reviews on this repo. Configure here.

Factor out common BeaconChain contract tests into BeaconChainTestSuite
in core testFixtures. Both InMemoryBeaconChainTest and KvDatabaseTest
now extend this shared suite, eliminating duplicated test logic for
getSealedBeaconBlocks, state/block CRUD, rollback, and null lookups.

Implementation-specific tests remain in their respective test classes:
- InMemory: uncommitted visibility, byte-array equality, state-by-number
- KvDatabase: persistence across restarts, repeated writes, P2P state

Closes Consensys#198
@cats2101
cats2101 force-pushed the refactor/shared-beacon-chain-test-suite branch from 3f0f54f to eaf8aea Compare April 5, 2026 19:19
@cats2101

Copy link
Copy Markdown
Author

Gentle ping — anything else needed here?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reuse tests for InMemory and KvDatabase implementation

1 participant