Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
  • Loading branch information
dustinxie committed Dec 11, 2024
1 parent 3168caa commit ac0fbeb
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 17 deletions.
17 changes: 13 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,20 @@ func ValidateRollDPoS(cfg Config) error {

// ValidateArchiveMode validates the state factory setting
func ValidateArchiveMode(cfg Config) error {
if !cfg.Chain.EnableArchiveMode || !cfg.Chain.EnableTrielessStateDB {
return nil
if cfg.Chain.EnableArchiveMode && cfg.Chain.EnableTrielessStateDB {
if len(cfg.Chain.VersionedMetadata) == 0 {
return errors.Wrap(ErrInvalidCfg, "State DB archive mode is enabled with empty metadata namespace")
}
if len(cfg.Chain.VersionedNamespaces) == 0 {
return errors.Wrap(ErrInvalidCfg, "State DB archive mode is enabled with empty versioned namespace")
}
for _, v := range cfg.Chain.VersionedNamespaces {
if len(v) == 0 {
return errors.Wrap(ErrInvalidCfg, "State DB archive mode is enabled with empty versioned namespace")
}
}
}

return errors.Wrap(ErrInvalidCfg, "Archive mode is incompatible with trieless state DB")
return nil
}

// ValidateAPI validates the api configs
Expand Down
48 changes: 35 additions & 13 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,20 +254,42 @@ func TestValidateRollDPoS(t *testing.T) {
}

func TestValidateArchiveMode(t *testing.T) {
r := require.New(t)
cfg := Default
cfg.Chain.EnableArchiveMode = true
cfg.Chain.EnableTrielessStateDB = true
require.Error(t, ErrInvalidCfg, errors.Cause(ValidateArchiveMode(cfg)))
require.EqualError(t, ValidateArchiveMode(cfg), "Archive mode is incompatible with trieless state DB: invalid config value")
cfg.Chain.EnableArchiveMode = false
cfg.Chain.EnableTrielessStateDB = true
require.NoError(t, errors.Cause(ValidateArchiveMode(cfg)))
cfg.Chain.EnableArchiveMode = true
cfg.Chain.EnableTrielessStateDB = false
require.NoError(t, errors.Cause(ValidateArchiveMode(cfg)))
cfg.Chain.EnableArchiveMode = false
cfg.Chain.EnableTrielessStateDB = false
require.NoError(t, errors.Cause(ValidateArchiveMode(cfg)))
cfg.Chain.VersionedMetadata = "meta"
for _, v := range [][2]bool{
{false, false},
{false, true},
{true, false},
{true, true},
} {
cfg.Chain.EnableArchiveMode = v[0]
cfg.Chain.EnableTrielessStateDB = v[1]
if !(cfg.Chain.EnableArchiveMode && cfg.Chain.EnableTrielessStateDB) {
r.NoError(ValidateArchiveMode(cfg))
continue
}
for _, v := range []struct {
ns []string
err string
}{
{[]string{"", ""}, "State DB archive mode is enabled with empty versioned namespace"},
{[]string{"Account", ""}, "State DB archive mode is enabled with empty versioned namespace"},
{[]string{"", "Account"}, "State DB archive mode is enabled with empty versioned namespace"},
{[]string{"Account", "Contract"}, ""},
} {
cfg.Chain.VersionedNamespaces = v.ns
if len(v.err) > 0 {
r.ErrorContains(ValidateArchiveMode(cfg), v.err)
} else {
r.NoError(ValidateArchiveMode(cfg))
}
}
cfg.Chain.VersionedMetadata = ""
r.ErrorContains(ValidateArchiveMode(cfg), "State DB archive mode is enabled with empty metadata namespace")
cfg.Chain.VersionedMetadata = "meta"
r.NoError(ValidateArchiveMode(cfg))
}
}

func TestValidateActPool(t *testing.T) {
Expand Down

0 comments on commit ac0fbeb

Please sign in to comment.