-
Notifications
You must be signed in to change notification settings - Fork 88
*: 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
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. 🚀 New features to boost your workflow:
|
}, | ||
} | ||
_, err := New(ledger, cfg, 0, logger, shutdown) | ||
require.Error(t, err) |
There was a problem hiding this comment.
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.
pkg/core/statesync/neotest_test.go
Outdated
if err != nil { | ||
return false | ||
} |
There was a problem hiding this comment.
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.
pkg/core/statesync/neotest_test.go
Outdated
if i > syncPoint { | ||
break | ||
} |
There was a problem hiding this comment.
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.
pkg/core/statesync/neotest_test.go
Outdated
require.Equal(t, 2, calls) | ||
require.True(t, module.IsActive()) | ||
// AddMPTNodes or AddContractStorageItems up to P → storageSynced | ||
if cc.name == "MPT-based" { |
There was a problem hiding this comment.
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.
pkg/core/statesync/neotest_test.go
Outdated
unknown := module.GetUnknownMPTNodesBatch(1) | ||
if len(unknown) == 0 { | ||
break | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Grap large batches, 1
is too inefficient, and it's not the purpose of this test to get one-slot batches.
pkg/core/statesync/neotest_test.go
Outdated
require.False(t, module.NeedStorageData()) | ||
require.Equal(t, bcBolt.GetConfig(), module.GetConfig()) | ||
}) | ||
if cc.name == "MPT-based" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
pkg/core/statesync/neotest_test.go
Outdated
}) | ||
|
||
t.Run("initialized: no previous state sync point", func(t *testing.T) { | ||
t.Run("pre-init: MPT-based AddContractStorageItems panic", func(t *testing.T) { |
There was a problem hiding this comment.
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.
pkg/core/statesync/neotest_test.go
Outdated
}) | ||
|
||
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) { |
There was a problem hiding this comment.
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.
pkg/core/statesync/neotest_test.go
Outdated
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()) |
There was a problem hiding this comment.
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.
pkg/core/statesync/neotest_test.go
Outdated
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()) |
There was a problem hiding this comment.
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.
pkg/core/statesync/neotest_test.go
Outdated
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some newly-added code of pkg/core/statesync/module.go
is still uncovered (error cases mostly), see https://app.codecov.io/gh/nspcc-dev/neo-go/commit/6c94a36a20bd40209dadf123a03b273359c89977/indirect-changes?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr%20comments&utm_term=nspcc-dev
pkg/core/statesync/neotest_test.go
Outdated
} | ||
|
||
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()) |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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>
Close #3906