From 670af050eea6fbe5afbcfb0f4a057a94920d0061 Mon Sep 17 00:00:00 2001 From: AnnaShaleva Date: Wed, 17 Nov 2021 14:04:43 +0300 Subject: [PATCH 01/14] cli: fix TestGetTimeoutContext test Problem: ``` --- FAIL: TestGetTimeoutContext (0.00s) --- FAIL: TestGetTimeoutContext/default (0.00s) options_test.go:44: Error Trace: options_test.go:44 Error: Should be true Test: TestGetTimeoutContext/default --- FAIL: TestGetTimeoutContext/set (0.00s) options_test.go:55: Error Trace: options_test.go:55 Error: Should be true Test: TestGetTimeoutContext/set FAIL ``` Solution: Allow deadline be equal to expected end time. --- cli/options/options_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cli/options/options_test.go b/cli/options/options_test.go index 57ea27683..22ded55d6 100644 --- a/cli/options/options_test.go +++ b/cli/options/options_test.go @@ -39,9 +39,9 @@ func TestGetTimeoutContext(t *testing.T) { set := flag.NewFlagSet("flagSet", flag.ExitOnError) ctx := cli.NewContext(cli.NewApp(), set, nil) actualCtx, _ := GetTimeoutContext(ctx) - end := time.Now() + end := time.Now().Add(DefaultTimeout) dl, _ := actualCtx.Deadline() - require.True(t, start.Before(dl) && dl.Before(end.Add(DefaultTimeout))) + require.True(t, start.Before(dl) && (dl.Before(end) || dl.Equal(end))) }) t.Run("set", func(t *testing.T) { @@ -50,8 +50,8 @@ func TestGetTimeoutContext(t *testing.T) { set.Duration("timeout", time.Duration(20), "") ctx := cli.NewContext(cli.NewApp(), set, nil) actualCtx, _ := GetTimeoutContext(ctx) - end := time.Now() + end := time.Now().Add(time.Nanosecond * 20) dl, _ := actualCtx.Deadline() - require.True(t, start.Before(dl) && dl.Before(end.Add(time.Nanosecond*20))) + require.True(t, start.Before(dl) && (dl.Before(end) || dl.Equal(end))) }) } From 991f1be8e6a779aec059210783862fc829611d19 Mon Sep 17 00:00:00 2001 From: AnnaShaleva Date: Wed, 17 Nov 2021 16:23:20 +0300 Subject: [PATCH 02/14] cli: fix TestHandleLoggingParams test Problem: ``` --- FAIL: TestHandleLoggingParams (0.02s) --- FAIL: TestHandleLoggingParams/default (0.00s) server_test.go:51: Error Trace: server_test.go:51 Error: Received unexpected error: couldn't open sink "C:\\Users\\Anna\\AppData\\Local\\Temp\\TestHandleLoggingParams226652490\\001/file.log": no sink found for scheme "c" Test: TestHandleLoggingParams/default --- FAIL: TestHandleLoggingParams/debug (0.00s) server_test.go:64: Error Trace: server_test.go:64 Error: Received unexpected error: couldn't open sink "C:\\Users\\Anna\\AppData\\Local\\Temp\\TestHandleLoggingParams226652490\\001/file.log": no sink found for scheme "c" Test: TestHandleLoggingParams/debug ``` Solution: Currently no solution is implemented, but we can use relative paths instead of absolute. --- cli/server/server_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cli/server/server_test.go b/cli/server/server_test.go index bce4d9336..fa59c5cc5 100644 --- a/cli/server/server_test.go +++ b/cli/server/server_test.go @@ -38,6 +38,7 @@ func TestGetConfigFromContext(t *testing.T) { } func TestHandleLoggingParams(t *testing.T) { + // This test is failing on Windows, see https://github.com/nspcc-dev/neo-go/issues/2269 d := t.TempDir() testLog := path.Join(d, "file.log") From 06beb4d5349dd70259b719665a14e8a1b33dd938 Mon Sep 17 00:00:00 2001 From: AnnaShaleva Date: Wed, 17 Nov 2021 16:39:05 +0300 Subject: [PATCH 03/14] core: fix TestMemCachedPersist test Problem: ``` --- FAIL: TestMemCachedPersist (0.07s) --- FAIL: TestMemCachedPersist/BoltDBStore (0.07s) testing.go:894: TempDir RemoveAll cleanup: remove C:\Users\Anna\AppData\Local\Temp\TestMemCachedPersist_BoltDBStore294966711\001\test_bolt_db: The process cannot access the file because it is being used by another process. ``` Solution: Release the resources occupied by the DB. --- pkg/core/storage/memcached_store_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/core/storage/memcached_store_test.go b/pkg/core/storage/memcached_store_test.go index 216c6b8e7..eb572d48f 100644 --- a/pkg/core/storage/memcached_store_test.go +++ b/pkg/core/storage/memcached_store_test.go @@ -109,6 +109,10 @@ func TestMemCachedPersist(t *testing.T) { }) t.Run("BoltDBStore", func(t *testing.T) { ps := newBoltStoreForTesting(t) + t.Cleanup(func() { + err := ps.Close() + require.NoError(t, err) + }) testMemCachedStorePersist(t, ps) }) } From 7c48177bf787491db3d559e8fdbbf98f2b9a40e0 Mon Sep 17 00:00:00 2001 From: AnnaShaleva Date: Wed, 17 Nov 2021 16:42:09 +0300 Subject: [PATCH 04/14] io: fix TestMakeDirForFile* tests Problem: ``` --- FAIL: TestMakeDirForFile_HappyPath (0.01s) testing.go:894: TempDir RemoveAll cleanup: remove C:\Users\Anna\AppData\Local\Temp\TestMakeDirForFile_HappyPath402638411\001\testDir\testFile.test: The process cannot access the file because it is being used by another process. --- FAIL: TestMakeDirForFile_Negative (0.01s) testing.go:894: TempDir RemoveAll cleanup: remove C:\Users\Anna\AppData\Local\Temp\TestMakeDirForFile_Negative672737582\001\testFile.test: The process cannot access the file because it is being used by another process. FAIL ``` Solution: Release resources occupied by os.Create. --- pkg/io/fileWriter_test.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pkg/io/fileWriter_test.go b/pkg/io/fileWriter_test.go index 65b0f872e..5a69135f4 100644 --- a/pkg/io/fileWriter_test.go +++ b/pkg/io/fileWriter_test.go @@ -10,19 +10,21 @@ import ( func TestMakeDirForFile_HappyPath(t *testing.T) { tempDir := t.TempDir() - filePath := path.Join(tempDir, "testDir/testFile.test") + filePath := path.Join(tempDir, "testDir", "testFile.test") err := MakeDirForFile(filePath, "test") require.NoError(t, err) - _, errChDir := os.Create(filePath) + f, errChDir := os.Create(filePath) require.NoError(t, errChDir) + require.NoError(t, f.Close()) } func TestMakeDirForFile_Negative(t *testing.T) { tempDir := t.TempDir() filePath := path.Join(tempDir, "testFile.test") - _, err := os.Create(filePath) + f, err := os.Create(filePath) require.NoError(t, err) + require.NoError(t, f.Close()) filePath = path.Join(filePath, "error") err = MakeDirForFile(filePath, "test") From 6cdb701a9d823039947c1478dd7991ec64480673 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Mon, 29 Nov 2021 11:09:39 +0300 Subject: [PATCH 05/14] vm: improve error message for (*executor).checkError It is helpful if something goes wrong. --- pkg/vm/cli/cli_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/vm/cli/cli_test.go b/pkg/vm/cli/cli_test.go index 3d3761614..654a36a84 100644 --- a/pkg/vm/cli/cli_test.go +++ b/pkg/vm/cli/cli_test.go @@ -104,7 +104,8 @@ func (e *executor) checkNextLine(t *testing.T, expected string) { func (e *executor) checkError(t *testing.T, expectedErr error) { line, err := e.out.ReadString('\n') require.NoError(t, err) - require.True(t, strings.HasPrefix(line, "Error: "+expectedErr.Error())) + expected := "Error: " + expectedErr.Error() + require.True(t, strings.HasPrefix(line, expected), fmt.Errorf("expected `%s`, got `%s`", expected, line)) } func (e *executor) checkStack(t *testing.T, items ...interface{}) { From aefb6f9feed79fed138350565922dbac168dca06 Mon Sep 17 00:00:00 2001 From: AnnaShaleva Date: Wed, 17 Nov 2021 14:14:22 +0300 Subject: [PATCH 06/14] *: fix tests failing due to path.Join usage Solution: Use `file/filepath` package to construct expected path. This package is OS-aware, see https://github.com/golang/go/issues/30616. --- cli/contract_test.go | 72 +++++++++++++-------------- cli/dump_test.go | 12 ++--- cli/multisig_test.go | 8 +-- cli/nep11_test.go | 6 +-- cli/nep17_test.go | 4 +- cli/server/dump_test.go | 8 +-- cli/server/server_test.go | 12 ++--- cli/smartcontract/smart_contract.go | 3 +- cli/wallet_test.go | 12 ++--- pkg/compiler/compiler.go | 4 +- pkg/compiler/compiler_test.go | 4 +- pkg/core/blockchain_test.go | 6 +-- pkg/core/notary_test.go | 5 +- pkg/core/oracle_test.go | 5 +- pkg/core/stateroot_test.go | 8 +-- pkg/core/storage/boltdb_store_test.go | 4 +- pkg/io/fileWriter.go | 4 +- pkg/io/fileWriter_test.go | 8 +-- pkg/vm/cli/cli_test.go | 18 +++---- pkg/wallet/regenerate_test.go | 28 +++++------ pkg/wallet/wallet_test.go | 3 +- 21 files changed, 118 insertions(+), 116 deletions(-) diff --git a/cli/contract_test.go b/cli/contract_test.go index d43eb8d3e..82cc47ad7 100644 --- a/cli/contract_test.go +++ b/cli/contract_test.go @@ -5,7 +5,7 @@ import ( "encoding/json" "io/ioutil" "os" - "path" + "path/filepath" "strconv" "strings" "testing" @@ -60,7 +60,7 @@ func TestCalcHash(t *testing.T) { "--in", "./testdata/verify.nef123", "--manifest", manifestPath)...) }) t.Run("invalid file", func(t *testing.T) { - p := path.Join(tmpDir, "neogo.calchash.verify.nef") + p := filepath.Join(tmpDir, "neogo.calchash.verify.nef") require.NoError(t, ioutil.WriteFile(p, src[:4], os.ModePerm)) e.RunWithError(t, append(cmd, "--sender", sender.StringLE(), "--in", p, "--manifest", manifestPath)...) }) @@ -92,7 +92,7 @@ func TestContractInitAndCompile(t *testing.T) { e.RunWithError(t, "neo-go", "contract", "init", "--name", "\x00") }) - ctrPath := path.Join(tmpDir, "testcontract") + ctrPath := filepath.Join(tmpDir, "testcontract") e.Run(t, "neo-go", "contract", "init", "--name", ctrPath) t.Run("don't rewrite existing directory", func(t *testing.T) { @@ -102,10 +102,10 @@ func TestContractInitAndCompile(t *testing.T) { // For proper nef generation. config.Version = "0.90.0-test" - srcPath := path.Join(ctrPath, "main.go") - cfgPath := path.Join(ctrPath, "neo-go.yml") - nefPath := path.Join(tmpDir, "testcontract.nef") - manifestPath := path.Join(tmpDir, "testcontract.manifest.json") + srcPath := filepath.Join(ctrPath, "main.go") + cfgPath := filepath.Join(ctrPath, "neo-go.yml") + nefPath := filepath.Join(tmpDir, "testcontract.nef") + manifestPath := filepath.Join(tmpDir, "testcontract.manifest.json") cmd := []string{"neo-go", "contract", "compile"} t.Run("missing source", func(t *testing.T) { e.RunWithError(t, cmd...) @@ -116,7 +116,7 @@ func TestContractInitAndCompile(t *testing.T) { e.RunWithError(t, cmd...) }) t.Run("provided non-existent config", func(t *testing.T) { - cfgName := path.Join(ctrPath, "notexists.yml") + cfgName := filepath.Join(ctrPath, "notexists.yml") e.RunWithError(t, append(cmd, "--config", cfgName)...) }) @@ -143,8 +143,8 @@ func TestDeployBigContract(t *testing.T) { config.Version = "0.90.0-test" tmpDir := t.TempDir() - nefName := path.Join(tmpDir, "deploy.nef") - manifestName := path.Join(tmpDir, "deploy.manifest.json") + nefName := filepath.Join(tmpDir, "deploy.nef") + manifestName := filepath.Join(tmpDir, "deploy.manifest.json") e.Run(t, "neo-go", "contract", "compile", "--in", "testdata/deploy/main.go", // compile single file "--config", "testdata/deploy/neo-go.yml", @@ -164,8 +164,8 @@ func TestContractDeployWithData(t *testing.T) { config.Version = "0.90.0-test" tmpDir := t.TempDir() - nefName := path.Join(tmpDir, "deploy.nef") - manifestName := path.Join(tmpDir, "deploy.manifest.json") + nefName := filepath.Join(tmpDir, "deploy.nef") + manifestName := filepath.Join(tmpDir, "deploy.manifest.json") eCompile.Run(t, "neo-go", "contract", "compile", "--in", "testdata/deploy/main.go", // compile single file "--config", "testdata/deploy/neo-go.yml", @@ -241,8 +241,8 @@ func TestDeployWithSigners(t *testing.T) { config.Version = "0.90.0-test" tmpDir := t.TempDir() - nefName := path.Join(tmpDir, "deploy.nef") - manifestName := path.Join(tmpDir, "deploy.manifest.json") + nefName := filepath.Join(tmpDir, "deploy.nef") + manifestName := filepath.Join(tmpDir, "deploy.manifest.json") e.Run(t, "neo-go", "contract", "compile", "--in", "testdata/deploy/main.go", "--config", "testdata/deploy/neo-go.yml", @@ -270,8 +270,8 @@ func TestContractManifestGroups(t *testing.T) { require.NoError(t, err) defer w.Close() - nefName := path.Join(tmpDir, "deploy.nef") - manifestName := path.Join(tmpDir, "deploy.manifest.json") + nefName := filepath.Join(tmpDir, "deploy.nef") + manifestName := filepath.Join(tmpDir, "deploy.manifest.json") e.Run(t, "neo-go", "contract", "compile", "--in", "testdata/deploy/main.go", // compile single file "--config", "testdata/deploy/neo-go.yml", @@ -302,8 +302,8 @@ func deployVerifyContract(t *testing.T, e *executor) util.Uint160 { func deployContract(t *testing.T, e *executor, inPath, configPath, wallet, address, pass string) util.Uint160 { tmpDir := t.TempDir() - nefName := path.Join(tmpDir, "contract.nef") - manifestName := path.Join(tmpDir, "contract.manifest.json") + nefName := filepath.Join(tmpDir, "contract.nef") + manifestName := filepath.Join(tmpDir, "contract.manifest.json") e.Run(t, "neo-go", "contract", "compile", "--in", inPath, "--config", configPath, @@ -330,8 +330,8 @@ func TestComlileAndInvokeFunction(t *testing.T) { config.Version = "0.90.0-test" tmpDir := t.TempDir() - nefName := path.Join(tmpDir, "deploy.nef") - manifestName := path.Join(tmpDir, "deploy.manifest.json") + nefName := filepath.Join(tmpDir, "deploy.nef") + manifestName := filepath.Join(tmpDir, "deploy.manifest.json") e.Run(t, "neo-go", "contract", "compile", "--in", "testdata/deploy/main.go", // compile single file "--config", "testdata/deploy/neo-go.yml", @@ -417,7 +417,7 @@ func TestComlileAndInvokeFunction(t *testing.T) { e.RunWithError(t, cmd...) }) t.Run("non-existent wallet", func(t *testing.T) { - cmd := append(cmd, "--wallet", path.Join(tmpDir, "not.exists"), + cmd := append(cmd, "--wallet", filepath.Join(tmpDir, "not.exists"), h.StringLE(), "getValue") e.RunWithError(t, cmd...) }) @@ -452,7 +452,7 @@ func TestComlileAndInvokeFunction(t *testing.T) { }) t.Run("real invoke and save tx", func(t *testing.T) { - txout := path.Join(tmpDir, "test_contract_tx.json") + txout := filepath.Join(tmpDir, "test_contract_tx.json") cmd = []string{"neo-go", "contract", "invokefunction", "--rpc-endpoint", "http://" + e.RPC.Addr, @@ -540,8 +540,8 @@ func TestComlileAndInvokeFunction(t *testing.T) { }) t.Run("Update", func(t *testing.T) { - nefName := path.Join(tmpDir, "updated.nef") - manifestName := path.Join(tmpDir, "updated.manifest.json") + nefName := filepath.Join(tmpDir, "updated.nef") + manifestName := filepath.Join(tmpDir, "updated.manifest.json") e.Run(t, "neo-go", "contract", "compile", "--config", "testdata/deploy/neo-go.yml", "--in", "testdata/deploy/", // compile all files in dir @@ -589,8 +589,8 @@ func TestContractInspect(t *testing.T) { const srcPath = "testdata/deploy/main.go" tmpDir := t.TempDir() - nefName := path.Join(tmpDir, "deploy.nef") - manifestName := path.Join(tmpDir, "deploy.manifest.json") + nefName := filepath.Join(tmpDir, "deploy.nef") + manifestName := filepath.Join(tmpDir, "deploy.manifest.json") e.Run(t, "neo-go", "contract", "compile", "--in", srcPath, "--config", "testdata/deploy/neo-go.yml", @@ -607,7 +607,7 @@ func TestContractInspect(t *testing.T) { }) t.Run("with nef", func(t *testing.T) { e.RunWithError(t, append(cmd, "--in", nefName, "--compile")...) - e.RunWithError(t, append(cmd, "--in", path.Join(tmpDir, "not.exists"))...) + e.RunWithError(t, append(cmd, "--in", filepath.Join(tmpDir, "not.exists"))...) e.Run(t, append(cmd, "--in", nefName)...) require.True(t, strings.Contains(e.Out.String(), "SYSCALL")) }) @@ -631,20 +631,20 @@ func TestCompileExamples(t *testing.T) { continue } t.Run(info.Name(), func(t *testing.T) { - infos, err := ioutil.ReadDir(path.Join(examplePath, info.Name())) + infos, err := ioutil.ReadDir(filepath.Join(examplePath, info.Name())) require.NoError(t, err) require.False(t, len(infos) == 0, "detected smart contract folder with no contract in it") - outF := path.Join(tmpDir, info.Name()+".nef") - manifestF := path.Join(tmpDir, info.Name()+".manifest.json") + outF := filepath.Join(tmpDir, info.Name()+".nef") + manifestF := filepath.Join(tmpDir, info.Name()+".manifest.json") cfgName := filterFilename(infos, ".yml") opts := []string{ "neo-go", "contract", "compile", - "--in", path.Join(examplePath, info.Name()), + "--in", filepath.Join(examplePath, info.Name()), "--out", outF, "--manifest", manifestF, - "--config", path.Join(examplePath, info.Name(), cfgName), + "--config", filepath.Join(examplePath, info.Name(), cfgName), } e.Run(t, opts...) @@ -669,13 +669,13 @@ func TestCompileExamples(t *testing.T) { t.Run("invalid manifest", func(t *testing.T) { const dir = "./testdata/" for _, name := range []string{"invalid1", "invalid2", "invalid3", "invalid4"} { - outF := path.Join(tmpDir, name+".nef") - manifestF := path.Join(tmpDir, name+".manifest.json") + outF := filepath.Join(tmpDir, name+".nef") + manifestF := filepath.Join(tmpDir, name+".manifest.json") e.RunWithError(t, "neo-go", "contract", "compile", - "--in", path.Join(dir, name), + "--in", filepath.Join(dir, name), "--out", outF, "--manifest", manifestF, - "--config", path.Join(dir, name, "invalid.yml"), + "--config", filepath.Join(dir, name, "invalid.yml"), ) } }) diff --git a/cli/dump_test.go b/cli/dump_test.go index 1318577b6..ae2719fff 100644 --- a/cli/dump_test.go +++ b/cli/dump_test.go @@ -3,7 +3,7 @@ package main import ( "io/ioutil" "os" - "path" + "path/filepath" "testing" "github.com/nspcc-dev/neo-go/pkg/config" @@ -14,8 +14,8 @@ import ( func TestDBRestore(t *testing.T) { tmpDir := t.TempDir() - chainPath := path.Join(tmpDir, "neogotestchain") - cfg, err := config.LoadFile("../config/protocol.unit_testnet.yml") + chainPath := filepath.Join(tmpDir, "neogotestchain") + cfg, err := config.LoadFile(filepath.Join("..", "config", "protocol.unit_testnet.yml")) require.NoError(t, err, "could not load config") cfg.ApplicationConfiguration.DBConfiguration.Type = "leveldb" cfg.ApplicationConfiguration.DBConfiguration.LevelDBOptions.DataDirectoryPath = chainPath @@ -23,13 +23,13 @@ func TestDBRestore(t *testing.T) { out, err := yaml.Marshal(cfg) require.NoError(t, err) - cfgPath := path.Join(tmpDir, "protocol.unit_testnet.yml") + cfgPath := filepath.Join(tmpDir, "protocol.unit_testnet.yml") require.NoError(t, ioutil.WriteFile(cfgPath, out, os.ModePerm)) // generated via `go run ./scripts/gendump/main.go --out ./cli/testdata/chain50x2.acc --blocks 50 --txs 2` const inDump = "./testdata/chain50x2.acc" e := newExecutor(t, false) - stateDump := path.Join(tmpDir, "neogo.teststate") + stateDump := filepath.Join(tmpDir, "neogo.teststate") baseArgs := []string{"neo-go", "db", "restore", "--unittest", "--config-path", tmpDir, "--in", inDump, "--dump", stateDump} @@ -46,7 +46,7 @@ func TestDBRestore(t *testing.T) { e.Run(t, baseArgs...) // Dump and compare. - dumpPath := path.Join(tmpDir, "testdump.acc") + dumpPath := filepath.Join(tmpDir, "testdump.acc") e.Run(t, "neo-go", "db", "dump", "--unittest", "--config-path", tmpDir, "--out", dumpPath) diff --git a/cli/multisig_test.go b/cli/multisig_test.go index 4919f1e96..f673b0af5 100644 --- a/cli/multisig_test.go +++ b/cli/multisig_test.go @@ -6,7 +6,7 @@ import ( "fmt" "math/big" "os" - "path" + "path/filepath" "testing" "github.com/nspcc-dev/neo-go/pkg/crypto/hash" @@ -32,8 +32,8 @@ func TestSignMultisigTx(t *testing.T) { // Create 2 wallets participating in multisig. tmpDir := t.TempDir() - wallet1Path := path.Join(tmpDir, "multiWallet1.json") - wallet2Path := path.Join(tmpDir, "multiWallet2.json") + wallet1Path := filepath.Join(tmpDir, "multiWallet1.json") + wallet2Path := filepath.Join(tmpDir, "multiWallet2.json") addAccount := func(w string, wif string) { e.Run(t, "neo-go", "wallet", "init", "--wallet", w) @@ -64,7 +64,7 @@ func TestSignMultisigTx(t *testing.T) { priv, err := keys.NewPrivateKey() require.NoError(t, err) - txPath := path.Join(tmpDir, "multisigtx.json") + txPath := filepath.Join(tmpDir, "multisigtx.json") t.Cleanup(func() { os.Remove(txPath) }) diff --git a/cli/nep11_test.go b/cli/nep11_test.go index 576d7184c..ea500dc07 100644 --- a/cli/nep11_test.go +++ b/cli/nep11_test.go @@ -6,7 +6,7 @@ import ( "io" "io/ioutil" "math/big" - "path" + "path/filepath" "strings" "testing" @@ -31,7 +31,7 @@ func TestNEP11Import(t *testing.T) { e := newExecutor(t, true) tmpDir := t.TempDir() - walletPath := path.Join(tmpDir, "walletForImport.json") + walletPath := filepath.Join(tmpDir, "walletForImport.json") // deploy NFT NeoNameService contract nnsContractHash := deployNNSContract(t, e) @@ -95,7 +95,7 @@ func TestNEP11_OwnerOf_BalanceOf_Transfer(t *testing.T) { // copy wallet to temp dir in order not to overwrite the original file bytesRead, err := ioutil.ReadFile(nftOwnerWallet) require.NoError(t, err) - wall := path.Join(tmpDir, "my_wallet.json") + wall := filepath.Join(tmpDir, "my_wallet.json") err = ioutil.WriteFile(wall, bytesRead, 0755) require.NoError(t, err) diff --git a/cli/nep17_test.go b/cli/nep17_test.go index bc86b0bca..6bf11aca4 100644 --- a/cli/nep17_test.go +++ b/cli/nep17_test.go @@ -3,7 +3,7 @@ package main import ( "io" "math/big" - "path" + "path/filepath" "strconv" "strings" "testing" @@ -298,7 +298,7 @@ func TestNEP17MultiTransfer(t *testing.T) { func TestNEP17ImportToken(t *testing.T) { e := newExecutor(t, true) tmpDir := t.TempDir() - walletPath := path.Join(tmpDir, "walletForImport.json") + walletPath := filepath.Join(tmpDir, "walletForImport.json") neoContractHash, err := e.Chain.GetNativeContractScriptHash(nativenames.Neo) require.NoError(t, err) diff --git a/cli/server/dump_test.go b/cli/server/dump_test.go index ddaa82e20..74877e44b 100644 --- a/cli/server/dump_test.go +++ b/cli/server/dump_test.go @@ -1,7 +1,7 @@ package server import ( - "path" + "path/filepath" "testing" "github.com/stretchr/testify/require" @@ -11,13 +11,13 @@ func TestGetPath(t *testing.T) { testPath := t.TempDir() actual, err := getPath(testPath, 123) require.NoError(t, err) - require.Equal(t, path.Join(testPath, "/BlockStorage_100000/dump-block-1000.json"), actual) + require.Equal(t, filepath.Join(testPath, "BlockStorage_100000", "dump-block-1000.json"), actual) actual, err = getPath(testPath, 1230) require.NoError(t, err) - require.Equal(t, path.Join(testPath, "/BlockStorage_100000/dump-block-2000.json"), actual) + require.Equal(t, filepath.Join(testPath, "BlockStorage_100000", "dump-block-2000.json"), actual) actual, err = getPath(testPath, 123000) require.NoError(t, err) - require.Equal(t, path.Join(testPath, "/BlockStorage_200000/dump-block-123000.json"), actual) + require.Equal(t, filepath.Join(testPath, "BlockStorage_200000", "dump-block-123000.json"), actual) } diff --git a/cli/server/server_test.go b/cli/server/server_test.go index fa59c5cc5..454076c75 100644 --- a/cli/server/server_test.go +++ b/cli/server/server_test.go @@ -3,7 +3,7 @@ package server import ( "flag" "os" - "path" + "path/filepath" "testing" "github.com/nspcc-dev/neo-go/pkg/config" @@ -40,7 +40,7 @@ func TestGetConfigFromContext(t *testing.T) { func TestHandleLoggingParams(t *testing.T) { // This test is failing on Windows, see https://github.com/nspcc-dev/neo-go/issues/2269 d := t.TempDir() - testLog := path.Join(d, "file.log") + testLog := filepath.Join(d, "file.log") t.Run("default", func(t *testing.T) { set := flag.NewFlagSet("flagSet", flag.ExitOnError) @@ -75,7 +75,7 @@ func TestInitBCWithMetrics(t *testing.T) { t.Cleanup(func() { require.NoError(t, os.Chdir(serverTestWD)) }) set := flag.NewFlagSet("flagSet", flag.ExitOnError) - set.String("config-path", path.Join(serverTestWD, "../../config"), "") + set.String("config-path", filepath.Join(serverTestWD, "..", "..", "config"), "") set.Bool("testnet", true, "") set.Bool("debug", true, "") ctx := cli.NewContext(cli.NewApp(), set, nil) @@ -102,7 +102,7 @@ func TestDumpDB(t *testing.T) { require.NoError(t, err) t.Cleanup(func() { require.NoError(t, os.Chdir(serverTestWD)) }) set := flag.NewFlagSet("flagSet", flag.ExitOnError) - set.String("config-path", path.Join(serverTestWD, "../../config"), "") + set.String("config-path", filepath.Join(serverTestWD, "..", "..", "config"), "") set.Bool("privnet", true, "") set.Bool("debug", true, "") set.Int("start", 0, "") @@ -119,7 +119,7 @@ func TestDumpDB(t *testing.T) { require.NoError(t, err) t.Cleanup(func() { require.NoError(t, os.Chdir(serverTestWD)) }) set := flag.NewFlagSet("flagSet", flag.ExitOnError) - set.String("config-path", path.Join(serverTestWD, "../../config"), "") + set.String("config-path", filepath.Join(serverTestWD, "..", "..", "config"), "") set.Bool("privnet", true, "") set.Bool("debug", true, "") set.Int("start", 0, "") @@ -141,7 +141,7 @@ func TestRestoreDB(t *testing.T) { //dump first set := flag.NewFlagSet("flagSet", flag.ExitOnError) - set.String("config-path", path.Join(serverTestWD, "../../config"), "") + set.String("config-path", filepath.Join(serverTestWD, "..", "..", "config"), "") set.Bool("privnet", true, "") set.Bool("debug", true, "") set.Int("start", 0, "") diff --git a/cli/smartcontract/smart_contract.go b/cli/smartcontract/smart_contract.go index 342072561..851176926 100644 --- a/cli/smartcontract/smart_contract.go +++ b/cli/smartcontract/smart_contract.go @@ -7,7 +7,6 @@ import ( "fmt" "io/ioutil" "os" - "path" "path/filepath" "strings" @@ -417,7 +416,7 @@ func initSmartContract(ctx *cli.Context) error { } basePath := contractName - contractName = path.Base(contractName) + contractName = filepath.Base(contractName) fileName := "main.go" // create base directory diff --git a/cli/wallet_test.go b/cli/wallet_test.go index 21067f7de..5a7bb2ede 100644 --- a/cli/wallet_test.go +++ b/cli/wallet_test.go @@ -5,7 +5,7 @@ import ( "encoding/json" "io/ioutil" "math/big" - "path" + "path/filepath" "strings" "testing" @@ -22,7 +22,7 @@ func TestWalletAccountRemove(t *testing.T) { tmpDir := t.TempDir() e := newExecutor(t, false) - walletPath := path.Join(tmpDir, "wallet.json") + walletPath := filepath.Join(tmpDir, "wallet.json") e.In.WriteString("acc1\r") e.In.WriteString("pass\r") e.In.WriteString("pass\r") @@ -49,11 +49,11 @@ func TestWalletInit(t *testing.T) { tmpDir := t.TempDir() e := newExecutor(t, false) - walletPath := path.Join(tmpDir, "wallet.json") + walletPath := filepath.Join(tmpDir, "wallet.json") e.Run(t, "neo-go", "wallet", "init", "--wallet", walletPath) t.Run("terminal escape codes", func(t *testing.T) { - walletPath := path.Join(tmpDir, "walletrussian.json") + walletPath := filepath.Join(tmpDir, "walletrussian.json") bksp := string([]byte{ byte(readline.CharBackward), byte(readline.CharDelete), @@ -261,7 +261,7 @@ func TestImportDeployed(t *testing.T) { tmpDir := t.TempDir() e := newExecutor(t, true) h := deployVerifyContract(t, e) - walletPath := path.Join(tmpDir, "wallet.json") + walletPath := filepath.Join(tmpDir, "wallet.json") e.Run(t, "neo-go", "wallet", "init", "--wallet", walletPath) @@ -393,7 +393,7 @@ func TestWalletConvert(t *testing.T) { tmpDir := t.TempDir() e := newExecutor(t, false) - outPath := path.Join(tmpDir, "wallet.json") + outPath := filepath.Join(tmpDir, "wallet.json") cmd := []string{"neo-go", "wallet", "convert"} t.Run("missing wallet", func(t *testing.T) { e.RunWithError(t, cmd...) diff --git a/pkg/compiler/compiler.go b/pkg/compiler/compiler.go index 6e90b5476..296782dd4 100644 --- a/pkg/compiler/compiler.go +++ b/pkg/compiler/compiler.go @@ -10,7 +10,7 @@ import ( "io" "io/ioutil" "os" - "path" + "path/filepath" "strings" "github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest" @@ -135,7 +135,7 @@ func getBuildInfo(name string, src interface{}) (*buildInfo, error) { } for i := range ds { if !ds[i].IsDir() && strings.HasSuffix(ds[i].Name(), ".go") { - names = append(names, path.Join(name, ds[i].Name())) + names = append(names, filepath.Join(name, ds[i].Name())) } } } diff --git a/pkg/compiler/compiler_test.go b/pkg/compiler/compiler_test.go index 07ace1e07..02b6acd99 100644 --- a/pkg/compiler/compiler_test.go +++ b/pkg/compiler/compiler_test.go @@ -4,7 +4,7 @@ import ( "fmt" "io/ioutil" "os" - "path" + "path/filepath" "strings" "testing" @@ -58,7 +58,7 @@ func TestCompiler(t *testing.T) { continue } - targetPath := path.Join(examplePath, info.Name()) + targetPath := filepath.Join(examplePath, info.Name()) require.NoError(t, compileFile(targetPath)) } }, diff --git a/pkg/core/blockchain_test.go b/pkg/core/blockchain_test.go index 36b45f85a..7619e171f 100644 --- a/pkg/core/blockchain_test.go +++ b/pkg/core/blockchain_test.go @@ -6,7 +6,7 @@ import ( "fmt" "math/big" "math/rand" - "path" + "path/filepath" "strings" "testing" "time" @@ -1707,9 +1707,9 @@ func TestMPTDeleteNoKey(t *testing.T) { // native contract is disabled. It's easy to forget about config while adding new // native contract. func TestConfigNativeUpdateHistory(t *testing.T) { - const prefixPath = "../../config" + var prefixPath = filepath.Join("..", "..", "config") check := func(t *testing.T, cfgFileSuffix interface{}) { - cfgPath := path.Join(prefixPath, fmt.Sprintf("protocol.%s.yml", cfgFileSuffix)) + cfgPath := filepath.Join(prefixPath, fmt.Sprintf("protocol.%s.yml", cfgFileSuffix)) cfg, err := config.LoadFile(cfgPath) require.NoError(t, err, fmt.Errorf("failed to load %s", cfgPath)) natives := native.NewContracts(cfg.ProtocolConfiguration) diff --git a/pkg/core/notary_test.go b/pkg/core/notary_test.go index 2ca1d8e89..67b5bbd3d 100644 --- a/pkg/core/notary_test.go +++ b/pkg/core/notary_test.go @@ -5,6 +5,7 @@ import ( "fmt" "math/rand" "path" + "path/filepath" "sync" "testing" "time" @@ -30,13 +31,13 @@ import ( "go.uber.org/zap/zaptest" ) -const notaryModulePath = "../services/notary/" +var notaryModulePath = filepath.Join("..", "services", "notary") func getTestNotary(t *testing.T, bc *Blockchain, walletPath, pass string, onTx func(tx *transaction.Transaction) error) (*wallet.Account, *notary.Notary, *mempool.Pool) { mainCfg := config.P2PNotary{ Enabled: true, UnlockWallet: config.Wallet{ - Path: path.Join(notaryModulePath, walletPath), + Path: filepath.Join(notaryModulePath, walletPath), Password: pass, }, } diff --git a/pkg/core/oracle_test.go b/pkg/core/oracle_test.go index 701ebfb83..7657446aa 100644 --- a/pkg/core/oracle_test.go +++ b/pkg/core/oracle_test.go @@ -8,6 +8,7 @@ import ( "net/http" "net/url" "path" + "path/filepath" "strings" "sync" "testing" @@ -28,7 +29,7 @@ import ( "go.uber.org/zap/zaptest" ) -const oracleModulePath = "../services/oracle/" +var oracleModulePath = filepath.Join("..", "services", "oracle") func getOracleConfig(t *testing.T, bc *Blockchain, w, pass string) oracle.Config { return oracle.Config{ @@ -38,7 +39,7 @@ func getOracleConfig(t *testing.T, bc *Blockchain, w, pass string) oracle.Config RefreshInterval: time.Second, AllowedContentTypes: []string{"application/json"}, UnlockWallet: config.Wallet{ - Path: path.Join(oracleModulePath, w), + Path: filepath.Join(oracleModulePath, w), Password: pass, }, }, diff --git a/pkg/core/stateroot_test.go b/pkg/core/stateroot_test.go index 6dd0703a3..cb66c078e 100644 --- a/pkg/core/stateroot_test.go +++ b/pkg/core/stateroot_test.go @@ -2,7 +2,7 @@ package core import ( "errors" - "path" + "path/filepath" "sort" "testing" "time" @@ -78,7 +78,7 @@ func TestStateRoot(t *testing.T) { transferTokenFromMultisigAccount(t, bc, h, bc.contracts.GAS.Hash, 1_0000_0000) tmpDir := t.TempDir() - w := createAndWriteWallet(t, accs[0], path.Join(tmpDir, "w"), "pass") + w := createAndWriteWallet(t, accs[0], filepath.Join(tmpDir, "w"), "pass") cfg := createStateRootConfig(w.Path(), "pass") srv, err := stateroot.New(cfg, zaptest.NewLogger(t), bc, nil) require.NoError(t, err) @@ -146,7 +146,7 @@ func TestStateRootInitNonZeroHeight(t *testing.T) { _, err := persistBlock(bc) require.NoError(t, err) tmpDir := t.TempDir() - w := createAndWriteWallet(t, accs[0], path.Join(tmpDir, "w"), "pass") + w := createAndWriteWallet(t, accs[0], filepath.Join(tmpDir, "w"), "pass") cfg := createStateRootConfig(w.Path(), "pass") srv, err := stateroot.New(cfg, zaptest.NewLogger(t), bc, nil) require.NoError(t, err) @@ -189,7 +189,7 @@ func TestStateRootFull(t *testing.T) { bc := newTestChain(t) h, pubs, accs := newMajorityMultisigWithGAS(t, 2) - w := createAndWriteWallet(t, accs[1], path.Join(tmpDir, "wallet2"), "two") + w := createAndWriteWallet(t, accs[1], filepath.Join(tmpDir, "wallet2"), "two") cfg := createStateRootConfig(w.Path(), "two") var lastValidated atomic.Value diff --git a/pkg/core/storage/boltdb_store_test.go b/pkg/core/storage/boltdb_store_test.go index cd1a84e39..dac682318 100644 --- a/pkg/core/storage/boltdb_store_test.go +++ b/pkg/core/storage/boltdb_store_test.go @@ -1,7 +1,7 @@ package storage import ( - "path" + "path/filepath" "testing" "github.com/stretchr/testify/require" @@ -9,7 +9,7 @@ import ( func newBoltStoreForTesting(t testing.TB) Store { d := t.TempDir() - testFileName := path.Join(d, "test_bolt_db") + testFileName := filepath.Join(d, "test_bolt_db") boltDBStore, err := NewBoltDBStore(BoltDBOptions{FilePath: testFileName}) require.NoError(t, err) return boltDBStore diff --git a/pkg/io/fileWriter.go b/pkg/io/fileWriter.go index 35f3e7c62..5e367b3eb 100644 --- a/pkg/io/fileWriter.go +++ b/pkg/io/fileWriter.go @@ -3,13 +3,13 @@ package io import ( "fmt" "os" - "path" + "path/filepath" ) // MakeDirForFile creates directory provided in filePath. func MakeDirForFile(filePath string, creator string) error { fileName := filePath - dir := path.Dir(fileName) + dir := filepath.Dir(fileName) err := os.MkdirAll(dir, os.ModePerm) if err != nil { return fmt.Errorf("could not create dir for %s: %w", creator, err) diff --git a/pkg/io/fileWriter_test.go b/pkg/io/fileWriter_test.go index 5a69135f4..121721dc2 100644 --- a/pkg/io/fileWriter_test.go +++ b/pkg/io/fileWriter_test.go @@ -2,7 +2,7 @@ package io import ( "os" - "path" + "path/filepath" "testing" "github.com/stretchr/testify/require" @@ -10,7 +10,7 @@ import ( func TestMakeDirForFile_HappyPath(t *testing.T) { tempDir := t.TempDir() - filePath := path.Join(tempDir, "testDir", "testFile.test") + filePath := filepath.Join(tempDir, "testDir", "testFile.test") err := MakeDirForFile(filePath, "test") require.NoError(t, err) @@ -21,12 +21,12 @@ func TestMakeDirForFile_HappyPath(t *testing.T) { func TestMakeDirForFile_Negative(t *testing.T) { tempDir := t.TempDir() - filePath := path.Join(tempDir, "testFile.test") + filePath := filepath.Join(tempDir, "testFile.test") f, err := os.Create(filePath) require.NoError(t, err) require.NoError(t, f.Close()) - filePath = path.Join(filePath, "error") + filePath = filepath.Join(filePath, "error") err = MakeDirForFile(filePath, "test") require.Errorf(t, err, "could not create dir for test: mkdir %s : not a directory", filePath) } diff --git a/pkg/vm/cli/cli_test.go b/pkg/vm/cli/cli_test.go index 654a36a84..83c7d1453 100644 --- a/pkg/vm/cli/cli_test.go +++ b/pkg/vm/cli/cli_test.go @@ -9,7 +9,7 @@ import ( gio "io" "io/ioutil" "os" - "path" + "path/filepath" "strings" "sync" "testing" @@ -200,9 +200,9 @@ func TestLoad(t *testing.T) { tmpDir := t.TempDir() t.Run("loadgo", func(t *testing.T) { - filename := path.Join(tmpDir, "vmtestcontract.go") + filename := filepath.Join(tmpDir, "vmtestcontract.go") require.NoError(t, ioutil.WriteFile(filename, []byte(src), os.ModePerm)) - filenameErr := path.Join(tmpDir, "vmtestcontract_err.go") + filenameErr := filepath.Join(tmpDir, "vmtestcontract_err.go") require.NoError(t, ioutil.WriteFile(filenameErr, []byte(src+"invalid_token"), os.ModePerm)) e := newTestVMCLI(t) @@ -225,7 +225,7 @@ func TestLoad(t *testing.T) { return 1 } ` - filename := path.Join(tmpDir, "vmtestcontract.go") + filename := filepath.Join(tmpDir, "vmtestcontract.go") require.NoError(t, ioutil.WriteFile(filename, []byte(srcAllowNotify), os.ModePerm)) e := newTestVMCLI(t) @@ -242,19 +242,19 @@ func TestLoad(t *testing.T) { require.NoError(t, err) nefFile, err := nef.NewFile(script) require.NoError(t, err) - filename := path.Join(tmpDir, "vmtestcontract.nef") + filename := filepath.Join(tmpDir, "vmtestcontract.nef") rawNef, err := nefFile.Bytes() require.NoError(t, err) require.NoError(t, ioutil.WriteFile(filename, rawNef, os.ModePerm)) m, err := di.ConvertToManifest(&compiler.Options{}) require.NoError(t, err) - manifestFile := path.Join(tmpDir, "vmtestcontract.manifest.json") + manifestFile := filepath.Join(tmpDir, "vmtestcontract.manifest.json") rawManifest, err := json.Marshal(m) require.NoError(t, err) require.NoError(t, ioutil.WriteFile(manifestFile, rawManifest, os.ModePerm)) - filenameErr := path.Join(tmpDir, "vmtestcontract_err.nef") + filenameErr := filepath.Join(tmpDir, "vmtestcontract_err.nef") require.NoError(t, ioutil.WriteFile(filenameErr, append([]byte{1, 2, 3, 4}, rawNef...), os.ModePerm)) - notExists := path.Join(tmpDir, "notexists.json") + notExists := filepath.Join(tmpDir, "notexists.json") e := newTestVMCLI(t) e.runProg(t, @@ -294,7 +294,7 @@ func TestRunWithDifferentArguments(t *testing.T) { }` tmpDir := t.TempDir() - filename := path.Join(tmpDir, "run_vmtestcontract.go") + filename := filepath.Join(tmpDir, "run_vmtestcontract.go") require.NoError(t, ioutil.WriteFile(filename, []byte(src), os.ModePerm)) e := newTestVMCLI(t) diff --git a/pkg/wallet/regenerate_test.go b/pkg/wallet/regenerate_test.go index 28a4e6fc7..168fcff34 100644 --- a/pkg/wallet/regenerate_test.go +++ b/pkg/wallet/regenerate_test.go @@ -4,7 +4,7 @@ import ( "encoding/json" "fmt" "io/ioutil" - "path" + "path/filepath" "testing" "github.com/nspcc-dev/neo-go/pkg/core/state" @@ -57,7 +57,7 @@ func TestRegenerateSoloWallet(t *testing.T) { if !regenerate { return } - walletPath := path.Join(dockerWalletDir, "wallet1_solo.json") + walletPath := filepath.Join(dockerWalletDir, "wallet1_solo.json") wif := privnetWIFs[0] acc1 := getAccount(t, wif, "one") acc2 := getAccount(t, wif, "one") @@ -76,7 +76,7 @@ func regenerateWallets(t *testing.T, dir string) { acc2 := getAccount(t, privnetWIFs[i], passwords[i]) require.NoError(t, acc2.ConvertMultisig(3, pubs)) - createWallet(t, path.Join(dir, fmt.Sprintf("wallet%d.json", i+1)), acc1, acc2) + createWallet(t, filepath.Join(dir, fmt.Sprintf("wallet%d.json", i+1)), acc1, acc2) } } @@ -107,9 +107,9 @@ func TestRegenerateWalletTestdata(t *testing.T) { acc3 := getAccount(t, privnetWIFs[1], "two") acc3.Default = true - createWallet(t, path.Join(walletDir, "wallet1.json"), acc1, acc2) + createWallet(t, filepath.Join(walletDir, "wallet1.json"), acc1, acc2) - createWallet(t, path.Join(walletDir, "wallet2.json"), acc1, acc2, acc3) + createWallet(t, filepath.Join(walletDir, "wallet2.json"), acc1, acc2, acc3) } func TestRegenerateNotaryWallets(t *testing.T) { @@ -117,21 +117,21 @@ func TestRegenerateNotaryWallets(t *testing.T) { return } const ( - walletDir = "../services/notary/testdata/" - acc1WIF = "L1MstxuD8SvS9HuFcV5oYzcdA1xX8D9bD9qPwg8fU5SSywYBecg3" - acc2WIF = "L2iGxPvxbyWpYEbCZk2L3PgT7sCQaSDAbBC4MRLAjhs1s2JZ1xs5" - acc3WIF = "L1xD2yiUyARX8DAkWa8qGpWpwjqW2u717VzUJyByk6s7HinhRVZv" - acc4WIF = "L1ioz93TNt6Nu1aoMpZQ4zgdtgC8ZvJMC6pyHFkrovdR3SFwbn6n" + acc1WIF = "L1MstxuD8SvS9HuFcV5oYzcdA1xX8D9bD9qPwg8fU5SSywYBecg3" + acc2WIF = "L2iGxPvxbyWpYEbCZk2L3PgT7sCQaSDAbBC4MRLAjhs1s2JZ1xs5" + acc3WIF = "L1xD2yiUyARX8DAkWa8qGpWpwjqW2u717VzUJyByk6s7HinhRVZv" + acc4WIF = "L1ioz93TNt6Nu1aoMpZQ4zgdtgC8ZvJMC6pyHFkrovdR3SFwbn6n" ) + var walletDir = filepath.Join("..", "services", "notary", "testdata") scryptParams := keys.ScryptParams{N: 2, R: 1, P: 1} acc1 := getAccountWithScrypt(t, acc1WIF, "one", scryptParams) acc2 := getAccountWithScrypt(t, acc2WIF, "one", scryptParams) acc3 := getAccountWithScrypt(t, acc3WIF, "four", scryptParams) - createWallet(t, path.Join(walletDir, "notary1.json"), acc1, acc2, acc3) + createWallet(t, filepath.Join(walletDir, "notary1.json"), acc1, acc2, acc3) acc4 := getAccountWithScrypt(t, acc4WIF, "two", scryptParams) - createWallet(t, path.Join(walletDir, "notary2.json"), acc4) + createWallet(t, filepath.Join(walletDir, "notary2.json"), acc4) } func TestRegenerateOracleWallets(t *testing.T) { @@ -145,10 +145,10 @@ func TestRegenerateOracleWallets(t *testing.T) { ) acc1 := getAccount(t, acc1WIF, "one") - createWallet(t, path.Join(walletDir, "oracle1.json"), acc1) + createWallet(t, filepath.Join(walletDir, "oracle1.json"), acc1) acc2 := getAccount(t, acc2WIF, "two") - createWallet(t, path.Join(walletDir, "oracle2.json"), acc2) + createWallet(t, filepath.Join(walletDir, "oracle2.json"), acc2) } func TestRegenerateExamplesWallet(t *testing.T) { diff --git a/pkg/wallet/wallet_test.go b/pkg/wallet/wallet_test.go index 68c97579b..6ac8f4071 100644 --- a/pkg/wallet/wallet_test.go +++ b/pkg/wallet/wallet_test.go @@ -3,6 +3,7 @@ package wallet import ( "encoding/json" "path" + "path/filepath" "testing" "github.com/nspcc-dev/neo-go/pkg/encoding/address" @@ -124,7 +125,7 @@ func TestJSONMarshallUnmarshal(t *testing.T) { func checkWalletConstructor(t *testing.T) *Wallet { tmpDir := t.TempDir() - file := path.Join(tmpDir, walletTemplate) + file := filepath.Join(tmpDir, walletTemplate) wallet, err := NewWallet(file) require.NoError(t, err) return wallet From 16da133d61d7a1fcde53370e697472fa9837ffbc Mon Sep 17 00:00:00 2001 From: AnnaShaleva Date: Wed, 17 Nov 2021 17:33:37 +0300 Subject: [PATCH 07/14] cli: release resources occupied by chain before `dumpDB` exit Problem: ``` --- FAIL: TestDumpDB (0.08s) --- FAIL: TestDumpDB/too_low_chain testing.go:894: TempDir RemoveAll cleanup: remove C:\Users\Anna\AppData\Local\Temp\TestDumpDB_too_low_chain357310492\001\chains\privnet\000001.log: The process cannot access the file because it is being used by another process. ``` Solution: Release resources occupied by the chain even on non-error command exit. --- cli/server/server.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cli/server/server.go b/cli/server/server.go index 73dc32cfa..1a37ca997 100644 --- a/cli/server/server.go +++ b/cli/server/server.go @@ -186,6 +186,11 @@ func dumpDB(ctx *cli.Context) error { if err != nil { return err } + defer func() { + pprof.ShutDown() + prometheus.ShutDown() + chain.Close() + }() chainCount := chain.BlockHeight() + 1 if start+count > chainCount { @@ -199,9 +204,6 @@ func dumpDB(ctx *cli.Context) error { if err != nil { return cli.NewExitError(err.Error(), 1) } - pprof.ShutDown() - prometheus.ShutDown() - chain.Close() return nil } From ebd128ee795c3a1ef6c5c8f6f015b0369ee7ee02 Mon Sep 17 00:00:00 2001 From: AnnaShaleva Date: Wed, 17 Nov 2021 18:30:51 +0300 Subject: [PATCH 08/14] .github: add windows-based tests workflow --- .github/workflows/run_tests.yml | 34 +++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index 4f814fce8..bb92216d3 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -65,8 +65,8 @@ jobs: path_to_write_report: ./coverage.txt verbose: true - tests: - name: Go + tests_ubuntu: + name: Ubuntu, Go runs-on: ubuntu-20.04 strategy: matrix: @@ -99,6 +99,36 @@ jobs: - name: Run tests run: go test -v -race ./... + tests_win: + name: Windows, Go (1.17) + runs-on: windows-2019 + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.17 + + - name: Restore Go modules from cache + uses: actions/cache@v2 + with: + path: /home/runner/go/pkg/mod + key: deps-${{ hashFiles('go.sum') }} + + - name: Update Go modules + run: go mod download -json + + - name: Sync VM submodule + run: | + git submodule sync + git submodule update --init + + - name: Run tests + run: go test -v -race ./... + build_cli: name: Build CLI runs-on: ubuntu-20.04 From 7770535d4f6df443debce076a9361056d1c6aa44 Mon Sep 17 00:00:00 2001 From: AnnaShaleva Date: Thu, 18 Nov 2021 18:48:05 +0300 Subject: [PATCH 09/14] .github: add job to build binaries on Windows --- .github/workflows/run_tests.yml | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index bb92216d3..421580d1f 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -129,8 +129,8 @@ jobs: - name: Run tests run: go test -v -race ./... - build_cli: - name: Build CLI + build_cli_ubuntu: + name: Build CLI (Ubuntu) runs-on: ubuntu-20.04 steps: @@ -155,8 +155,34 @@ jobs: - name: Build CLI run: make build + build_cli_win: + name: Build CLI (Windows) + runs-on: windows-2019 + + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.17 + + - name: Restore Go modules from cache + uses: actions/cache@v2 + with: + path: /home/runner/go/pkg/mod + key: deps-${{ hashFiles('go.sum') }} + + - name: Update Go modules + run: go mod download -json + + - name: Build CLI + run: make build + build_image: - needs: build_cli + needs: build_cli_ubuntu name: Build Docker image runs-on: ubuntu-20.04 From f97f6168fc8bb3be8a463061947634cbd93934d3 Mon Sep 17 00:00:00 2001 From: AnnaShaleva Date: Fri, 19 Nov 2021 15:31:25 +0300 Subject: [PATCH 10/14] .github: remove golang from build_image job We're building inside Docker container, so we don't need golang to be installed on the host machine. --- .github/workflows/run_tests.yml | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index 421580d1f..b6bc40852 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -191,19 +191,5 @@ jobs: with: fetch-depth: 0 - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: 1.17 - - - name: Restore Go modules from cache - uses: actions/cache@v2 - with: - path: /home/runner/go/pkg/mod - key: deps-${{ hashFiles('go.sum') }} - - - name: Update Go modules - run: go mod download -json - - name: Build Docker image run: make image From b940167a6b699d07cc1d08b4bb35726d9dfd412c Mon Sep 17 00:00:00 2001 From: AnnaShaleva Date: Fri, 19 Nov 2021 15:42:53 +0300 Subject: [PATCH 11/14] .github: create separate workflow to build CLI/image There's too much jobs in Tests workflow, so we can split them into several parts. --- .github/workflows/build.yml | 80 +++++++++++++++++++++++++++++++++ .github/workflows/run_tests.yml | 65 --------------------------- 2 files changed, 80 insertions(+), 65 deletions(-) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 000000000..7e91de926 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,80 @@ +name: Build + +on: + pull_request: + branches: + - master + types: [opened, synchronize] + paths-ignore: + - 'scripts/**' + - '**/*.md' + workflow_dispatch: + +env: + GO111MODULE: "on" + +jobs: + build_cli_ubuntu: + name: Build CLI (Ubuntu) + runs-on: ubuntu-20.04 + + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.17 + + - name: Restore Go modules from cache + uses: actions/cache@v2 + with: + path: /home/runner/go/pkg/mod + key: deps-${{ hashFiles('go.sum') }} + + - name: Update Go modules + run: go mod download -json + + - name: Build CLI + run: make build + + build_cli_win: + name: Build CLI (Windows) + runs-on: windows-2019 + + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.17 + + - name: Restore Go modules from cache + uses: actions/cache@v2 + with: + path: /home/runner/go/pkg/mod + key: deps-${{ hashFiles('go.sum') }} + + - name: Update Go modules + run: go mod download -json + + - name: Build CLI + run: make build + + build_image: + needs: build_cli_ubuntu + name: Build Docker image + runs-on: ubuntu-20.04 + + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Build Docker image + run: make image diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index b6bc40852..95585515c 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -128,68 +128,3 @@ jobs: - name: Run tests run: go test -v -race ./... - - build_cli_ubuntu: - name: Build CLI (Ubuntu) - runs-on: ubuntu-20.04 - - steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: 1.17 - - - name: Restore Go modules from cache - uses: actions/cache@v2 - with: - path: /home/runner/go/pkg/mod - key: deps-${{ hashFiles('go.sum') }} - - - name: Update Go modules - run: go mod download -json - - - name: Build CLI - run: make build - - build_cli_win: - name: Build CLI (Windows) - runs-on: windows-2019 - - steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: 1.17 - - - name: Restore Go modules from cache - uses: actions/cache@v2 - with: - path: /home/runner/go/pkg/mod - key: deps-${{ hashFiles('go.sum') }} - - - name: Update Go modules - run: go mod download -json - - - name: Build CLI - run: make build - - build_image: - needs: build_cli_ubuntu - name: Build Docker image - runs-on: ubuntu-20.04 - - steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - - name: Build Docker image - run: make image From e64a6178440e5c24e051c8c224301f1f2fa4a667 Mon Sep 17 00:00:00 2001 From: AnnaShaleva Date: Fri, 19 Nov 2021 15:23:51 +0300 Subject: [PATCH 12/14] .github: add action to build WSC image --- .docker/privnet-entrypoint.ps1 | 15 ++++++++++++++ .github/workflows/build.yml | 23 ++++++++++++++++----- .github/workflows/run_tests.yml | 6 +++--- Dockerfile.wsc | 36 +++++++++++++++++++++++++++++++++ Makefile | 8 ++++++-- 5 files changed, 78 insertions(+), 10 deletions(-) create mode 100644 .docker/privnet-entrypoint.ps1 create mode 100644 Dockerfile.wsc diff --git a/.docker/privnet-entrypoint.ps1 b/.docker/privnet-entrypoint.ps1 new file mode 100644 index 000000000..94cd4fc99 --- /dev/null +++ b/.docker/privnet-entrypoint.ps1 @@ -0,0 +1,15 @@ +#!C:\Program Files\PowerShell\7\pwsh.EXE -File + +$bin = '/usr/bin/neo-go.exe' + +for ( $i = 0; $i -lt $args.count; $i++ ) { + if ($args[$i] -eq "node"){ + Write-Host "=> Try to restore blocks before running node" + if (($Env:ACC -ne $null) -and (Test-Path $Env:ACC -PathType Leaf)) { + & $bin db restore -p --config-path /config -i $Env:ACC + } + break + } +} + +& $bin $args diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7e91de926..27d4f338f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -40,9 +40,9 @@ jobs: - name: Build CLI run: make build - build_cli_win: - name: Build CLI (Windows) - runs-on: windows-2019 + build_cli_wsc: + name: Build CLI (Windows Server Core) + runs-on: windows-2022 steps: - uses: actions/checkout@v2 @@ -66,9 +66,9 @@ jobs: - name: Build CLI run: make build - build_image: + build_image_ubuntu: needs: build_cli_ubuntu - name: Build Docker image + name: Build Docker image (Ubuntu) runs-on: ubuntu-20.04 steps: @@ -78,3 +78,16 @@ jobs: - name: Build Docker image run: make image + + build_image_wsc: + needs: build_cli_wsc + name: Build Docker image (Windows Server Core) + runs-on: windows-2022 + + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Build Docker image + run: make image-wsc diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index 95585515c..4d434a19c 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -99,9 +99,9 @@ jobs: - name: Run tests run: go test -v -race ./... - tests_win: - name: Windows, Go (1.17) - runs-on: windows-2019 + tests_wsc: + name: Windows Server Core, Go (1.17) + runs-on: windows-2022 steps: - uses: actions/checkout@v2 with: diff --git a/Dockerfile.wsc b/Dockerfile.wsc new file mode 100644 index 000000000..6ed9760ab --- /dev/null +++ b/Dockerfile.wsc @@ -0,0 +1,36 @@ +# Builder image +FROM golang:windowsservercore-ltsc2022 as builder + +COPY . /neo-go + +WORKDIR /neo-go + +ARG REPO=repository +ARG VERSION=dev + +SHELL ["cmd", "/S", "/C"] +RUN go env -w CGO_ENABLED=0 +ENV GOGC=off + +RUN go build -trimpath -v -o ./bin/neo-go.exe -ldflags="-X %REPO%/pkg/config.Version=%VERSION%" ./cli/main.go + +# Executable image +FROM mcr.microsoft.com/windows/servercore:ltsc2022 + +ARG VERSION +LABEL version=%VERSION% + +WORKDIR / + +COPY --from=builder /neo-go/config /config +COPY --from=builder /neo-go/.docker/privnet-entrypoint.ps1 /usr/bin/privnet-entrypoint.ps1 +COPY --from=builder /neo-go/bin/neo-go.exe /usr/bin/neo-go.exe + +SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop';", "$ProgressPreference = 'SilentlyContinue';"] + +# Check executable version. +RUN /usr/bin/neo-go.exe --version + +ENTRYPOINT ["powershell", "-File", "/usr/bin/privnet-entrypoint.ps1"] + +CMD ["node", "--config-path", "/config", "--privnet"] diff --git a/Makefile b/Makefile index 60fc274d6..0ca1116a7 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ IMAGE_REPO=nspccdev/neo-go # All of the targets are phony here because we don't really use make dependency # tracking for files -.PHONY: build deps image image-latest image-push image-push-latest check-version clean-cluster push-tag \ +.PHONY: build deps image image-wsc image-latest image-push image-push-latest check-version clean-cluster push-tag \ test vet lint fmt cover build: deps @@ -49,9 +49,13 @@ postinst: install && systemctl enable neo-go.service image: deps - @echo "=> Building image" + @echo "=> Building image for Ubuntu" @docker build -t $(IMAGE_REPO):$(VERSION) --build-arg REPO=$(REPO) --build-arg VERSION=$(VERSION) . +image-wsc: deps + @echo "=> Building image for Windows Server Core" + @docker build -f Dockerfile.wsc -t $(IMAGE_REPO):$(VERSION)_WindowsServerCore --build-arg REPO=$(REPO) --build-arg VERSION=$(VERSION) . + image-latest: deps @echo "=> Building image with 'latest' tag" @docker build -t $(IMAGE_REPO):latest --build-arg REPO=$(REPO) --build-arg VERSION=$(VERSION) . From d2d75b8ba556c02d9c174098878c31d3a193f6fd Mon Sep 17 00:00:00 2001 From: AnnaShaleva Date: Thu, 25 Nov 2021 10:53:33 +0300 Subject: [PATCH 13/14] .github: unify Tests workflow --- .github/workflows/run_tests.yml | 46 +++++++++------------------------ 1 file changed, 12 insertions(+), 34 deletions(-) diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index 4d434a19c..b7e6c81a3 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -65,12 +65,20 @@ jobs: path_to_write_report: ./coverage.txt verbose: true - tests_ubuntu: - name: Ubuntu, Go - runs-on: ubuntu-20.04 + tests: + name: Run tests + runs-on: ${{ matrix.os }} strategy: matrix: - go_versions: [ '1.15', '1.16' ] + os: [ubuntu-20.04, windows-2022] + go_versions: [ '1.15', '1.16', '1.17' ] + exclude: + - os: windows-2022 + go_versions: '1.15' + - os: windows-2022 + go_versions: '1.16' + - os: ubuntu-20.04 + go_versions: '1.17' fail-fast: false steps: - uses: actions/checkout@v2 @@ -98,33 +106,3 @@ jobs: - name: Run tests run: go test -v -race ./... - - tests_wsc: - name: Windows Server Core, Go (1.17) - runs-on: windows-2022 - steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: 1.17 - - - name: Restore Go modules from cache - uses: actions/cache@v2 - with: - path: /home/runner/go/pkg/mod - key: deps-${{ hashFiles('go.sum') }} - - - name: Update Go modules - run: go mod download -json - - - name: Sync VM submodule - run: | - git submodule sync - git submodule update --init - - - name: Run tests - run: go test -v -race ./... From 5ef9f4498ebdbed31ed1491b1cae4e0a9ba24cdc Mon Sep 17 00:00:00 2001 From: AnnaShaleva Date: Thu, 25 Nov 2021 11:32:44 +0300 Subject: [PATCH 14/14] .github: add job to publish image for WSC Also, remove Go setup from publishing jobs because we don't need Go on runner. --- .github/workflows/publish_to_dockerhub.yml | 106 +++++++++++++++++---- Makefile | 10 +- 2 files changed, 92 insertions(+), 24 deletions(-) diff --git a/.github/workflows/publish_to_dockerhub.yml b/.github/workflows/publish_to_dockerhub.yml index 741d9acff..8e3b5e7fa 100644 --- a/.github/workflows/publish_to_dockerhub.yml +++ b/.github/workflows/publish_to_dockerhub.yml @@ -15,11 +15,11 @@ on: workflow_dispatch: inputs: ref: - description: 'Ref to build Docker image [default: latest master; examples: v0.92.0, 0a4ff9d3e4a9ab432fd5812eb18c98e03b5a7432]' + description: 'Ref to build Docker images for Ubuntu and Windows Server Core [default: latest master; examples: v0.92.0, 0a4ff9d3e4a9ab432fd5812eb18c98e03b5a7432]' required: false default: '' push_image: - description: 'Push image to DockerHub [default: false; examples: true, false]' + description: 'Push images to DockerHub [default: false; examples: true, false]' required: false default: 'false' @@ -29,8 +29,8 @@ env: # A workflow run. jobs: - test: - name: Run tests before publishing + tests_ubuntu: + name: Run Ubuntu-based tests before publishing runs-on: ubuntu-20.04 steps: @@ -70,10 +70,10 @@ jobs: - name: Run tests run: make test - publish: + publish_ubuntu: # Ensure test job passes before pushing image. - needs: test - name: Publish image to DockerHub + needs: tests_ubuntu + name: Publish Ubuntu-based image to DockerHub runs-on: ubuntu-20.04 steps: - name: Checkout (manual run) @@ -91,20 +91,6 @@ jobs: # Allows to fetch all history for all branches and tags. Need this for proper versioning. fetch-depth: 0 - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: 1.17 - - - name: Restore go modules from cache - uses: actions/cache@v2 - with: - path: /home/runner/go/pkg/mod - key: deps-${{ hashFiles('go.sum') }} - - - name: Update Go modules - run: go mod download -json - - name: Build image run: make image @@ -125,3 +111,81 @@ jobs: - name: Push image with 'latest' tag to registry if: ${{ github.event_name == 'release' && github.event.release.target_commitish == 'master' }} run: make image-push-latest + + tests_wsc: + name: Run WindowsServerCore-based tests before publishing + runs-on: windows-2022 + + steps: + - name: Checkout (manual run) + if: ${{ github.event_name == 'workflow_dispatch' }} + uses: actions/checkout@v2 + with: + ref: ${{ github.event.inputs.ref }} + # Allows to fetch all history for all branches and tags. Need this for proper versioning. + fetch-depth: 0 + + - name: Checkout (automatical run) + if: ${{ github.event_name != 'workflow_dispatch' }} + uses: actions/checkout@v2 + with: + # Allows to fetch all history for all branches and tags. Need this for proper versioning. + fetch-depth: 0 + + - name: Sync VM submodule + run: | + git submodule sync + git submodule update --init + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.17 + + - name: Restore go modules from cache + uses: actions/cache@v2 + with: + path: /home/runner/go/pkg/mod + key: deps-${{ hashFiles('go.sum') }} + + - name: Update Go modules + run: go mod download -json + + - name: Run tests + run: make test + publish_wsc: + # Ensure test job passes before pushing image. + # TODO: currently test_wsc job is failing, so we have `always()` condition. + # After #2269 and #2268 this condition should be removed. + if: ${{ always() }} + needs: tests_wsc + name: Publish WindowsServerCore-based image to DockerHub + runs-on: windows-2022 + steps: + - name: Checkout (manual run) + if: ${{ github.event_name == 'workflow_dispatch' }} + uses: actions/checkout@v2 + with: + ref: ${{ github.event.inputs.ref }} + # Allows to fetch all history for all branches and tags. Need this for proper versioning. + fetch-depth: 0 + + - name: Checkout (automatical run) + if: ${{ github.event_name != 'workflow_dispatch' }} + uses: actions/checkout@v2 + with: + # Allows to fetch all history for all branches and tags. Need this for proper versioning. + fetch-depth: 0 + + - name: Build image + run: make image-wsc + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + + - name: Push image to registry + if: ${{ github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.push_image == 'true') }} + run: make image-wsc-push diff --git a/Makefile b/Makefile index 0ca1116a7..2099b5248 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ IMAGE_REPO=nspccdev/neo-go # All of the targets are phony here because we don't really use make dependency # tracking for files -.PHONY: build deps image image-wsc image-latest image-push image-push-latest check-version clean-cluster push-tag \ +.PHONY: build deps image image-wsc image-latest image-push image-wsc-push image-push-latest check-version clean-cluster push-tag \ test vet lint fmt cover build: deps @@ -61,11 +61,15 @@ image-latest: deps @docker build -t $(IMAGE_REPO):latest --build-arg REPO=$(REPO) --build-arg VERSION=$(VERSION) . image-push: - @echo "=> Publish image" + @echo "=> Publish image for Ubuntu" @docker push $(IMAGE_REPO):$(VERSION) +image-wsc-push: + @echo "=> Publish image for Windows Server Core" + @docker push $(IMAGE_REPO):$(VERSION)_WindowsServerCore + image-push-latest: - @echo "=> Publish image with 'latest' tag" + @echo "=> Publish image for Ubuntu with 'latest' tag" @docker push $(IMAGE_REPO):latest check-version: