internal: avoid race access to config.Version by tests

Network server constructor reads config.Version variable, and
testcli.DeployContract writes dummy config.Version which causes
race in tests. Avoid this race by moving config.Version initialisation
to a separate package and perform it inside test packages init().

Close #3011, close #3017.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
This commit is contained in:
Anna Shaleva 2023-08-29 20:39:27 +03:00
parent 91c928e8d3
commit eeb439f548
8 changed files with 34 additions and 35 deletions

View file

@ -22,6 +22,7 @@ import (
"github.com/nspcc-dev/neo-go/cli/paramcontext"
"github.com/nspcc-dev/neo-go/internal/basicchain"
"github.com/nspcc-dev/neo-go/internal/random"
"github.com/nspcc-dev/neo-go/internal/versionutil"
"github.com/nspcc-dev/neo-go/pkg/compiler"
"github.com/nspcc-dev/neo-go/pkg/config"
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
@ -44,6 +45,9 @@ import (
"go.uber.org/atomic"
)
// Keep contract NEFs consistent between runs.
const _ = versionutil.TestVersion
type readCloser struct {
sync.Mutex
bytes.Buffer
@ -351,8 +355,6 @@ go 1.18`)
// via `loadnef` command. It returns the name of manifest and NEF files ready to be used in CLI
// commands.
func prepareLoadnefSrc(t *testing.T, tmpDir, src string) (string, string) {
config.Version = "0.92.0-test"
nefFile, di, err := compiler.CompileWithOptions("test.go", strings.NewReader(src), nil)
require.NoError(t, err)
filename := filepath.Join(tmpDir, "vmtestcontract.nef")