Skip to content

*: add tests to statefetcher and statesync module #3918

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

Merged
merged 1 commit into from
Jun 20, 2025
Merged

Conversation

AliceInHunterland
Copy link
Contributor

Close #3906

Copy link

codecov bot commented Jun 5, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.05%. Comparing base (05163de) to head (bc4deb5).
Report is 8 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3918      +/-   ##
==========================================
+ Coverage   81.78%   82.05%   +0.27%     
==========================================
  Files         345      345              
  Lines       48921    48933      +12     
==========================================
+ Hits        40010    40153     +143     
+ Misses       7242     7107     -135     
- Partials     1669     1673       +4     

☔ 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.

},
}
_, err := New(ledger, cfg, 0, logger, shutdown)
require.Error(t, err)
Copy link
Member

Choose a reason for hiding this comment

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

Check error text or exact error here and below.

Comment on lines 552 to 554
if err != nil {
return false
}
Copy link
Member

Choose a reason for hiding this comment

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

Remove it, it's useless after require.NoError check.

Comment on lines 754 to 676
if i > syncPoint {
break
}
Copy link
Member

Choose a reason for hiding this comment

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

Unify this condition with cycle constraint.

require.Equal(t, 2, calls)
require.True(t, module.IsActive())
// AddMPTNodes or AddContractStorageItems up to P → storageSynced
if cc.name == "MPT-based" {
Copy link
Member

Choose a reason for hiding this comment

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

It's a bad pattern, don't bind it to test name. Pass mode as a parameter to checking function, see how it is done in TestStateSyncModule_RestoreBasicChain for example.

Comment on lines 763 to 766
unknown := module.GetUnknownMPTNodesBatch(1)
if len(unknown) == 0 {
break
}
Copy link
Member

Choose a reason for hiding this comment

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

Grap large batches, 1is too inefficient, and it's not the purpose of this test to get one-slot batches.

require.False(t, module.NeedStorageData())
require.Equal(t, bcBolt.GetConfig(), module.GetConfig())
})
if cc.name == "MPT-based" {
Copy link
Member

Choose a reason for hiding this comment

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

Ditto.

})

t.Run("initialized: no previous state sync point", func(t *testing.T) {
t.Run("pre-init: MPT-based AddContractStorageItems panic", func(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

No need to duplicate tests. This functionality is already covered in TestStateSyncModule_RestoreBasicChain.

})

t.Run("error: outdated state sync point in the storage", func(t *testing.T) {
bcBolt, _, _ := chain.NewMultiWithCustomConfig(t, boltCfg)
t.Run("pre-init: storage-based AddContractStorageItems error", func(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

Ditto here and two methods below.

Comment on lines 87 to 92
t.Run("inactive: spout chain is too low to start state sync process", func(t *testing.T) {
bcBolt, _, _ := chain.NewMultiWithCustomConfig(t, cc.cfg)
module := bcBolt.GetStateSyncModule()
require.NoError(t, module.Init(uint32(2*stateSyncInterval-1)))
require.False(t, module.IsActive())
require.Equal(t, bcBolt.GetConfig(), module.GetConfig())
Copy link
Member

Choose a reason for hiding this comment

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

This test is not contract storage specific, move it out of the loop, to the place where it was before.

Comment on lines 95 to 105
t.Run("inactive: bolt chain height is close enough to spout chain height", func(t *testing.T) {
bcBolt, _, _ := chain.NewMultiWithCustomConfig(t, cc.cfg)
for i := uint32(1); i < bcSpout.BlockHeight()-stateSyncInterval; i++ {
b, err := bcSpout.GetBlock(bcSpout.GetHeaderHash(i))
require.NoError(t, err)
require.NoError(t, bcBolt.AddBlock(b))
}
module := bcBolt.GetStateSyncModule()
require.NoError(t, module.Init(bcSpout.BlockHeight()))
require.False(t, module.IsActive())
require.Equal(t, bcBolt.GetConfig(), module.GetConfig())
Copy link
Member

Choose a reason for hiding this comment

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

As far as this one.

require.False(t, module.NeedStorageData())
require.True(t, module.NeedBlocks())
require.Equal(t, uint32(stateSyncPoint-stateSyncInterval-1), module.BlockHeight())
t.Run("error: bolt chain is too low to start state sync process", func(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

Ditto. What I need for TestStateSyncModule_Init is to extend only those part that is related to contract storage sync initialization, that's it. We need to cover newly-added code of (s *Module) Init. The rest part of this test should be kept unchanged, I expect as less changes in git diff as possible for this test.

Copy link
Member

@AnnaShaleva AnnaShaleva left a comment

Choose a reason for hiding this comment

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

}

t.Run("inactive: spout chain is too low to start state sync process", func(t *testing.T) {
bcBolt, _, _ := chain.NewMultiWithCustomConfig(t, boltCfg)
module := bcBolt.GetStateSyncModule()
require.NoError(t, module.Init(uint32(2*stateSyncInterval-1)))
require.False(t, module.IsActive())
require.Equal(t, bcBolt.GetConfig(), module.GetConfig())
Copy link
Member

Choose a reason for hiding this comment

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

Here and below, remove this check, it's useless. module is derived from bcBolt.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

module.GetConfig() is not covered by tests.

Copy link
Member

Choose a reason for hiding this comment

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

Create a separate unit-test for it. Because it's immutable field in fact, and I see no point in checking it again and again, especially in the integration test.

Copy link
Member

@AnnaShaleva AnnaShaleva left a comment

Choose a reason for hiding this comment

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

It's important to maintain statesync tests in a proper state, because this code is not a hot-path and it's easy to break it with some new changes. That's why I'm asking to be strict and precise with these checks.

Close #3906

Signed-off-by: Ekaterina Pavlova <ekt@morphbits.io>
@AnnaShaleva AnnaShaleva merged commit 6cd4fd7 into master Jun 20, 2025
33 of 34 checks passed
@AnnaShaleva AnnaShaleva deleted the tests branch June 20, 2025 13:52
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.

Cover NeoFSStateFetcher with unit tests
2 participants