From 8fe2ae843727d52c3527b04e412582f14d50d072 Mon Sep 17 00:00:00 2001 From: Ekaterina Pavlova Date: Fri, 22 Nov 2024 11:37:52 +0300 Subject: [PATCH 1/2] config: add UnitTestNet configuration to embed configs Tests should use embed config too. Signed-off-by: Ekaterina Pavlova --- config/config_embed.go | 5 +++++ pkg/config/config.go | 2 ++ 2 files changed, 7 insertions(+) diff --git a/config/config_embed.go b/config/config_embed.go index c1f66676f0..5e1a04874e 100644 --- a/config/config_embed.go +++ b/config/config_embed.go @@ -30,3 +30,8 @@ var MainNetNeoFS []byte // //go:embed protocol.testnet.neofs.yml var TestNetNeoFS []byte + +// UnitTestNet is the unit test network configuration. +// +//go:embed protocol.unit_testnet.yml +var UnitTestNet []byte diff --git a/pkg/config/config.go b/pkg/config/config.go index 0278614333..ac8bc5d7be 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -137,6 +137,8 @@ func getEmbeddedConfig(configPath string) ([]byte, error) { return config.MainNetNeoFS, nil case fmt.Sprintf("%s/protocol.%s.yml", DefaultConfigPath, netmode.TestNetNeoFS): return config.TestNetNeoFS, nil + case fmt.Sprintf("%s/protocol.%s.yml", DefaultConfigPath, netmode.UnitTestNet): + return config.UnitTestNet, nil default: return nil, fmt.Errorf("config '%s' doesn't exist and no matching embedded config was found", configPath) } From e993c1bdac34ca6fb97c5247f7bc2e3d1887cc5c Mon Sep 17 00:00:00 2001 From: Ekaterina Pavlova Date: Wed, 11 Dec 2024 21:42:00 +0300 Subject: [PATCH 2/2] basicchain: use UnitTestNet default config It's important to have the same chain configuration for all tests. Otherwise, a mismatched hardfork configuration is used to dump/restore the basic chain. Close #3681 Signed-off-by: Ekaterina Pavlova --- config/protocol.unit_testnet.yml | 5 ++++- pkg/core/blockchain_neotest_test.go | 2 +- pkg/core/native/invocation_test.go | 3 +++ pkg/core/native/native_test/neo_test.go | 11 +++++++++++ pkg/neotest/chain/chain.go | 17 ++++++----------- pkg/services/rpcsrv/client_test.go | 5 ++++- pkg/services/rpcsrv/server_test.go | 2 +- 7 files changed, 30 insertions(+), 15 deletions(-) diff --git a/config/protocol.unit_testnet.yml b/config/protocol.unit_testnet.yml index d2753f6e1c..ff821d161d 100644 --- a/config/protocol.unit_testnet.yml +++ b/config/protocol.unit_testnet.yml @@ -18,7 +18,10 @@ ProtocolConfiguration: VerifyTransactions: true P2PSigExtensions: true Hardforks: - Aspidochelone: 25 + Aspidochelone: 3 + Basilisk: 6 + Cockatrice: 9 + Domovoi: 12 ApplicationConfiguration: SkipBlockVerification: false diff --git a/pkg/core/blockchain_neotest_test.go b/pkg/core/blockchain_neotest_test.go index 79490f8386..8b88ecf33d 100644 --- a/pkg/core/blockchain_neotest_test.go +++ b/pkg/core/blockchain_neotest_test.go @@ -272,7 +272,7 @@ func TestBlockchain_StartFromExistingDB(t *testing.T) { _, _, _, err = chain.NewMultiWithCustomConfigAndStoreNoCheck(t, customConfig, cache) require.Error(t, err) - require.True(t, strings.Contains(err.Error(), fmt.Sprintf("native %s: version mismatch for the latest hardfork Echidna (stored contract state differs from autogenerated one)", nativenames.CryptoLib)), err) + require.True(t, strings.Contains(err.Error(), fmt.Sprintf("native %s: version mismatch for the latest hardfork Domovoi (stored contract state differs from autogenerated one)", nativenames.CryptoLib)), err) }) t.Run("good", func(t *testing.T) { diff --git a/pkg/core/native/invocation_test.go b/pkg/core/native/invocation_test.go index ced088b20b..50762afdb9 100644 --- a/pkg/core/native/invocation_test.go +++ b/pkg/core/native/invocation_test.go @@ -139,6 +139,9 @@ func TestNativeContract_InvokeInternal(t *testing.T) { mdDeploy := manState.Manifest.ABI.GetMethod("deploy", 2) require.NotNil(t, mdDeploy) t.Run("fail, bad call flag", func(t *testing.T) { + bc, _, _ := chain.NewMultiWithCustomConfig(t, func(c *config.Blockchain) { + c.Hardforks = nil + }) ic, err := bc.GetTestVM(trigger.Application, nil, nil) require.NoError(t, err) v := ic.SpawnVM() diff --git a/pkg/core/native/native_test/neo_test.go b/pkg/core/native/native_test/neo_test.go index f0ef78ed70..616208c9ab 100644 --- a/pkg/core/native/native_test/neo_test.go +++ b/pkg/core/native/native_test/neo_test.go @@ -401,6 +401,17 @@ func TestNEO_RecursiveGASMint(t *testing.T) { func TestNEO_GetCommitteeAddress(t *testing.T) { neoValidatorInvoker := newNeoValidatorsClient(t) e := neoValidatorInvoker.Executor + cfg := neoValidatorInvoker.Chain.GetConfig() + + maxHardforkHeight := uint32(0) + for _, height := range cfg.Hardforks { + if height > maxHardforkHeight { + maxHardforkHeight = height + } + } + for range maxHardforkHeight { + neoValidatorInvoker.AddNewBlock(t) + } standByCommitteePublicKeys, err := keys.NewPublicKeysFromStrings(e.Chain.GetConfig().StandbyCommittee) require.NoError(t, err) slices.SortFunc(standByCommitteePublicKeys, (*keys.PublicKey).Cmp) diff --git a/pkg/neotest/chain/chain.go b/pkg/neotest/chain/chain.go index ad5b0ecfb4..4f5f48494e 100644 --- a/pkg/neotest/chain/chain.go +++ b/pkg/neotest/chain/chain.go @@ -258,18 +258,13 @@ func NewMultiWithOptionsNoCheck(t testing.TB, options *Options) (*core.Blockchai options = &Options{} } - cfg := config.Blockchain{ - ProtocolConfiguration: config.ProtocolConfiguration{ - Magic: netmode.UnitTestNet, - MaxTraceableBlocks: MaxTraceableBlocks, - TimePerBlock: TimePerBlock, - StandbyCommittee: standByCommittee, - ValidatorsCount: 4, - VerifyTransactions: true, - }, + cfg, err := config.Load(config.DefaultConfigPath, netmode.UnitTestNet) + if err != nil { + return nil, nil, nil, err } + bcfg := cfg.Blockchain() if options.BlockchainConfigHook != nil { - options.BlockchainConfigHook(&cfg) + options.BlockchainConfigHook(&bcfg) } store := options.Store @@ -282,7 +277,7 @@ func NewMultiWithOptionsNoCheck(t testing.TB, options *Options) (*core.Blockchai logger = zaptest.NewLogger(t) } - bc, err := core.NewBlockchain(store, cfg, logger) + bc, err := core.NewBlockchain(store, bcfg, logger) if err == nil && !options.SkipRun { go bc.Run() t.Cleanup(bc.Close) diff --git a/pkg/services/rpcsrv/client_test.go b/pkg/services/rpcsrv/client_test.go index 9f24c7b53f..a61dde844b 100644 --- a/pkg/services/rpcsrv/client_test.go +++ b/pkg/services/rpcsrv/client_test.go @@ -2457,7 +2457,10 @@ func TestClient_GetVersion_Hardforks(t *testing.T) { v, err := c.GetVersion() require.NoError(t, err) expected := map[config.Hardfork]uint32{ - config.HFAspidochelone: 25, + config.HFAspidochelone: 3, + config.HFBasilisk: 6, + config.HFCockatrice: 9, + config.HFDomovoi: 12, } require.InDeltaMapValues(t, expected, v.Protocol.Hardforks, 0) } diff --git a/pkg/services/rpcsrv/server_test.go b/pkg/services/rpcsrv/server_test.go index 5041b44bca..041fe0deb6 100644 --- a/pkg/services/rpcsrv/server_test.go +++ b/pkg/services/rpcsrv/server_test.go @@ -121,7 +121,7 @@ const ( // not yet deployed to the testing basic chain. invokescriptContractAVM = "VwIADBQBDAMOBQYMDQIODw0DDgcJAAAAAErZMCQE2zBwaEH4J+yMqiYEEUAMFA0PAwIJAAIBAwcDBAUCAQAOBgwJStkwJATbMHFpQfgn7IyqJgQSQBNA" // block20StateRootLE is an LE stateroot of block #20 of basic testing chain. - block20StateRootLE = "394e20adf99a6ba160df7351770dfb193ee8af174b7b3ed45f4e2ae8c43694e8" + block20StateRootLE = "570ba0814003f6e6a2a2e41d1b727f8af756e9c26d2453c8316868607b66da0a" ) var (