Skip to content

Commit ac0fbeb

Browse files
committed
update test
1 parent 3168caa commit ac0fbeb

File tree

2 files changed

+48
-17
lines changed

2 files changed

+48
-17
lines changed

config/config.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,20 @@ func ValidateRollDPoS(cfg Config) error {
256256

257257
// ValidateArchiveMode validates the state factory setting
258258
func ValidateArchiveMode(cfg Config) error {
259-
if !cfg.Chain.EnableArchiveMode || !cfg.Chain.EnableTrielessStateDB {
260-
return nil
259+
if cfg.Chain.EnableArchiveMode && cfg.Chain.EnableTrielessStateDB {
260+
if len(cfg.Chain.VersionedMetadata) == 0 {
261+
return errors.Wrap(ErrInvalidCfg, "State DB archive mode is enabled with empty metadata namespace")
262+
}
263+
if len(cfg.Chain.VersionedNamespaces) == 0 {
264+
return errors.Wrap(ErrInvalidCfg, "State DB archive mode is enabled with empty versioned namespace")
265+
}
266+
for _, v := range cfg.Chain.VersionedNamespaces {
267+
if len(v) == 0 {
268+
return errors.Wrap(ErrInvalidCfg, "State DB archive mode is enabled with empty versioned namespace")
269+
}
270+
}
261271
}
262-
263-
return errors.Wrap(ErrInvalidCfg, "Archive mode is incompatible with trieless state DB")
272+
return nil
264273
}
265274

266275
// ValidateAPI validates the api configs

config/config_test.go

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -254,20 +254,42 @@ func TestValidateRollDPoS(t *testing.T) {
254254
}
255255

256256
func TestValidateArchiveMode(t *testing.T) {
257+
r := require.New(t)
257258
cfg := Default
258-
cfg.Chain.EnableArchiveMode = true
259-
cfg.Chain.EnableTrielessStateDB = true
260-
require.Error(t, ErrInvalidCfg, errors.Cause(ValidateArchiveMode(cfg)))
261-
require.EqualError(t, ValidateArchiveMode(cfg), "Archive mode is incompatible with trieless state DB: invalid config value")
262-
cfg.Chain.EnableArchiveMode = false
263-
cfg.Chain.EnableTrielessStateDB = true
264-
require.NoError(t, errors.Cause(ValidateArchiveMode(cfg)))
265-
cfg.Chain.EnableArchiveMode = true
266-
cfg.Chain.EnableTrielessStateDB = false
267-
require.NoError(t, errors.Cause(ValidateArchiveMode(cfg)))
268-
cfg.Chain.EnableArchiveMode = false
269-
cfg.Chain.EnableTrielessStateDB = false
270-
require.NoError(t, errors.Cause(ValidateArchiveMode(cfg)))
259+
cfg.Chain.VersionedMetadata = "meta"
260+
for _, v := range [][2]bool{
261+
{false, false},
262+
{false, true},
263+
{true, false},
264+
{true, true},
265+
} {
266+
cfg.Chain.EnableArchiveMode = v[0]
267+
cfg.Chain.EnableTrielessStateDB = v[1]
268+
if !(cfg.Chain.EnableArchiveMode && cfg.Chain.EnableTrielessStateDB) {
269+
r.NoError(ValidateArchiveMode(cfg))
270+
continue
271+
}
272+
for _, v := range []struct {
273+
ns []string
274+
err string
275+
}{
276+
{[]string{"", ""}, "State DB archive mode is enabled with empty versioned namespace"},
277+
{[]string{"Account", ""}, "State DB archive mode is enabled with empty versioned namespace"},
278+
{[]string{"", "Account"}, "State DB archive mode is enabled with empty versioned namespace"},
279+
{[]string{"Account", "Contract"}, ""},
280+
} {
281+
cfg.Chain.VersionedNamespaces = v.ns
282+
if len(v.err) > 0 {
283+
r.ErrorContains(ValidateArchiveMode(cfg), v.err)
284+
} else {
285+
r.NoError(ValidateArchiveMode(cfg))
286+
}
287+
}
288+
cfg.Chain.VersionedMetadata = ""
289+
r.ErrorContains(ValidateArchiveMode(cfg), "State DB archive mode is enabled with empty metadata namespace")
290+
cfg.Chain.VersionedMetadata = "meta"
291+
r.NoError(ValidateArchiveMode(cfg))
292+
}
271293
}
272294

273295
func TestValidateActPool(t *testing.T) {

0 commit comments

Comments
 (0)