From 36e128516b6fccc14615e62dd28c31573a260a2e Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Thu, 18 Apr 2024 16:46:21 +0300 Subject: [PATCH] core: add nativenames.All list It's useful to keep the ordered set of native contract names. Signed-off-by: Anna Shaleva --- pkg/core/blockchain_neotest_test.go | 14 ++++++++++++++ pkg/core/native/nativenames/names.go | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/pkg/core/blockchain_neotest_test.go b/pkg/core/blockchain_neotest_test.go index 2226106f2..1ecd0baeb 100644 --- a/pkg/core/blockchain_neotest_test.go +++ b/pkg/core/blockchain_neotest_test.go @@ -2480,3 +2480,17 @@ func TestBlockchain_GenesisTransactionExtension(t *testing.T) { require.Equal(t, int64(amount), actualNeo.Int64()) require.Equal(t, 0, int(lub)) } + +// TestNativenames ensures that nativenames.All contains all expected native contract names +// in the right order. +func TestNativenames(t *testing.T) { + bc, _ := chain.NewSingleWithCustomConfig(t, func(cfg *config.Blockchain) { + cfg.Hardforks = map[string]uint32{} + cfg.P2PSigExtensions = true + }) + natives := bc.GetNatives() + require.Equal(t, len(natives), len(nativenames.All)) + for i, cs := range natives { + require.Equal(t, cs.Manifest.Name, nativenames.All[i], i) + } +} diff --git a/pkg/core/native/nativenames/names.go b/pkg/core/native/nativenames/names.go index 3ddb814a0..7de5b0171 100644 --- a/pkg/core/native/nativenames/names.go +++ b/pkg/core/native/nativenames/names.go @@ -14,6 +14,20 @@ const ( StdLib = "StdLib" ) +// All contains the list of all native contract names ordered by the contract ID. +var All = []string{ + Management, + StdLib, + CryptoLib, + Ledger, + Neo, + Gas, + Policy, + Designation, + Oracle, + Notary, +} + // IsValid checks if the name is a valid native contract's name. func IsValid(name string) bool { return name == Management ||