Skip to content

Commit

Permalink
Merge pull request #3696 from nspcc-dev/basic-chain-tests
Browse files Browse the repository at this point in the history
basicchain: use UnitTestNet default config for generation
  • Loading branch information
AnnaShaleva authored Dec 12, 2024
2 parents 4fa5fdc + e993c1b commit 6d1eea3
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 14 deletions.
5 changes: 5 additions & 0 deletions config/config_embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 4 additions & 1 deletion config/protocol.unit_testnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ ProtocolConfiguration:
VerifyTransactions: true
P2PSigExtensions: true
Hardforks:
Aspidochelone: 25
Aspidochelone: 3
Basilisk: 6
Cockatrice: 9
Domovoi: 12

ApplicationConfiguration:
SkipBlockVerification: false
Expand Down
2 changes: 2 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/core/native/invocation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
11 changes: 11 additions & 0 deletions pkg/core/native/native_test/neo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 6 additions & 11 deletions pkg/neotest/chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion pkg/services/rpcsrv/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/services/rpcsrv/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit 6d1eea3

Please sign in to comment.