Skip to content

chore: Add validator unit tests#1834

Open
sergerad wants to merge 2 commits intonextfrom
sergerad-validator-tests
Open

chore: Add validator unit tests#1834
sergerad wants to merge 2 commits intonextfrom
sergerad-validator-tests

Conversation

@sergerad
Copy link
Collaborator

No description provided.

@sergerad sergerad added the no changelog This PR does not require an entry in the `CHANGELOG.md` file label Mar 25, 2026
/// database that does not contain the parent (genesis). This triggers the same
/// `NoPrevBlockHeader` error via `load_block_header` returning `None`.
#[tokio::test]
async fn genesis_replacement_rejected() {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@Mirko-von-Leipzig note that because the API takes in a ProposedBlock, its impossible for genesis block to be overridden (a proposed block can only be constructed with reference to some parent block).

So this test is a contrived way of testing the related logic.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah. I see, for some reason I assumed we were getting the proposed block's header, but its actually the parents..

I was essentially worried one could construct a proposed genesis block via bytes (since that's what we receive), but the literal definition prohibits that.

I'm also okay with removing this test, its testing the code path but not really something practical. Up to you - we could also name it a database protection test I guess :D In case we lose the block header somehow.

Or actually -- I guess this tests that the database must be properly initialized with genesis which is good. In which case just a test rename?

Up to you.

Copy link
Collaborator

@Mirko-von-Leipzig Mirko-von-Leipzig left a comment

Choose a reason for hiding this comment

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

This is great! Thank you!

async fn chain_tip_replacement_succeeds() {
let mut tv = TestValidator::new().await;

// Apply block 1 to advance the chain tip.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: explain the why not the what

Suggested change
// Apply block 1 to advance the chain tip.
// The genesis block can never be replaced, so we advance the chain
// to block 1, which we can then replace.


/// A block with the wrong previous block commitment should be rejected.
#[tokio::test]
async fn commitment_mismatch_rejected() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we add a similar test for replacement + commitment mismatch?

/// database that does not contain the parent (genesis). This triggers the same
/// `NoPrevBlockHeader` error via `load_block_header` returning `None`.
#[tokio::test]
async fn genesis_replacement_rejected() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah. I see, for some reason I assumed we were getting the proposed block's header, but its actually the parents..

I was essentially worried one could construct a proposed genesis block via bytes (since that's what we receive), but the literal definition prohibits that.

I'm also okay with removing this test, its testing the code path but not really something practical. Up to you - we could also name it a database protection test I guess :D In case we lose the block header somehow.

Or actually -- I guess this tests that the database must be properly initialized with genesis which is good. In which case just a test rename?

Up to you.

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

Labels

no changelog This PR does not require an entry in the `CHANGELOG.md` file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants