Merge pull request #1791 from nspcc-dev/drop-go-1-13

*: drop go 1.13
This commit is contained in:
Roman Khimov 2021-03-01 17:20:26 +03:00 committed by GitHub
commit 10cc19b33c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
46 changed files with 148 additions and 244 deletions

View file

@ -3,11 +3,6 @@ orbs:
codecov: codecov/codecov@1.0.5 codecov: codecov/codecov@1.0.5
executors: executors:
go1_13:
docker:
- image: circleci/golang:1.13
environment:
GO111MODULE: "on"
go1_14: go1_14:
docker: docker:
- image: circleci/golang:1.14 - image: circleci/golang:1.14
@ -54,16 +49,6 @@ jobs:
name: go-vet name: go-vet
command: go vet ./... command: go vet ./...
test_1_13:
working_directory: /go/src/github.com/nspcc-dev/neo-go
executor: go1_13
steps:
- checkout
- run: git submodule sync
- run: git submodule update --init
- gomod
- run: go test -v -race ./...
test_1_14: test_1_14:
working_directory: /go/src/github.com/nspcc-dev/neo-go working_directory: /go/src/github.com/nspcc-dev/neo-go
executor: go1_14 executor: go1_14
@ -132,10 +117,6 @@ workflows:
filters: filters:
tags: tags:
only: v/[0-9]+\.[0-9]+\.[0-9]+/ only: v/[0-9]+\.[0-9]+\.[0-9]+/
- test_1_13:
filters:
tags:
only: v/[0-9]+\.[0-9]+\.[0-9]+/
- test_1_14: - test_1_14:
filters: filters:
tags: tags:

View file

@ -109,7 +109,7 @@ jobs:
runs-on: ubuntu-18.04 runs-on: ubuntu-18.04
strategy: strategy:
matrix: matrix:
go_versions: [ '1.13', '1.14', '1.15' ] go_versions: [ '1.14', '1.15' ]
fail-fast: false fail-fast: false
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2

View file

@ -36,7 +36,7 @@ Neo 3 code (0.90.0 being compatible with Neo 3 preview2).
## Installation ## Installation
Go: 1.13+ Go: 1.14+
Install dependencies. Install dependencies.

View file

