forked from TrueCloudLab/neoneo-go
core: distinguish empty Hardforks map from nil
Ensure that Blockchain constructor is able to distinguish empty Hardforks map (no hardforks should be enabled) from nil hardforks map (the default value should be used in this case, i.e. all hardforks should be active from genesis). Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
This commit is contained in:
parent
235f4398c6
commit
4ca2686583
2 changed files with 10 additions and 3 deletions
|
@ -289,7 +289,7 @@ func NewBlockchain(s storage.Store, cfg config.Blockchain, log *zap.Logger) (*Bl
|
||||||
cfg.Hardforks[hf.String()] = 0
|
cfg.Hardforks[hf.String()] = 0
|
||||||
}
|
}
|
||||||
log.Info("Hardforks are not set, using default value")
|
log.Info("Hardforks are not set, using default value")
|
||||||
} else {
|
} else if len(cfg.Hardforks) != 0 {
|
||||||
// Explicitly set the height of all old omitted hardforks to 0 for proper
|
// Explicitly set the height of all old omitted hardforks to 0 for proper
|
||||||
// IsHardforkEnabled behaviour.
|
// IsHardforkEnabled behaviour.
|
||||||
for _, hf := range config.Hardforks {
|
for _, hf := range config.Hardforks {
|
||||||
|
|
|
@ -361,9 +361,9 @@ func TestBlockchain_IsRunning(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewBlockchain_InitHardforks(t *testing.T) {
|
func TestNewBlockchain_InitHardforks(t *testing.T) {
|
||||||
t.Run("empty set", func(t *testing.T) {
|
t.Run("nil set", func(t *testing.T) {
|
||||||
bc := newTestChainWithCustomCfg(t, func(c *config.Config) {
|
bc := newTestChainWithCustomCfg(t, func(c *config.Config) {
|
||||||
c.ProtocolConfiguration.Hardforks = map[string]uint32{}
|
c.ProtocolConfiguration.Hardforks = nil
|
||||||
require.NoError(t, c.ProtocolConfiguration.Validate())
|
require.NoError(t, c.ProtocolConfiguration.Validate())
|
||||||
})
|
})
|
||||||
require.Equal(t, map[string]uint32{
|
require.Equal(t, map[string]uint32{
|
||||||
|
@ -372,6 +372,13 @@ func TestNewBlockchain_InitHardforks(t *testing.T) {
|
||||||
config.HFCockatrice.String(): 0,
|
config.HFCockatrice.String(): 0,
|
||||||
}, bc.GetConfig().Hardforks)
|
}, bc.GetConfig().Hardforks)
|
||||||
})
|
})
|
||||||
|
t.Run("empty set", func(t *testing.T) {
|
||||||
|
bc := newTestChainWithCustomCfg(t, func(c *config.Config) {
|
||||||
|
c.ProtocolConfiguration.Hardforks = map[string]uint32{}
|
||||||
|
require.NoError(t, c.ProtocolConfiguration.Validate())
|
||||||
|
})
|
||||||
|
require.Equal(t, map[string]uint32{}, bc.GetConfig().Hardforks)
|
||||||
|
})
|
||||||
t.Run("missing old", func(t *testing.T) {
|
t.Run("missing old", func(t *testing.T) {
|
||||||
bc := newTestChainWithCustomCfg(t, func(c *config.Config) {
|
bc := newTestChainWithCustomCfg(t, func(c *config.Config) {
|
||||||
c.ProtocolConfiguration.Hardforks = map[string]uint32{config.HFBasilisk.String(): 5}
|
c.ProtocolConfiguration.Hardforks = map[string]uint32{config.HFBasilisk.String(): 5}
|
||||||
|
|
Loading…
Reference in a new issue