*: upgrade tests to use T.Cleanup()
This commit is contained in:
parent
0cec99a3ea
commit
2c81fc8b8e
41 changed files with 137 additions and 220 deletions
|
@ -13,7 +13,6 @@ import (
|
|||
// stop working after validator will change.
|
||||
func TestRegisterCandidate(t *testing.T) {
|
||||
e := newExecutor(t, true)
|
||||
defer e.Close(t)
|
||||
|
||||
e.In.WriteString("one\r")
|
||||
e.Run(t, "neo-go", "wallet", "nep17", "multitransfer",
|
||||
|
|
|
@ -27,7 +27,6 @@ import (
|
|||
|
||||
func TestCalcHash(t *testing.T) {
|
||||
e := newExecutor(t, false)
|
||||
defer e.Close(t)
|
||||
|
||||
nefPath := "./testdata/verify.nef"
|
||||
src, err := ioutil.ReadFile(nefPath)
|
||||
|
@ -58,7 +57,9 @@ func TestCalcHash(t *testing.T) {
|
|||
})
|
||||
t.Run("invalid file", func(t *testing.T) {
|
||||
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))
|
||||
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) {
|
||||
tmpDir := path.Join(os.TempDir(), "neogo.inittest")
|
||||
require.NoError(t, os.Mkdir(tmpDir, os.ModePerm))
|
||||
defer os.RemoveAll(tmpDir)
|
||||
t.Cleanup(func() {
|
||||
os.RemoveAll(tmpDir)
|
||||
})
|
||||
|
||||
e := newExecutor(t, false)
|
||||
defer e.Close(t)
|
||||
|
||||
t.Run("no path is provided", func(t *testing.T) {
|
||||
e.RunWithError(t, "neo-go", "contract", "init")
|
||||
|
@ -140,14 +142,15 @@ func TestDeployBigContract(t *testing.T) {
|
|||
e := newExecutorWithConfig(t, true, func(c *config.Config) {
|
||||
c.ApplicationConfiguration.RPC.MaxGasInvoke = fixedn.Fixed8(1)
|
||||
})
|
||||
defer e.Close(t)
|
||||
|
||||
// For proper nef generation.
|
||||
config.Version = "0.90.0-test"
|
||||
|
||||
tmpDir := path.Join(os.TempDir(), "neogo.test.deployfail")
|
||||
require.NoError(t, os.Mkdir(tmpDir, os.ModePerm))
|
||||
defer os.RemoveAll(tmpDir)
|
||||
t.Cleanup(func() {
|
||||
os.RemoveAll(tmpDir)
|
||||
})
|
||||
|
||||
nefName := path.Join(tmpDir, "deploy.nef")
|
||||
manifestName := path.Join(tmpDir, "deploy.manifest.json")
|
||||
|
@ -165,14 +168,15 @@ func TestDeployBigContract(t *testing.T) {
|
|||
|
||||
func TestComlileAndInvokeFunction(t *testing.T) {
|
||||
e := newExecutor(t, true)
|
||||
defer e.Close(t)
|
||||
|
||||
// For proper nef generation.
|
||||
config.Version = "0.90.0-test"
|
||||
|
||||
tmpDir := path.Join(os.TempDir(), "neogo.test.compileandinvoke")
|
||||
require.NoError(t, os.Mkdir(tmpDir, os.ModePerm))
|
||||
defer os.RemoveAll(tmpDir)
|
||||
t.Cleanup(func() {
|
||||
os.RemoveAll(tmpDir)
|
||||
})
|
||||
|
||||
nefName := path.Join(tmpDir, "deploy.nef")
|
||||
manifestName := path.Join(tmpDir, "deploy.manifest.json")
|
||||
|
@ -314,10 +318,10 @@ func TestComlileAndInvokeFunction(t *testing.T) {
|
|||
"--in", "testdata/deploy/", // compile all files in dir
|
||||
"--out", nefName, "--manifest", manifestName)
|
||||
|
||||
defer func() {
|
||||
t.Cleanup(func() {
|
||||
os.Remove(nefName)
|
||||
os.Remove(manifestName)
|
||||
}()
|
||||
})
|
||||
|
||||
rawNef, err := ioutil.ReadFile(nefName)
|
||||
require.NoError(t, err)
|
||||
|
@ -349,7 +353,6 @@ func TestComlileAndInvokeFunction(t *testing.T) {
|
|||
|
||||
func TestContractInspect(t *testing.T) {
|
||||
e := newExecutor(t, false)
|
||||
defer e.Close(t)
|
||||
|
||||
// For proper nef generation.
|
||||
config.Version = "0.90.0-test"
|
||||
|
@ -357,7 +360,9 @@ func TestContractInspect(t *testing.T) {
|
|||
|
||||
tmpDir := path.Join(os.TempDir(), "neogo.test.contract.inspect")
|
||||
require.NoError(t, os.Mkdir(tmpDir, os.ModePerm))
|
||||
defer os.RemoveAll(tmpDir)
|
||||
t.Cleanup(func() {
|
||||
os.RemoveAll(tmpDir)
|
||||
})
|
||||
|
||||
nefName := path.Join(tmpDir, "deploy.nef")
|
||||
manifestName := path.Join(tmpDir, "deploy.manifest.json")
|
||||
|
@ -394,7 +399,6 @@ func TestCompileExamples(t *testing.T) {
|
|||
tmpDir := os.TempDir()
|
||||
|
||||
e := newExecutor(t, false)
|
||||
defer e.Close(t)
|
||||
|
||||
for _, info := range infos {
|
||||
t.Run(info.Name(), func(t *testing.T) {
|
||||
|
@ -404,10 +408,10 @@ func TestCompileExamples(t *testing.T) {
|
|||
|
||||
outPath := path.Join(tmpDir, info.Name()+".nef")
|
||||
manifestPath := path.Join(tmpDir, info.Name()+".manifest.json")
|
||||
defer func() {
|
||||
t.Cleanup(func() {
|
||||
os.Remove(outPath)
|
||||
os.Remove(manifestPath)
|
||||
}()
|
||||
})
|
||||
|
||||
cfgName := filterFilename(infos, ".yml")
|
||||
opts := []string{
|
||||
|
@ -426,10 +430,10 @@ func TestCompileExamples(t *testing.T) {
|
|||
for _, name := range []string{"invalid1", "invalid2", "invalid3"} {
|
||||
outPath := path.Join(tmpDir, name+".nef")
|
||||
manifestPath := path.Join(tmpDir, name+".manifest.json")
|
||||
defer func() {
|
||||
t.Cleanup(func() {
|
||||
os.Remove(outPath)
|
||||
os.Remove(manifestPath)
|
||||
}()
|
||||
})
|
||||
e.RunWithError(t, "neo-go", "contract", "compile",
|
||||
"--in", path.Join(dir, name),
|
||||
"--out", outPath,
|
||||
|
|
|
@ -14,7 +14,9 @@ import (
|
|||
func TestDBRestore(t *testing.T) {
|
||||
tmpDir := path.Join(os.TempDir(), "neogo.restoretest")
|
||||
require.NoError(t, os.Mkdir(tmpDir, os.ModePerm))
|
||||
defer os.RemoveAll(tmpDir)
|
||||
t.Cleanup(func() {
|
||||
os.RemoveAll(tmpDir)
|
||||
})
|
||||
|
||||
chainPath := path.Join(tmpDir, "neogotestchain")
|
||||
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`
|
||||
const inDump = "./testdata/chain50x2.acc"
|
||||
e := newExecutor(t, false)
|
||||
defer e.Close(t)
|
||||
stateDump := path.Join(tmpDir, "neogo.teststate")
|
||||
baseArgs := []string{"neo-go", "db", "restore", "--unittest",
|
||||
"--config-path", tmpDir, "--in", inDump, "--dump", stateDump}
|
||||
|
|
|
@ -102,6 +102,9 @@ func newExecutorWithConfig(t *testing.T, needChain bool, f func(*config.Config))
|
|||
if needChain {
|
||||
e.Chain, e.RPC, e.NetSrv = newTestChain(t, f)
|
||||
}
|
||||
t.Cleanup(func() {
|
||||
e.Close(t)
|
||||
})
|
||||
return e
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
|
||||
func TestCLIVersion(t *testing.T) {
|
||||
e := newExecutor(t, false)
|
||||
defer e.Close(t)
|
||||
e.Run(t, "neo-go", "--version")
|
||||
e.checkNextLine(t, "^neo-go version")
|
||||
e.checkEOF(t)
|
||||
|
|
|
@ -20,7 +20,6 @@ import (
|
|||
// 2. Transfer from multisig to another account.
|
||||
func TestSignMultisigTx(t *testing.T) {
|
||||
e := newExecutor(t, true)
|
||||
defer e.Close(t)
|
||||
|
||||
privs, pubs := generateKeys(t, 3)
|
||||
script, err := smartcontract.CreateMultiSigRedeemScript(2, pubs)
|
||||
|
@ -31,9 +30,11 @@ func TestSignMultisigTx(t *testing.T) {
|
|||
// Create 2 wallets participating in multisig.
|
||||
tmpDir := os.TempDir()
|
||||
wallet1Path := path.Join(tmpDir, "multiWallet1.json")
|
||||
defer os.Remove(wallet1Path)
|
||||
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) {
|
||||
e.Run(t, "neo-go", "wallet", "init", "--wallet", w)
|
||||
|
@ -64,7 +65,9 @@ func TestSignMultisigTx(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
txPath := path.Join(tmpDir, "multisigtx.json")
|
||||
defer os.Remove(txPath)
|
||||
t.Cleanup(func() {
|
||||
os.Remove(txPath)
|
||||
})
|
||||
e.In.WriteString("pass\r")
|
||||
e.Run(t, "neo-go", "wallet", "nep17", "transfer",
|
||||
"--rpc-endpoint", "http://"+e.RPC.Addr,
|
||||
|
|
|
@ -18,7 +18,6 @@ import (
|
|||
|
||||
func TestNEP17Balance(t *testing.T) {
|
||||
e := newExecutor(t, true)
|
||||
defer e.Close(t)
|
||||
cmdbalance := []string{"neo-go", "wallet", "nep17", "balance"}
|
||||
cmdbase := append(cmdbalance,
|
||||
"--rpc-endpoint", "http://"+e.RPC.Addr,
|
||||
|
@ -106,7 +105,6 @@ func TestNEP17Transfer(t *testing.T) {
|
|||
defer w.Close()
|
||||
|
||||
e := newExecutor(t, true)
|
||||
defer e.Close(t)
|
||||
args := []string{
|
||||
"neo-go", "wallet", "nep17", "transfer",
|
||||
"--rpc-endpoint", "http://" + e.RPC.Addr,
|
||||
|
@ -164,7 +162,6 @@ func TestNEP17MultiTransfer(t *testing.T) {
|
|||
privs, _ := generateKeys(t, 3)
|
||||
|
||||
e := newExecutor(t, true)
|
||||
defer e.Close(t)
|
||||
neoContractHash, err := e.Chain.GetNativeContractScriptHash(nativenames.Neo)
|
||||
require.NoError(t, err)
|
||||
args := []string{
|
||||
|
@ -191,7 +188,6 @@ func TestNEP17MultiTransfer(t *testing.T) {
|
|||
|
||||
func TestNEP17ImportToken(t *testing.T) {
|
||||
e := newExecutor(t, true)
|
||||
defer e.Close(t)
|
||||
|
||||
tmpDir := os.TempDir()
|
||||
walletPath := path.Join(tmpDir, "walletForImport.json")
|
||||
|
|
|
@ -11,7 +11,6 @@ import (
|
|||
|
||||
func TestGetRPCClient(t *testing.T) {
|
||||
e := newExecutor(t, true)
|
||||
defer e.Close(t)
|
||||
|
||||
t.Run("no endpoint", func(t *testing.T) {
|
||||
set := flag.NewFlagSet("flagSet", flag.ExitOnError)
|
||||
|
|
|
@ -11,10 +11,10 @@ import (
|
|||
func TestGetPath(t *testing.T) {
|
||||
testPath, err := ioutil.TempDir("./", "")
|
||||
require.NoError(t, err)
|
||||
defer func() {
|
||||
t.Cleanup(func() {
|
||||
err := os.RemoveAll(testPath)
|
||||
require.NoError(t, err)
|
||||
}()
|
||||
})
|
||||
path, err := getPath(testPath, 123)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, testPath+"/BlockStorage_100000/dump-block-1000.json", path)
|
||||
|
|
|
@ -29,9 +29,9 @@ func TestGetConfigFromContext(t *testing.T) {
|
|||
func TestHandleLoggingParams(t *testing.T) {
|
||||
testLog, err := ioutil.TempFile("./", "*.log")
|
||||
require.NoError(t, err)
|
||||
defer func() {
|
||||
t.Cleanup(func() {
|
||||
require.NoError(t, os.Remove(testLog.Name()))
|
||||
}()
|
||||
})
|
||||
|
||||
t.Run("default", func(t *testing.T) {
|
||||
set := flag.NewFlagSet("flagSet", flag.ExitOnError)
|
||||
|
@ -63,10 +63,10 @@ func TestInitBCWithMetrics(t *testing.T) {
|
|||
d, err := ioutil.TempDir("./", "")
|
||||
require.NoError(t, err)
|
||||
os.Chdir(d)
|
||||
defer func() {
|
||||
t.Cleanup(func() {
|
||||
os.Chdir("..")
|
||||
os.RemoveAll(d)
|
||||
}()
|
||||
})
|
||||
|
||||
set := flag.NewFlagSet("flagSet", flag.ExitOnError)
|
||||
set.String("config-path", "../../../config", "")
|
||||
|
@ -79,9 +79,11 @@ func TestInitBCWithMetrics(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
chain, prometheus, pprof, err := initBCWithMetrics(cfg, logger)
|
||||
require.NoError(t, err)
|
||||
defer chain.Close()
|
||||
defer prometheus.ShutDown()
|
||||
defer pprof.ShutDown()
|
||||
t.Cleanup(func() {
|
||||
chain.Close()
|
||||
prometheus.ShutDown()
|
||||
pprof.ShutDown()
|
||||
})
|
||||
require.Equal(t, netmode.TestNet, chain.GetConfig().Magic)
|
||||
}
|
||||
|
||||
|
@ -90,10 +92,10 @@ func TestDumpDB(t *testing.T) {
|
|||
d, err := ioutil.TempDir("./", "")
|
||||
require.NoError(t, err)
|
||||
os.Chdir(d)
|
||||
defer func() {
|
||||
t.Cleanup(func() {
|
||||
os.Chdir("..")
|
||||
os.RemoveAll(d)
|
||||
}()
|
||||
})
|
||||
testDump := "file.acc"
|
||||
set := flag.NewFlagSet("flagSet", flag.ExitOnError)
|
||||
set.String("config-path", "../../../config", "")
|
||||
|
@ -111,10 +113,10 @@ func TestDumpDB(t *testing.T) {
|
|||
d, err := ioutil.TempDir("./", "")
|
||||
require.NoError(t, err)
|
||||
os.Chdir(d)
|
||||
defer func() {
|
||||
t.Cleanup(func() {
|
||||
os.Chdir("..")
|
||||
os.RemoveAll(d)
|
||||
}()
|
||||
})
|
||||
testDump := "file.acc"
|
||||
set := flag.NewFlagSet("flagSet", flag.ExitOnError)
|
||||
set.String("config-path", "../../../config", "")
|
||||
|
@ -135,10 +137,10 @@ func TestRestoreDB(t *testing.T) {
|
|||
testDump := "file1.acc"
|
||||
saveDump := "file2.acc"
|
||||
os.Chdir(d)
|
||||
defer func() {
|
||||
t.Cleanup(func() {
|
||||
os.Chdir("..")
|
||||
os.RemoveAll(d)
|
||||
}()
|
||||
})
|
||||
|
||||
//dump first
|
||||
set := flag.NewFlagSet("flagSet", flag.ExitOnError)
|
||||
|
|
|
@ -18,10 +18,10 @@ func TestInitSmartContract(t *testing.T) {
|
|||
d, err := ioutil.TempDir("./", "")
|
||||
require.NoError(t, err)
|
||||
os.Chdir(d)
|
||||
defer func() {
|
||||
t.Cleanup(func() {
|
||||
os.Chdir("..")
|
||||
os.RemoveAll(d)
|
||||
}()
|
||||
})
|
||||
contractName := "testContract"
|
||||
|
||||
set := flag.NewFlagSet("flagSet", flag.ExitOnError)
|
||||
|
|
|
@ -22,10 +22,11 @@ import (
|
|||
func TestWalletInit(t *testing.T) {
|
||||
tmpDir := path.Join(os.TempDir(), "neogo.test.walletinit")
|
||||
require.NoError(t, os.Mkdir(tmpDir, os.ModePerm))
|
||||
defer os.RemoveAll(tmpDir)
|
||||
t.Cleanup(func() {
|
||||
os.RemoveAll(tmpDir)
|
||||
})
|
||||
|
||||
e := newExecutor(t, false)
|
||||
defer e.Close(t)
|
||||
|
||||
walletPath := path.Join(tmpDir, "wallet.json")
|
||||
e.Run(t, "neo-go", "wallet", "init", "--wallet", walletPath)
|
||||
|
@ -90,7 +91,7 @@ func TestWalletInit(t *testing.T) {
|
|||
|
||||
w, err := wallet.NewWalletFromFile(walletPath)
|
||||
require.NoError(t, err)
|
||||
defer w.Close()
|
||||
t.Cleanup(w.Close)
|
||||
acc := w.GetAccount(priv.GetScriptHash())
|
||||
require.NotNil(t, acc)
|
||||
require.Equal(t, "test_account", acc.Label)
|
||||
|
@ -121,7 +122,7 @@ func TestWalletInit(t *testing.T) {
|
|||
|
||||
w, err := wallet.NewWalletFromFile(walletPath)
|
||||
require.NoError(t, err)
|
||||
defer w.Close()
|
||||
t.Cleanup(w.Close)
|
||||
actual := w.GetAccount(acc.PrivateKey().GetScriptHash())
|
||||
require.NotNil(t, actual)
|
||||
require.NoError(t, actual.Decrypt("somepass"))
|
||||
|
@ -157,7 +158,7 @@ func TestWalletInit(t *testing.T) {
|
|||
|
||||
w, err := wallet.NewWalletFromFile(walletPath)
|
||||
require.NoError(t, err)
|
||||
defer w.Close()
|
||||
t.Cleanup(w.Close)
|
||||
actual := w.GetAccount(hash.Hash160(script))
|
||||
require.NotNil(t, actual)
|
||||
require.NoError(t, actual.Decrypt("multipass"))
|
||||
|
@ -168,7 +169,6 @@ func TestWalletInit(t *testing.T) {
|
|||
|
||||
func TestWalletExport(t *testing.T) {
|
||||
e := newExecutor(t, false)
|
||||
defer e.Close(t)
|
||||
|
||||
t.Run("Encrypted", func(t *testing.T) {
|
||||
e.Run(t, "neo-go", "wallet", "export",
|
||||
|
@ -195,12 +195,11 @@ func TestWalletExport(t *testing.T) {
|
|||
|
||||
func TestClaimGas(t *testing.T) {
|
||||
e := newExecutor(t, true)
|
||||
defer e.Close(t)
|
||||
|
||||
const walletPath = "testdata/testwallet.json"
|
||||
w, err := wallet.NewWalletFromFile(walletPath)
|
||||
require.NoError(t, err)
|
||||
defer w.Close()
|
||||
t.Cleanup(w.Close)
|
||||
|
||||
args := []string{
|
||||
"neo-go", "wallet", "nep17", "multitransfer",
|
||||
|
@ -243,7 +242,6 @@ func TestClaimGas(t *testing.T) {
|
|||
|
||||
func TestImportDeployed(t *testing.T) {
|
||||
e := newExecutor(t, true)
|
||||
defer e.Close(t)
|
||||
|
||||
e.In.WriteString("one\r")
|
||||
e.Run(t, "neo-go", "contract", "deploy",
|
||||
|
@ -262,7 +260,9 @@ func TestImportDeployed(t *testing.T) {
|
|||
tmpDir := os.TempDir()
|
||||
walletPath := path.Join(tmpDir, "wallet.json")
|
||||
e.Run(t, "neo-go", "wallet", "init", "--wallet", walletPath)
|
||||
defer os.Remove(walletPath)
|
||||
t.Cleanup(func() {
|
||||
os.Remove(walletPath)
|
||||
})
|
||||
|
||||
priv, err := keys.NewPrivateKey()
|
||||
require.NoError(t, err)
|
||||
|
@ -274,7 +274,9 @@ func TestImportDeployed(t *testing.T) {
|
|||
"--contract", h.StringLE())
|
||||
|
||||
w, err := wallet.NewWalletFromFile(walletPath)
|
||||
defer w.Close()
|
||||
t.Cleanup(func() {
|
||||
w.Close()
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 1, len(w.Accounts))
|
||||
contractAddr := w.Accounts[0].Address
|
||||
|
@ -309,7 +311,6 @@ func TestImportDeployed(t *testing.T) {
|
|||
|
||||
func TestWalletDump(t *testing.T) {
|
||||
e := newExecutor(t, false)
|
||||
defer e.Close(t)
|
||||
|
||||
cmd := []string{"neo-go", "wallet", "dump", "--wallet", "testdata/testwallet.json"}
|
||||
e.Run(t, cmd...)
|
||||
|
@ -340,10 +341,11 @@ func TestWalletDump(t *testing.T) {
|
|||
func TestWalletConvert(t *testing.T) {
|
||||
tmpDir := path.Join(os.TempDir(), "neogo.test.convert")
|
||||
require.NoError(t, os.Mkdir(tmpDir, os.ModePerm))
|
||||
defer os.RemoveAll(tmpDir)
|
||||
t.Cleanup(func() {
|
||||
os.RemoveAll(tmpDir)
|
||||
})
|
||||
|
||||
e := newExecutor(t, false)
|
||||
defer e.Close(t)
|
||||
|
||||
outPath := path.Join(tmpDir, "wallet.json")
|
||||
cmd := []string{"neo-go", "wallet", "convert"}
|
||||
|
|
|
@ -62,10 +62,10 @@ func TestCompiler(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
err = os.MkdirAll(exampleSavePath, os.ModePerm)
|
||||
require.NoError(t, err)
|
||||
defer func() {
|
||||
t.Cleanup(func() {
|
||||
err := os.RemoveAll(exampleSavePath)
|
||||
require.NoError(t, err)
|
||||
}()
|
||||
})
|
||||
outfile := exampleSavePath + "/test.nef"
|
||||
_, err = compiler.CompileAndSave(exampleCompilePath+"/"+infos[0].Name(), &compiler.Options{Outfile: outfile})
|
||||
require.NoError(t, err)
|
||||
|
|
|
@ -44,7 +44,6 @@ func TestNewService(t *testing.T) {
|
|||
require.NotPanics(t, func() { txx = srv.getVerifiedTx() })
|
||||
require.Len(t, txx, 1)
|
||||
require.Equal(t, tx, txx[0])
|
||||
srv.Chain.Close()
|
||||
}
|
||||
|
||||
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
|
||||
srv, acc := initServiceNextConsensus(t, newAcc, 1)
|
||||
bc := srv.Chain.(*core.Blockchain)
|
||||
defer bc.Close()
|
||||
|
||||
height := bc.BlockHeight()
|
||||
checkNextConsensus(t, bc, height, acc.Contract.ScriptHash())
|
||||
|
@ -219,7 +217,6 @@ func TestService_GetVerified(t *testing.T) {
|
|||
require.Contains(t, txx, txs[1])
|
||||
require.NotContains(t, txx, txs[2])
|
||||
})
|
||||
srv.Chain.Close()
|
||||
}
|
||||
|
||||
func TestService_ValidatePayload(t *testing.T) {
|
||||
|
@ -257,7 +254,6 @@ func TestService_ValidatePayload(t *testing.T) {
|
|||
require.NoError(t, p.Sign(priv))
|
||||
require.True(t, srv.validatePayload(p))
|
||||
})
|
||||
srv.Chain.Close()
|
||||
}
|
||||
|
||||
func TestService_getTx(t *testing.T) {
|
||||
|
@ -294,13 +290,12 @@ func TestService_getTx(t *testing.T) {
|
|||
require.NotNil(t, got)
|
||||
require.Equal(t, h, got.Hash())
|
||||
})
|
||||
srv.Chain.Close()
|
||||
}
|
||||
|
||||
func TestService_PrepareRequest(t *testing.T) {
|
||||
srv := newTestServiceWithState(t, true)
|
||||
srv.dbft.Start()
|
||||
defer srv.dbft.Timer.Stop()
|
||||
t.Cleanup(srv.dbft.Timer.Stop)
|
||||
|
||||
priv, _ := getTestValidator(1)
|
||||
p := new(Payload)
|
||||
|
@ -359,12 +354,10 @@ func TestService_OnPayload(t *testing.T) {
|
|||
require.NoError(t, p.Sign(priv))
|
||||
srv.OnPayload(&p.Extensible)
|
||||
shouldReceive(t, srv.messages)
|
||||
srv.Chain.Close()
|
||||
}
|
||||
|
||||
func TestVerifyBlock(t *testing.T) {
|
||||
srv := newTestService(t)
|
||||
defer srv.Chain.Close()
|
||||
|
||||
srv.lastTimestamp = 1
|
||||
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)
|
||||
|
||||
go chain.Run()
|
||||
|
||||
t.Cleanup(chain.Close)
|
||||
return chain
|
||||
}
|
||||
|
||||
|
|
|
@ -262,7 +262,6 @@ func TestPayload_Sign(t *testing.T) {
|
|||
p := randomPayload(t, prepareRequestType)
|
||||
h := priv.PublicKey().GetScriptHash()
|
||||
bc := newTestChain(t, false)
|
||||
defer bc.Close()
|
||||
require.Error(t, bc.VerifyWitness(h, p, &p.Witness, payloadGasLimit))
|
||||
require.NoError(t, p.Sign(priv))
|
||||
require.NoError(t, bc.VerifyWitness(h, p, &p.Witness, payloadGasLimit))
|
||||
|
|
|
@ -23,7 +23,6 @@ func TestRecoveryMessageSetters(t *testing.T) {
|
|||
|
||||
func testRecoveryMessageSetters(t *testing.T, enableStateRoot bool) {
|
||||
srv := newTestServiceWithState(t, enableStateRoot)
|
||||
defer srv.Chain.Close()
|
||||
privs := make([]*privateKey, testchain.Size())
|
||||
pubs := make([]crypto.PublicKey, testchain.Size())
|
||||
for i := 0; i < testchain.Size(); i++ {
|
||||
|
|
|
@ -41,7 +41,6 @@ import (
|
|||
|
||||
func TestVerifyHeader(t *testing.T) {
|
||||
bc := newTestChain(t)
|
||||
defer bc.Close()
|
||||
prev := bc.topBlock.Load().(*block.Block).Header()
|
||||
t.Run("Invalid", 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) {
|
||||
bc := newTestChain(t)
|
||||
defer bc.Close()
|
||||
lastBlock := bc.topBlock.Load().(*block.Block)
|
||||
h1 := newBlock(bc.config, 1, lastBlock.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) {
|
||||
c.ProtocolConfiguration.StateRootInHeader = true
|
||||
})
|
||||
defer bc.Close()
|
||||
|
||||
sr, err := bc.GetStateRoot(bc.BlockHeight())
|
||||
require.NoError(t, err)
|
||||
|
@ -159,7 +156,6 @@ func TestAddBlockStateRoot(t *testing.T) {
|
|||
|
||||
func TestAddBadBlock(t *testing.T) {
|
||||
bc := newTestChain(t)
|
||||
defer bc.Close()
|
||||
// It has ValidUntilBlock == 0, which is wrong
|
||||
tx := transaction.New(netmode.UnitTestNet, []byte{byte(opcode.PUSH1)}, 0)
|
||||
tx.Signers = []transaction.Signer{{
|
||||
|
@ -250,7 +246,6 @@ func (bc *Blockchain) newTestTx(h util.Uint160, script []byte) *transaction.Tran
|
|||
|
||||
func TestVerifyTx(t *testing.T) {
|
||||
bc := newTestChain(t)
|
||||
defer bc.Close()
|
||||
|
||||
accs := make([]*wallet.Account, 5)
|
||||
for i := range accs {
|
||||
|
@ -1063,7 +1058,6 @@ func TestVerifyTx(t *testing.T) {
|
|||
|
||||
func TestVerifyHashAgainstScript(t *testing.T) {
|
||||
bc := newTestChain(t)
|
||||
defer bc.Close()
|
||||
|
||||
cs, csInvalid := getTestContractState(bc)
|
||||
ic := bc.newInteropContext(trigger.Verification, bc.dao, nil, nil)
|
||||
|
@ -1137,7 +1131,6 @@ func TestVerifyHashAgainstScript(t *testing.T) {
|
|||
|
||||
func TestIsTxStillRelevant(t *testing.T) {
|
||||
bc := newTestChain(t)
|
||||
defer bc.Close()
|
||||
|
||||
mp := bc.GetMemPool()
|
||||
newTx := func(t *testing.T) *transaction.Transaction {
|
||||
|
@ -1233,7 +1226,6 @@ func TestMemPoolRemoval(t *testing.T) {
|
|||
const added = 16
|
||||
const notAdded = 32
|
||||
bc := newTestChain(t)
|
||||
defer bc.Close()
|
||||
addedTxes := make([]*transaction.Transaction, added)
|
||||
notAddedTxes := make([]*transaction.Transaction, notAdded)
|
||||
for i := range addedTxes {
|
||||
|
@ -1310,7 +1302,6 @@ func TestGetTransaction(t *testing.T) {
|
|||
|
||||
func TestGetClaimable(t *testing.T) {
|
||||
bc := newTestChain(t)
|
||||
defer bc.Close()
|
||||
|
||||
_, err := bc.genBlocks(10)
|
||||
require.NoError(t, err)
|
||||
|
@ -1327,7 +1318,8 @@ func TestClose(t *testing.T) {
|
|||
r := recover()
|
||||
assert.NotNil(t, r)
|
||||
}()
|
||||
bc := newTestChain(t)
|
||||
bc := initTestChain(t, nil, nil)
|
||||
go bc.Run()
|
||||
_, err := bc.genBlocks(10)
|
||||
require.NoError(t, err)
|
||||
bc.Close()
|
||||
|
@ -1350,7 +1342,6 @@ func TestSubscriptions(t *testing.T) {
|
|||
executionCh := make(chan *state.AppExecResult, chBufSize)
|
||||
|
||||
bc := newTestChain(t)
|
||||
defer bc.Close()
|
||||
bc.SubscribeForBlocks(blockCh)
|
||||
bc.SubscribeForTransactions(txCh)
|
||||
bc.SubscribeForNotifications(notificationCh)
|
||||
|
@ -1473,7 +1464,6 @@ func testDumpAndRestore(t *testing.T, dumpF, restoreF func(c *config.Config)) {
|
|||
}
|
||||
|
||||
bc := newTestChainWithCustomCfg(t, dumpF)
|
||||
defer bc.Close()
|
||||
|
||||
initBasicChain(t, bc)
|
||||
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()
|
||||
t.Run("invalid start", func(t *testing.T) {
|
||||
bc2 := newTestChainWithCustomCfg(t, restoreF)
|
||||
defer bc2.Close()
|
||||
|
||||
r := io.NewBinReaderFromBuf(buf)
|
||||
require.Error(t, chaindump.Restore(bc2, r, 2, 1, nil))
|
||||
})
|
||||
t.Run("good", func(t *testing.T) {
|
||||
bc2 := newTestChainWithCustomCfg(t, restoreF)
|
||||
defer bc2.Close()
|
||||
|
||||
r := io.NewBinReaderFromBuf(buf)
|
||||
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.RemoveUntraceableBlocks = true
|
||||
})
|
||||
defer bc.Close()
|
||||
|
||||
tx1, err := testchain.NewTransferFromOwner(bc, bc.contracts.NEO.Hash, util.Uint160{}, 1, 0, bc.BlockHeight()+1)
|
||||
require.NoError(t, err)
|
||||
|
@ -1576,7 +1563,6 @@ func TestRemoveUntraceable(t *testing.T) {
|
|||
|
||||
func TestInvalidNotification(t *testing.T) {
|
||||
bc := newTestChain(t)
|
||||
defer bc.Close()
|
||||
|
||||
cs, _ := getTestContractState(bc)
|
||||
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.
|
||||
func TestMPTDeleteNoKey(t *testing.T) {
|
||||
bc := newTestChain(t)
|
||||
defer bc.Close()
|
||||
|
||||
cs, _ := getTestContractState(bc)
|
||||
require.NoError(t, bc.contracts.Management.PutContractState(bc.dao, cs))
|
||||
|
|
|
@ -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 {
|
||||
chain := initTestChain(t, st, f)
|
||||
go chain.Run()
|
||||
t.Cleanup(chain.Close)
|
||||
return chain
|
||||
}
|
||||
|
||||
|
@ -174,7 +175,6 @@ func TestBug1728(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
bc := newTestChain(t)
|
||||
defer bc.Close()
|
||||
|
||||
aer, err := invokeContractMethod(bc, 10000000000,
|
||||
bc.contracts.Management.Hash, "deploy", rawNef, rawManifest)
|
||||
|
@ -242,13 +242,14 @@ func TestCreateBasicChain(t *testing.T) {
|
|||
const prefix = "../rpc/server/testdata/"
|
||||
|
||||
bc := newTestChain(t)
|
||||
defer bc.Close()
|
||||
initBasicChain(t, bc)
|
||||
|
||||
if saveChain {
|
||||
outStream, err := os.Create(prefix + "testblocks.acc")
|
||||
require.NoError(t, err)
|
||||
defer outStream.Close()
|
||||
t.Cleanup(func() {
|
||||
outStream.Close()
|
||||
})
|
||||
|
||||
writer := io.NewBinWriterFromIO(outStream)
|
||||
writer.WriteU32LE(bc.BlockHeight())
|
||||
|
|
|
@ -36,7 +36,6 @@ import (
|
|||
|
||||
func TestStorageFind(t *testing.T) {
|
||||
v, contractState, context, chain := createVMAndContractState(t)
|
||||
defer chain.Close()
|
||||
|
||||
arr := []stackitem.Item{
|
||||
stackitem.NewBigInteger(big.NewInt(42)),
|
||||
|
|
|
@ -32,7 +32,6 @@ import (
|
|||
|
||||
func TestContractIsStandard(t *testing.T) {
|
||||
v, ic, chain := createVM(t)
|
||||
defer chain.Close()
|
||||
|
||||
t.Run("contract not stored", func(t *testing.T) {
|
||||
priv, err := keys.NewPrivateKey()
|
||||
|
@ -91,8 +90,7 @@ func TestContractIsStandard(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestContractCreateAccount(t *testing.T) {
|
||||
v, ic, chain := createVM(t)
|
||||
defer chain.Close()
|
||||
v, ic, _ := createVM(t)
|
||||
t.Run("Good", func(t *testing.T) {
|
||||
priv, err := keys.NewPrivateKey()
|
||||
require.NoError(t, err)
|
||||
|
@ -112,8 +110,7 @@ func TestContractCreateAccount(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestContractCreateMultisigAccount(t *testing.T) {
|
||||
v, ic, chain := createVM(t)
|
||||
defer chain.Close()
|
||||
v, ic, _ := createVM(t)
|
||||
t.Run("Good", func(t *testing.T) {
|
||||
m, n := 3, 5
|
||||
pubs := make(keys.PublicKeys, n)
|
||||
|
@ -159,8 +156,7 @@ func TestContractCreateMultisigAccount(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestRuntimeGasLeft(t *testing.T) {
|
||||
v, ic, chain := createVM(t)
|
||||
defer chain.Close()
|
||||
v, ic, _ := createVM(t)
|
||||
|
||||
v.GasLimit = 100
|
||||
v.AddGas(58)
|
||||
|
@ -169,8 +165,7 @@ func TestRuntimeGasLeft(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestRuntimeGetNotifications(t *testing.T) {
|
||||
v, ic, chain := createVM(t)
|
||||
defer chain.Close()
|
||||
v, ic, _ := createVM(t)
|
||||
|
||||
ic.Notifications = []state.NotificationEvent{
|
||||
{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) {
|
||||
v, ic, chain := createVM(t)
|
||||
defer chain.Close()
|
||||
v, ic, _ := createVM(t)
|
||||
|
||||
ic.VM.Invocations[hash.Hash160([]byte{2})] = 42
|
||||
|
||||
|
@ -231,7 +225,6 @@ func TestRuntimeGetInvocationCounter(t *testing.T) {
|
|||
|
||||
func TestStoragePut(t *testing.T) {
|
||||
_, cs, ic, bc := createVMAndContractState(t)
|
||||
defer bc.Close()
|
||||
|
||||
require.NoError(t, bc.contracts.Management.PutContractState(ic.DAO, cs))
|
||||
|
||||
|
@ -304,7 +297,6 @@ func TestStoragePut(t *testing.T) {
|
|||
|
||||
func TestStorageDelete(t *testing.T) {
|
||||
v, cs, ic, bc := createVMAndContractState(t)
|
||||
defer bc.Close()
|
||||
|
||||
require.NoError(t, bc.contracts.Management.PutContractState(ic.DAO, cs))
|
||||
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) {
|
||||
_, ic, bc := createVM(t)
|
||||
defer bc.Close()
|
||||
|
||||
cs, currCs := getTestContractState(bc)
|
||||
require.NoError(t, bc.contracts.Management.PutContractState(ic.DAO, cs))
|
||||
|
@ -805,8 +796,7 @@ func TestContractCall(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestContractGetCallFlags(t *testing.T) {
|
||||
v, ic, bc := createVM(t)
|
||||
defer bc.Close()
|
||||
v, ic, _ := createVM(t)
|
||||
|
||||
v.LoadScriptWithHash([]byte{byte(opcode.RET)}, util.Uint160{1, 2, 3}, callflag.All)
|
||||
require.NoError(t, contractGetCallFlags(ic))
|
||||
|
@ -815,7 +805,6 @@ func TestContractGetCallFlags(t *testing.T) {
|
|||
|
||||
func TestRuntimeCheckWitness(t *testing.T) {
|
||||
_, ic, bc := createVM(t)
|
||||
defer bc.Close()
|
||||
|
||||
script := []byte{byte(opcode.RET)}
|
||||
scriptHash := hash.Hash160(script)
|
||||
|
@ -1008,7 +997,6 @@ func TestRuntimeCheckWitness(t *testing.T) {
|
|||
|
||||
func TestLoadToken(t *testing.T) {
|
||||
bc := newTestChain(t)
|
||||
defer bc.Close()
|
||||
|
||||
cs, _ := getTestContractState(bc)
|
||||
require.NoError(t, bc.contracts.Management.PutContractState(bc.dao, cs))
|
||||
|
|
|
@ -18,7 +18,6 @@ func testNonInterop(t *testing.T, value interface{}, f func(*interop.Context) er
|
|||
v := vm.New()
|
||||
v.Estack().PushVal(value)
|
||||
chain := newTestChain(t)
|
||||
defer chain.Close()
|
||||
d := dao.NewSimple(storage.NewMemoryStore(), netmode.UnitTestNet, chain.config.StateRootInHeader)
|
||||
context := chain.newInteropContext(trigger.Application, d, nil, nil)
|
||||
context.VM = v
|
||||
|
|
|
@ -29,7 +29,7 @@ func TestSubscriptions(t *testing.T) {
|
|||
subChan1 := make(chan Event, 3)
|
||||
subChan2 := make(chan Event, 3)
|
||||
mp.SubscribeForTransactions(subChan1)
|
||||
defer mp.StopSubscriptions()
|
||||
t.Cleanup(mp.StopSubscriptions)
|
||||
|
||||
txs := make([]*transaction.Transaction, 4)
|
||||
for i := range txs {
|
||||
|
|
|
@ -166,7 +166,6 @@ func (tn *testNative) callOtherContractWithReturn(ic *interop.Context, args []st
|
|||
|
||||
func TestNativeContract_Invoke(t *testing.T) {
|
||||
chain := newTestChain(t)
|
||||
defer chain.Close()
|
||||
|
||||
tn := newTestNative()
|
||||
chain.registerNative(tn)
|
||||
|
@ -206,7 +205,6 @@ func TestNativeContract_Invoke(t *testing.T) {
|
|||
|
||||
func TestNativeContract_InvokeInternal(t *testing.T) {
|
||||
chain := newTestChain(t)
|
||||
defer chain.Close()
|
||||
|
||||
tn := newTestNative()
|
||||
chain.registerNative(tn)
|
||||
|
@ -251,7 +249,6 @@ func TestNativeContract_InvokeInternal(t *testing.T) {
|
|||
|
||||
func TestNativeContract_InvokeOtherContract(t *testing.T) {
|
||||
chain := newTestChain(t)
|
||||
defer chain.Close()
|
||||
|
||||
tn := newTestNative()
|
||||
chain.registerNative(tn)
|
||||
|
|
|
@ -80,7 +80,6 @@ func (bc *Blockchain) getNodesByRole(t *testing.T, ok bool, r native.Role, index
|
|||
|
||||
func TestDesignate_DesignateAsRoleTx(t *testing.T) {
|
||||
bc := newTestChain(t)
|
||||
defer bc.Close()
|
||||
|
||||
priv, err := keys.NewPrivateKey()
|
||||
require.NoError(t, err)
|
||||
|
@ -104,7 +103,6 @@ func TestDesignate_DesignateAsRoleTx(t *testing.T) {
|
|||
|
||||
func TestDesignate_DesignateAsRole(t *testing.T) {
|
||||
bc := newTestChain(t)
|
||||
defer bc.Close()
|
||||
|
||||
des := bc.contracts.Designate
|
||||
tx := transaction.New(netmode.UnitTestNet, []byte{}, 0)
|
||||
|
|
|
@ -12,7 +12,6 @@ import (
|
|||
|
||||
func TestLedgerGetTransactionHeight(t *testing.T) {
|
||||
_, tx, _, chain := createVMAndTX(t)
|
||||
defer chain.Close()
|
||||
|
||||
ledger := chain.contracts.ByName(nativenames.Ledger).Metadata().Hash
|
||||
|
||||
|
@ -39,7 +38,6 @@ func TestLedgerGetTransactionHeight(t *testing.T) {
|
|||
|
||||
func TestLedgerGetTransaction(t *testing.T) {
|
||||
_, tx, _, chain := createVMAndTX(t)
|
||||
defer chain.Close()
|
||||
ledger := chain.contracts.ByName(nativenames.Ledger).Metadata().Hash
|
||||
|
||||
t.Run("success", func(t *testing.T) {
|
||||
|
@ -80,7 +78,6 @@ func TestLedgerGetTransaction(t *testing.T) {
|
|||
|
||||
func TestLedgerGetTransactionFromBlock(t *testing.T) {
|
||||
chain := newTestChain(t)
|
||||
defer chain.Close()
|
||||
ledger := chain.contracts.ByName(nativenames.Ledger).Metadata().Hash
|
||||
|
||||
res, err := invokeContractMethod(chain, 100000000, ledger, "currentIndex") // adds a block
|
||||
|
@ -132,7 +129,6 @@ func TestLedgerGetTransactionFromBlock(t *testing.T) {
|
|||
|
||||
func TestLedgerGetBlock(t *testing.T) {
|
||||
chain := newTestChain(t)
|
||||
defer chain.Close()
|
||||
ledger := chain.contracts.ByName(nativenames.Ledger).Metadata().Hash
|
||||
|
||||
bhash := chain.GetHeaderHash(0)
|
||||
|
|
|
@ -30,7 +30,6 @@ import (
|
|||
// leads to tx deserialization failure.
|
||||
func TestRestoreAfterDeploy(t *testing.T) {
|
||||
bc := newTestChain(t)
|
||||
defer bc.Close()
|
||||
|
||||
// nef.NewFile() cares about version a lot.
|
||||
config.Version = "0.90.0-test"
|
||||
|
@ -61,7 +60,6 @@ func TestStartFromHeight(t *testing.T) {
|
|||
bc := newTestChainWithCustomCfgAndStore(t, st, nil)
|
||||
cs1, _ := getTestContractState(bc)
|
||||
func() {
|
||||
defer bc.Close()
|
||||
require.NoError(t, bc.contracts.Management.PutContractState(bc.dao, cs1))
|
||||
checkContractState(t, bc, cs1.Hash, cs1)
|
||||
_, err := bc.dao.Store.Persist()
|
||||
|
@ -74,7 +72,6 @@ func TestStartFromHeight(t *testing.T) {
|
|||
|
||||
func TestContractDeployAndUpdateWithParameter(t *testing.T) {
|
||||
bc := newTestChain(t)
|
||||
defer bc.Close()
|
||||
|
||||
// nef.NewFile() cares about version a lot.
|
||||
config.Version = "0.90.0-test"
|
||||
|
@ -125,7 +122,6 @@ func TestContractDeployAndUpdateWithParameter(t *testing.T) {
|
|||
|
||||
func TestContractDeploy(t *testing.T) {
|
||||
bc := newTestChain(t)
|
||||
defer bc.Close()
|
||||
|
||||
// nef.NewFile() cares about version a lot.
|
||||
config.Version = "0.90.0-test"
|
||||
|
@ -277,7 +273,6 @@ func TestContractDeploy(t *testing.T) {
|
|||
|
||||
r := io.NewBinReaderFromBuf(w.Bytes())
|
||||
bc2 := newTestChain(t)
|
||||
defer bc2.Close()
|
||||
|
||||
require.NoError(t, chaindump.Restore(bc2, r, 0, bc.BlockHeight()+1, nil))
|
||||
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) {
|
||||
bc := newTestChain(t)
|
||||
defer bc.Close()
|
||||
|
||||
// nef.NewFile() cares about version a lot.
|
||||
config.Version = "0.90.0-test"
|
||||
|
@ -526,7 +520,6 @@ func TestContractUpdate(t *testing.T) {
|
|||
|
||||
func TestGetContract(t *testing.T) {
|
||||
bc := newTestChain(t)
|
||||
defer bc.Close()
|
||||
|
||||
mgmtHash := bc.ManagementContractHash()
|
||||
cs1, _ := getTestContractState(bc)
|
||||
|
@ -553,7 +546,6 @@ func TestGetContract(t *testing.T) {
|
|||
|
||||
func TestContractDestroy(t *testing.T) {
|
||||
bc := newTestChain(t)
|
||||
defer bc.Close()
|
||||
|
||||
mgmtHash := bc.ManagementContractHash()
|
||||
cs1, _ := getTestContractState(bc)
|
||||
|
@ -607,7 +599,6 @@ func compareContractStates(t *testing.T, expected *state.Contract, actual stacki
|
|||
|
||||
func TestMinimumDeploymentFee(t *testing.T) {
|
||||
chain := newTestChain(t)
|
||||
defer chain.Close()
|
||||
|
||||
t.Run("get, internal method", func(t *testing.T) {
|
||||
n := chain.contracts.Management.GetMinimumDeploymentFee(chain.dao)
|
||||
|
|
|
@ -21,7 +21,6 @@ import (
|
|||
|
||||
func TestNameService_Price(t *testing.T) {
|
||||
bc := newTestChain(t)
|
||||
defer bc.Close()
|
||||
|
||||
testGetSet(t, bc, bc.contracts.NameService.Hash, "Price",
|
||||
native.DefaultDomainPrice, 1, 10000_00000000)
|
||||
|
@ -29,7 +28,6 @@ func TestNameService_Price(t *testing.T) {
|
|||
|
||||
func TestNonfungible(t *testing.T) {
|
||||
bc := newTestChain(t)
|
||||
defer bc.Close()
|
||||
|
||||
acc := newAccountWithGAS(t, bc)
|
||||
testNameServiceInvokeAux(t, bc, defaultNameServiceSysfee, acc, "symbol", "NNS")
|
||||
|
@ -39,7 +37,6 @@ func TestNonfungible(t *testing.T) {
|
|||
|
||||
func TestAddRoot(t *testing.T) {
|
||||
bc := newTestChain(t)
|
||||
defer bc.Close()
|
||||
|
||||
transferFundsToCommittee(t, bc)
|
||||
nsHash := bc.contracts.NameService.Hash
|
||||
|
@ -61,7 +58,6 @@ func TestAddRoot(t *testing.T) {
|
|||
|
||||
func TestExpiration(t *testing.T) {
|
||||
bc := newTestChain(t)
|
||||
defer bc.Close()
|
||||
|
||||
transferFundsToCommittee(t, bc)
|
||||
acc := newAccountWithGAS(t, bc)
|
||||
|
@ -130,7 +126,6 @@ const secondsInYear = 365 * 24 * 3600
|
|||
|
||||
func TestRegisterAndRenew(t *testing.T) {
|
||||
bc := newTestChain(t)
|
||||
defer bc.Close()
|
||||
|
||||
transferFundsToCommittee(t, bc)
|
||||
|
||||
|
@ -181,7 +176,6 @@ func TestRegisterAndRenew(t *testing.T) {
|
|||
|
||||
func TestSetGetRecord(t *testing.T) {
|
||||
bc := newTestChain(t)
|
||||
defer bc.Close()
|
||||
|
||||
transferFundsToCommittee(t, bc)
|
||||
acc := newAccountWithGAS(t, bc)
|
||||
|
@ -222,7 +216,6 @@ func TestSetGetRecord(t *testing.T) {
|
|||
|
||||
func TestSetAdmin(t *testing.T) {
|
||||
bc := newTestChain(t)
|
||||
defer bc.Close()
|
||||
|
||||
transferFundsToCommittee(t, bc)
|
||||
owner := newAccountWithGAS(t, bc)
|
||||
|
@ -265,7 +258,6 @@ func TestSetAdmin(t *testing.T) {
|
|||
|
||||
func TestTransfer(t *testing.T) {
|
||||
bc := newTestChain(t)
|
||||
defer bc.Close()
|
||||
|
||||
transferFundsToCommittee(t, bc)
|
||||
from := newAccountWithGAS(t, bc)
|
||||
|
@ -299,7 +291,6 @@ func TestTransfer(t *testing.T) {
|
|||
|
||||
func TestTokensOf(t *testing.T) {
|
||||
bc := newTestChain(t)
|
||||
defer bc.Close()
|
||||
|
||||
transferFundsToCommittee(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) {
|
||||
bc := newTestChain(t)
|
||||
defer bc.Close()
|
||||
|
||||
transferFundsToCommittee(t, bc)
|
||||
acc := newAccountWithGAS(t, bc)
|
||||
|
|
|
@ -38,7 +38,6 @@ func checkTxHalt(t *testing.T, bc *Blockchain, h util.Uint256) {
|
|||
|
||||
func TestNEO_Vote(t *testing.T) {
|
||||
bc := newTestChain(t)
|
||||
defer bc.Close()
|
||||
|
||||
neo := bc.contracts.NEO
|
||||
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) {
|
||||
bc := newTestChain(t)
|
||||
defer bc.Close()
|
||||
|
||||
testGetSet(t, bc, bc.contracts.NEO.Hash, "GasPerBlock",
|
||||
5*native.GASFactor, 0, 10*native.GASFactor)
|
||||
|
@ -203,7 +201,6 @@ func TestNEO_SetGasPerBlock(t *testing.T) {
|
|||
|
||||
func TestNEO_CalculateBonus(t *testing.T) {
|
||||
bc := newTestChain(t)
|
||||
defer bc.Close()
|
||||
|
||||
neo := bc.contracts.NEO
|
||||
tx := transaction.New(netmode.UnitTestNet, []byte{}, 0)
|
||||
|
@ -233,7 +230,6 @@ func TestNEO_CalculateBonus(t *testing.T) {
|
|||
|
||||
func TestNEO_CommitteeBountyOnPersist(t *testing.T) {
|
||||
bc := newTestChain(t)
|
||||
defer bc.Close()
|
||||
|
||||
hs := make([]util.Uint160, testchain.CommitteeSize())
|
||||
for i := range hs {
|
||||
|
@ -256,7 +252,6 @@ func TestNEO_CommitteeBountyOnPersist(t *testing.T) {
|
|||
|
||||
func TestNEO_TransferOnPayment(t *testing.T) {
|
||||
bc := newTestChain(t)
|
||||
defer bc.Close()
|
||||
|
||||
cs, _ := getTestContractState(bc)
|
||||
require.NoError(t, bc.contracts.Management.PutContractState(bc.dao, cs))
|
||||
|
|
|
@ -22,7 +22,6 @@ import (
|
|||
|
||||
func TestNotaryContractPipeline(t *testing.T) {
|
||||
chain := newTestChain(t)
|
||||
defer chain.Close()
|
||||
|
||||
notaryHash := chain.contracts.Notary.Hash
|
||||
gasHash := chain.contracts.GAS.Hash
|
||||
|
@ -249,7 +248,6 @@ func TestNotaryContractPipeline(t *testing.T) {
|
|||
func TestNotaryNodesReward(t *testing.T) {
|
||||
checkReward := func(nKeys int, nNotaryNodes int, spendFullDeposit bool) {
|
||||
chain := newTestChain(t)
|
||||
defer chain.Close()
|
||||
notaryHash := chain.contracts.Notary.Hash
|
||||
gasHash := chain.contracts.GAS.Hash
|
||||
signer := testchain.MultisigScriptHash()
|
||||
|
@ -326,7 +324,6 @@ func TestNotaryNodesReward(t *testing.T) {
|
|||
|
||||
func TestMaxNotValidBeforeDelta(t *testing.T) {
|
||||
chain := newTestChain(t)
|
||||
defer chain.Close()
|
||||
|
||||
testGetSet(t, chain, chain.contracts.Notary.Hash, "MaxNotValidBeforeDelta",
|
||||
140, int64(chain.GetConfig().ValidatorsCount), transaction.MaxValidUntilBlockIncrement/2)
|
||||
|
|
|
@ -115,7 +115,6 @@ func putOracleRequest(t *testing.T, h util.Uint160, bc *Blockchain,
|
|||
|
||||
func TestOracle_Request(t *testing.T) {
|
||||
bc := newTestChain(t)
|
||||
defer bc.Close()
|
||||
|
||||
orc := bc.contracts.Oracle
|
||||
cs := getOracleContractState(orc.Hash)
|
||||
|
|
|
@ -78,7 +78,6 @@ func testGetSet(t *testing.T, chain *Blockchain, hash util.Uint160, name string,
|
|||
|
||||
func TestMaxTransactionsPerBlock(t *testing.T) {
|
||||
chain := newTestChain(t)
|
||||
defer chain.Close()
|
||||
|
||||
t.Run("get, internal method", func(t *testing.T) {
|
||||
n := chain.contracts.Policy.GetMaxTransactionsPerBlockInternal(chain.dao)
|
||||
|
@ -90,7 +89,6 @@ func TestMaxTransactionsPerBlock(t *testing.T) {
|
|||
|
||||
func TestMaxBlockSize(t *testing.T) {
|
||||
chain := newTestChain(t)
|
||||
defer chain.Close()
|
||||
|
||||
t.Run("get, internal method", func(t *testing.T) {
|
||||
n := chain.contracts.Policy.GetMaxBlockSizeInternal(chain.dao)
|
||||
|
@ -102,7 +100,6 @@ func TestMaxBlockSize(t *testing.T) {
|
|||
|
||||
func TestFeePerByte(t *testing.T) {
|
||||
chain := newTestChain(t)
|
||||
defer chain.Close()
|
||||
|
||||
t.Run("get, internal method", func(t *testing.T) {
|
||||
n := chain.contracts.Policy.GetFeePerByteInternal(chain.dao)
|
||||
|
@ -114,7 +111,6 @@ func TestFeePerByte(t *testing.T) {
|
|||
|
||||
func TestExecFeeFactor(t *testing.T) {
|
||||
chain := newTestChain(t)
|
||||
defer chain.Close()
|
||||
|
||||
t.Run("get, internal method", func(t *testing.T) {
|
||||
n := chain.contracts.Policy.GetExecFeeFactorInternal(chain.dao)
|
||||
|
@ -126,7 +122,6 @@ func TestExecFeeFactor(t *testing.T) {
|
|||
|
||||
func TestBlockSystemFee(t *testing.T) {
|
||||
chain := newTestChain(t)
|
||||
defer chain.Close()
|
||||
|
||||
t.Run("get, internal method", func(t *testing.T) {
|
||||
n := chain.contracts.Policy.GetMaxBlockSystemFeeInternal(chain.dao)
|
||||
|
@ -138,7 +133,6 @@ func TestBlockSystemFee(t *testing.T) {
|
|||
|
||||
func TestStoragePrice(t *testing.T) {
|
||||
chain := newTestChain(t)
|
||||
defer chain.Close()
|
||||
|
||||
t.Run("get, internal method", func(t *testing.T) {
|
||||
n := chain.contracts.Policy.GetStoragePriceInternal(chain.dao)
|
||||
|
@ -150,7 +144,6 @@ func TestStoragePrice(t *testing.T) {
|
|||
|
||||
func TestBlockedAccounts(t *testing.T) {
|
||||
chain := newTestChain(t)
|
||||
defer chain.Close()
|
||||
account := util.Uint160{1, 2, 3}
|
||||
policyHash := chain.contracts.Policy.Metadata().Hash
|
||||
|
||||
|
|
|
@ -59,7 +59,6 @@ func getTestNotary(t *testing.T, bc *Blockchain, walletPath, pass string, onTx f
|
|||
|
||||
func TestNotary(t *testing.T) {
|
||||
bc := newTestChain(t)
|
||||
defer bc.Close()
|
||||
var (
|
||||
nonce uint32
|
||||
nvbDiffFallback uint32 = 20
|
||||
|
@ -641,10 +640,10 @@ func TestNotary(t *testing.T) {
|
|||
// Subscriptions test
|
||||
mp1.RunSubscriptions()
|
||||
go ntr1.Run()
|
||||
defer func() {
|
||||
t.Cleanup(func() {
|
||||
ntr1.Stop()
|
||||
mp1.StopSubscriptions()
|
||||
}()
|
||||
})
|
||||
finalizeWithError = false
|
||||
requester1, _ := wallet.NewAccount()
|
||||
requester2, _ := wallet.NewAccount()
|
||||
|
|
|
@ -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
|
||||
func TestCreateResponseTx(t *testing.T) {
|
||||
bc := newTestChain(t)
|
||||
defer bc.Close()
|
||||
|
||||
require.Equal(t, int64(30), bc.GetBaseExecFee())
|
||||
require.Equal(t, int64(1000), bc.FeePerByte())
|
||||
|
@ -116,7 +115,6 @@ func TestOracle_InvalidWallet(t *testing.T) {
|
|||
|
||||
func TestOracle(t *testing.T) {
|
||||
bc := newTestChain(t)
|
||||
defer bc.Close()
|
||||
|
||||
oracleCtr := bc.contracts.Oracle
|
||||
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))
|
||||
|
||||
go bc.Run()
|
||||
defer bc.Close()
|
||||
go orc.Run()
|
||||
defer orc.Shutdown()
|
||||
t.Cleanup(orc.Shutdown)
|
||||
|
||||
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)
|
||||
|
|
|
@ -11,10 +11,10 @@ import (
|
|||
func newBoltStoreForTesting(t *testing.T) Store {
|
||||
testFileName := "test_bolt_db"
|
||||
file, err := ioutil.TempFile("", testFileName)
|
||||
defer func() {
|
||||
t.Cleanup(func() {
|
||||
err := os.RemoveAll(testFileName)
|
||||
require.NoError(t, err)
|
||||
}()
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, file.Close())
|
||||
boltDBStore, err := NewBoltDBStore(BoltDBOptions{FilePath: testFileName})
|
||||
|
|
|
@ -15,7 +15,9 @@ func TestMakeDirForFile_HappyPath(t *testing.T) {
|
|||
|
||||
filePath := tempDir + "/testDir/testFile.test"
|
||||
err = MakeDirForFile(filePath, "test")
|
||||
defer removeDir(t, tempDir)
|
||||
t.Cleanup(func() {
|
||||
removeDir(t, tempDir)
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
_, errChDir := os.Create(filePath)
|
||||
|
@ -34,6 +36,8 @@ func TestMakeDirForFile_Negative(t *testing.T) {
|
|||
filePath := file.Name() + "/error"
|
||||
dir := path.Dir(filePath)
|
||||
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)
|
||||
}
|
||||
|
|
|
@ -192,5 +192,6 @@ func newTestServer(t *testing.T, serverConfig ServerConfig) *Server {
|
|||
s, err := newServerFromConstructors(serverConfig, fakechain.NewFakeChain(), zaptest.NewLogger(t),
|
||||
newFakeTransp, newFakeConsensus, newTestDiscovery)
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(s.discovery.Close)
|
||||
return s
|
||||
}
|
||||
|
|
|
@ -53,7 +53,6 @@ func TestNewServer(t *testing.T) {
|
|||
|
||||
t.Run("set defaults", func(t *testing.T) {
|
||||
s = newTestServer(t, ServerConfig{MinPeers: -1})
|
||||
defer s.discovery.Close()
|
||||
|
||||
require.True(t, s.ID() != 0)
|
||||
require.Equal(t, defaultMinPeers, s.ServerConfig.MinPeers)
|
||||
|
@ -67,7 +66,6 @@ func TestNewServer(t *testing.T) {
|
|||
AttemptConnPeers: 3,
|
||||
}
|
||||
s = newTestServer(t, cfg)
|
||||
defer s.discovery.Close()
|
||||
|
||||
require.True(t, s.ID() != 0)
|
||||
require.Equal(t, 1, s.ServerConfig.MinPeers)
|
||||
|
@ -140,10 +138,10 @@ func TestServerRegisterPeer(t *testing.T) {
|
|||
}
|
||||
|
||||
ch := startWithChannel(s)
|
||||
defer func() {
|
||||
t.Cleanup(func() {
|
||||
s.Shutdown()
|
||||
<-ch
|
||||
}()
|
||||
})
|
||||
|
||||
s.register <- ps[0]
|
||||
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()
|
||||
close(finished)
|
||||
}()
|
||||
defer func() {
|
||||
t.Cleanup(func() {
|
||||
// close via quit as server was started via `run()`, not `Start()`
|
||||
close(s.quit)
|
||||
<-finished
|
||||
}()
|
||||
})
|
||||
|
||||
na, _ := net.ResolveTCPAddr("tcp", "0.0.0.0:3000")
|
||||
p.netaddr = *na
|
||||
|
@ -379,18 +377,18 @@ func (s *Server) testHandleMessage(t *testing.T, p Peer, cmd CommandType, pl pay
|
|||
return s
|
||||
}
|
||||
|
||||
func startTestServer(t *testing.T) (*Server, func()) {
|
||||
func startTestServer(t *testing.T) *Server {
|
||||
s := newTestServer(t, ServerConfig{Port: 0, UserAgent: "/test/"})
|
||||
ch := startWithChannel(s)
|
||||
return s, func() {
|
||||
t.Cleanup(func() {
|
||||
s.Shutdown()
|
||||
<-ch
|
||||
}
|
||||
})
|
||||
return s
|
||||
}
|
||||
|
||||
func TestBlock(t *testing.T) {
|
||||
s, shutdown := startTestServer(t)
|
||||
defer shutdown()
|
||||
s := startTestServer(t)
|
||||
|
||||
atomic2.StoreUint32(&s.chain.(*fakechain.FakeChain).Blockheight, 12344)
|
||||
require.Equal(t, uint32(12344), s.chain.BlockHeight())
|
||||
|
@ -402,8 +400,7 @@ func TestBlock(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestConsensus(t *testing.T) {
|
||||
s, shutdown := startTestServer(t)
|
||||
defer shutdown()
|
||||
s := startTestServer(t)
|
||||
|
||||
atomic2.StoreUint32(&s.chain.(*fakechain.FakeChain).Blockheight, 4)
|
||||
p := newLocalPeer(t, s)
|
||||
|
@ -450,8 +447,7 @@ func TestConsensus(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTransaction(t *testing.T) {
|
||||
s, shutdown := startTestServer(t)
|
||||
defer shutdown()
|
||||
s := startTestServer(t)
|
||||
|
||||
t.Run("good", func(t *testing.T) {
|
||||
tx := newDummyTx()
|
||||
|
@ -503,8 +499,7 @@ func (s *Server) testHandleGetData(t *testing.T, invType payload.InventoryType,
|
|||
}
|
||||
|
||||
func TestGetData(t *testing.T) {
|
||||
s, shutdown := startTestServer(t)
|
||||
defer shutdown()
|
||||
s := startTestServer(t)
|
||||
s.chain.(*fakechain.FakeChain).UtilityTokenBalance = big.NewInt(1000000)
|
||||
|
||||
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) {
|
||||
s, shutdown := startTestServer(t)
|
||||
func initGetBlocksTest(t *testing.T) (*Server, []*block.Block) {
|
||||
s := startTestServer(t)
|
||||
|
||||
var blocks []*block.Block
|
||||
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)
|
||||
blocks = append(blocks, b)
|
||||
}
|
||||
return s, shutdown, blocks
|
||||
return s, blocks
|
||||
}
|
||||
|
||||
func TestGetBlocks(t *testing.T) {
|
||||
s, shutdown, blocks := initGetBlocksTest(t)
|
||||
defer shutdown()
|
||||
s, blocks := initGetBlocksTest(t)
|
||||
|
||||
expected := make([]util.Uint256, len(blocks))
|
||||
for i := range blocks {
|
||||
|
@ -608,8 +602,7 @@ func TestGetBlocks(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGetBlockByIndex(t *testing.T) {
|
||||
s, shutdown, blocks := initGetBlocksTest(t)
|
||||
defer shutdown()
|
||||
s, blocks := initGetBlocksTest(t)
|
||||
|
||||
var expected []*block.Block
|
||||
var actual []*block.Block
|
||||
|
@ -643,8 +636,7 @@ func TestGetBlockByIndex(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGetHeaders(t *testing.T) {
|
||||
s, shutdown, blocks := initGetBlocksTest(t)
|
||||
defer shutdown()
|
||||
s, blocks := initGetBlocksTest(t)
|
||||
|
||||
expected := make([]*block.Header, len(blocks))
|
||||
for i := range blocks {
|
||||
|
@ -683,8 +675,7 @@ func TestGetHeaders(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestInv(t *testing.T) {
|
||||
s, shutdown := startTestServer(t)
|
||||
defer shutdown()
|
||||
s := startTestServer(t)
|
||||
s.chain.(*fakechain.FakeChain).UtilityTokenBalance = big.NewInt(10000000)
|
||||
|
||||
var actual []util.Uint256
|
||||
|
@ -749,8 +740,7 @@ func TestInv(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestRequestTx(t *testing.T) {
|
||||
s, shutdown := startTestServer(t)
|
||||
defer shutdown()
|
||||
s := startTestServer(t)
|
||||
|
||||
var actual []util.Uint256
|
||||
p := newLocalPeer(t, s)
|
||||
|
@ -795,8 +785,7 @@ func TestRequestTx(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestAddrs(t *testing.T) {
|
||||
s, shutdown := startTestServer(t)
|
||||
defer shutdown()
|
||||
s := startTestServer(t)
|
||||
|
||||
ips := make([][16]byte, 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 TestMemPool(t *testing.T) {
|
||||
s, shutdown := startTestServer(t)
|
||||
defer shutdown()
|
||||
s := startTestServer(t)
|
||||
|
||||
var actual []util.Uint256
|
||||
p := newLocalPeer(t, s)
|
||||
|
|
|
@ -1439,7 +1439,6 @@ func testRPCClient(t *testing.T, newClient func(context.Context, string, Options
|
|||
for _, testCase := range testBatch {
|
||||
t.Run(testCase.name, func(t *testing.T) {
|
||||
srv := initTestServer(t, testCase.serverResponse)
|
||||
defer srv.Close()
|
||||
|
||||
endpoint := srv.URL
|
||||
opts := Options{}
|
||||
|
@ -1467,7 +1466,6 @@ func testRPCClient(t *testing.T, newClient func(context.Context, string, Options
|
|||
}
|
||||
for serverResponse, testBatch := range rpcClientErrorCases {
|
||||
srv := initTestServer(t, serverResponse)
|
||||
defer srv.Close()
|
||||
|
||||
endpoint := srv.URL
|
||||
opts := Options{}
|
||||
|
@ -1524,6 +1522,8 @@ func initTestServer(t *testing.T, resp string) *httptest.Server {
|
|||
requestHandler(t, r.In, w, resp)
|
||||
}))
|
||||
|
||||
t.Cleanup(srv.Close)
|
||||
|
||||
return srv
|
||||
}
|
||||
|
||||
|
@ -1582,7 +1582,7 @@ func TestCalculateValidUntilBlock(t *testing.T) {
|
|||
}
|
||||
requestHandler(t, r.In, w, response)
|
||||
}))
|
||||
defer srv.Close()
|
||||
t.Cleanup(srv.Close)
|
||||
|
||||
endpoint := srv.URL
|
||||
opts := Options{}
|
||||
|
@ -1616,7 +1616,7 @@ func TestGetNetwork(t *testing.T) {
|
|||
// request handler already have `getversion` response wrapper
|
||||
requestHandler(t, r.In, w, "")
|
||||
}))
|
||||
defer srv.Close()
|
||||
t.Cleanup(srv.Close)
|
||||
endpoint := srv.URL
|
||||
opts := Options{}
|
||||
|
||||
|
@ -1648,7 +1648,7 @@ func TestUninitedClient(t *testing.T) {
|
|||
// request handler already have `getversion` response wrapper
|
||||
requestHandler(t, r.In, w, "")
|
||||
}))
|
||||
defer srv.Close()
|
||||
t.Cleanup(srv.Close)
|
||||
endpoint := srv.URL
|
||||
opts := Options{}
|
||||
|
||||
|
|
|
@ -17,7 +17,6 @@ import (
|
|||
|
||||
func TestWSClientClose(t *testing.T) {
|
||||
srv := initTestServer(t, "")
|
||||
defer srv.Close()
|
||||
wsc, err := NewWS(context.TODO(), httpURLtoWS(srv.URL), Options{})
|
||||
require.NoError(t, err)
|
||||
wsc.Close()
|
||||
|
@ -42,7 +41,6 @@ func TestWSClientSubscription(t *testing.T) {
|
|||
for name, f := range cases {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
srv := initTestServer(t, `{"jsonrpc": "2.0", "id": 1, "result": "55aaff00"}`)
|
||||
defer srv.Close()
|
||||
wsc, err := NewWS(context.TODO(), httpURLtoWS(srv.URL), Options{})
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, wsc.Init())
|
||||
|
@ -56,7 +54,6 @@ func TestWSClientSubscription(t *testing.T) {
|
|||
for name, f := range cases {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
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{})
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, wsc.Init())
|
||||
|
@ -106,7 +103,6 @@ func TestWSClientUnsubscription(t *testing.T) {
|
|||
for name, rc := range cases {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
srv := initTestServer(t, rc.response)
|
||||
defer srv.Close()
|
||||
wsc, err := NewWS(context.TODO(), httpURLtoWS(srv.URL), Options{})
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, wsc.Init())
|
||||
|
@ -165,7 +161,6 @@ func TestWSClientEvents(t *testing.T) {
|
|||
func TestWSExecutionVMStateCheck(t *testing.T) {
|
||||
// Will answer successfully if request slips through.
|
||||
srv := initTestServer(t, `{"jsonrpc": "2.0", "id": 1, "result": "55aaff00"}`)
|
||||
defer srv.Close()
|
||||
wsc, err := NewWS(context.TODO(), httpURLtoWS(srv.URL), Options{})
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, wsc.Init())
|
||||
|
@ -330,7 +325,6 @@ func TestWSFilteredSubscriptions(t *testing.T) {
|
|||
ws.Close()
|
||||
}
|
||||
}))
|
||||
defer srv.Close()
|
||||
wsc, err := NewWS(context.TODO(), httpURLtoWS(srv.URL), Options{})
|
||||
require.NoError(t, err)
|
||||
wsc.network = netmode.UnitTestNet
|
||||
|
@ -342,7 +336,6 @@ func TestWSFilteredSubscriptions(t *testing.T) {
|
|||
|
||||
func TestNewWS(t *testing.T) {
|
||||
srv := initTestServer(t, "")
|
||||
defer srv.Close()
|
||||
|
||||
t.Run("good", func(t *testing.T) {
|
||||
c, err := NewWS(context.TODO(), httpURLtoWS(srv.URL), Options{})
|
||||
|
|
|
@ -164,7 +164,9 @@ func TestLoad(t *testing.T) {
|
|||
}`
|
||||
tmpDir := path.Join(os.TempDir(), "vmcliloadtest")
|
||||
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) {
|
||||
filename := path.Join(tmpDir, "vmtestcontract.go")
|
||||
|
@ -244,7 +246,9 @@ func TestRunWithDifferentArguments(t *testing.T) {
|
|||
|
||||
filename := path.Join(os.TempDir(), "run_vmtestcontract.go")
|
||||
require.NoError(t, ioutil.WriteFile(filename, []byte(src), os.ModePerm))
|
||||
defer os.Remove(filename)
|
||||
t.Cleanup(func() {
|
||||
os.Remove(filename)
|
||||
})
|
||||
|
||||
e := newTestVMCLI(t)
|
||||
e.runProg(t,
|
||||
|
|
|
@ -89,7 +89,9 @@ func TestSave(t *testing.T) {
|
|||
Default: false,
|
||||
})
|
||||
|
||||
defer removeWallet(t, file.Name())
|
||||
t.Cleanup(func() {
|
||||
removeWallet(t, file.Name())
|
||||
})
|
||||
errForSave := wallet.Save()
|
||||
require.NoError(t, errForSave)
|
||||
|
||||
|
@ -129,7 +131,9 @@ func checkWalletConstructor(t *testing.T) *Wallet {
|
|||
file, err := ioutil.TempFile("", walletTemplate)
|
||||
require.NoError(t, err)
|
||||
wallet, err := NewWallet(file.Name())
|
||||
defer removeWallet(t, file.Name())
|
||||
t.Cleanup(func() {
|
||||
removeWallet(t, file.Name())
|
||||
})
|
||||
require.NoError(t, err)
|
||||
return wallet
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue