Merge pull request #2147 from nspcc-dev/drop-go-1.14

Drop Go 1.14, use 1.17
This commit is contained in:
Roman Khimov 2021-08-26 17:59:21 +03:00 committed by GitHub
commit 734eef3290
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 168 additions and 373 deletions

View file

@ -3,11 +3,6 @@ orbs:
codecov: codecov/codecov@1.0.5 codecov: codecov/codecov@1.0.5
executors: executors:
go1_14:
docker:
- image: circleci/golang:1.14
environment:
GO111MODULE: "on"
go1_15: go1_15:
docker: docker:
- image: circleci/golang:1.15 - image: circleci/golang:1.15
@ -18,6 +13,9 @@ executors:
- image: circleci/golang:1.16 - image: circleci/golang:1.16
environment: environment:
GO111MODULE: "on" GO111MODULE: "on"
go1_17:
docker:
- image: circleci/golang:1.17
commands: commands:
gomod: gomod:
@ -34,7 +32,7 @@ commands:
jobs: jobs:
lint: lint:
working_directory: /go/src/github.com/nspcc-dev/neo-go working_directory: /go/src/github.com/nspcc-dev/neo-go
executor: go1_16 executor: go1_17
steps: steps:
- checkout - checkout
- gomod - gomod
@ -44,15 +42,6 @@ jobs:
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.40.0 curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.40.0
make lint make lint
test_1_14:
working_directory: /go/src/github.com/nspcc-dev/neo-go
executor: go1_14
steps:
- checkout
- run: git submodule sync
- run: git submodule update --init
- gomod
- run: go test -v -race ./...
test_1_15: test_1_15:
working_directory: /go/src/github.com/nspcc-dev/neo-go working_directory: /go/src/github.com/nspcc-dev/neo-go
executor: go1_15 executor: go1_15
@ -63,9 +52,19 @@ jobs:
- gomod - gomod
- run: go test -v -race ./... - run: go test -v -race ./...
test_cover: test_1_16:
working_directory: /go/src/github.com/nspcc-dev/neo-go working_directory: /go/src/github.com/nspcc-dev/neo-go
executor: go1_16 executor: go1_16
steps:
- checkout
- run: git submodule sync
- run: git submodule update --init
- gomod
- run: go test -v -race ./...
test_cover:
working_directory: /go/src/github.com/nspcc-dev/neo-go
executor: go1_17
environment: environment:
CGO_ENABLED: 0 CGO_ENABLED: 0
steps: steps:
@ -79,7 +78,7 @@ jobs:
build_cli: build_cli:
working_directory: /go/src/github.com/nspcc-dev/neo-go working_directory: /go/src/github.com/nspcc-dev/neo-go
executor: go1_16 executor: go1_17
steps: steps:
- checkout - checkout
- gomod - gomod
@ -90,7 +89,7 @@ jobs:
build_image: build_image:
working_directory: /go/src/github.com/nspcc-dev/neo-go working_directory: /go/src/github.com/nspcc-dev/neo-go
executor: go1_16 executor: go1_17
docker: docker:
- image: golang:1-alpine - image: golang:1-alpine
steps: steps:
@ -118,11 +117,11 @@ workflows:
filters: filters:
tags: tags:
only: v/[0-9]+\.[0-9]+\.[0-9]+/ only: v/[0-9]+\.[0-9]+\.[0-9]+/
- test_1_14: - test_1_15:
filters: filters:
tags: tags:
only: v/[0-9]+\.[0-9]+\.[0-9]+/ only: v/[0-9]+\.[0-9]+\.[0-9]+/
- test_1_15: - test_1_16:
filters: filters:
tags: tags:
only: v/[0-9]+\.[0-9]+\.[0-9]+/ only: v/[0-9]+\.[0-9]+\.[0-9]+/

View file

@ -57,7 +57,7 @@ jobs:
- name: Set up Go - name: Set up Go
uses: actions/setup-go@v2 uses: actions/setup-go@v2
with: with:
go-version: 1.16 go-version: 1.17
- name: Restore go modules from cache - name: Restore go modules from cache
uses: actions/cache@v2 uses: actions/cache@v2
@ -94,7 +94,7 @@ jobs:
- name: Set up Go - name: Set up Go
uses: actions/setup-go@v2 uses: actions/setup-go@v2
with: with:
go-version: 1.16 go-version: 1.17
- name: Restore go modules from cache - name: Restore go modules from cache
uses: actions/cache@v2 uses: actions/cache@v2

View file

@ -44,7 +44,7 @@ jobs:
- name: Set up Go - name: Set up Go
uses: actions/setup-go@v2 uses: actions/setup-go@v2
with: with:
go-version: 1.16 go-version: 1.17
- name: Restore Go modules from cache - name: Restore Go modules from cache
uses: actions/cache@v2 uses: actions/cache@v2
@ -70,7 +70,7 @@ jobs:
runs-on: ubuntu-18.04 runs-on: ubuntu-18.04
strategy: strategy:
matrix: matrix:
go_versions: [ '1.14', '1.15', '1.16' ] go_versions: [ '1.15', '1.16' ]
fail-fast: false fail-fast: false
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
@ -111,7 +111,7 @@ jobs:
- name: Set up Go - name: Set up Go
uses: actions/setup-go@v2 uses: actions/setup-go@v2
with: with:
go-version: 1.16 go-version: 1.17
- name: Restore Go modules from cache - name: Restore Go modules from cache
uses: actions/cache@v2 uses: actions/cache@v2
@ -138,7 +138,7 @@ jobs:
- name: Set up Go - name: Set up Go
uses: actions/setup-go@v2 uses: actions/setup-go@v2
with: with:
go-version: 1.16 go-version: 1.17
- name: Restore Go modules from cache - name: Restore Go modules from cache
uses: actions/cache@v2 uses: actions/cache@v2

View file

@ -1,6 +1,6 @@
language: go language: go
go: go:
- 1.14.x - 1.15.x
env: env:
- GO111MODULE=on - GO111MODULE=on
install: install:

View file

@ -48,7 +48,7 @@ NeoGo, `:latest` points to the latest release) or build yourself.
### Building ### Building
To build NeoGo you need Go 1.14+ and `make`: To build NeoGo you need Go 1.15+ and `make`:
``` ```
make build make build

View file

@ -28,6 +28,7 @@ import (
) )
func TestCalcHash(t *testing.T) { func TestCalcHash(t *testing.T) {
tmpDir := t.TempDir()
e := newExecutor(t, false) e := newExecutor(t, false)
nefPath := "./testdata/verify.nef" nefPath := "./testdata/verify.nef"
@ -58,13 +59,9 @@ func TestCalcHash(t *testing.T) {
"--in", "./testdata/verify.nef123", "--manifest", manifestPath)...) "--in", "./testdata/verify.nef123", "--manifest", manifestPath)...)
}) })
t.Run("invalid file", func(t *testing.T) { t.Run("invalid file", func(t *testing.T) {
p, err := ioutil.TempFile("", "neogo.calchash.verify.nef") p := path.Join(tmpDir, "neogo.calchash.verify.nef")
require.NoError(t, err) require.NoError(t, ioutil.WriteFile(p, src[:4], os.ModePerm))
t.Cleanup(func() { e.RunWithError(t, append(cmd, "--sender", sender.StringLE(), "--in", p, "--manifest", manifestPath)...)
os.Remove(p.Name())
})
require.NoError(t, ioutil.WriteFile(p.Name(), src[:4], os.ModePerm))
e.RunWithError(t, append(cmd, "--sender", sender.StringLE(), "--in", p.Name(), "--manifest", manifestPath)...)
}) })
cmd = append(cmd, "--in", nefPath, "--manifest", manifestPath) cmd = append(cmd, "--in", nefPath, "--manifest", manifestPath)
@ -84,12 +81,7 @@ func TestCalcHash(t *testing.T) {
} }
func TestContractInitAndCompile(t *testing.T) { func TestContractInitAndCompile(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "neogo.inittest") tmpDir := t.TempDir()
require.NoError(t, err)
t.Cleanup(func() {
os.RemoveAll(tmpDir)
})
e := newExecutor(t, false) e := newExecutor(t, false)
t.Run("no path is provided", func(t *testing.T) { t.Run("no path is provided", func(t *testing.T) {
@ -148,12 +140,7 @@ func TestDeployBigContract(t *testing.T) {
// For proper nef generation. // For proper nef generation.
config.Version = "0.90.0-test" config.Version = "0.90.0-test"
tmpDir := t.TempDir()
tmpDir, err := ioutil.TempDir("", "neogo.test.deployfail")
require.NoError(t, err)
t.Cleanup(func() {
os.RemoveAll(tmpDir)
})
nefName := path.Join(tmpDir, "deploy.nef") nefName := path.Join(tmpDir, "deploy.nef")
manifestName := path.Join(tmpDir, "deploy.manifest.json") manifestName := path.Join(tmpDir, "deploy.manifest.json")
@ -174,12 +161,7 @@ func TestContractDeployWithData(t *testing.T) {
// For proper nef generation. // For proper nef generation.
config.Version = "0.90.0-test" config.Version = "0.90.0-test"
tmpDir := t.TempDir()
tmpDir, err := ioutil.TempDir("", "neogo.test.deployfail")
require.NoError(t, err)
t.Cleanup(func() {
os.RemoveAll(tmpDir)
})
nefName := path.Join(tmpDir, "deploy.nef") nefName := path.Join(tmpDir, "deploy.nef")
manifestName := path.Join(tmpDir, "deploy.manifest.json") manifestName := path.Join(tmpDir, "deploy.manifest.json")
@ -232,12 +214,7 @@ func TestContractManifestGroups(t *testing.T) {
// For proper nef generation. // For proper nef generation.
config.Version = "0.90.0-test" config.Version = "0.90.0-test"
tmpDir := t.TempDir()
tmpDir, err := ioutil.TempDir("", "neogo.test.deployfail")
require.NoError(t, err)
t.Cleanup(func() {
os.RemoveAll(tmpDir)
})
w, err := wallet.NewWalletFromFile(testWalletPath) w, err := wallet.NewWalletFromFile(testWalletPath)
require.NoError(t, err) require.NoError(t, err)
@ -273,11 +250,7 @@ func deployVerifyContract(t *testing.T, e *executor) util.Uint160 {
} }
func deployContract(t *testing.T, e *executor, inPath, configPath, wallet, address, pass string) util.Uint160 { func deployContract(t *testing.T, e *executor, inPath, configPath, wallet, address, pass string) util.Uint160 {
tmpDir, err := ioutil.TempDir(os.TempDir(), "neogo.test.deploycontract*") tmpDir := t.TempDir()
require.NoError(t, err)
t.Cleanup(func() {
os.RemoveAll(tmpDir)
})
nefName := path.Join(tmpDir, "contract.nef") nefName := path.Join(tmpDir, "contract.nef")
manifestName := path.Join(tmpDir, "contract.manifest.json") manifestName := path.Join(tmpDir, "contract.manifest.json")
e.Run(t, "neo-go", "contract", "compile", e.Run(t, "neo-go", "contract", "compile",
@ -303,12 +276,7 @@ func TestComlileAndInvokeFunction(t *testing.T) {
// For proper nef generation. // For proper nef generation.
config.Version = "0.90.0-test" config.Version = "0.90.0-test"
tmpDir := t.TempDir()
tmpDir, err := ioutil.TempDir("", "neogo.test.compileandinvoke")
require.NoError(t, err)
t.Cleanup(func() {
os.RemoveAll(tmpDir)
})
nefName := path.Join(tmpDir, "deploy.nef") nefName := path.Join(tmpDir, "deploy.nef")
manifestName := path.Join(tmpDir, "deploy.manifest.json") manifestName := path.Join(tmpDir, "deploy.manifest.json")
@ -556,12 +524,7 @@ func TestContractInspect(t *testing.T) {
// For proper nef generation. // For proper nef generation.
config.Version = "0.90.0-test" config.Version = "0.90.0-test"
const srcPath = "testdata/deploy/main.go" const srcPath = "testdata/deploy/main.go"
tmpDir := t.TempDir()
tmpDir, err := ioutil.TempDir("", "neogo.test.contract.inspect")
require.NoError(t, err)
t.Cleanup(func() {
os.RemoveAll(tmpDir)
})
nefName := path.Join(tmpDir, "deploy.nef") nefName := path.Join(tmpDir, "deploy.nef")
manifestName := path.Join(tmpDir, "deploy.manifest.json") manifestName := path.Join(tmpDir, "deploy.manifest.json")
@ -588,6 +551,7 @@ func TestContractInspect(t *testing.T) {
} }
func TestCompileExamples(t *testing.T) { func TestCompileExamples(t *testing.T) {
tmpDir := t.TempDir()
const examplePath = "../examples" const examplePath = "../examples"
infos, err := ioutil.ReadDir(examplePath) infos, err := ioutil.ReadDir(examplePath)
require.NoError(t, err) require.NoError(t, err)
@ -608,21 +572,15 @@ func TestCompileExamples(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
require.False(t, len(infos) == 0, "detected smart contract folder with no contract in it") require.False(t, len(infos) == 0, "detected smart contract folder with no contract in it")
outF, err := ioutil.TempFile("", info.Name()+".nef") outF := path.Join(tmpDir, info.Name()+".nef")
require.NoError(t, err) manifestF := path.Join(tmpDir, info.Name()+".manifest.json")
manifestF, err := ioutil.TempFile("", info.Name()+".manifest.json")
require.NoError(t, err)
t.Cleanup(func() {
os.Remove(outF.Name())
os.Remove(manifestF.Name())
})
cfgName := filterFilename(infos, ".yml") cfgName := filterFilename(infos, ".yml")
opts := []string{ opts := []string{
"neo-go", "contract", "compile", "neo-go", "contract", "compile",
"--in", path.Join(examplePath, info.Name()), "--in", path.Join(examplePath, info.Name()),
"--out", outF.Name(), "--out", outF,
"--manifest", manifestF.Name(), "--manifest", manifestF,
"--config", path.Join(examplePath, info.Name(), cfgName), "--config", path.Join(examplePath, info.Name(), cfgName),
} }
e.Run(t, opts...) e.Run(t, opts...)
@ -632,18 +590,12 @@ func TestCompileExamples(t *testing.T) {
t.Run("invalid events in manifest", func(t *testing.T) { t.Run("invalid events in manifest", func(t *testing.T) {
const dir = "./testdata/" const dir = "./testdata/"
for _, name := range []string{"invalid1", "invalid2", "invalid3"} { for _, name := range []string{"invalid1", "invalid2", "invalid3"} {
outF, err := ioutil.TempFile("", name+".nef") outF := path.Join(tmpDir, name+".nef")
require.NoError(t, err) manifestF := path.Join(tmpDir, name+".manifest.json")
manifestF, err := ioutil.TempFile("", name+".manifest.json")
require.NoError(t, err)
t.Cleanup(func() {
os.Remove(outF.Name())
os.Remove(manifestF.Name())
})
e.RunWithError(t, "neo-go", "contract", "compile", e.RunWithError(t, "neo-go", "contract", "compile",
"--in", path.Join(dir, name), "--in", path.Join(dir, name),
"--out", outF.Name(), "--out", outF,
"--manifest", manifestF.Name(), "--manifest", manifestF,
"--config", path.Join(dir, name, "invalid.yml"), "--config", path.Join(dir, name, "invalid.yml"),
) )
} }

View file

@ -12,11 +12,7 @@ import (
) )
func TestDBRestore(t *testing.T) { func TestDBRestore(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "neogo.restoretest") tmpDir := t.TempDir()
require.NoError(t, err)
t.Cleanup(func() {
os.RemoveAll(tmpDir)
})
chainPath := path.Join(tmpDir, "neogotestchain") chainPath := path.Join(tmpDir, "neogotestchain")
cfg, err := config.LoadFile("../config/protocol.unit_testnet.yml") cfg, err := config.LoadFile("../config/protocol.unit_testnet.yml")

View file

@ -2,7 +2,6 @@ package main
import ( import (
"encoding/hex" "encoding/hex"
"io/ioutil"
"math/big" "math/big"
"os" "os"
"path" "path"
@ -28,13 +27,9 @@ func TestSignMultisigTx(t *testing.T) {
multisigAddr := address.Uint160ToString(multisigHash) multisigAddr := address.Uint160ToString(multisigHash)
// Create 2 wallets participating in multisig. // Create 2 wallets participating in multisig.
tmpDir, err := ioutil.TempDir("", "neogo.wallettest") tmpDir := t.TempDir()
require.NoError(t, err)
wallet1Path := path.Join(tmpDir, "multiWallet1.json") wallet1Path := path.Join(tmpDir, "multiWallet1.json")
wallet2Path := path.Join(tmpDir, "multiWallet2.json") wallet2Path := path.Join(tmpDir, "multiWallet2.json")
t.Cleanup(func() {
os.RemoveAll(tmpDir)
})
addAccount := func(w string, wif string) { addAccount := func(w string, wif string) {
e.Run(t, "neo-go", "wallet", "init", "--wallet", w) e.Run(t, "neo-go", "wallet", "init", "--wallet", w)

View file

@ -6,7 +6,6 @@ import (
"io" "io"
"io/ioutil" "io/ioutil"
"math/big" "math/big"
"os"
"path" "path"
"strings" "strings"
"testing" "testing"
@ -31,10 +30,8 @@ const (
func TestNEP11Import(t *testing.T) { func TestNEP11Import(t *testing.T) {
e := newExecutor(t, true) e := newExecutor(t, true)
tmpDir, err := ioutil.TempDir("", "neogo.nep11import") tmpDir := t.TempDir()
require.NoError(t, err)
walletPath := path.Join(tmpDir, "walletForImport.json") walletPath := path.Join(tmpDir, "walletForImport.json")
t.Cleanup(func() { os.RemoveAll(tmpDir) })
// deploy NFT NeoNameService contract // deploy NFT NeoNameService contract
nnsContractHash := deployNNSContract(t, e) nnsContractHash := deployNNSContract(t, e)
@ -93,12 +90,7 @@ func TestNEP11Import(t *testing.T) {
func TestNEP11_OwnerOf_BalanceOf_Transfer(t *testing.T) { func TestNEP11_OwnerOf_BalanceOf_Transfer(t *testing.T) {
e := newExecutor(t, true) e := newExecutor(t, true)
tmpDir := t.TempDir()
tmpDir, err := ioutil.TempDir(os.TempDir(), "neogo.test.nftwallet*")
require.NoError(t, err)
t.Cleanup(func() {
os.RemoveAll(tmpDir)
})
// copy wallet to temp dir in order not to overwrite the original file // copy wallet to temp dir in order not to overwrite the original file
bytesRead, err := ioutil.ReadFile(nftOwnerWallet) bytesRead, err := ioutil.ReadFile(nftOwnerWallet)

View file

@ -2,9 +2,7 @@ package main
import ( import (
"io" "io"
"io/ioutil"
"math/big" "math/big"
"os"
"path" "path"
"strconv" "strconv"
"strings" "strings"
@ -260,10 +258,7 @@ func TestNEP17MultiTransfer(t *testing.T) {
func TestNEP17ImportToken(t *testing.T) { func TestNEP17ImportToken(t *testing.T) {
e := newExecutor(t, true) e := newExecutor(t, true)
tmpDir := t.TempDir()
tmpDir, err := ioutil.TempDir("", "neogo.nep17import")
require.NoError(t, err)
t.Cleanup(func() { os.RemoveAll(tmpDir) })
walletPath := path.Join(tmpDir, "walletForImport.json") walletPath := path.Join(tmpDir, "walletForImport.json")
neoContractHash, err := e.Chain.GetNativeContractScriptHash(nativenames.Neo) neoContractHash, err := e.Chain.GetNativeContractScriptHash(nativenames.Neo)

View file

@ -1,8 +1,6 @@
package server package server
import ( import (
"io/ioutil"
"os"
"path" "path"
"testing" "testing"
@ -10,12 +8,7 @@ import (
) )
func TestGetPath(t *testing.T) { func TestGetPath(t *testing.T) {
testPath, err := ioutil.TempDir("./", "") testPath := t.TempDir()
require.NoError(t, err)
t.Cleanup(func() {
err := os.RemoveAll(testPath)
require.NoError(t, err)
})
actual, err := getPath(testPath, 123) actual, err := getPath(testPath, 123)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, path.Join(testPath, "/BlockStorage_100000/dump-block-1000.json"), actual) require.Equal(t, path.Join(testPath, "/BlockStorage_100000/dump-block-1000.json"), actual)

View file

@ -2,8 +2,8 @@ package server
import ( import (
"flag" "flag"
"io/ioutil"
"os" "os"
"path"
"testing" "testing"
"github.com/nspcc-dev/neo-go/pkg/config" "github.com/nspcc-dev/neo-go/pkg/config"
@ -16,6 +16,17 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
) )
// serverTestWD is the default working directory for server tests.
var serverTestWD string
func init() {
var err error
serverTestWD, err = os.Getwd()
if err != nil {
panic("can't get current working directory")
}
}
func TestGetConfigFromContext(t *testing.T) { func TestGetConfigFromContext(t *testing.T) {
set := flag.NewFlagSet("flagSet", flag.ExitOnError) set := flag.NewFlagSet("flagSet", flag.ExitOnError)
set.String("config-path", "../../config", "") set.String("config-path", "../../config", "")
@ -27,17 +38,14 @@ func TestGetConfigFromContext(t *testing.T) {
} }
func TestHandleLoggingParams(t *testing.T) { func TestHandleLoggingParams(t *testing.T) {
testLog, err := ioutil.TempFile("./", "*.log") d := t.TempDir()
require.NoError(t, err) testLog := path.Join(d, "file.log")
t.Cleanup(func() {
require.NoError(t, os.Remove(testLog.Name()))
})
t.Run("default", func(t *testing.T) { t.Run("default", func(t *testing.T) {
set := flag.NewFlagSet("flagSet", flag.ExitOnError) set := flag.NewFlagSet("flagSet", flag.ExitOnError)
ctx := cli.NewContext(cli.NewApp(), set, nil) ctx := cli.NewContext(cli.NewApp(), set, nil)
cfg := config.ApplicationConfiguration{ cfg := config.ApplicationConfiguration{
LogPath: testLog.Name(), LogPath: testLog,
} }
logger, err := handleLoggingParams(ctx, cfg) logger, err := handleLoggingParams(ctx, cfg)
require.NoError(t, err) require.NoError(t, err)
@ -50,7 +58,7 @@ func TestHandleLoggingParams(t *testing.T) {
set.Bool("debug", true, "") set.Bool("debug", true, "")
ctx := cli.NewContext(cli.NewApp(), set, nil) ctx := cli.NewContext(cli.NewApp(), set, nil)
cfg := config.ApplicationConfiguration{ cfg := config.ApplicationConfiguration{
LogPath: testLog.Name(), LogPath: testLog,
} }
logger, err := handleLoggingParams(ctx, cfg) logger, err := handleLoggingParams(ctx, cfg)
require.NoError(t, err) require.NoError(t, err)
@ -60,18 +68,13 @@ func TestHandleLoggingParams(t *testing.T) {
} }
func TestInitBCWithMetrics(t *testing.T) { func TestInitBCWithMetrics(t *testing.T) {
d, err := ioutil.TempDir("./", "") d := t.TempDir()
err := os.Chdir(d)
require.NoError(t, err) require.NoError(t, err)
err = os.Chdir(d) t.Cleanup(func() { require.NoError(t, os.Chdir(serverTestWD)) })
require.NoError(t, err)
t.Cleanup(func() {
err = os.Chdir("..")
require.NoError(t, err)
os.RemoveAll(d)
})
set := flag.NewFlagSet("flagSet", flag.ExitOnError) set := flag.NewFlagSet("flagSet", flag.ExitOnError)
set.String("config-path", "../../../config", "") set.String("config-path", path.Join(serverTestWD, "../../config"), "")
set.Bool("testnet", true, "") set.Bool("testnet", true, "")
set.Bool("debug", true, "") set.Bool("debug", true, "")
ctx := cli.NewContext(cli.NewApp(), set, nil) ctx := cli.NewContext(cli.NewApp(), set, nil)
@ -90,19 +93,15 @@ func TestInitBCWithMetrics(t *testing.T) {
} }
func TestDumpDB(t *testing.T) { func TestDumpDB(t *testing.T) {
testDump := "file.acc"
t.Run("too low chain", func(t *testing.T) { t.Run("too low chain", func(t *testing.T) {
d, err := ioutil.TempDir("./", "") d := t.TempDir()
err := os.Chdir(d)
require.NoError(t, err) require.NoError(t, err)
err = os.Chdir(d) t.Cleanup(func() { require.NoError(t, os.Chdir(serverTestWD)) })
require.NoError(t, err)
t.Cleanup(func() {
err = os.Chdir("..")
require.NoError(t, err)
os.RemoveAll(d)
})
testDump := "file.acc"
set := flag.NewFlagSet("flagSet", flag.ExitOnError) set := flag.NewFlagSet("flagSet", flag.ExitOnError)
set.String("config-path", "../../../config", "") set.String("config-path", path.Join(serverTestWD, "../../config"), "")
set.Bool("privnet", true, "") set.Bool("privnet", true, "")
set.Bool("debug", true, "") set.Bool("debug", true, "")
set.Int("start", 0, "") set.Int("start", 0, "")
@ -114,18 +113,12 @@ func TestDumpDB(t *testing.T) {
}) })
t.Run("positive", func(t *testing.T) { t.Run("positive", func(t *testing.T) {
d, err := ioutil.TempDir("./", "") d := t.TempDir()
err := os.Chdir(d)
require.NoError(t, err) require.NoError(t, err)
err = os.Chdir(d) t.Cleanup(func() { require.NoError(t, os.Chdir(serverTestWD)) })
require.NoError(t, err)
t.Cleanup(func() {
err = os.Chdir("..")
require.NoError(t, err)
os.RemoveAll(d)
})
testDump := "file.acc"
set := flag.NewFlagSet("flagSet", flag.ExitOnError) set := flag.NewFlagSet("flagSet", flag.ExitOnError)
set.String("config-path", "../../../config", "") set.String("config-path", path.Join(serverTestWD, "../../config"), "")
set.Bool("privnet", true, "") set.Bool("privnet", true, "")
set.Bool("debug", true, "") set.Bool("debug", true, "")
set.Int("start", 0, "") set.Int("start", 0, "")
@ -138,21 +131,16 @@ func TestDumpDB(t *testing.T) {
} }
func TestRestoreDB(t *testing.T) { func TestRestoreDB(t *testing.T) {
d, err := ioutil.TempDir("./", "") d := t.TempDir()
require.NoError(t, err)
testDump := "file1.acc" testDump := "file1.acc"
saveDump := "file2.acc" saveDump := "file2.acc"
err = os.Chdir(d) err := os.Chdir(d)
require.NoError(t, err) require.NoError(t, err)
t.Cleanup(func() { t.Cleanup(func() { require.NoError(t, os.Chdir(serverTestWD)) })
err = os.Chdir("..")
require.NoError(t, err)
os.RemoveAll(d)
})
//dump first //dump first
set := flag.NewFlagSet("flagSet", flag.ExitOnError) set := flag.NewFlagSet("flagSet", flag.ExitOnError)
set.String("config-path", "../../../config", "") set.String("config-path", path.Join(serverTestWD, "../../config"), "")
set.Bool("privnet", true, "") set.Bool("privnet", true, "")
set.Bool("debug", true, "") set.Bool("debug", true, "")
set.Int("start", 0, "") set.Int("start", 0, "")

View file

@ -16,15 +16,12 @@ import (
) )
func TestInitSmartContract(t *testing.T) { func TestInitSmartContract(t *testing.T) {
d, err := ioutil.TempDir("./", "") d := t.TempDir()
testWD, err := os.Getwd()
require.NoError(t, err) require.NoError(t, err)
err = os.Chdir(d) err = os.Chdir(d)
require.NoError(t, err) require.NoError(t, err)
t.Cleanup(func() { t.Cleanup(func() { require.NoError(t, os.Chdir(testWD)) })
err = os.Chdir("..")
require.NoError(t, err)
os.RemoveAll(d)
})
contractName := "testContract" contractName := "testContract"
set := flag.NewFlagSet("flagSet", flag.ExitOnError) set := flag.NewFlagSet("flagSet", flag.ExitOnError)

View file

@ -5,7 +5,6 @@ import (
"encoding/json" "encoding/json"
"io/ioutil" "io/ioutil"
"math/big" "math/big"
"os"
"path" "path"
"strings" "strings"
"testing" "testing"
@ -20,12 +19,7 @@ import (
) )
func TestWalletAccountRemove(t *testing.T) { func TestWalletAccountRemove(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "neogo.test.walletinit") tmpDir := t.TempDir()
require.NoError(t, err)
t.Cleanup(func() {
os.RemoveAll(tmpDir)
})
e := newExecutor(t, false) e := newExecutor(t, false)
walletPath := path.Join(tmpDir, "wallet.json") walletPath := path.Join(tmpDir, "wallet.json")
@ -52,12 +46,7 @@ func TestWalletAccountRemove(t *testing.T) {
} }
func TestWalletInit(t *testing.T) { func TestWalletInit(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "neogo.test.walletinit") tmpDir := t.TempDir()
require.NoError(t, err)
t.Cleanup(func() {
os.RemoveAll(tmpDir)
})
e := newExecutor(t, false) e := newExecutor(t, false)
walletPath := path.Join(tmpDir, "wallet.json") walletPath := path.Join(tmpDir, "wallet.json")
@ -268,15 +257,11 @@ func TestClaimGas(t *testing.T) {
} }
func TestImportDeployed(t *testing.T) { func TestImportDeployed(t *testing.T) {
tmpDir := t.TempDir()
e := newExecutor(t, true) e := newExecutor(t, true)
h := deployVerifyContract(t, e) h := deployVerifyContract(t, e)
tmpDir, err := ioutil.TempDir("", "neogo.importdeployed")
require.NoError(t, err)
t.Cleanup(func() {
os.Remove(tmpDir)
})
walletPath := path.Join(tmpDir, "wallet.json") walletPath := path.Join(tmpDir, "wallet.json")
e.Run(t, "neo-go", "wallet", "init", "--wallet", walletPath) e.Run(t, "neo-go", "wallet", "init", "--wallet", walletPath)
priv, err := keys.NewPrivateKey() priv, err := keys.NewPrivateKey()
@ -402,12 +387,7 @@ func TestDumpKeys(t *testing.T) {
// Testcase is the wallet of privnet validator. // Testcase is the wallet of privnet validator.
func TestWalletConvert(t *testing.T) { func TestWalletConvert(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "neogo.test.convert") tmpDir := t.TempDir()
require.NoError(t, err)
t.Cleanup(func() {
os.RemoveAll(tmpDir)
})
e := newExecutor(t, false) e := newExecutor(t, false)
outPath := path.Join(tmpDir, "wallet.json") outPath := path.Join(tmpDir, "wallet.json")

View file

@ -48,7 +48,7 @@ The compiler uses Go parser internally and depends on regular Go compiler
presence, so make sure you have it installed and set up. On some distributions presence, so make sure you have it installed and set up. On some distributions
this requires you to set proper `GOROOT` environment variable, like this requires you to set proper `GOROOT` environment variable, like
``` ```
export GOROOT=/usr/lib64/go/1.14 export GOROOT=/usr/lib64/go/1.15
``` ```
### Compiling ### Compiling

2
go.mod
View file

@ -31,4 +31,4 @@ require (
gopkg.in/yaml.v2 v2.4.0 gopkg.in/yaml.v2 v2.4.0
) )
go 1.14 go 1.15

View file

@ -2,8 +2,6 @@ package core
import ( import (
"errors" "errors"
"io/ioutil"
"os"
"path" "path"
"sort" "sort"
"testing" "testing"
@ -79,11 +77,7 @@ func TestStateRoot(t *testing.T) {
updateIndex := bc.BlockHeight() updateIndex := bc.BlockHeight()
transferTokenFromMultisigAccount(t, bc, h, bc.contracts.GAS.Hash, 1_0000_0000) transferTokenFromMultisigAccount(t, bc, h, bc.contracts.GAS.Hash, 1_0000_0000)
tmpDir, err := ioutil.TempDir("", "neogo.test.stateroot") tmpDir := t.TempDir()
require.NoError(t, err)
t.Cleanup(func() {
os.RemoveAll(tmpDir)
})
w := createAndWriteWallet(t, accs[0], path.Join(tmpDir, "w"), "pass") w := createAndWriteWallet(t, accs[0], path.Join(tmpDir, "w"), "pass")
cfg := createStateRootConfig(w.Path(), "pass") cfg := createStateRootConfig(w.Path(), "pass")
srv, err := stateroot.New(cfg, zaptest.NewLogger(t), bc, nil) srv, err := stateroot.New(cfg, zaptest.NewLogger(t), bc, nil)
@ -151,11 +145,7 @@ func TestStateRootInitNonZeroHeight(t *testing.T) {
_, err := persistBlock(bc) _, err := persistBlock(bc)
require.NoError(t, err) require.NoError(t, err)
tmpDir, err := ioutil.TempDir("", "neogo.initsnz") tmpDir := t.TempDir()
require.NoError(t, err)
t.Cleanup(func() {
os.RemoveAll(tmpDir)
})
w := createAndWriteWallet(t, accs[0], path.Join(tmpDir, "w"), "pass") w := createAndWriteWallet(t, accs[0], path.Join(tmpDir, "w"), "pass")
cfg := createStateRootConfig(w.Path(), "pass") cfg := createStateRootConfig(w.Path(), "pass")
srv, err := stateroot.New(cfg, zaptest.NewLogger(t), bc, nil) srv, err := stateroot.New(cfg, zaptest.NewLogger(t), bc, nil)
@ -195,12 +185,7 @@ func createStateRootConfig(walletPath, password string) config.StateRoot {
} }
func TestStateRootFull(t *testing.T) { func TestStateRootFull(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "neogo.stateroot4") tmpDir := t.TempDir()
require.NoError(t, err)
t.Cleanup(func() {
os.RemoveAll(tmpDir)
})
bc := newTestChain(t) bc := newTestChain(t)
h, pubs, accs := newMajorityMultisigWithGAS(t, 2) h, pubs, accs := newMajorityMultisigWithGAS(t, 2)

View file

@ -1,33 +1,13 @@
package storage package storage
import ( import (
"io/ioutil"
"os"
"testing" "testing"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
type tempBadgerDB struct {
*BadgerDBStore
dir string
}
func (tbdb *tempBadgerDB) Close() error {
err := tbdb.BadgerDBStore.Close()
// Make test fail if failed to cleanup, even though technically it's
// not a BadgerDBStore problem.
osErr := os.RemoveAll(tbdb.dir)
if osErr != nil {
return osErr
}
return err
}
func newBadgerDBForTesting(t *testing.T) Store { func newBadgerDBForTesting(t *testing.T) Store {
bdbDir, err := ioutil.TempDir(os.TempDir(), "testbadgerdb") bdbDir := t.TempDir()
require.Nil(t, err, "failed to setup temporary directory")
dbConfig := DBConfiguration{ dbConfig := DBConfiguration{
Type: "badgerdb", Type: "badgerdb",
BadgerDBOptions: BadgerDBOptions{ BadgerDBOptions: BadgerDBOptions{
@ -36,9 +16,5 @@ func newBadgerDBForTesting(t *testing.T) Store {
} }
newBadgerStore, err := NewBadgerDBStore(dbConfig.BadgerDBOptions) newBadgerStore, err := NewBadgerDBStore(dbConfig.BadgerDBOptions)
require.Nil(t, err, "NewBadgerDBStore error") require.Nil(t, err, "NewBadgerDBStore error")
tbdb := &tempBadgerDB{ return newBadgerStore
BadgerDBStore: newBadgerStore,
dir: bdbDir,
}
return tbdb
} }

View file

@ -1,23 +1,16 @@
package storage package storage
import ( import (
"io/ioutil" "path"
"os"
"testing" "testing"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
func newBoltStoreForTesting(t *testing.T) Store { func newBoltStoreForTesting(t *testing.T) Store {
testFileName := "test_bolt_db" d := t.TempDir()
file, err := ioutil.TempFile("", testFileName) testFileName := path.Join(d, "test_bolt_db")
t.Cleanup(func() { boltDBStore, err := NewBoltDBStore(BoltDBOptions{FilePath: testFileName})
err := os.RemoveAll(file.Name())
require.NoError(t, err)
})
require.NoError(t, err)
require.NoError(t, file.Close())
boltDBStore, err := NewBoltDBStore(BoltDBOptions{FilePath: file.Name()})
require.NoError(t, err) require.NoError(t, err)
return boltDBStore return boltDBStore
} }

View file

@ -1,33 +1,13 @@
package storage package storage
import ( import (
"io/ioutil"
"os"
"testing" "testing"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
type tempLevelDB struct {
LevelDBStore
dir string
}
func (tldb *tempLevelDB) Close() error {
err := tldb.LevelDBStore.Close()
// Make test fail if failed to cleanup, even though technically it's
// not a LevelDBStore problem.
osErr := os.RemoveAll(tldb.dir)
if osErr != nil {
return osErr
}
return err
}
func newLevelDBForTesting(t *testing.T) Store { func newLevelDBForTesting(t *testing.T) Store {
ldbDir, err := ioutil.TempDir(os.TempDir(), "testleveldb") ldbDir := t.TempDir()
require.Nil(t, err, "failed to setup temporary directory")
dbConfig := DBConfiguration{ dbConfig := DBConfiguration{
Type: "leveldb", Type: "leveldb",
LevelDBOptions: LevelDBOptions{ LevelDBOptions: LevelDBOptions{
@ -36,6 +16,5 @@ func newLevelDBForTesting(t *testing.T) Store {
} }
newLevelStore, err := NewLevelDBStore(dbConfig.LevelDBOptions) newLevelStore, err := NewLevelDBStore(dbConfig.LevelDBOptions)
require.Nil(t, err, "NewLevelDBStore error") require.Nil(t, err, "NewLevelDBStore error")
tldb := &tempLevelDB{LevelDBStore: *newLevelStore, dir: ldbDir} return newLevelStore
return tldb
} }

View file

@ -64,7 +64,7 @@ func NewPrivateKeyFromBytes(b []byte) (*PrivateKey, error) {
d = new(big.Int).SetBytes(b) d = new(big.Int).SetBytes(b)
) )
x, y := c.ScalarBaseMult(d.Bytes()) x, y := c.ScalarBaseMult(b)
return &PrivateKey{ return &PrivateKey{
ecdsa.PrivateKey{ ecdsa.PrivateKey{
@ -85,7 +85,7 @@ func NewPrivateKeyFromASN1(b []byte) (*PrivateKey, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
return NewPrivateKeyFromBytes(privkey.D.Bytes()) return &PrivateKey{*privkey}, nil
} }
// PublicKey derives the public key from the private key. // PublicKey derives the public key from the private key.
@ -155,10 +155,9 @@ func (p *PrivateKey) SignHashable(net uint32, hh hash.Hashable) []byte {
func getSignatureSlice(curve elliptic.Curve, r, s *big.Int) []byte { func getSignatureSlice(curve elliptic.Curve, r, s *big.Int) []byte {
params := curve.Params() params := curve.Params()
curveOrderByteSize := params.P.BitLen() / 8 curveOrderByteSize := params.P.BitLen() / 8
rBytes, sBytes := r.Bytes(), s.Bytes()
signature := make([]byte, curveOrderByteSize*2) signature := make([]byte, curveOrderByteSize*2)
copy(signature[curveOrderByteSize-len(rBytes):], rBytes) _ = r.FillBytes(signature[:curveOrderByteSize])
copy(signature[curveOrderByteSize*2-len(sBytes):], sBytes) _ = s.FillBytes(signature[curveOrderByteSize:])
return signature return signature
} }
@ -170,9 +169,8 @@ func (p *PrivateKey) String() string {
// Bytes returns the underlying bytes of the PrivateKey. // Bytes returns the underlying bytes of the PrivateKey.
func (p *PrivateKey) Bytes() []byte { func (p *PrivateKey) Bytes() []byte {
bytes := p.D.Bytes()
result := make([]byte, 32) result := make([]byte, 32)
copy(result[32-len(bytes):], bytes) _ = p.D.FillBytes(result)
return result return result
} }

View file

@ -8,7 +8,6 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
gio "io"
"math/big" "math/big"
"github.com/btcsuite/btcd/btcec" "github.com/btcsuite/btcd/btcec"
@ -143,29 +142,10 @@ func (p *PublicKey) getBytes(compressed bool) []byte {
return []byte{0x00} return []byte{0x00}
} }
var resLen = 1 + coordLen
if !compressed {
resLen += coordLen
}
var res = make([]byte, resLen)
var prefix byte
xBytes := p.X.Bytes()
copy(res[1+coordLen-len(xBytes):], xBytes)
if compressed { if compressed {
if p.Y.Bit(0) == 0 { return elliptic.MarshalCompressed(p.Curve, p.X, p.Y)
prefix = 0x02
} else {
prefix = 0x03
}
} else {
prefix = 0x04
yBytes := p.Y.Bytes()
copy(res[1+coordLen+coordLen-len(yBytes):], yBytes)
} }
res[0] = prefix return elliptic.Marshal(p.Curve, p.X, p.Y)
return res
} }
// Bytes returns byte array representation of the public key in compressed // Bytes returns byte array representation of the public key in compressed
@ -239,8 +219,7 @@ func (p *PublicKey) DecodeBytes(data []byte) error {
return b.Err return b.Err
} }
b.ReadB() if b.Len() != 0 {
if b.Err != gio.EOF {
return errors.New("extra data") return errors.New("extra data")
} }
return nil return nil
@ -270,7 +249,7 @@ func (p *PublicKey) DecodeBinary(r *io.BinReader) {
return return
case 0x02, 0x03: case 0x02, 0x03:
// Compressed public keys // Compressed public keys
xbytes := make([]byte, 32) xbytes := make([]byte, coordLen)
r.ReadBytes(xbytes) r.ReadBytes(xbytes)
if r.Err != nil { if r.Err != nil {
return return
@ -283,8 +262,8 @@ func (p *PublicKey) DecodeBinary(r *io.BinReader) {
return return
} }
case 0x04: case 0x04:
xbytes := make([]byte, 32) xbytes := make([]byte, coordLen)
ybytes := make([]byte, 32) ybytes := make([]byte, coordLen)
r.ReadBytes(xbytes) r.ReadBytes(xbytes)
r.ReadBytes(ybytes) r.ReadBytes(ybytes)
if r.Err != nil { if r.Err != nil {

View file

@ -165,7 +165,7 @@ func TestUnique(t *testing.T) {
require.Equal(t, 1, unique.Len()) require.Equal(t, 1, unique.Len())
} }
func getPubKey(t *testing.T) *PublicKey { func getPubKey(t testing.TB) *PublicKey {
pubKey, err := NewPublicKeyFromString("031ee4e73a17d8f76dc02532e2620bcb12425b33c0c9f9694cc2caa8226b68cad4") pubKey, err := NewPublicKeyFromString("031ee4e73a17d8f76dc02532e2620bcb12425b33c0c9f9694cc2caa8226b68cad4")
require.NoError(t, err) require.NoError(t, err)
return pubKey return pubKey
@ -212,3 +212,37 @@ func TestUnmarshallJSONBadFormat(t *testing.T) {
err := json.Unmarshal([]byte(str), actual) err := json.Unmarshal([]byte(str), actual)
require.Error(t, err) require.Error(t, err)
} }
func BenchmarkPublicEqual(t *testing.B) {
k11 := getPubKey(t)
k12 := getPubKey(t)
k2, err := NewPublicKeyFromString("03b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c")
require.NoError(t, err)
for n := 0; n < t.N; n++ {
_ = k11.Equal(k12)
_ = k11.Equal(k2)
}
}
func BenchmarkPublicBytes(t *testing.B) {
k := getPubKey(t)
for n := 0; n < t.N; n++ {
_ = k.Bytes()
}
}
func BenchmarkPublicUncompressedBytes(t *testing.B) {
k := getPubKey(t)
for n := 0; n < t.N; n++ {
_ = k.Bytes()
}
}
func BenchmarkPublicDecodeBytes(t *testing.B) {
keyBytes, err := hex.DecodeString("03b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c")
require.NoError(t, err)
k := new(PublicKey)
for n := 0; n < t.N; n++ {
require.NoError(t, k.DecodeBytes(keyBytes))
}
}

View file

@ -1,7 +1,6 @@
package io package io
import ( import (
"io/ioutil"
"os" "os"
"path" "path"
"testing" "testing"
@ -10,34 +9,22 @@ import (
) )
func TestMakeDirForFile_HappyPath(t *testing.T) { func TestMakeDirForFile_HappyPath(t *testing.T) {
tempDir, err := ioutil.TempDir("", "test") tempDir := t.TempDir()
require.NoError(t, err) filePath := path.Join(tempDir, "testDir/testFile.test")
err := MakeDirForFile(filePath, "test")
filePath := tempDir + "/testDir/testFile.test"
err = MakeDirForFile(filePath, "test")
t.Cleanup(func() {
removeDir(t, tempDir)
})
require.NoError(t, err) require.NoError(t, err)
_, errChDir := os.Create(filePath) _, errChDir := os.Create(filePath)
require.NoError(t, errChDir) require.NoError(t, errChDir)
} }
func removeDir(t *testing.T, dirName string) {
err := os.RemoveAll(dirName)
require.NoError(t, err)
}
func TestMakeDirForFile_Negative(t *testing.T) { func TestMakeDirForFile_Negative(t *testing.T) {
file, err := ioutil.TempFile("", "test") tempDir := t.TempDir()
filePath := path.Join(tempDir, "testFile.test")
_, err := os.Create(filePath)
require.NoError(t, err) require.NoError(t, err)
filePath := file.Name() + "/error" filePath = path.Join(filePath, "error")
dir := path.Dir(filePath)
err = MakeDirForFile(filePath, "test") err = MakeDirForFile(filePath, "test")
t.Cleanup(func() {
removeDir(t, dir)
})
require.Errorf(t, err, "could not create dir for test: mkdir %s : not a directory", filePath) require.Errorf(t, err, "could not create dir for test: mkdir %s : not a directory", filePath)
} }

View file

@ -162,11 +162,7 @@ func TestLoad(t *testing.T) {
return a * b return a * b
} }
}` }`
tmpDir, err := ioutil.TempDir("", "neogo.vmcliloadtest") tmpDir := t.TempDir()
require.NoError(t, err)
t.Cleanup(func() {
os.RemoveAll(tmpDir)
})
t.Run("loadgo", func(t *testing.T) { t.Run("loadgo", func(t *testing.T) {
filename := path.Join(tmpDir, "vmtestcontract.go") filename := path.Join(tmpDir, "vmtestcontract.go")
@ -262,11 +258,7 @@ func TestRunWithDifferentArguments(t *testing.T) {
return arg return arg
}` }`
tmpDir, err := ioutil.TempDir("", "neogo.vmcliruntest") tmpDir := t.TempDir()
require.NoError(t, err)
t.Cleanup(func() {
os.RemoveAll(tmpDir)
})
filename := path.Join(tmpDir, "run_vmtestcontract.go") filename := path.Join(tmpDir, "run_vmtestcontract.go")
require.NoError(t, ioutil.WriteFile(filename, []byte(src), os.ModePerm)) require.NoError(t, ioutil.WriteFile(filename, []byte(src), os.ModePerm))

View file

@ -2,8 +2,6 @@ package wallet
import ( import (
"encoding/json" "encoding/json"
"io/ioutil"
"os"
"path" "path"
"testing" "testing"
@ -75,10 +73,8 @@ func TestPath(t *testing.T) {
} }
func TestSave(t *testing.T) { func TestSave(t *testing.T) {
file, err := ioutil.TempFile("", walletTemplate) wallet := checkWalletConstructor(t)
require.NoError(t, err)
wallet, err := NewWallet(file.Name())
require.NoError(t, err)
wallet.AddAccount(&Account{ wallet.AddAccount(&Account{
privateKey: nil, privateKey: nil,
publicKey: nil, publicKey: nil,
@ -91,9 +87,6 @@ func TestSave(t *testing.T) {
Default: false, Default: false,
}) })
t.Cleanup(func() {
removeWallet(t, file.Name())
})
errForSave := wallet.Save() errForSave := wallet.Save()
require.NoError(t, errForSave) require.NoError(t, errForSave)
@ -130,21 +123,13 @@ func TestJSONMarshallUnmarshal(t *testing.T) {
} }
func checkWalletConstructor(t *testing.T) *Wallet { func checkWalletConstructor(t *testing.T) *Wallet {
file, err := ioutil.TempFile("", walletTemplate) tmpDir := t.TempDir()
require.NoError(t, err) file := path.Join(tmpDir, walletTemplate)
wallet, err := NewWallet(file.Name()) wallet, err := NewWallet(file)
t.Cleanup(func() {
removeWallet(t, file.Name())
})
require.NoError(t, err) require.NoError(t, err)
return wallet return wallet
} }
func removeWallet(t *testing.T, walletPath string) {
err := os.RemoveAll(walletPath)
require.NoError(t, err)
}
func TestWallet_AddToken(t *testing.T) { func TestWallet_AddToken(t *testing.T) {
w := checkWalletConstructor(t) w := checkWalletConstructor(t)
tok := NewToken(util.Uint160{1, 2, 3}, "Rubl", "RUB", 2, manifest.NEP17StandardName) tok := NewToken(util.Uint160{1, 2, 3}, "Rubl", "RUB", 2, manifest.NEP17StandardName)