@ -13,7 +13,6 @@ import (
// stop working after validator will change. // stop working after validator will change.
func TestRegisterCandidate(t *testing.T) { func TestRegisterCandidate(t *testing.T) {
e := newExecutor(t, true) e := newExecutor(t, true)
defer e.Close(t)
e.In.WriteString("one\r") e.In.WriteString("one\r")
e.Run(t, "neo-go", "wallet", "nep17", "multitransfer", e.Run(t, "neo-go", "wallet", "nep17", "multitransfer",

View file

@ -27,7 +27,6 @@ import (
func TestCalcHash(t *testing.T) { func TestCalcHash(t *testing.T) {
e := newExecutor(t, false) e := newExecutor(t, false)
defer e.Close(t)
nefPath := "./testdata/verify.nef" nefPath := "./testdata/verify.nef"
src, err := ioutil.ReadFile(nefPath) src, err := ioutil.ReadFile(nefPath)
@ -58,7 +57,9 @@ func TestCalcHash(t *testing.T) {
}) })
t.Run("invalid file", func(t *testing.T) { t.Run("invalid file", func(t *testing.T) {
p := path.Join(os.TempDir(), "neogo.calchash.verify.nef") p := path.Join(os.TempDir(), "neogo.calchash.verify.nef")
defer os.Remove(p) t.Cleanup(func() {
os.Remove(p)
})
require.NoError(t, ioutil.WriteFile(p, src[:4], os.ModePerm)) require.NoError(t, ioutil.WriteFile(p, src[:4], os.ModePerm))
e.RunWithError(t, append(cmd, "--sender", sender.StringLE(), "--in", p, "--manifest", manifestPath)...) e.RunWithError(t, append(cmd, "--sender", sender.StringLE(), "--in", p, "--manifest", manifestPath)...)
}) })
@ -82,10 +83,11 @@ func TestCalcHash(t *testing.T) {
func TestContractInitAndCompile(t *testing.T) { func TestContractInitAndCompile(t *testing.T) {
tmpDir := path.Join(os.TempDir(), "neogo.inittest") tmpDir := path.Join(os.TempDir(), "neogo.inittest")
require.NoError(t, os.Mkdir(tmpDir, os.ModePerm)) require.NoError(t, os.Mkdir(tmpDir, os.ModePerm))
defer os.RemoveAll(tmpDir) t.Cleanup(func() {
os.RemoveAll(tmpDir)
})
e := newExecutor(t, false) e := newExecutor(t, false)
defer e.Close(t)
t.Run("no path is provided", func(t *testing.T) { t.Run("no path is provided", func(t *testing.T) {
e.RunWithError(t, "neo-go", "contract", "init") e.RunWithError(t, "neo-go", "contract", "init")
@ -140,14 +142,15 @@ func TestDeployBigContract(t *testing.T) {
e := newExecutorWithConfig(t, true, func(c *config.Config) { e := newExecutorWithConfig(t, true, func(c *config.Config) {
c.ApplicationConfiguration.RPC.MaxGasInvoke = fixedn.Fixed8(1) c.ApplicationConfiguration.RPC.MaxGasInvoke = fixedn.Fixed8(1)
}) })
defer e.Close(t)
// For proper nef generation. // For proper nef generation.
config.Version = "0.90.0-test" config.Version = "0.90.0-test"
tmpDir := path.Join(os.TempDir(), "neogo.test.deployfail") tmpDir := path.Join(os.TempDir(), "neogo.test.deployfail")
require.NoError(t, os.Mkdir(tmpDir, os.ModePerm)) require.NoError(t, os.Mkdir(tmpDir, os.ModePerm))
defer os.RemoveAll(tmpDir) 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")
@ -165,14 +168,15 @@ func TestDeployBigContract(t *testing.T) {
func TestComlileAndInvokeFunction(t *testing.T) { func TestComlileAndInvokeFunction(t *testing.T) {
e := newExecutor(t, true) e := newExecutor(t, true)
defer e.Close(t)
// For proper nef generation. // For proper nef generation.
config.Version = "0.90.0-test" config.Version = "0.90.0-test"
tmpDir := path.Join(os.TempDir(), "neogo.test.compileandinvoke") tmpDir := path.Join(os.TempDir(), "neogo.test.compileandinvoke")
require.NoError(t, os.Mkdir(tmpDir, os.ModePerm)) require.NoError(t, os.Mkdir(tmpDir, os.ModePerm))
defer os.RemoveAll(tmpDir) 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")
@ -314,10 +318,10 @@ func TestComlileAndInvokeFunction(t *testing.T) {
"--in", "testdata/deploy/", // compile all files in dir "--in", "testdata/deploy/", // compile all files in dir
"--out", nefName, "--manifest", manifestName) "--out", nefName, "--manifest", manifestName)
defer func() { t.Cleanup(func() {
os.Remove(nefName) os.Remove(nefName)
os.Remove(manifestName) os.Remove(manifestName)
}() })
rawNef, err := ioutil.ReadFile(nefName) rawNef, err := ioutil.ReadFile(nefName)
require.NoError(t, err) require.NoError(t, err)
@ -349,7 +353,6 @@ func TestComlileAndInvokeFunction(t *testing.T) {
func TestContractInspect(t *testing.T) { func TestContractInspect(t *testing.T) {
e := newExecutor(t, false) e := newExecutor(t, false)
defer e.Close(t)
// For proper nef generation. // For proper nef generation.
config.Version = "0.90.0-test" config.Version = "0.90.0-test"
@ -357,7 +360,9 @@ func TestContractInspect(t *testing.T) {
tmpDir := path.Join(os.TempDir(), "neogo.test.contract.inspect") tmpDir := path.Join(os.TempDir(), "neogo.test.contract.inspect")
require.NoError(t, os.Mkdir(tmpDir, os.ModePerm)) require.NoError(t, os.Mkdir(tmpDir, os.ModePerm))
defer os.RemoveAll(tmpDir) 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")
@ -394,7 +399,6 @@ func TestCompileExamples(t *testing.T) {
tmpDir := os.TempDir() tmpDir := os.TempDir()
e := newExecutor(t, false) e := newExecutor(t, false)
defer e.Close(t)
for _, info := range infos { for _, info := range infos {
t.Run(info.Name(), func(t *testing.T) { t.Run(info.Name(), func(t *testing.T) {
@ -404,10 +408,10 @@ func TestCompileExamples(t *testing.T) {
outPath := path.Join(tmpDir, info.Name()+".nef") outPath := path.Join(tmpDir, info.Name()+".nef")
manifestPath := path.Join(tmpDir, info.Name()+".manifest.json") manifestPath := path.Join(tmpDir, info.Name()+".manifest.json")
defer func() { t.Cleanup(func() {
os.Remove(outPath) os.Remove(outPath)
os.Remove(manifestPath) os.Remove(manifestPath)
}() })
cfgName := filterFilename(infos, ".yml") cfgName := filterFilename(infos, ".yml")
opts := []string{ opts := []string{
@ -426,10 +430,10 @@ func TestCompileExamples(t *testing.T) {
for _, name := range []string{"invalid1", "invalid2", "invalid3"} { for _, name := range []string{"invalid1", "invalid2", "invalid3"} {
outPath := path.Join(tmpDir, name+".nef") outPath := path.Join(tmpDir, name+".nef")
manifestPath := path.Join(tmpDir, name+".manifest.json") manifestPath := path.Join(tmpDir, name+".manifest.json")
defer func() { t.Cleanup(func() {
os.Remove(outPath) os.Remove(outPath)
os.Remove(manifestPath) os.Remove(manifestPath)
}() })
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", outPath, "--out", outPath,

View file

@ -14,7 +14,9 @@ import (
func TestDBRestore(t *testing.T) { func TestDBRestore(t *testing.T) {
tmpDir := path.Join(os.TempDir(), "neogo.restoretest") tmpDir := path.Join(os.TempDir(), "neogo.restoretest")
require.NoError(t, os.Mkdir(tmpDir, os.ModePerm)) require.NoError(t, os.Mkdir(tmpDir, os.ModePerm))
defer os.RemoveAll(tmpDir) 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")
@ -31,7 +33,6 @@ func TestDBRestore(t *testing.T) {
// generated via `go run ./scripts/gendump/main.go --out ./cli/testdata/chain50x2.acc --blocks 50 --txs 2` // generated via `go run ./scripts/gendump/main.go --out ./cli/testdata/chain50x2.acc --blocks 50 --txs 2`
const inDump = "./testdata/chain50x2.acc" const inDump = "./testdata/chain50x2.acc"
e := newExecutor(t, false) e := newExecutor(t, false)
defer e.Close(t)
stateDump := path.Join(tmpDir, "neogo.teststate") stateDump := path.Join(tmpDir, "neogo.teststate")
baseArgs := []string{"neo-go", "db", "restore", "--unittest", baseArgs := []string{"neo-go", "db", "restore", "--unittest",
"--config-path", tmpDir, "--in", inDump, "--dump", stateDump} "--config-path", tmpDir, "--in", inDump, "--dump", stateDump}

View file

@ -102,6 +102,9 @@ func newExecutorWithConfig(t *testing.T, needChain bool, f func(*config.Config))
if needChain { if needChain {
e.Chain, e.RPC, e.NetSrv = newTestChain(t, f) e.Chain, e.RPC, e.NetSrv = newTestChain(t, f)
} }
t.Cleanup(func() {
e.Close(t)
})
return e return e
} }

View file

@ -6,7 +6,6 @@ import (
func TestCLIVersion(t *testing.T) { func TestCLIVersion(t *testing.T) {
e := newExecutor(t, false) e := newExecutor(t, false)
defer e.Close(t)
e.Run(t, "neo-go", "--version") e.Run(t, "neo-go", "--version")
e.checkNextLine(t, "^neo-go version") e.checkNextLine(t, "^neo-go version")
e.checkEOF(t) e.checkEOF(t)

View file

@ -20,7 +20,6 @@ import (
// 2. Transfer from multisig to another account. // 2. Transfer from multisig to another account.
func TestSignMultisigTx(t *testing.T) { func TestSignMultisigTx(t *testing.T) {
e := newExecutor(t, true) e := newExecutor(t, true)
defer e.Close(t)
privs, pubs := generateKeys(t, 3) privs, pubs := generateKeys(t, 3)
script, err := smartcontract.CreateMultiSigRedeemScript(2, pubs) script, err := smartcontract.CreateMultiSigRedeemScript(2, pubs)
@ -31,9 +30,11 @@ func TestSignMultisigTx(t *testing.T) {
// Create 2 wallets participating in multisig. // Create 2 wallets participating in multisig.
tmpDir := os.TempDir() tmpDir := os.TempDir()
wallet1Path := path.Join(tmpDir, "multiWallet1.json") wallet1Path := path.Join(tmpDir, "multiWallet1.json")
defer os.Remove(wallet1Path)
wallet2Path := path.Join(tmpDir, "multiWallet2.json") wallet2Path := path.Join(tmpDir, "multiWallet2.json")
defer os.Remove(wallet2Path) t.Cleanup(func() {
os.Remove(wallet1Path)
os.Remove(wallet2Path)
})
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)
@ -64,7 +65,9 @@ func TestSignMultisigTx(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
txPath := path.Join(tmpDir, "multisigtx.json") txPath := path.Join(tmpDir, "multisigtx.json")
defer os.Remove(txPath) t.Cleanup(func() {
os.Remove(txPath)
})
e.In.WriteString("pass\r") e.In.WriteString("pass\r")
e.Run(t, "neo-go", "wallet", "nep17", "transfer", e.Run(t, "neo-go", "wallet", "nep17", "transfer",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addr,

View file

@ -18,7 +18,6 @@ import (
func TestNEP17Balance(t *testing.T) { func TestNEP17Balance(t *testing.T) {
e := newExecutor(t, true) e := newExecutor(t, true)
defer e.Close(t)
cmdbalance := []string{"neo-go", "wallet", "nep17", "balance"} cmdbalance := []string{"neo-go", "wallet", "nep17", "balance"}
cmdbase := append(cmdbalance, cmdbase := append(cmdbalance,
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addr,
@ -106,7 +105,6 @@ func TestNEP17Transfer(t *testing.T) {
defer w.Close() defer w.Close()
e := newExecutor(t, true) e := newExecutor(t, true)
defer e.Close(t)
args := []string{ args := []string{
"neo-go", "wallet", "nep17", "transfer", "neo-go", "wallet", "nep17", "transfer",
"--rpc-endpoint", "http://" + e.RPC.Addr, "--rpc-endpoint", "http://" + e.RPC.Addr,
@ -164,7 +162,6 @@ func TestNEP17MultiTransfer(t *testing.T) {
privs, _ := generateKeys(t, 3) privs, _ := generateKeys(t, 3)
e := newExecutor(t, true) e := newExecutor(t, true)
defer e.Close(t)
neoContractHash, err := e.Chain.GetNativeContractScriptHash(nativenames.Neo) neoContractHash, err := e.Chain.GetNativeContractScriptHash(nativenames.Neo)
require.NoError(t, err) require.NoError(t, err)
args := []string{ args := []string{
@ -191,7 +188,6 @@ func TestNEP17MultiTransfer(t *testing.T) {
func TestNEP17ImportToken(t *testing.T) { func TestNEP17ImportToken(t *testing.T) {
e := newExecutor(t, true) e := newExecutor(t, true)
defer e.Close(t)
tmpDir := os.TempDir() tmpDir := os.TempDir()
walletPath := path.Join(tmpDir, "walletForImport.json") walletPath := path.Join(tmpDir, "walletForImport.json")

View file

@ -11,7 +11,6 @@ import (
func TestGetRPCClient(t *testing.T) { func TestGetRPCClient(t *testing.T) {
e := newExecutor(t, true) e := newExecutor(t, true)
defer e.Close(t)
t.Run("no endpoint", func(t *testing.T) { t.Run("no endpoint", func(t *testing.T) {
set := flag.NewFlagSet("flagSet", flag.ExitOnError) set := flag.NewFlagSet("flagSet", flag.ExitOnError)

View file

@ -11,10 +11,10 @@ import (
func TestGetPath(t *testing.T) { func TestGetPath(t *testing.T) {
testPath, err := ioutil.TempDir("./", "") testPath, err := ioutil.TempDir("./", "")
require.NoError(t, err) require.NoError(t, err)
defer func() { t.Cleanup(func() {
err := os.RemoveAll(testPath) err := os.RemoveAll(testPath)
require.NoError(t, err) require.NoError(t, err)
}() })
path, err := getPath(testPath, 123) path, err := getPath(testPath, 123)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, testPath+"/BlockStorage_100000/dump-block-1000.json", path) require.Equal(t, testPath+"/BlockStorage_100000/dump-block-1000.json", path)

View file

@ -29,9 +29,9 @@ func TestGetConfigFromContext(t *testing.T) {
func TestHandleLoggingParams(t *testing.T) { func TestHandleLoggingParams(t *testing.T) {
testLog, err := ioutil.TempFile("./", "*.log") testLog, err := ioutil.TempFile("./", "*.log")
require.NoError(t, err) require.NoError(t, err)
defer func() { t.Cleanup(func() {
require.NoError(t, os.Remove(testLog.Name())) 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)
@ -63,10 +63,10 @@ func TestInitBCWithMetrics(t *testing.T) {
d, err := ioutil.TempDir("./", "") d, err := ioutil.TempDir("./", "")
require.NoError(t, err) require.NoError(t, err)
os.Chdir(d) os.Chdir(d)
defer func() { t.Cleanup(func() {
os.Chdir("..") os.Chdir("..")
os.RemoveAll(d) os.RemoveAll(d)
}() })
set := flag.NewFlagSet("flagSet", flag.ExitOnError) set := flag.NewFlagSet("flagSet", flag.ExitOnError)
set.String("config-path", "../../../config", "") set.String("config-path", "../../../config", "")
@ -79,9 +79,11 @@ func TestInitBCWithMetrics(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
chain, prometheus, pprof, err := initBCWithMetrics(cfg, logger) chain, prometheus, pprof, err := initBCWithMetrics(cfg, logger)
require.NoError(t, err) require.NoError(t, err)
defer chain.Close() t.Cleanup(func() {
defer prometheus.ShutDown() chain.Close()
defer pprof.ShutDown() prometheus.ShutDown()
pprof.ShutDown()
})
require.Equal(t, netmode.TestNet, chain.GetConfig().Magic) require.Equal(t, netmode.TestNet, chain.GetConfig().Magic)
} }
@ -90,10 +92,10 @@ func TestDumpDB(t *testing.T) {
d, err := ioutil.TempDir("./", "") d, err := ioutil.TempDir("./", "")
require.NoError(t, err) require.NoError(t, err)
os.Chdir(d) os.Chdir(d)
defer func() { t.Cleanup(func() {
os.Chdir("..") os.Chdir("..")
os.RemoveAll(d) os.RemoveAll(d)
}() })
testDump := "file.acc" testDump := "file.acc"
set := flag.NewFlagSet("flagSet", flag.ExitOnError) set := flag.NewFlagSet("flagSet", flag.ExitOnError)
set.String("config-path", "../../../config", "") set.String("config-path", "../../../config", "")
@ -111,10 +113,10 @@ func TestDumpDB(t *testing.T) {
d, err := ioutil.TempDir("./", "") d, err := ioutil.TempDir("./", "")
require.NoError(t, err) require.NoError(t, err)
os.Chdir(d) os.Chdir(d)
defer func() { t.Cleanup(func() {
os.Chdir("..") os.Chdir("..")
os.RemoveAll(d) os.RemoveAll(d)
}() })
testDump := "file.acc" testDump := "file.acc"
set := flag.NewFlagSet("flagSet", flag.ExitOnError) set := flag.NewFlagSet("flagSet", flag.ExitOnError)
set.String("config-path", "../../../config", "") set.String("config-path", "../../../config", "")
@ -135,10 +137,10 @@ func TestRestoreDB(t *testing.T) {
testDump := "file1.acc" testDump := "file1.acc"
saveDump := "file2.acc" saveDump := "file2.acc"
os.Chdir(d) os.Chdir(d)
defer func() { t.Cleanup(func() {
os.Chdir("..") os.Chdir("..")
os.RemoveAll(d) os.RemoveAll(d)
}() })
//dump first //dump first
set := flag.NewFlagSet("flagSet", flag.ExitOnError) set := flag.NewFlagSet("flagSet", flag.ExitOnError)

View file

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

View file

@ -22,10 +22,11 @@ import (
func TestWalletInit(t *testing.T) { func TestWalletInit(t *testing.T) {
tmpDir := path.Join(os.TempDir(), "neogo.test.walletinit") tmpDir := path.Join(os.TempDir(), "neogo.test.walletinit")
require.NoError(t, os.Mkdir(tmpDir, os.ModePerm)) require.NoError(t, os.Mkdir(tmpDir, os.ModePerm))
defer os.RemoveAll(tmpDir) t.Cleanup(func() {
os.RemoveAll(tmpDir)
})
e := newExecutor(t, false) e := newExecutor(t, false)
defer e.Close(t)
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)
@ -90,7 +91,7 @@ func TestWalletInit(t *testing.T) {
w, err := wallet.NewWalletFromFile(walletPath) w, err := wallet.NewWalletFromFile(walletPath)
require.NoError(t, err) require.NoError(t, err)
defer w.Close() t.Cleanup(w.Close)
acc := w.GetAccount(priv.GetScriptHash()) acc := w.GetAccount(priv.GetScriptHash())
require.NotNil(t, acc) require.NotNil(t, acc)
require.Equal(t, "test_account", acc.Label) require.Equal(t, "test_account", acc.Label)
@ -121,7 +122,7 @@ func TestWalletInit(t *testing.T) {
w, err := wallet.NewWalletFromFile(walletPath) w, err := wallet.NewWalletFromFile(walletPath)
require.NoError(t, err) require.NoError(t, err)
defer w.Close() t.Cleanup(w.Close)
actual := w.GetAccount(acc.PrivateKey().GetScriptHash()) actual := w.GetAccount(acc.PrivateKey().GetScriptHash())
require.NotNil(t, actual) require.NotNil(t, actual)
require.NoError(t, actual.Decrypt("somepass")) require.NoError(t, actual.Decrypt("somepass"))
@ -157,7 +158,7 @@ func TestWalletInit(t *testing.T) {
w, err := wallet.NewWalletFromFile(walletPath) w, err := wallet.NewWalletFromFile(walletPath)
require.NoError(t, err) require.NoError(t, err)
defer w.Close() t.Cleanup(w.Close)
actual := w.GetAccount(hash.Hash160(script)) actual := w.GetAccount(hash.Hash160(script))
require.NotNil(t, actual) require.NotNil(t, actual)
require.NoError(t, actual.Decrypt("multipass")) require.NoError(t, actual.Decrypt("multipass"))
@ -168,7 +169,6 @@ func TestWalletInit(t *testing.T) {
func TestWalletExport(t *testing.T) { func TestWalletExport(t *testing.T) {
e := newExecutor(t, false) e := newExecutor(t, false)
defer e.Close(t)
t.Run("Encrypted", func(t *testing.T) { t.Run("Encrypted", func(t *testing.T) {
e.Run(t, "neo-go", "wallet", "export", e.Run(t, "neo-go", "wallet", "export",
@ -195,12 +195,11 @@ func TestWalletExport(t *testing.T) {
func TestClaimGas(t *testing.T) { func TestClaimGas(t *testing.T) {
e := newExecutor(t, true) e := newExecutor(t, true)
defer e.Close(t)
const walletPath = "testdata/testwallet.json" const walletPath = "testdata/testwallet.json"
w, err := wallet.NewWalletFromFile(walletPath) w, err := wallet.NewWalletFromFile(walletPath)
require.NoError(t, err) require.NoError(t, err)
defer w.Close() t.Cleanup(w.Close)
args := []string{ args := []string{
"neo-go", "wallet", "nep17", "multitransfer", "neo-go", "wallet", "nep17", "multitransfer",
@ -243,7 +242,6 @@ func TestClaimGas(t *testing.T) {
func TestImportDeployed(t *testing.T) { func TestImportDeployed(t *testing.T) {
e := newExecutor(t, true) e := newExecutor(t, true)
defer e.Close(t)
e.In.WriteString("one\r") e.In.WriteString("one\r")
e.Run(t, "neo-go", "contract", "deploy", e.Run(t, "neo-go", "contract", "deploy",
@ -262,7 +260,9 @@ func TestImportDeployed(t *testing.T) {
tmpDir := os.TempDir() tmpDir := os.TempDir()
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)
defer os.Remove(walletPath) t.Cleanup(func() {
os.Remove(walletPath)
})
priv, err := keys.NewPrivateKey() priv, err := keys.NewPrivateKey()
require.NoError(t, err) require.NoError(t, err)
@ -274,7 +274,9 @@ func TestImportDeployed(t *testing.T) {
"--contract", h.StringLE()) "--contract", h.StringLE())
w, err := wallet.NewWalletFromFile(walletPath) w, err := wallet.NewWalletFromFile(walletPath)
defer w.Close() t.Cleanup(func() {
w.Close()
})
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, 1, len(w.Accounts)) require.Equal(t, 1, len(w.Accounts))
contractAddr := w.Accounts[0].Address contractAddr := w.Accounts[0].Address
@ -309,7 +311,6 @@ func TestImportDeployed(t *testing.T) {
func TestWalletDump(t *testing.T) { func TestWalletDump(t *testing.T) {
e := newExecutor(t, false) e := newExecutor(t, false)
defer e.Close(t)
cmd := []string{"neo-go", "wallet", "dump", "--wallet", "testdata/testwallet.json"} cmd := []string{"neo-go", "wallet", "dump", "--wallet", "testdata/testwallet.json"}
e.Run(t, cmd...) e.Run(t, cmd...)
@ -340,10 +341,11 @@ func TestWalletDump(t *testing.T) {
func TestWalletConvert(t *testing.T) { func TestWalletConvert(t *testing.T) {
tmpDir := path.Join(os.TempDir(), "neogo.test.convert") tmpDir := path.Join(os.TempDir(), "neogo.test.convert")
require.NoError(t, os.Mkdir(tmpDir, os.ModePerm)) require.NoError(t, os.Mkdir(tmpDir, os.ModePerm))
defer os.RemoveAll(tmpDir) t.Cleanup(func() {
os.RemoveAll(tmpDir)
})
e := newExecutor(t, false) e := newExecutor(t, false)
defer e.Close(t)
outPath := path.Join(tmpDir, "wallet.json") outPath := path.Join(tmpDir, "wallet.json")
cmd := []string{"neo-go", "wallet", "convert"} cmd := []string{"neo-go", "wallet", "convert"}

4
go.mod
View file

@ -12,7 +12,7 @@ require (
github.com/gorilla/websocket v1.4.2 github.com/gorilla/websocket v1.4.2
github.com/hashicorp/golang-lru v0.5.4 github.com/hashicorp/golang-lru v0.5.4
github.com/mr-tron/base58 v1.1.2 github.com/mr-tron/base58 v1.1.2
github.com/nspcc-dev/dbft v0.0.0-20210122071512-d9a728094f0d github.com/nspcc-dev/dbft v0.0.0-20210301140418-d31e1e0c272f
github.com/nspcc-dev/rfc6979 v0.2.0 github.com/nspcc-dev/rfc6979 v0.2.0
github.com/pierrec/lz4 v2.5.2+incompatible github.com/pierrec/lz4 v2.5.2+incompatible
github.com/prometheus/client_golang v1.2.1 github.com/prometheus/client_golang v1.2.1
@ -30,4 +30,4 @@ require (
gopkg.in/yaml.v2 v2.2.4 gopkg.in/yaml.v2 v2.2.4
) )
go 1.13 go 1.14

6
go.sum
View file

@ -173,6 +173,12 @@ github.com/nspcc-dev/dbft v0.0.0-20200219114139-199d286ed6c1 h1:yEx9WznS+rjE0jl0
github.com/nspcc-dev/dbft v0.0.0-20200219114139-199d286ed6c1/go.mod h1:O0qtn62prQSqizzoagHmuuKoz8QMkU3SzBoKdEvm3aQ= github.com/nspcc-dev/dbft v0.0.0-20200219114139-199d286ed6c1/go.mod h1:O0qtn62prQSqizzoagHmuuKoz8QMkU3SzBoKdEvm3aQ=
github.com/nspcc-dev/dbft v0.0.0-20210122071512-d9a728094f0d h1:uUaRysqa/9VtHETVARUlteqfbXAgwxR2nvUc4DzK4pI= github.com/nspcc-dev/dbft v0.0.0-20210122071512-d9a728094f0d h1:uUaRysqa/9VtHETVARUlteqfbXAgwxR2nvUc4DzK4pI=
github.com/nspcc-dev/dbft v0.0.0-20210122071512-d9a728094f0d/go.mod h1:I5D0W3tu3epdt2RMCTxS//HDr4S+OHRqajouQTOAHI8= github.com/nspcc-dev/dbft v0.0.0-20210122071512-d9a728094f0d/go.mod h1:I5D0W3tu3epdt2RMCTxS//HDr4S+OHRqajouQTOAHI8=
github.com/nspcc-dev/dbft v0.0.0-20210301082123-a8be68a63b6f h1:jKbF0lOzhkRGa0mndMWS+n/pxWLkuD+0IYBzSIPBZfo=
github.com/nspcc-dev/dbft v0.0.0-20210301082123-a8be68a63b6f/go.mod h1:U8MSnEShH+o5hexfWJdze6uMFJteP0ko7J2frO7Yu1Y=
github.com/nspcc-dev/dbft v0.0.0-20210301092823-72d7079ea827 h1:0/kXunWrz9a+4V1rcHMEcrKOJ/n/9VcFcAosEXTH7r4=
github.com/nspcc-dev/dbft v0.0.0-20210301092823-72d7079ea827/go.mod h1:U8MSnEShH+o5hexfWJdze6uMFJteP0ko7J2frO7Yu1Y=
github.com/nspcc-dev/dbft v0.0.0-20210301140418-d31e1e0c272f h1:d5vDIXpt9xFQeXg6LzCzCh5Lf8HS5EHLSBGLGwdWywQ=
github.com/nspcc-dev/dbft v0.0.0-20210301140418-d31e1e0c272f/go.mod h1:U8MSnEShH+o5hexfWJdze6uMFJteP0ko7J2frO7Yu1Y=
github.com/nspcc-dev/neo-go v0.73.1-pre.0.20200303142215-f5a1b928ce09/go.mod h1:pPYwPZ2ks+uMnlRLUyXOpLieaDQSEaf4NM3zHVbRjmg= github.com/nspcc-dev/neo-go v0.73.1-pre.0.20200303142215-f5a1b928ce09/go.mod h1:pPYwPZ2ks+uMnlRLUyXOpLieaDQSEaf4NM3zHVbRjmg=
github.com/nspcc-dev/neofs-crypto v0.2.0 h1:ftN+59WqxSWz/RCgXYOfhmltOOqU+udsNQSvN6wkFck= github.com/nspcc-dev/neofs-crypto v0.2.0 h1:ftN+59WqxSWz/RCgXYOfhmltOOqU+udsNQSvN6wkFck=
github.com/nspcc-dev/neofs-crypto v0.2.0/go.mod h1:F/96fUzPM3wR+UGsPi3faVNmFlA9KAEAUQR7dMxZmNA= github.com/nspcc-dev/neofs-crypto v0.2.0/go.mod h1:F/96fUzPM3wR+UGsPi3faVNmFlA9KAEAUQR7dMxZmNA=

View file

@ -62,10 +62,10 @@ func TestCompiler(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
err = os.MkdirAll(exampleSavePath, os.ModePerm) err = os.MkdirAll(exampleSavePath, os.ModePerm)
require.NoError(t, err) require.NoError(t, err)
defer func() { t.Cleanup(func() {
err := os.RemoveAll(exampleSavePath) err := os.RemoveAll(exampleSavePath)
require.NoError(t, err) require.NoError(t, err)
}() })
outfile := exampleSavePath + "/test.nef" outfile := exampleSavePath + "/test.nef"
_, err = compiler.CompileAndSave(exampleCompilePath+"/"+infos[0].Name(), &compiler.Options{Outfile: outfile}) _, err = compiler.CompileAndSave(exampleCompilePath+"/"+infos[0].Name(), &compiler.Options{Outfile: outfile})
require.NoError(t, err) require.NoError(t, err)

View file

@ -44,7 +44,6 @@ func TestNewService(t *testing.T) {
require.NotPanics(t, func() { txx = srv.getVerifiedTx() }) require.NotPanics(t, func() { txx = srv.getVerifiedTx() })
require.Len(t, txx, 1) require.Len(t, txx, 1)
require.Equal(t, tx, txx[0]) require.Equal(t, tx, txx[0])
srv.Chain.Close()
} }
func initServiceNextConsensus(t *testing.T, newAcc *wallet.Account, offset uint32) (*service, *wallet.Account) { func initServiceNextConsensus(t *testing.T, newAcc *wallet.Account, offset uint32) (*service, *wallet.Account) {
@ -129,7 +128,6 @@ func TestService_NextConsensus(t *testing.T) {
t.Run("vote 1 block before update", func(t *testing.T) { // voting occurs every block in SingleTestChain t.Run("vote 1 block before update", func(t *testing.T) { // voting occurs every block in SingleTestChain
srv, acc := initServiceNextConsensus(t, newAcc, 1) srv, acc := initServiceNextConsensus(t, newAcc, 1)
bc := srv.Chain.(*core.Blockchain) bc := srv.Chain.(*core.Blockchain)
defer bc.Close()
height := bc.BlockHeight() height := bc.BlockHeight()
checkNextConsensus(t, bc, height, acc.Contract.ScriptHash()) checkNextConsensus(t, bc, height, acc.Contract.ScriptHash())
@ -219,7 +217,6 @@ func TestService_GetVerified(t *testing.T) {
require.Contains(t, txx, txs[1]) require.Contains(t, txx, txs[1])
require.NotContains(t, txx, txs[2]) require.NotContains(t, txx, txs[2])
}) })
srv.Chain.Close()
} }
func TestService_ValidatePayload(t *testing.T) { func TestService_ValidatePayload(t *testing.T) {
@ -257,7 +254,6 @@ func TestService_ValidatePayload(t *testing.T) {
require.NoError(t, p.Sign(priv)) require.NoError(t, p.Sign(priv))
require.True(t, srv.validatePayload(p)) require.True(t, srv.validatePayload(p))
}) })
srv.Chain.Close()
} }
func TestService_getTx(t *testing.T) { func TestService_getTx(t *testing.T) {
@ -294,13 +290,12 @@ func TestService_getTx(t *testing.T) {
require.NotNil(t, got) require.NotNil(t, got)
require.Equal(t, h, got.Hash()) require.Equal(t, h, got.Hash())
}) })
srv.Chain.Close()
} }
func TestService_PrepareRequest(t *testing.T) { func TestService_PrepareRequest(t *testing.T) {
srv := newTestServiceWithState(t, true) srv := newTestServiceWithState(t, true)
srv.dbft.Start() srv.dbft.Start()
defer srv.dbft.Timer.Stop() t.Cleanup(srv.dbft.Timer.Stop)
priv, _ := getTestValidator(1) priv, _ := getTestValidator(1)
p := new(Payload) p := new(Payload)
@ -359,12 +354,10 @@ func TestService_OnPayload(t *testing.T) {
require.NoError(t, p.Sign(priv)) require.NoError(t, p.Sign(priv))
srv.OnPayload(&p.Extensible) srv.OnPayload(&p.Extensible)
shouldReceive(t, srv.messages) shouldReceive(t, srv.messages)
srv.Chain.Close()
} }
func TestVerifyBlock(t *testing.T) { func TestVerifyBlock(t *testing.T) {
srv := newTestService(t) srv := newTestService(t)
defer srv.Chain.Close()
srv.lastTimestamp = 1 srv.lastTimestamp = 1
t.Run("good empty", func(t *testing.T) { t.Run("good empty", func(t *testing.T) {
@ -513,7 +506,7 @@ func newTestChain(t *testing.T, stateRootInHeader bool) *core.Blockchain {
require.NoError(t, err) require.NoError(t, err)
go chain.Run() go chain.Run()
t.Cleanup(chain.Close)
return chain return chain
} }

View file

@ -262,7 +262,6 @@ func TestPayload_Sign(t *testing.T) {
p := randomPayload(t, prepareRequestType) p := randomPayload(t, prepareRequestType)
h := priv.PublicKey().GetScriptHash() h := priv.PublicKey().GetScriptHash()
bc := newTestChain(t, false) bc := newTestChain(t, false)
defer bc.Close()
require.Error(t, bc.VerifyWitness(h, p, &p.Witness, payloadGasLimit)) require.Error(t, bc.VerifyWitness(h, p, &p.Witness, payloadGasLimit))
require.NoError(t, p.Sign(priv)) require.NoError(t, p.Sign(priv))
require.NoError(t, bc.VerifyWitness(h, p, &p.Witness, payloadGasLimit)) require.NoError(t, bc.VerifyWitness(h, p, &p.Witness, payloadGasLimit))

View file

@ -23,7 +23,6 @@ func TestRecoveryMessageSetters(t *testing.T) {
func testRecoveryMessageSetters(t *testing.T, enableStateRoot bool) { func testRecoveryMessageSetters(t *testing.T, enableStateRoot bool) {
srv := newTestServiceWithState(t, enableStateRoot) srv := newTestServiceWithState(t, enableStateRoot)
defer srv.Chain.Close()
privs := make([]*privateKey, testchain.Size()) privs := make([]*privateKey, testchain.Size())
pubs := make([]crypto.PublicKey, testchain.Size()) pubs := make([]crypto.PublicKey, testchain.Size())
for i := 0; i < testchain.Size(); i++ { for i := 0; i < testchain.Size(); i++ {

View file

@ -41,7 +41,6 @@ import (
func TestVerifyHeader(t *testing.T) { func TestVerifyHeader(t *testing.T) {
bc := newTestChain(t) bc := newTestChain(t)
defer bc.Close()
prev := bc.topBlock.Load().(*block.Block).Header() prev := bc.topBlock.Load().(*block.Block).Header()
t.Run("Invalid", func(t *testing.T) { t.Run("Invalid", func(t *testing.T) {
t.Run("Hash", func(t *testing.T) { t.Run("Hash", func(t *testing.T) {
@ -68,7 +67,6 @@ func TestVerifyHeader(t *testing.T) {
func TestAddHeaders(t *testing.T) { func TestAddHeaders(t *testing.T) {
bc := newTestChain(t) bc := newTestChain(t)
defer bc.Close()
lastBlock := bc.topBlock.Load().(*block.Block) lastBlock := bc.topBlock.Load().(*block.Block)
h1 := newBlock(bc.config, 1, lastBlock.Hash()).Header() h1 := newBlock(bc.config, 1, lastBlock.Hash()).Header()
h2 := newBlock(bc.config, 2, h1.Hash()).Header() h2 := newBlock(bc.config, 2, h1.Hash()).Header()
@ -132,7 +130,6 @@ func TestAddBlockStateRoot(t *testing.T) {
bc := newTestChainWithCustomCfg(t, func(c *config.Config) { bc := newTestChainWithCustomCfg(t, func(c *config.Config) {
c.ProtocolConfiguration.StateRootInHeader = true c.ProtocolConfiguration.StateRootInHeader = true
}) })
defer bc.Close()
sr, err := bc.GetStateRoot(bc.BlockHeight()) sr, err := bc.GetStateRoot(bc.BlockHeight())
require.NoError(t, err) require.NoError(t, err)
@ -159,7 +156,6 @@ func TestAddBlockStateRoot(t *testing.T) {
func TestAddBadBlock(t *testing.T) { func TestAddBadBlock(t *testing.T) {
bc := newTestChain(t) bc := newTestChain(t)
defer bc.Close()
// It has ValidUntilBlock == 0, which is wrong // It has ValidUntilBlock == 0, which is wrong
tx := transaction.New(netmode.UnitTestNet, []byte{byte(opcode.PUSH1)}, 0) tx := transaction.New(netmode.UnitTestNet, []byte{byte(opcode.PUSH1)}, 0)
tx.Signers = []transaction.Signer{{ tx.Signers = []transaction.Signer{{
@ -250,7 +246,6 @@ func (bc *Blockchain) newTestTx(h util.Uint160, script []byte) *transaction.Tran
func TestVerifyTx(t *testing.T) { func TestVerifyTx(t *testing.T) {
bc := newTestChain(t) bc := newTestChain(t)
defer bc.Close()
accs := make([]*wallet.Account, 5) accs := make([]*wallet.Account, 5)
for i := range accs { for i := range accs {
@ -1063,7 +1058,6 @@ func TestVerifyTx(t *testing.T) {
func TestVerifyHashAgainstScript(t *testing.T) { func TestVerifyHashAgainstScript(t *testing.T) {
bc := newTestChain(t) bc := newTestChain(t)
defer bc.Close()
cs, csInvalid := getTestContractState(bc) cs, csInvalid := getTestContractState(bc)
ic := bc.newInteropContext(trigger.Verification, bc.dao, nil, nil) ic := bc.newInteropContext(trigger.Verification, bc.dao, nil, nil)
@ -1137,7 +1131,6 @@ func TestVerifyHashAgainstScript(t *testing.T) {
func TestIsTxStillRelevant(t *testing.T) { func TestIsTxStillRelevant(t *testing.T) {
bc := newTestChain(t) bc := newTestChain(t)
defer bc.Close()
mp := bc.GetMemPool() mp := bc.GetMemPool()
newTx := func(t *testing.T) *transaction.Transaction { newTx := func(t *testing.T) *transaction.Transaction {
@ -1233,7 +1226,6 @@ func TestMemPoolRemoval(t *testing.T) {
const added = 16 const added = 16
const notAdded = 32 const notAdded = 32
bc := newTestChain(t) bc := newTestChain(t)
defer bc.Close()
addedTxes := make([]*transaction.Transaction, added) addedTxes := make([]*transaction.Transaction, added)
notAddedTxes := make([]*transaction.Transaction, notAdded) notAddedTxes := make([]*transaction.Transaction, notAdded)
for i := range addedTxes { for i := range addedTxes {
@ -1310,7 +1302,6 @@ func TestGetTransaction(t *testing.T) {
func TestGetClaimable(t *testing.T) { func TestGetClaimable(t *testing.T) {
bc := newTestChain(t) bc := newTestChain(t)
defer bc.Close()
_, err := bc.genBlocks(10) _, err := bc.genBlocks(10)
require.NoError(t, err) require.NoError(t, err)
@ -1327,7 +1318,8 @@ func TestClose(t *testing.T) {
r := recover() r := recover()
assert.NotNil(t, r) assert.NotNil(t, r)
}() }()
bc := newTestChain(t) bc := initTestChain(t, nil, nil)
go bc.Run()
_, err := bc.genBlocks(10) _, err := bc.genBlocks(10)
require.NoError(t, err) require.NoError(t, err)
bc.Close() bc.Close()
@ -1350,7 +1342,6 @@ func TestSubscriptions(t *testing.T) {
executionCh := make(chan *state.AppExecResult, chBufSize) executionCh := make(chan *state.AppExecResult, chBufSize)
bc := newTestChain(t) bc := newTestChain(t)
defer bc.Close()
bc.SubscribeForBlocks(blockCh) bc.SubscribeForBlocks(blockCh)
bc.SubscribeForTransactions(txCh) bc.SubscribeForTransactions(txCh)
bc.SubscribeForNotifications(notificationCh) bc.SubscribeForNotifications(notificationCh)
@ -1473,7 +1464,6 @@ func testDumpAndRestore(t *testing.T, dumpF, restoreF func(c *config.Config)) {
} }
bc := newTestChainWithCustomCfg(t, dumpF) bc := newTestChainWithCustomCfg(t, dumpF)
defer bc.Close()
initBasicChain(t, bc) initBasicChain(t, bc)
require.True(t, bc.BlockHeight() > 5) // ensure that test is valid require.True(t, bc.BlockHeight() > 5) // ensure that test is valid
@ -1485,14 +1475,12 @@ func testDumpAndRestore(t *testing.T, dumpF, restoreF func(c *config.Config)) {
buf := w.Bytes() buf := w.Bytes()
t.Run("invalid start", func(t *testing.T) { t.Run("invalid start", func(t *testing.T) {
bc2 := newTestChainWithCustomCfg(t, restoreF) bc2 := newTestChainWithCustomCfg(t, restoreF)
defer bc2.Close()
r := io.NewBinReaderFromBuf(buf) r := io.NewBinReaderFromBuf(buf)
require.Error(t, chaindump.Restore(bc2, r, 2, 1, nil)) require.Error(t, chaindump.Restore(bc2, r, 2, 1, nil))
}) })
t.Run("good", func(t *testing.T) { t.Run("good", func(t *testing.T) {
bc2 := newTestChainWithCustomCfg(t, restoreF) bc2 := newTestChainWithCustomCfg(t, restoreF)
defer bc2.Close()
r := io.NewBinReaderFromBuf(buf) r := io.NewBinReaderFromBuf(buf)
require.NoError(t, chaindump.Restore(bc2, r, 0, 2, nil)) require.NoError(t, chaindump.Restore(bc2, r, 0, 2, nil))
@ -1547,7 +1535,6 @@ func TestRemoveUntraceable(t *testing.T) {
c.ProtocolConfiguration.MaxTraceableBlocks = 2 c.ProtocolConfiguration.MaxTraceableBlocks = 2
c.ProtocolConfiguration.RemoveUntraceableBlocks = true c.ProtocolConfiguration.RemoveUntraceableBlocks = true
}) })
defer bc.Close()
tx1, err := testchain.NewTransferFromOwner(bc, bc.contracts.NEO.Hash, util.Uint160{}, 1, 0, bc.BlockHeight()+1) tx1, err := testchain.NewTransferFromOwner(bc, bc.contracts.NEO.Hash, util.Uint160{}, 1, 0, bc.BlockHeight()+1)
require.NoError(t, err) require.NoError(t, err)
@ -1576,7 +1563,6 @@ func TestRemoveUntraceable(t *testing.T) {
func TestInvalidNotification(t *testing.T) { func TestInvalidNotification(t *testing.T) {
bc := newTestChain(t) bc := newTestChain(t)
defer bc.Close()
cs, _ := getTestContractState(bc) cs, _ := getTestContractState(bc)
require.NoError(t, bc.contracts.Management.PutContractState(bc.dao, cs)) require.NoError(t, bc.contracts.Management.PutContractState(bc.dao, cs))
@ -1591,7 +1577,6 @@ func TestInvalidNotification(t *testing.T) {
// Test that deletion of non-existent doesn't result in error in tx or block addition. // Test that deletion of non-existent doesn't result in error in tx or block addition.
func TestMPTDeleteNoKey(t *testing.T) { func TestMPTDeleteNoKey(t *testing.T) {
bc := newTestChain(t) bc := newTestChain(t)
defer bc.Close()
cs, _ := getTestContractState(bc) cs, _ := getTestContractState(bc)
require.NoError(t, bc.contracts.Management.PutContractState(bc.dao, cs)) require.NoError(t, bc.contracts.Management.PutContractState(bc.dao, cs))

View file

@ -59,6 +59,7 @@ func newTestChainWithCustomCfg(t *testing.T, f func(*config.Config)) *Blockchain
func newTestChainWithCustomCfgAndStore(t *testing.T, st storage.Store, f func(*config.Config)) *Blockchain { func newTestChainWithCustomCfgAndStore(t *testing.T, st storage.Store, f func(*config.Config)) *Blockchain {
chain := initTestChain(t, st, f) chain := initTestChain(t, st, f)
go chain.Run() go chain.Run()
t.Cleanup(chain.Close)
return chain return chain
} }
@ -174,7 +175,6 @@ func TestBug1728(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
bc := newTestChain(t) bc := newTestChain(t)
defer bc.Close()
aer, err := invokeContractMethod(bc, 10000000000, aer, err := invokeContractMethod(bc, 10000000000,
bc.contracts.Management.Hash, "deploy", rawNef, rawManifest) bc.contracts.Management.Hash, "deploy", rawNef, rawManifest)
@ -242,13 +242,14 @@ func TestCreateBasicChain(t *testing.T) {
const prefix = "../rpc/server/testdata/" const prefix = "../rpc/server/testdata/"
bc := newTestChain(t) bc := newTestChain(t)
defer bc.Close()
initBasicChain(t, bc) initBasicChain(t, bc)
if saveChain { if saveChain {
outStream, err := os.Create(prefix + "testblocks.acc") outStream, err := os.Create(prefix + "testblocks.acc")
require.NoError(t, err) require.NoError(t, err)
defer outStream.Close() t.Cleanup(func() {
outStream.Close()
})
writer := io.NewBinWriterFromIO(outStream) writer := io.NewBinWriterFromIO(outStream)
writer.WriteU32LE(bc.BlockHeight()) writer.WriteU32LE(bc.BlockHeight())

View file

@ -36,7 +36,6 @@ import (
func TestStorageFind(t *testing.T) { func TestStorageFind(t *testing.T) {
v, contractState, context, chain := createVMAndContractState(t) v, contractState, context, chain := createVMAndContractState(t)
defer chain.Close()
arr := []stackitem.Item{ arr := []stackitem.Item{
stackitem.NewBigInteger(big.NewInt(42)), stackitem.NewBigInteger(big.NewInt(42)),

View file

@ -32,7 +32,6 @@ import (
func TestContractIsStandard(t *testing.T) { func TestContractIsStandard(t *testing.T) {
v, ic, chain := createVM(t) v, ic, chain := createVM(t)
defer chain.Close()
t.Run("contract not stored", func(t *testing.T) { t.Run("contract not stored", func(t *testing.T) {
priv, err := keys.NewPrivateKey() priv, err := keys.NewPrivateKey()
@ -91,8 +90,7 @@ func TestContractIsStandard(t *testing.T) {
} }
func TestContractCreateAccount(t *testing.T) { func TestContractCreateAccount(t *testing.T) {
v, ic, chain := createVM(t) v, ic, _ := createVM(t)
defer chain.Close()
t.Run("Good", func(t *testing.T) { t.Run("Good", func(t *testing.T) {
priv, err := keys.NewPrivateKey() priv, err := keys.NewPrivateKey()
require.NoError(t, err) require.NoError(t, err)
@ -112,8 +110,7 @@ func TestContractCreateAccount(t *testing.T) {
} }
func TestContractCreateMultisigAccount(t *testing.T) { func TestContractCreateMultisigAccount(t *testing.T) {
v, ic, chain := createVM(t) v, ic, _ := createVM(t)
defer chain.Close()
t.Run("Good", func(t *testing.T) { t.Run("Good", func(t *testing.T) {
m, n := 3, 5 m, n := 3, 5
pubs := make(keys.PublicKeys, n) pubs := make(keys.PublicKeys, n)
@ -159,8 +156,7 @@ func TestContractCreateMultisigAccount(t *testing.T) {
} }
func TestRuntimeGasLeft(t *testing.T) { func TestRuntimeGasLeft(t *testing.T) {
v, ic, chain := createVM(t) v, ic, _ := createVM(t)
defer chain.Close()
v.GasLimit = 100 v.GasLimit = 100
v.AddGas(58) v.AddGas(58)
@ -169,8 +165,7 @@ func TestRuntimeGasLeft(t *testing.T) {
} }
func TestRuntimeGetNotifications(t *testing.T) { func TestRuntimeGetNotifications(t *testing.T) {
v, ic, chain := createVM(t) v, ic, _ := createVM(t)
defer chain.Close()
ic.Notifications = []state.NotificationEvent{ ic.Notifications = []state.NotificationEvent{
{ScriptHash: util.Uint160{1}, Name: "Event1", Item: stackitem.NewArray([]stackitem.Item{stackitem.NewByteArray([]byte{11})})}, {ScriptHash: util.Uint160{1}, Name: "Event1", Item: stackitem.NewArray([]stackitem.Item{stackitem.NewByteArray([]byte{11})})},
@ -211,8 +206,7 @@ func TestRuntimeGetNotifications(t *testing.T) {
} }
func TestRuntimeGetInvocationCounter(t *testing.T) { func TestRuntimeGetInvocationCounter(t *testing.T) {
v, ic, chain := createVM(t) v, ic, _ := createVM(t)
defer chain.Close()
ic.VM.Invocations[hash.Hash160([]byte{2})] = 42 ic.VM.Invocations[hash.Hash160([]byte{2})] = 42
@ -231,7 +225,6 @@ func TestRuntimeGetInvocationCounter(t *testing.T) {
func TestStoragePut(t *testing.T) { func TestStoragePut(t *testing.T) {
_, cs, ic, bc := createVMAndContractState(t) _, cs, ic, bc := createVMAndContractState(t)
defer bc.Close()
require.NoError(t, bc.contracts.Management.PutContractState(ic.DAO, cs)) require.NoError(t, bc.contracts.Management.PutContractState(ic.DAO, cs))
@ -304,7 +297,6 @@ func TestStoragePut(t *testing.T) {
func TestStorageDelete(t *testing.T) { func TestStorageDelete(t *testing.T) {
v, cs, ic, bc := createVMAndContractState(t) v, cs, ic, bc := createVMAndContractState(t)
defer bc.Close()
require.NoError(t, bc.contracts.Management.PutContractState(ic.DAO, cs)) require.NoError(t, bc.contracts.Management.PutContractState(ic.DAO, cs))
v.LoadScriptWithHash(cs.NEF.Script, cs.Hash, callflag.All) v.LoadScriptWithHash(cs.NEF.Script, cs.Hash, callflag.All)
@ -675,7 +667,6 @@ func loadScriptWithHashAndFlags(ic *interop.Context, script []byte, hash util.Ui
func TestContractCall(t *testing.T) { func TestContractCall(t *testing.T) {
_, ic, bc := createVM(t) _, ic, bc := createVM(t)
defer bc.Close()
cs, currCs := getTestContractState(bc) cs, currCs := getTestContractState(bc)
require.NoError(t, bc.contracts.Management.PutContractState(ic.DAO, cs)) require.NoError(t, bc.contracts.Management.PutContractState(ic.DAO, cs))
@ -805,8 +796,7 @@ func TestContractCall(t *testing.T) {
} }
func TestContractGetCallFlags(t *testing.T) { func TestContractGetCallFlags(t *testing.T) {
v, ic, bc := createVM(t) v, ic, _ := createVM(t)
defer bc.Close()
v.LoadScriptWithHash([]byte{byte(opcode.RET)}, util.Uint160{1, 2, 3}, callflag.All) v.LoadScriptWithHash([]byte{byte(opcode.RET)}, util.Uint160{1, 2, 3}, callflag.All)
require.NoError(t, contractGetCallFlags(ic)) require.NoError(t, contractGetCallFlags(ic))
@ -815,7 +805,6 @@ func TestContractGetCallFlags(t *testing.T) {
func TestRuntimeCheckWitness(t *testing.T) { func TestRuntimeCheckWitness(t *testing.T) {
_, ic, bc := createVM(t) _, ic, bc := createVM(t)
defer bc.Close()
script := []byte{byte(opcode.RET)} script := []byte{byte(opcode.RET)}
scriptHash := hash.Hash160(script) scriptHash := hash.Hash160(script)
@ -1008,7 +997,6 @@ func TestRuntimeCheckWitness(t *testing.T) {
func TestLoadToken(t *testing.T) { func TestLoadToken(t *testing.T) {
bc := newTestChain(t) bc := newTestChain(t)
defer bc.Close()
cs, _ := getTestContractState(bc) cs, _ := getTestContractState(bc)
require.NoError(t, bc.contracts.Management.PutContractState(bc.dao, cs)) require.NoError(t, bc.contracts.Management.PutContractState(bc.dao, cs))

View file

@ -18,7 +18,6 @@ func testNonInterop(t *testing.T, value interface{}, f func(*interop.Context) er
v := vm.New() v := vm.New()
v.Estack().PushVal(value) v.Estack().PushVal(value)
chain := newTestChain(t) chain := newTestChain(t)
defer chain.Close()
d := dao.NewSimple(storage.NewMemoryStore(), netmode.UnitTestNet, chain.config.StateRootInHeader) d := dao.NewSimple(storage.NewMemoryStore(), netmode.UnitTestNet, chain.config.StateRootInHeader)
context := chain.newInteropContext(trigger.Application, d, nil, nil) context := chain.newInteropContext(trigger.Application, d, nil, nil)
context.VM = v context.VM = v

View file

@ -29,7 +29,7 @@ func TestSubscriptions(t *testing.T) {
subChan1 := make(chan Event, 3) subChan1 := make(chan Event, 3)
subChan2 := make(chan Event, 3) subChan2 := make(chan Event, 3)
mp.SubscribeForTransactions(subChan1) mp.SubscribeForTransactions(subChan1)
defer mp.StopSubscriptions() t.Cleanup(mp.StopSubscriptions)
txs := make([]*transaction.Transaction, 4) txs := make([]*transaction.Transaction, 4)
for i := range txs { for i := range txs {

View file

@ -166,7 +166,6 @@ func (tn *testNative) callOtherContractWithReturn(ic *interop.Context, args []st
func TestNativeContract_Invoke(t *testing.T) { func TestNativeContract_Invoke(t *testing.T) {
chain := newTestChain(t) chain := newTestChain(t)
defer chain.Close()
tn := newTestNative() tn := newTestNative()
chain.registerNative(tn) chain.registerNative(tn)
@ -206,7 +205,6 @@ func TestNativeContract_Invoke(t *testing.T) {
func TestNativeContract_InvokeInternal(t *testing.T) { func TestNativeContract_InvokeInternal(t *testing.T) {
chain := newTestChain(t) chain := newTestChain(t)
defer chain.Close()
tn := newTestNative() tn := newTestNative()
chain.registerNative(tn) chain.registerNative(tn)
@ -251,7 +249,6 @@ func TestNativeContract_InvokeInternal(t *testing.T) {
func TestNativeContract_InvokeOtherContract(t *testing.T) { func TestNativeContract_InvokeOtherContract(t *testing.T) {
chain := newTestChain(t) chain := newTestChain(t)
defer chain.Close()
tn := newTestNative() tn := newTestNative()
chain.registerNative(tn) chain.registerNative(tn)

View file

@ -80,7 +80,6 @@ func (bc *Blockchain) getNodesByRole(t *testing.T, ok bool, r native.Role, index
func TestDesignate_DesignateAsRoleTx(t *testing.T) { func TestDesignate_DesignateAsRoleTx(t *testing.T) {
bc := newTestChain(t) bc := newTestChain(t)
defer bc.Close()
priv, err := keys.NewPrivateKey() priv, err := keys.NewPrivateKey()
require.NoError(t, err) require.NoError(t, err)
@ -104,7 +103,6 @@ func TestDesignate_DesignateAsRoleTx(t *testing.T) {
func TestDesignate_DesignateAsRole(t *testing.T) { func TestDesignate_DesignateAsRole(t *testing.T) {
bc := newTestChain(t) bc := newTestChain(t)
defer bc.Close()
des := bc.contracts.Designate des := bc.contracts.Designate
tx := transaction.New(netmode.UnitTestNet, []byte{}, 0) tx := transaction.New(netmode.UnitTestNet, []byte{}, 0)

View file

@ -12,7 +12,6 @@ import (
func TestLedgerGetTransactionHeight(t *testing.T) { func TestLedgerGetTransactionHeight(t *testing.T) {
_, tx, _, chain := createVMAndTX(t) _, tx, _, chain := createVMAndTX(t)
defer chain.Close()
ledger := chain.contracts.ByName(nativenames.Ledger).Metadata().Hash ledger := chain.contracts.ByName(nativenames.Ledger).Metadata().Hash
@ -39,7 +38,6 @@ func TestLedgerGetTransactionHeight(t *testing.T) {
func TestLedgerGetTransaction(t *testing.T) { func TestLedgerGetTransaction(t *testing.T) {
_, tx, _, chain := createVMAndTX(t) _, tx, _, chain := createVMAndTX(t)
defer chain.Close()
ledger := chain.contracts.ByName(nativenames.Ledger).Metadata().Hash ledger := chain.contracts.ByName(nativenames.Ledger).Metadata().Hash
t.Run("success", func(t *testing.T) { t.Run("success", func(t *testing.T) {
@ -80,7 +78,6 @@ func TestLedgerGetTransaction(t *testing.T) {
func TestLedgerGetTransactionFromBlock(t *testing.T) { func TestLedgerGetTransactionFromBlock(t *testing.T) {
chain := newTestChain(t) chain := newTestChain(t)
defer chain.Close()
ledger := chain.contracts.ByName(nativenames.Ledger).Metadata().Hash ledger := chain.contracts.ByName(nativenames.Ledger).Metadata().Hash
res, err := invokeContractMethod(chain, 100000000, ledger, "currentIndex") // adds a block res, err := invokeContractMethod(chain, 100000000, ledger, "currentIndex") // adds a block
@ -132,7 +129,6 @@ func TestLedgerGetTransactionFromBlock(t *testing.T) {
func TestLedgerGetBlock(t *testing.T) { func TestLedgerGetBlock(t *testing.T) {
chain := newTestChain(t) chain := newTestChain(t)
defer chain.Close()
ledger := chain.contracts.ByName(nativenames.Ledger).Metadata().Hash ledger := chain.contracts.ByName(nativenames.Ledger).Metadata().Hash
bhash := chain.GetHeaderHash(0) bhash := chain.GetHeaderHash(0)

View file

@ -30,7 +30,6 @@ import (
// leads to tx deserialization failure. // leads to tx deserialization failure.
func TestRestoreAfterDeploy(t *testing.T) { func TestRestoreAfterDeploy(t *testing.T) {
bc := newTestChain(t) bc := newTestChain(t)
defer bc.Close()
// nef.NewFile() cares about version a lot. // nef.NewFile() cares about version a lot.
config.Version = "0.90.0-test" config.Version = "0.90.0-test"
@ -61,7 +60,6 @@ func TestStartFromHeight(t *testing.T) {
bc := newTestChainWithCustomCfgAndStore(t, st, nil) bc := newTestChainWithCustomCfgAndStore(t, st, nil)
cs1, _ := getTestContractState(bc) cs1, _ := getTestContractState(bc)
func() { func() {
defer bc.Close()
require.NoError(t, bc.contracts.Management.PutContractState(bc.dao, cs1)) require.NoError(t, bc.contracts.Management.PutContractState(bc.dao, cs1))
checkContractState(t, bc, cs1.Hash, cs1) checkContractState(t, bc, cs1.Hash, cs1)
_, err := bc.dao.Store.Persist() _, err := bc.dao.Store.Persist()
@ -74,7 +72,6 @@ func TestStartFromHeight(t *testing.T) {
func TestContractDeployAndUpdateWithParameter(t *testing.T) { func TestContractDeployAndUpdateWithParameter(t *testing.T) {
bc := newTestChain(t) bc := newTestChain(t)
defer bc.Close()
// nef.NewFile() cares about version a lot. // nef.NewFile() cares about version a lot.
config.Version = "0.90.0-test" config.Version = "0.90.0-test"
@ -125,7 +122,6 @@ func TestContractDeployAndUpdateWithParameter(t *testing.T) {
func TestContractDeploy(t *testing.T) { func TestContractDeploy(t *testing.T) {
bc := newTestChain(t) bc := newTestChain(t)
defer bc.Close()
// nef.NewFile() cares about version a lot. // nef.NewFile() cares about version a lot.
config.Version = "0.90.0-test" config.Version = "0.90.0-test"
@ -277,7 +273,6 @@ func TestContractDeploy(t *testing.T) {
r := io.NewBinReaderFromBuf(w.Bytes()) r := io.NewBinReaderFromBuf(w.Bytes())
bc2 := newTestChain(t) bc2 := newTestChain(t)
defer bc2.Close()
require.NoError(t, chaindump.Restore(bc2, r, 0, bc.BlockHeight()+1, nil)) require.NoError(t, chaindump.Restore(bc2, r, 0, bc.BlockHeight()+1, nil))
require.NoError(t, r.Err) require.NoError(t, r.Err)
@ -364,7 +359,6 @@ func checkContractState(t *testing.T, bc *Blockchain, h util.Uint160, cs *state.
func TestContractUpdate(t *testing.T) { func TestContractUpdate(t *testing.T) {
bc := newTestChain(t) bc := newTestChain(t)
defer bc.Close()
// nef.NewFile() cares about version a lot. // nef.NewFile() cares about version a lot.
config.Version = "0.90.0-test" config.Version = "0.90.0-test"
@ -526,7 +520,6 @@ func TestContractUpdate(t *testing.T) {
func TestGetContract(t *testing.T) { func TestGetContract(t *testing.T) {
bc := newTestChain(t) bc := newTestChain(t)
defer bc.Close()
mgmtHash := bc.ManagementContractHash() mgmtHash := bc.ManagementContractHash()
cs1, _ := getTestContractState(bc) cs1, _ := getTestContractState(bc)
@ -553,7 +546,6 @@ func TestGetContract(t *testing.T) {
func TestContractDestroy(t *testing.T) { func TestContractDestroy(t *testing.T) {
bc := newTestChain(t) bc := newTestChain(t)
defer bc.Close()
mgmtHash := bc.ManagementContractHash() mgmtHash := bc.ManagementContractHash()
cs1, _ := getTestContractState(bc) cs1, _ := getTestContractState(bc)
@ -607,7 +599,6 @@ func compareContractStates(t *testing.T, expected *state.Contract, actual stacki
func TestMinimumDeploymentFee(t *testing.T) { func TestMinimumDeploymentFee(t *testing.T) {
chain := newTestChain(t) chain := newTestChain(t)
defer chain.Close()
t.Run("get, internal method", func(t *testing.T) { t.Run("get, internal method", func(t *testing.T) {
n := chain.contracts.Management.GetMinimumDeploymentFee(chain.dao) n := chain.contracts.Management.GetMinimumDeploymentFee(chain.dao)

View file

@ -21,7 +21,6 @@ import (
func TestNameService_Price(t *testing.T) { func TestNameService_Price(t *testing.T) {
bc := newTestChain(t) bc := newTestChain(t)
defer bc.Close()
testGetSet(t, bc, bc.contracts.NameService.Hash, "Price", testGetSet(t, bc, bc.contracts.NameService.Hash, "Price",
native.DefaultDomainPrice, 1, 10000_00000000) native.DefaultDomainPrice, 1, 10000_00000000)
@ -29,7 +28,6 @@ func TestNameService_Price(t *testing.T) {
func TestNonfungible(t *testing.T) { func TestNonfungible(t *testing.T) {
bc := newTestChain(t) bc := newTestChain(t)
defer bc.Close()
acc := newAccountWithGAS(t, bc) acc := newAccountWithGAS(t, bc)
testNameServiceInvokeAux(t, bc, defaultNameServiceSysfee, acc, "symbol", "NNS") testNameServiceInvokeAux(t, bc, defaultNameServiceSysfee, acc, "symbol", "NNS")
@ -39,7 +37,6 @@ func TestNonfungible(t *testing.T) {
func TestAddRoot(t *testing.T) { func TestAddRoot(t *testing.T) {
bc := newTestChain(t) bc := newTestChain(t)
defer bc.Close()
transferFundsToCommittee(t, bc) transferFundsToCommittee(t, bc)
nsHash := bc.contracts.NameService.Hash nsHash := bc.contracts.NameService.Hash
@ -61,7 +58,6 @@ func TestAddRoot(t *testing.T) {
func TestExpiration(t *testing.T) { func TestExpiration(t *testing.T) {
bc := newTestChain(t) bc := newTestChain(t)
defer bc.Close()
transferFundsToCommittee(t, bc) transferFundsToCommittee(t, bc)
acc := newAccountWithGAS(t, bc) acc := newAccountWithGAS(t, bc)
@ -130,7 +126,6 @@ const secondsInYear = 365 * 24 * 3600
func TestRegisterAndRenew(t *testing.T) { func TestRegisterAndRenew(t *testing.T) {
bc := newTestChain(t) bc := newTestChain(t)
defer bc.Close()
transferFundsToCommittee(t, bc) transferFundsToCommittee(t, bc)
@ -181,7 +176,6 @@ func TestRegisterAndRenew(t *testing.T) {
func TestSetGetRecord(t *testing.T) { func TestSetGetRecord(t *testing.T) {
bc := newTestChain(t) bc := newTestChain(t)
defer bc.Close()
transferFundsToCommittee(t, bc) transferFundsToCommittee(t, bc)
acc := newAccountWithGAS(t, bc) acc := newAccountWithGAS(t, bc)
@ -222,7 +216,6 @@ func TestSetGetRecord(t *testing.T) {
func TestSetAdmin(t *testing.T) { func TestSetAdmin(t *testing.T) {
bc := newTestChain(t) bc := newTestChain(t)
defer bc.Close()
transferFundsToCommittee(t, bc) transferFundsToCommittee(t, bc)
owner := newAccountWithGAS(t, bc) owner := newAccountWithGAS(t, bc)
@ -265,7 +258,6 @@ func TestSetAdmin(t *testing.T) {
func TestTransfer(t *testing.T) { func TestTransfer(t *testing.T) {
bc := newTestChain(t) bc := newTestChain(t)
defer bc.Close()
transferFundsToCommittee(t, bc) transferFundsToCommittee(t, bc)
from := newAccountWithGAS(t, bc) from := newAccountWithGAS(t, bc)
@ -299,7 +291,6 @@ func TestTransfer(t *testing.T) {
func TestTokensOf(t *testing.T) { func TestTokensOf(t *testing.T) {
bc := newTestChain(t) bc := newTestChain(t)
defer bc.Close()
transferFundsToCommittee(t, bc) transferFundsToCommittee(t, bc)
acc1 := newAccountWithGAS(t, bc) acc1 := newAccountWithGAS(t, bc)
@ -356,7 +347,6 @@ func testTokensOf(t *testing.T, bc *Blockchain, signer *wallet.Account, result [
func TestResolve(t *testing.T) { func TestResolve(t *testing.T) {
bc := newTestChain(t) bc := newTestChain(t)
defer bc.Close()
transferFundsToCommittee(t, bc) transferFundsToCommittee(t, bc)
acc := newAccountWithGAS(t, bc) acc := newAccountWithGAS(t, bc)

View file

@ -38,7 +38,6 @@ func checkTxHalt(t *testing.T, bc *Blockchain, h util.Uint256) {
func TestNEO_Vote(t *testing.T) { func TestNEO_Vote(t *testing.T) {
bc := newTestChain(t) bc := newTestChain(t)
defer bc.Close()
neo := bc.contracts.NEO neo := bc.contracts.NEO
tx := transaction.New(netmode.UnitTestNet, []byte{byte(opcode.PUSH1)}, 0) tx := transaction.New(netmode.UnitTestNet, []byte{byte(opcode.PUSH1)}, 0)
@ -195,7 +194,6 @@ func TestNEO_Vote(t *testing.T) {
func TestNEO_SetGasPerBlock(t *testing.T) { func TestNEO_SetGasPerBlock(t *testing.T) {
bc := newTestChain(t) bc := newTestChain(t)
defer bc.Close()
testGetSet(t, bc, bc.contracts.NEO.Hash, "GasPerBlock", testGetSet(t, bc, bc.contracts.NEO.Hash, "GasPerBlock",
5*native.GASFactor, 0, 10*native.GASFactor) 5*native.GASFactor, 0, 10*native.GASFactor)
@ -203,7 +201,6 @@ func TestNEO_SetGasPerBlock(t *testing.T) {
func TestNEO_CalculateBonus(t *testing.T) { func TestNEO_CalculateBonus(t *testing.T) {
bc := newTestChain(t) bc := newTestChain(t)
defer bc.Close()
neo := bc.contracts.NEO neo := bc.contracts.NEO
tx := transaction.New(netmode.UnitTestNet, []byte{}, 0) tx := transaction.New(netmode.UnitTestNet, []byte{}, 0)
@ -233,7 +230,6 @@ func TestNEO_CalculateBonus(t *testing.T) {
func TestNEO_CommitteeBountyOnPersist(t *testing.T) { func TestNEO_CommitteeBountyOnPersist(t *testing.T) {
bc := newTestChain(t) bc := newTestChain(t)
defer bc.Close()
hs := make([]util.Uint160, testchain.CommitteeSize()) hs := make([]util.Uint160, testchain.CommitteeSize())
for i := range hs { for i := range hs {
@ -256,7 +252,6 @@ func TestNEO_CommitteeBountyOnPersist(t *testing.T) {
func TestNEO_TransferOnPayment(t *testing.T) { func TestNEO_TransferOnPayment(t *testing.T) {
bc := newTestChain(t) bc := newTestChain(t)
defer bc.Close()
cs, _ := getTestContractState(bc) cs, _ := getTestContractState(bc)
require.NoError(t, bc.contracts.Management.PutContractState(bc.dao, cs)) require.NoError(t, bc.contracts.Management.PutContractState(bc.dao, cs))

View file

@ -22,7 +22,6 @@ import (
func TestNotaryContractPipeline(t *testing.T) { func TestNotaryContractPipeline(t *testing.T) {
chain := newTestChain(t) chain := newTestChain(t)
defer chain.Close()
notaryHash := chain.contracts.Notary.Hash notaryHash := chain.contracts.Notary.Hash
gasHash := chain.contracts.GAS.Hash gasHash := chain.contracts.GAS.Hash
@ -249,7 +248,6 @@ func TestNotaryContractPipeline(t *testing.T) {
func TestNotaryNodesReward(t *testing.T) { func TestNotaryNodesReward(t *testing.T) {
checkReward := func(nKeys int, nNotaryNodes int, spendFullDeposit bool) { checkReward := func(nKeys int, nNotaryNodes int, spendFullDeposit bool) {
chain := newTestChain(t) chain := newTestChain(t)
defer chain.Close()
notaryHash := chain.contracts.Notary.Hash notaryHash := chain.contracts.Notary.Hash
gasHash := chain.contracts.GAS.Hash gasHash := chain.contracts.GAS.Hash
signer := testchain.MultisigScriptHash() signer := testchain.MultisigScriptHash()
@ -326,7 +324,6 @@ func TestNotaryNodesReward(t *testing.T) {
func TestMaxNotValidBeforeDelta(t *testing.T) { func TestMaxNotValidBeforeDelta(t *testing.T) {
chain := newTestChain(t) chain := newTestChain(t)
defer chain.Close()
testGetSet(t, chain, chain.contracts.Notary.Hash, "MaxNotValidBeforeDelta", testGetSet(t, chain, chain.contracts.Notary.Hash, "MaxNotValidBeforeDelta",
140, int64(chain.GetConfig().ValidatorsCount), transaction.MaxValidUntilBlockIncrement/2) 140, int64(chain.GetConfig().ValidatorsCount), transaction.MaxValidUntilBlockIncrement/2)

View file

@ -115,7 +115,6 @@ func putOracleRequest(t *testing.T, h util.Uint160, bc *Blockchain,
func TestOracle_Request(t *testing.T) { func TestOracle_Request(t *testing.T) {
bc := newTestChain(t) bc := newTestChain(t)
defer bc.Close()
orc := bc.contracts.Oracle orc := bc.contracts.Oracle
cs := getOracleContractState(orc.Hash) cs := getOracleContractState(orc.Hash)

View file

@ -78,7 +78,6 @@ func testGetSet(t *testing.T, chain *Blockchain, hash util.Uint160, name string,
func TestMaxTransactionsPerBlock(t *testing.T) { func TestMaxTransactionsPerBlock(t *testing.T) {
chain := newTestChain(t) chain := newTestChain(t)
defer chain.Close()
t.Run("get, internal method", func(t *testing.T) { t.Run("get, internal method", func(t *testing.T) {
n := chain.contracts.Policy.GetMaxTransactionsPerBlockInternal(chain.dao) n := chain.contracts.Policy.GetMaxTransactionsPerBlockInternal(chain.dao)
@ -90,7 +89,6 @@ func TestMaxTransactionsPerBlock(t *testing.T) {
func TestMaxBlockSize(t *testing.T) { func TestMaxBlockSize(t *testing.T) {
chain := newTestChain(t) chain := newTestChain(t)
defer chain.Close()
t.Run("get, internal method", func(t *testing.T) { t.Run("get, internal method", func(t *testing.T) {
n := chain.contracts.Policy.GetMaxBlockSizeInternal(chain.dao) n := chain.contracts.Policy.GetMaxBlockSizeInternal(chain.dao)
@ -102,7 +100,6 @@ func TestMaxBlockSize(t *testing.T) {
func TestFeePerByte(t *testing.T) { func TestFeePerByte(t *testing.T) {
chain := newTestChain(t) chain := newTestChain(t)
defer chain.Close()
t.Run("get, internal method", func(t *testing.T) { t.Run("get, internal method", func(t *testing.T) {
n := chain.contracts.Policy.GetFeePerByteInternal(chain.dao) n := chain.contracts.Policy.GetFeePerByteInternal(chain.dao)
@ -114,7 +111,6 @@ func TestFeePerByte(t *testing.T) {
func TestExecFeeFactor(t *testing.T) { func TestExecFeeFactor(t *testing.T) {
chain := newTestChain(t) chain := newTestChain(t)
defer chain.Close()
t.Run("get, internal method", func(t *testing.T) { t.Run("get, internal method", func(t *testing.T) {
n := chain.contracts.Policy.GetExecFeeFactorInternal(chain.dao) n := chain.contracts.Policy.GetExecFeeFactorInternal(chain.dao)
@ -126,7 +122,6 @@ func TestExecFeeFactor(t *testing.T) {
func TestBlockSystemFee(t *testing.T) { func TestBlockSystemFee(t *testing.T) {
chain := newTestChain(t) chain := newTestChain(t)
defer chain.Close()
t.Run("get, internal method", func(t *testing.T) { t.Run("get, internal method", func(t *testing.T) {
n := chain.contracts.Policy.GetMaxBlockSystemFeeInternal(chain.dao) n := chain.contracts.Policy.GetMaxBlockSystemFeeInternal(chain.dao)
@ -138,7 +133,6 @@ func TestBlockSystemFee(t *testing.T) {
func TestStoragePrice(t *testing.T) { func TestStoragePrice(t *testing.T) {
chain := newTestChain(t) chain := newTestChain(t)
defer chain.Close()
t.Run("get, internal method", func(t *testing.T) { t.Run("get, internal method", func(t *testing.T) {
n := chain.contracts.Policy.GetStoragePriceInternal(chain.dao) n := chain.contracts.Policy.GetStoragePriceInternal(chain.dao)
@ -150,7 +144,6 @@ func TestStoragePrice(t *testing.T) {
func TestBlockedAccounts(t *testing.T) { func TestBlockedAccounts(t *testing.T) {
chain := newTestChain(t) chain := newTestChain(t)
defer chain.Close()
account := util.Uint160{1, 2, 3} account := util.Uint160{1, 2, 3}
policyHash := chain.contracts.Policy.Metadata().Hash policyHash := chain.contracts.Policy.Metadata().Hash

View file

@ -59,7 +59,6 @@ func getTestNotary(t *testing.T, bc *Blockchain, walletPath, pass string, onTx f
func TestNotary(t *testing.T) { func TestNotary(t *testing.T) {
bc := newTestChain(t) bc := newTestChain(t)
defer bc.Close()
var ( var (
nonce uint32 nonce uint32
nvbDiffFallback uint32 = 20 nvbDiffFallback uint32 = 20
@ -641,10 +640,10 @@ func TestNotary(t *testing.T) {
// Subscriptions test // Subscriptions test
mp1.RunSubscriptions() mp1.RunSubscriptions()
go ntr1.Run() go ntr1.Run()
defer func() { t.Cleanup(func() {
ntr1.Stop() ntr1.Stop()
mp1.StopSubscriptions() mp1.StopSubscriptions()
}() })
finalizeWithError = false finalizeWithError = false
requester1, _ := wallet.NewAccount() requester1, _ := wallet.NewAccount()
requester2, _ := wallet.NewAccount() requester2, _ := wallet.NewAccount()
@ -662,6 +661,6 @@ func TestNotary(t *testing.T) {
mtx.RLock() mtx.RLock()
defer mtx.RUnlock() defer mtx.RUnlock()
return completedTxes[requests[0].MainTransaction.Hash()] != nil return completedTxes[requests[0].MainTransaction.Hash()] != nil
}, time.Second, time.Millisecond) }, 2*time.Second, 10*time.Millisecond)
checkFallbackTxs(t, requests, false) checkFallbackTxs(t, requests, false)
} }

View file

@ -76,7 +76,6 @@ func getTestOracle(t *testing.T, bc *Blockchain, walletPath, pass string) (
// https://github.com/neo-project/neo-modules/blob/master/tests/Neo.Plugins.OracleService.Tests/UT_OracleService.cs#L61 // https://github.com/neo-project/neo-modules/blob/master/tests/Neo.Plugins.OracleService.Tests/UT_OracleService.cs#L61
func TestCreateResponseTx(t *testing.T) { func TestCreateResponseTx(t *testing.T) {
bc := newTestChain(t) bc := newTestChain(t)
defer bc.Close()
require.Equal(t, int64(30), bc.GetBaseExecFee()) require.Equal(t, int64(30), bc.GetBaseExecFee())
require.Equal(t, int64(1000), bc.FeePerByte()) require.Equal(t, int64(1000), bc.FeePerByte())
@ -116,7 +115,6 @@ func TestOracle_InvalidWallet(t *testing.T) {
func TestOracle(t *testing.T) { func TestOracle(t *testing.T) {
bc := newTestChain(t) bc := newTestChain(t)
defer bc.Close()
oracleCtr := bc.contracts.Oracle oracleCtr := bc.contracts.Oracle
acc1, orc1, m1, ch1 := getTestOracle(t, bc, "./testdata/oracle1.json", "one") acc1, orc1, m1, ch1 := getTestOracle(t, bc, "./testdata/oracle1.json", "one")
@ -272,9 +270,8 @@ func TestOracleFull(t *testing.T) {
require.NoError(t, bc.contracts.Management.PutContractState(bc.dao, cs)) require.NoError(t, bc.contracts.Management.PutContractState(bc.dao, cs))
go bc.Run() go bc.Run()
defer bc.Close()
go orc.Run() go orc.Run()
defer orc.Shutdown() t.Cleanup(orc.Shutdown)
bc.setNodesByRole(t, true, native.RoleOracle, keys.PublicKeys{acc.PrivateKey().PublicKey()}) bc.setNodesByRole(t, true, native.RoleOracle, keys.PublicKeys{acc.PrivateKey().PublicKey()})
putOracleRequest(t, cs.Hash, bc, "http://get.1234", new(string), "handle", []byte{}, 10_000_000) putOracleRequest(t, cs.Hash, bc, "http://get.1234", new(string), "handle", []byte{}, 10_000_000)

View file

@ -11,10 +11,10 @@ import (
func newBoltStoreForTesting(t *testing.T) Store { func newBoltStoreForTesting(t *testing.T) Store {
testFileName := "test_bolt_db" testFileName := "test_bolt_db"
file, err := ioutil.TempFile("", testFileName) file, err := ioutil.TempFile("", testFileName)
defer func() { t.Cleanup(func() {
err := os.RemoveAll(testFileName) err := os.RemoveAll(testFileName)
require.NoError(t, err) require.NoError(t, err)
}() })
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, file.Close()) require.NoError(t, file.Close())
boltDBStore, err := NewBoltDBStore(BoltDBOptions{FilePath: testFileName}) boltDBStore, err := NewBoltDBStore(BoltDBOptions{FilePath: testFileName})

View file

@ -15,7 +15,9 @@ func TestMakeDirForFile_HappyPath(t *testing.T) {
filePath := tempDir + "/testDir/testFile.test" filePath := tempDir + "/testDir/testFile.test"
err = MakeDirForFile(filePath, "test") err = MakeDirForFile(filePath, "test")
defer removeDir(t, tempDir) t.Cleanup(func() {
removeDir(t, tempDir)
})
require.NoError(t, err) require.NoError(t, err)
_, errChDir := os.Create(filePath) _, errChDir := os.Create(filePath)
@ -34,6 +36,8 @@ func TestMakeDirForFile_Negative(t *testing.T) {
filePath := file.Name() + "/error" filePath := file.Name() + "/error"
dir := path.Dir(filePath) dir := path.Dir(filePath)
err = MakeDirForFile(filePath, "test") err = MakeDirForFile(filePath, "test")
defer removeDir(t, dir) 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

@ -192,5 +192,6 @@ func newTestServer(t *testing.T, serverConfig ServerConfig) *Server {
s, err := newServerFromConstructors(serverConfig, fakechain.NewFakeChain(), zaptest.NewLogger(t), s, err := newServerFromConstructors(serverConfig, fakechain.NewFakeChain(), zaptest.NewLogger(t),
newFakeTransp, newFakeConsensus, newTestDiscovery) newFakeTransp, newFakeConsensus, newTestDiscovery)
require.NoError(t, err) require.NoError(t, err)
t.Cleanup(s.discovery.Close)
return s return s
} }

View file

@ -53,7 +53,6 @@ func TestNewServer(t *testing.T) {
t.Run("set defaults", func(t *testing.T) { t.Run("set defaults", func(t *testing.T) {
s = newTestServer(t, ServerConfig{MinPeers: -1}) s = newTestServer(t, ServerConfig{MinPeers: -1})
defer s.discovery.Close()
require.True(t, s.ID() != 0) require.True(t, s.ID() != 0)
require.Equal(t, defaultMinPeers, s.ServerConfig.MinPeers) require.Equal(t, defaultMinPeers, s.ServerConfig.MinPeers)
@ -67,7 +66,6 @@ func TestNewServer(t *testing.T) {
AttemptConnPeers: 3, AttemptConnPeers: 3,
} }
s = newTestServer(t, cfg) s = newTestServer(t, cfg)
defer s.discovery.Close()
require.True(t, s.ID() != 0) require.True(t, s.ID() != 0)
require.Equal(t, 1, s.ServerConfig.MinPeers) require.Equal(t, 1, s.ServerConfig.MinPeers)
@ -140,10 +138,10 @@ func TestServerRegisterPeer(t *testing.T) {
} }
ch := startWithChannel(s) ch := startWithChannel(s)
defer func() { t.Cleanup(func() {
s.Shutdown() s.Shutdown()
<-ch <-ch
}() })
s.register <- ps[0] s.register <- ps[0]
require.Eventually(t, func() bool { return 1 == s.PeerCount() }, time.Second, time.Millisecond*10) require.Eventually(t, func() bool { return 1 == s.PeerCount() }, time.Second, time.Millisecond*10)
@ -317,11 +315,11 @@ func TestServerNotSendsVerack(t *testing.T) {
s.run() s.run()
close(finished) close(finished)
}() }()
defer func() { t.Cleanup(func() {
// close via quit as server was started via `run()`, not `Start()` // close via quit as server was started via `run()`, not `Start()`
close(s.quit) close(s.quit)
<-finished <-finished
}() })
na, _ := net.ResolveTCPAddr("tcp", "0.0.0.0:3000") na, _ := net.ResolveTCPAddr("tcp", "0.0.0.0:3000")
p.netaddr = *na p.netaddr = *na
@ -379,18 +377,18 @@ func (s *Server) testHandleMessage(t *testing.T, p Peer, cmd CommandType, pl pay
return s return s
} }
func startTestServer(t *testing.T) (*Server, func()) { func startTestServer(t *testing.T) *Server {
s := newTestServer(t, ServerConfig{Port: 0, UserAgent: "/test/"}) s := newTestServer(t, ServerConfig{Port: 0, UserAgent: "/test/"})
ch := startWithChannel(s) ch := startWithChannel(s)
return s, func() { t.Cleanup(func() {
s.Shutdown() s.Shutdown()
<-ch <-ch
} })
return s
} }
func TestBlock(t *testing.T) { func TestBlock(t *testing.T) {
s, shutdown := startTestServer(t) s := startTestServer(t)
defer shutdown()
atomic2.StoreUint32(&s.chain.(*fakechain.FakeChain).Blockheight, 12344) atomic2.StoreUint32(&s.chain.(*fakechain.FakeChain).Blockheight, 12344)
require.Equal(t, uint32(12344), s.chain.BlockHeight()) require.Equal(t, uint32(12344), s.chain.BlockHeight())
@ -402,8 +400,7 @@ func TestBlock(t *testing.T) {
} }
func TestConsensus(t *testing.T) { func TestConsensus(t *testing.T) {
s, shutdown := startTestServer(t) s := startTestServer(t)
defer shutdown()
atomic2.StoreUint32(&s.chain.(*fakechain.FakeChain).Blockheight, 4) atomic2.StoreUint32(&s.chain.(*fakechain.FakeChain).Blockheight, 4)
p := newLocalPeer(t, s) p := newLocalPeer(t, s)
@ -450,8 +447,7 @@ func TestConsensus(t *testing.T) {
} }
func TestTransaction(t *testing.T) { func TestTransaction(t *testing.T) {
s, shutdown := startTestServer(t) s := startTestServer(t)
defer shutdown()
t.Run("good", func(t *testing.T) { t.Run("good", func(t *testing.T) {
tx := newDummyTx() tx := newDummyTx()
@ -503,8 +499,7 @@ func (s *Server) testHandleGetData(t *testing.T, invType payload.InventoryType,
} }
func TestGetData(t *testing.T) { func TestGetData(t *testing.T) {
s, shutdown := startTestServer(t) s := startTestServer(t)
defer shutdown()
s.chain.(*fakechain.FakeChain).UtilityTokenBalance = big.NewInt(1000000) s.chain.(*fakechain.FakeChain).UtilityTokenBalance = big.NewInt(1000000)
t.Run("block", func(t *testing.T) { t.Run("block", func(t *testing.T) {
@ -563,8 +558,8 @@ func TestGetData(t *testing.T) {
}) })
} }
func initGetBlocksTest(t *testing.T) (*Server, func(), []*block.Block) { func initGetBlocksTest(t *testing.T) (*Server, []*block.Block) {
s, shutdown := startTestServer(t) s := startTestServer(t)
var blocks []*block.Block var blocks []*block.Block
for i := uint32(12); i <= 15; i++ { for i := uint32(12); i <= 15; i++ {
@ -572,12 +567,11 @@ func initGetBlocksTest(t *testing.T) (*Server, func(), []*block.Block) {
s.chain.(*fakechain.FakeChain).PutBlock(b) s.chain.(*fakechain.FakeChain).PutBlock(b)
blocks = append(blocks, b) blocks = append(blocks, b)
} }
return s, shutdown, blocks return s, blocks
} }
func TestGetBlocks(t *testing.T) { func TestGetBlocks(t *testing.T) {
s, shutdown, blocks := initGetBlocksTest(t) s, blocks := initGetBlocksTest(t)
defer shutdown()
expected := make([]util.Uint256, len(blocks)) expected := make([]util.Uint256, len(blocks))
for i := range blocks { for i := range blocks {
@ -608,8 +602,7 @@ func TestGetBlocks(t *testing.T) {
} }
func TestGetBlockByIndex(t *testing.T) { func TestGetBlockByIndex(t *testing.T) {
s, shutdown, blocks := initGetBlocksTest(t) s, blocks := initGetBlocksTest(t)
defer shutdown()
var expected []*block.Block var expected []*block.Block
var actual []*block.Block var actual []*block.Block
@ -643,8 +636,7 @@ func TestGetBlockByIndex(t *testing.T) {
} }
func TestGetHeaders(t *testing.T) { func TestGetHeaders(t *testing.T) {
s, shutdown, blocks := initGetBlocksTest(t) s, blocks := initGetBlocksTest(t)
defer shutdown()
expected := make([]*block.Header, len(blocks)) expected := make([]*block.Header, len(blocks))
for i := range blocks { for i := range blocks {
@ -683,8 +675,7 @@ func TestGetHeaders(t *testing.T) {
} }
func TestInv(t *testing.T) { func TestInv(t *testing.T) {
s, shutdown := startTestServer(t) s := startTestServer(t)
defer shutdown()
s.chain.(*fakechain.FakeChain).UtilityTokenBalance = big.NewInt(10000000) s.chain.(*fakechain.FakeChain).UtilityTokenBalance = big.NewInt(10000000)
var actual []util.Uint256 var actual []util.Uint256
@ -749,8 +740,7 @@ func TestInv(t *testing.T) {
} }
func TestRequestTx(t *testing.T) { func TestRequestTx(t *testing.T) {
s, shutdown := startTestServer(t) s := startTestServer(t)
defer shutdown()
var actual []util.Uint256 var actual []util.Uint256
p := newLocalPeer(t, s) p := newLocalPeer(t, s)
@ -795,8 +785,7 @@ func TestRequestTx(t *testing.T) {
} }
func TestAddrs(t *testing.T) { func TestAddrs(t *testing.T) {
s, shutdown := startTestServer(t) s := startTestServer(t)
defer shutdown()
ips := make([][16]byte, 4) ips := make([][16]byte, 4)
copy(ips[0][:], net.IPv4(1, 2, 3, 4)) copy(ips[0][:], net.IPv4(1, 2, 3, 4))
@ -855,8 +844,7 @@ func (f feerStub) P2PSigExtensionsEnabled() bool { return false }
func (f feerStub) GetBaseExecFee() int64 { return interop.DefaultBaseExecFee } func (f feerStub) GetBaseExecFee() int64 { return interop.DefaultBaseExecFee }
func TestMemPool(t *testing.T) { func TestMemPool(t *testing.T) {
s, shutdown := startTestServer(t) s := startTestServer(t)
defer shutdown()
var actual []util.Uint256 var actual []util.Uint256
p := newLocalPeer(t, s) p := newLocalPeer(t, s)

View file

@ -1439,7 +1439,6 @@ func testRPCClient(t *testing.T, newClient func(context.Context, string, Options
for _, testCase := range testBatch { for _, testCase := range testBatch {
t.Run(testCase.name, func(t *testing.T) { t.Run(testCase.name, func(t *testing.T) {
srv := initTestServer(t, testCase.serverResponse) srv := initTestServer(t, testCase.serverResponse)
defer srv.Close()
endpoint := srv.URL endpoint := srv.URL
opts := Options{} opts := Options{}
@ -1467,7 +1466,6 @@ func testRPCClient(t *testing.T, newClient func(context.Context, string, Options
} }
for serverResponse, testBatch := range rpcClientErrorCases { for serverResponse, testBatch := range rpcClientErrorCases {
srv := initTestServer(t, serverResponse) srv := initTestServer(t, serverResponse)
defer srv.Close()
endpoint := srv.URL endpoint := srv.URL
opts := Options{} opts := Options{}
@ -1524,6 +1522,8 @@ func initTestServer(t *testing.T, resp string) *httptest.Server {
requestHandler(t, r.In, w, resp) requestHandler(t, r.In, w, resp)
})) }))
t.Cleanup(srv.Close)
return srv return srv
} }
@ -1582,7 +1582,7 @@ func TestCalculateValidUntilBlock(t *testing.T) {
} }
requestHandler(t, r.In, w, response) requestHandler(t, r.In, w, response)
})) }))
defer srv.Close() t.Cleanup(srv.Close)
endpoint := srv.URL endpoint := srv.URL
opts := Options{} opts := Options{}
@ -1616,7 +1616,7 @@ func TestGetNetwork(t *testing.T) {
// request handler already have `getversion` response wrapper // request handler already have `getversion` response wrapper
requestHandler(t, r.In, w, "") requestHandler(t, r.In, w, "")
})) }))
defer srv.Close() t.Cleanup(srv.Close)
endpoint := srv.URL endpoint := srv.URL
opts := Options{} opts := Options{}
@ -1648,7 +1648,7 @@ func TestUninitedClient(t *testing.T) {
// request handler already have `getversion` response wrapper // request handler already have `getversion` response wrapper
requestHandler(t, r.In, w, "") requestHandler(t, r.In, w, "")
})) }))
defer srv.Close() t.Cleanup(srv.Close)
endpoint := srv.URL endpoint := srv.URL
opts := Options{} opts := Options{}

View file

@ -17,7 +17,6 @@ import (
func TestWSClientClose(t *testing.T) { func TestWSClientClose(t *testing.T) {
srv := initTestServer(t, "") srv := initTestServer(t, "")
defer srv.Close()
wsc, err := NewWS(context.TODO(), httpURLtoWS(srv.URL), Options{}) wsc, err := NewWS(context.TODO(), httpURLtoWS(srv.URL), Options{})
require.NoError(t, err) require.NoError(t, err)
wsc.Close() wsc.Close()
@ -42,7 +41,6 @@ func TestWSClientSubscription(t *testing.T) {
for name, f := range cases { for name, f := range cases {
t.Run(name, func(t *testing.T) { t.Run(name, func(t *testing.T) {
srv := initTestServer(t, `{"jsonrpc": "2.0", "id": 1, "result": "55aaff00"}`) srv := initTestServer(t, `{"jsonrpc": "2.0", "id": 1, "result": "55aaff00"}`)
defer srv.Close()
wsc, err := NewWS(context.TODO(), httpURLtoWS(srv.URL), Options{}) wsc, err := NewWS(context.TODO(), httpURLtoWS(srv.URL), Options{})
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, wsc.Init()) require.NoError(t, wsc.Init())
@ -56,7 +54,6 @@ func TestWSClientSubscription(t *testing.T) {
for name, f := range cases { for name, f := range cases {
t.Run(name, func(t *testing.T) { t.Run(name, func(t *testing.T) {
srv := initTestServer(t, `{"jsonrpc": "2.0", "id": 1, "error":{"code":-32602,"message":"Invalid Params"}}`) srv := initTestServer(t, `{"jsonrpc": "2.0", "id": 1, "error":{"code":-32602,"message":"Invalid Params"}}`)
defer srv.Close()
wsc, err := NewWS(context.TODO(), httpURLtoWS(srv.URL), Options{}) wsc, err := NewWS(context.TODO(), httpURLtoWS(srv.URL), Options{})
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, wsc.Init()) require.NoError(t, wsc.Init())
@ -106,7 +103,6 @@ func TestWSClientUnsubscription(t *testing.T) {
for name, rc := range cases { for name, rc := range cases {
t.Run(name, func(t *testing.T) { t.Run(name, func(t *testing.T) {
srv := initTestServer(t, rc.response) srv := initTestServer(t, rc.response)
defer srv.Close()
wsc, err := NewWS(context.TODO(), httpURLtoWS(srv.URL), Options{}) wsc, err := NewWS(context.TODO(), httpURLtoWS(srv.URL), Options{})
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, wsc.Init()) require.NoError(t, wsc.Init())
@ -165,7 +161,6 @@ func TestWSClientEvents(t *testing.T) {
func TestWSExecutionVMStateCheck(t *testing.T) { func TestWSExecutionVMStateCheck(t *testing.T) {
// Will answer successfully if request slips through. // Will answer successfully if request slips through.
srv := initTestServer(t, `{"jsonrpc": "2.0", "id": 1, "result": "55aaff00"}`) srv := initTestServer(t, `{"jsonrpc": "2.0", "id": 1, "result": "55aaff00"}`)
defer srv.Close()
wsc, err := NewWS(context.TODO(), httpURLtoWS(srv.URL), Options{}) wsc, err := NewWS(context.TODO(), httpURLtoWS(srv.URL), Options{})
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, wsc.Init()) require.NoError(t, wsc.Init())
@ -330,7 +325,6 @@ func TestWSFilteredSubscriptions(t *testing.T) {
ws.Close() ws.Close()
} }
})) }))
defer srv.Close()
wsc, err := NewWS(context.TODO(), httpURLtoWS(srv.URL), Options{}) wsc, err := NewWS(context.TODO(), httpURLtoWS(srv.URL), Options{})
require.NoError(t, err) require.NoError(t, err)
wsc.network = netmode.UnitTestNet wsc.network = netmode.UnitTestNet
@ -342,7 +336,6 @@ func TestWSFilteredSubscriptions(t *testing.T) {
func TestNewWS(t *testing.T) { func TestNewWS(t *testing.T) {
srv := initTestServer(t, "") srv := initTestServer(t, "")
defer srv.Close()
t.Run("good", func(t *testing.T) { t.Run("good", func(t *testing.T) {
c, err := NewWS(context.TODO(), httpURLtoWS(srv.URL), Options{}) c, err := NewWS(context.TODO(), httpURLtoWS(srv.URL), Options{})

View file

@ -164,7 +164,9 @@ func TestLoad(t *testing.T) {
}` }`
tmpDir := path.Join(os.TempDir(), "vmcliloadtest") tmpDir := path.Join(os.TempDir(), "vmcliloadtest")
require.NoError(t, os.Mkdir(tmpDir, os.ModePerm)) require.NoError(t, os.Mkdir(tmpDir, os.ModePerm))
defer os.RemoveAll(tmpDir) 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")
@ -244,7 +246,9 @@ func TestRunWithDifferentArguments(t *testing.T) {
filename := path.Join(os.TempDir(), "run_vmtestcontract.go") filename := path.Join(os.TempDir(), "run_vmtestcontract.go")
require.NoError(t, ioutil.WriteFile(filename, []byte(src), os.ModePerm)) require.NoError(t, ioutil.WriteFile(filename, []byte(src), os.ModePerm))
defer os.Remove(filename) t.Cleanup(func() {
os.Remove(filename)
})
e := newTestVMCLI(t) e := newTestVMCLI(t)
e.runProg(t, e.runProg(t,

View file

@ -89,7 +89,9 @@ func TestSave(t *testing.T) {
Default: false, Default: false,
}) })
defer removeWallet(t, file.Name()) t.Cleanup(func() {
removeWallet(t, file.Name())
})
errForSave := wallet.Save() errForSave := wallet.Save()
require.NoError(t, errForSave) require.NoError(t, errForSave)
@ -129,7 +131,9 @@ func checkWalletConstructor(t *testing.T) *Wallet {
file, err := ioutil.TempFile("", walletTemplate) file, err := ioutil.TempFile("", walletTemplate)
require.NoError(t, err) require.NoError(t, err)
wallet, err := NewWallet(file.Name()) wallet, err := NewWallet(file.Name())
defer removeWallet(t, file.Name()) t.Cleanup(func() {
removeWallet(t, file.Name())
})
require.NoError(t, err) require.NoError(t, err)
return wallet return wallet
} }