Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor state tests to always use initialized state #3310

Merged
merged 7 commits into from
Aug 19, 2024

Conversation

StephenButtolph
Copy link
Contributor

Why this should be merged

Previously some tests relied on using an uninitialized testing struct.

How this works

  • Update the tests that relied on uninitialized structs to use initialized structs.
  • Remove support for creating partially initialized structs.
  • Introduce a genesistest package so that constructing a simple State instance is easier for external packages.

How this was tested

  • CI

@StephenButtolph StephenButtolph added cleanup Code quality improvement acp77 acp103 labels Aug 19, 2024
@StephenButtolph StephenButtolph self-assigned this Aug 19, 2024
@StephenButtolph StephenButtolph added this to the v1.11.11 milestone Aug 19, 2024
Comment on lines +693 to +696
test.checkStakerInState(require, rebuiltState, staker)
test.checkValidatorsSet(require, rebuiltState, staker)
test.checkValidatorUptimes(require, rebuiltState, staker)
test.checkDiffs(require, rebuiltState, staker, 0 /*height*/)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These were checking the wrong state 😞.

@@ -675,7 +674,8 @@ func TestPersistStakers(t *testing.T) {
t.Run(fmt.Sprintf("%s - subnetID %s", name, subnetID), func(t *testing.T) {
require := require.New(t)

state, db := newUninitializedState(require)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using an uninitialized state here was super jank imo

})
}
}
}

func newInitializedState(require *require.Assertions) State {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oddly enough, this wouldn't call load previously... so the initialization flow wasn't as expected for a normal initialization.

vms/platformvm/state/state.go Outdated Show resolved Hide resolved
vms/platformvm/state/state.go Outdated Show resolved Hide resolved
@StephenButtolph StephenButtolph added this pull request to the merge queue Aug 19, 2024
Merged via the queue into master with commit acfcfe4 Aug 19, 2024
21 checks passed
@StephenButtolph StephenButtolph deleted the refactor-state-tests branch August 19, 2024 22:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
acp77 acp103 cleanup Code quality improvement
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants