forked from TrueCloudLab/neoneo-go
*: make tests use TempDir(), fix #1319
Simplify things, drop TempFile at the same time (refs. #1764)
This commit is contained in:
parent
f4ba21a41a
commit
6d074a96e9
16 changed files with 93 additions and 308 deletions
|
@ -28,6 +28,7 @@ import (
|
|||
)
|
||||
|
||||
func TestCalcHash(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
e := newExecutor(t, false)
|
||||
|
||||
nefPath := "./testdata/verify.nef"
|
||||
|
@ -58,13 +59,9 @@ func TestCalcHash(t *testing.T) {
|
|||
"--in", "./testdata/verify.nef123", "--manifest", manifestPath)...)
|
||||
})
|
||||
t.Run("invalid file", func(t *testing.T) {
|
||||
p, err := ioutil.TempFile("", "neogo.calchash.verify.nef")
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
os.Remove(p.Name())
|
||||
})
|
||||
require.NoError(t, ioutil.WriteFile(p.Name(), src[:4], os.ModePerm))
|
||||
e.RunWithError(t, append(cmd, "--sender", sender.StringLE(), "--in", p.Name(), "--manifest", manifestPath)...)
|
||||
p := path.Join(tmpDir, "neogo.calchash.verify.nef")
|
||||
require.NoError(t, ioutil.WriteFile(p, src[:4], os.ModePerm))
|
||||
e.RunWithError(t, append(cmd, "--sender", sender.StringLE(), "--in", p, "--manifest", manifestPath)...)
|
||||
})
|
||||
|
||||
cmd = append(cmd, "--in", nefPath, "--manifest", manifestPath)
|
||||
|
@ -84,12 +81,7 @@ func TestCalcHash(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestContractInitAndCompile(t *testing.T) {
|
||||
tmpDir, err := ioutil.TempDir("", "neogo.inittest")
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
os.RemoveAll(tmpDir)
|
||||
})
|
||||
|
||||
tmpDir := t.TempDir()
|
||||
e := newExecutor(t, false)
|
||||
|
||||
t.Run("no path is provided", func(t *testing.T) {
|
||||
|
@ -148,12 +140,7 @@ func TestDeployBigContract(t *testing.T) {
|
|||
|
||||
// For proper nef generation.
|
||||
config.Version = "0.90.0-test"
|
||||
|
||||
tmpDir, err := ioutil.TempDir("", "neogo.test.deployfail")
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
os.RemoveAll(tmpDir)
|
||||
})
|
||||
tmpDir := t.TempDir()
|
||||
|
||||
nefName := path.Join(tmpDir, "deploy.nef")
|
||||
manifestName := path.Join(tmpDir, "deploy.manifest.json")
|
||||
|
@ -174,12 +161,7 @@ func TestContractDeployWithData(t *testing.T) {
|
|||
|
||||
// For proper nef generation.
|
||||
config.Version = "0.90.0-test"
|
||||
|
||||
tmpDir, err := ioutil.TempDir("", "neogo.test.deployfail")
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
os.RemoveAll(tmpDir)
|
||||
})
|
||||
tmpDir := t.TempDir()
|
||||
|
||||
nefName := path.Join(tmpDir, "deploy.nef")
|
||||
manifestName := path.Join(tmpDir, "deploy.manifest.json")
|
||||
|
@ -232,12 +214,7 @@ func TestContractManifestGroups(t *testing.T) {
|
|||
|
||||
// For proper nef generation.
|
||||
config.Version = "0.90.0-test"
|
||||
|
||||
tmpDir, err := ioutil.TempDir("", "neogo.test.deployfail")
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
os.RemoveAll(tmpDir)
|
||||
})
|
||||
tmpDir := t.TempDir()
|
||||
|
||||
w, err := wallet.NewWalletFromFile(testWalletPath)
|
||||
require.NoError(t, err)
|
||||
|
@ -273,11 +250,7 @@ func deployVerifyContract(t *testing.T, e *executor) util.Uint160 {
|
|||
}
|
||||
|
||||
func deployContract(t *testing.T, e *executor, inPath, configPath, wallet, address, pass string) util.Uint160 {
|
||||
tmpDir, err := ioutil.TempDir(os.TempDir(), "neogo.test.deploycontract*")
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
os.RemoveAll(tmpDir)
|
||||
})
|
||||
tmpDir := t.TempDir()
|
||||
nefName := path.Join(tmpDir, "contract.nef")
|
||||
manifestName := path.Join(tmpDir, "contract.manifest.json")
|
||||
e.Run(t, "neo-go", "contract", "compile",
|
||||
|
@ -303,12 +276,7 @@ func TestComlileAndInvokeFunction(t *testing.T) {
|
|||
|
||||
// For proper nef generation.
|
||||
config.Version = "0.90.0-test"
|
||||
|
||||
tmpDir, err := ioutil.TempDir("", "neogo.test.compileandinvoke")
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
os.RemoveAll(tmpDir)
|
||||
})
|
||||
tmpDir := t.TempDir()
|
||||
|
||||
nefName := path.Join(tmpDir, "deploy.nef")
|
||||
manifestName := path.Join(tmpDir, "deploy.manifest.json")
|
||||
|
@ -556,12 +524,7 @@ func TestContractInspect(t *testing.T) {
|
|||
// For proper nef generation.
|
||||
config.Version = "0.90.0-test"
|
||||
const srcPath = "testdata/deploy/main.go"
|
||||
|
||||
tmpDir, err := ioutil.TempDir("", "neogo.test.contract.inspect")
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
os.RemoveAll(tmpDir)
|
||||
})
|
||||
tmpDir := t.TempDir()
|
||||
|
||||
nefName := path.Join(tmpDir, "deploy.nef")
|
||||
manifestName := path.Join(tmpDir, "deploy.manifest.json")
|
||||
|
@ -588,6 +551,7 @@ func TestContractInspect(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCompileExamples(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
const examplePath = "../examples"
|
||||
infos, err := ioutil.ReadDir(examplePath)
|
||||
require.NoError(t, err)
|
||||
|
@ -608,21 +572,15 @@ func TestCompileExamples(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
require.False(t, len(infos) == 0, "detected smart contract folder with no contract in it")
|
||||
|
||||
outF, err := ioutil.TempFile("", info.Name()+".nef")
|
||||
require.NoError(t, err)
|
||||
manifestF, err := ioutil.TempFile("", info.Name()+".manifest.json")
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
os.Remove(outF.Name())
|
||||
os.Remove(manifestF.Name())
|
||||
})
|
||||
outF := path.Join(tmpDir, info.Name()+".nef")
|
||||
manifestF := path.Join(tmpDir, info.Name()+".manifest.json")
|
||||
|
||||
cfgName := filterFilename(infos, ".yml")
|
||||
opts := []string{
|
||||
"neo-go", "contract", "compile",
|
||||
"--in", path.Join(examplePath, info.Name()),
|
||||
"--out", outF.Name(),
|
||||
"--manifest", manifestF.Name(),
|
||||
"--out", outF,
|
||||
"--manifest", manifestF,
|
||||
"--config", path.Join(examplePath, info.Name(), cfgName),
|
||||
}
|
||||
e.Run(t, opts...)
|
||||
|
@ -632,18 +590,12 @@ func TestCompileExamples(t *testing.T) {
|
|||
t.Run("invalid events in manifest", func(t *testing.T) {
|
||||
const dir = "./testdata/"
|
||||
for _, name := range []string{"invalid1", "invalid2", "invalid3"} {
|
||||
outF, err := ioutil.TempFile("", name+".nef")
|
||||
require.NoError(t, err)
|
||||
manifestF, err := ioutil.TempFile("", name+".manifest.json")
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
os.Remove(outF.Name())
|
||||
os.Remove(manifestF.Name())
|
||||
})
|
||||
outF := path.Join(tmpDir, name+".nef")
|
||||
manifestF := path.Join(tmpDir, name+".manifest.json")
|
||||
e.RunWithError(t, "neo-go", "contract", "compile",
|
||||
"--in", path.Join(dir, name),
|
||||
"--out", outF.Name(),
|
||||
"--manifest", manifestF.Name(),
|
||||
"--out", outF,
|
||||
"--manifest", manifestF,
|
||||
"--config", path.Join(dir, name, "invalid.yml"),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -12,11 +12,7 @@ import (
|
|||
)
|
||||
|
||||
func TestDBRestore(t *testing.T) {
|
||||
tmpDir, err := ioutil.TempDir("", "neogo.restoretest")
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
os.RemoveAll(tmpDir)
|
||||
})
|
||||
tmpDir := t.TempDir()
|
||||
|
||||
chainPath := path.Join(tmpDir, "neogotestchain")
|
||||
cfg, err := config.LoadFile("../config/protocol.unit_testnet.yml")
|
||||
|
|
|
@ -2,7 +2,6 @@ package main
|
|||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"io/ioutil"
|
||||
"math/big"
|
||||
"os"
|
||||
"path"
|
||||
|
@ -28,13 +27,9 @@ func TestSignMultisigTx(t *testing.T) {
|
|||
multisigAddr := address.Uint160ToString(multisigHash)
|
||||
|
||||
// Create 2 wallets participating in multisig.
|
||||
tmpDir, err := ioutil.TempDir("", "neogo.wallettest")
|
||||
require.NoError(t, err)
|
||||
tmpDir := t.TempDir()
|
||||
wallet1Path := path.Join(tmpDir, "multiWallet1.json")
|
||||
wallet2Path := path.Join(tmpDir, "multiWallet2.json")
|
||||
t.Cleanup(func() {
|
||||
os.RemoveAll(tmpDir)
|
||||
})
|
||||
|
||||
addAccount := func(w string, wif string) {
|
||||
e.Run(t, "neo-go", "wallet", "init", "--wallet", w)
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
"io"
|
||||
"io/ioutil"
|
||||
"math/big"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
"testing"
|
||||
|
@ -31,10 +30,8 @@ const (
|
|||
func TestNEP11Import(t *testing.T) {
|
||||
e := newExecutor(t, true)
|
||||
|
||||
tmpDir, err := ioutil.TempDir("", "neogo.nep11import")
|
||||
require.NoError(t, err)
|
||||
tmpDir := t.TempDir()
|
||||
walletPath := path.Join(tmpDir, "walletForImport.json")
|
||||
t.Cleanup(func() { os.RemoveAll(tmpDir) })
|
||||
|
||||
// deploy NFT NeoNameService contract
|
||||
nnsContractHash := deployNNSContract(t, e)
|
||||
|
@ -93,12 +90,7 @@ func TestNEP11Import(t *testing.T) {
|
|||
|
||||
func TestNEP11_OwnerOf_BalanceOf_Transfer(t *testing.T) {
|
||||
e := newExecutor(t, true)
|
||||
|
||||
tmpDir, err := ioutil.TempDir(os.TempDir(), "neogo.test.nftwallet*")
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
os.RemoveAll(tmpDir)
|
||||
})
|
||||
tmpDir := t.TempDir()
|
||||
|
||||
// copy wallet to temp dir in order not to overwrite the original file
|
||||
bytesRead, err := ioutil.ReadFile(nftOwnerWallet)
|
||||
|
|
|
@ -2,9 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"math/big"
|
||||
"os"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
@ -260,10 +258,7 @@ func TestNEP17MultiTransfer(t *testing.T) {
|
|||
|
||||
func TestNEP17ImportToken(t *testing.T) {
|
||||
e := newExecutor(t, true)
|
||||
|
||||
tmpDir, err := ioutil.TempDir("", "neogo.nep17import")
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() { os.RemoveAll(tmpDir) })
|
||||
tmpDir := t.TempDir()
|
||||
walletPath := path.Join(tmpDir, "walletForImport.json")
|
||||
|
||||
neoContractHash, err := e.Chain.GetNativeContractScriptHash(nativenames.Neo)
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
|
@ -10,12 +8,7 @@ import (
|
|||
)
|
||||
|
||||
func TestGetPath(t *testing.T) {
|
||||
testPath, err := ioutil.TempDir("./", "")
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
err := os.RemoveAll(testPath)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
testPath := t.TempDir()
|
||||
actual, err := getPath(testPath, 123)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, path.Join(testPath, "/BlockStorage_100000/dump-block-1000.json"), actual)
|
||||
|
|
|
@ -2,8 +2,8 @@ package server
|
|||
|
||||
import (
|
||||
"flag"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/config"
|
||||
|
@ -16,6 +16,17 @@ import (
|
|||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// serverTestWD is the default working directory for server tests.
|
||||
var serverTestWD string
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
serverTestWD, err = os.Getwd()
|
||||
if err != nil {
|
||||
panic("can't get current working directory")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetConfigFromContext(t *testing.T) {
|
||||
set := flag.NewFlagSet("flagSet", flag.ExitOnError)
|
||||
set.String("config-path", "../../config", "")
|
||||
|
@ -27,17 +38,14 @@ func TestGetConfigFromContext(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestHandleLoggingParams(t *testing.T) {
|
||||
testLog, err := ioutil.TempFile("./", "*.log")
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
require.NoError(t, os.Remove(testLog.Name()))
|
||||
})
|
||||
d := t.TempDir()
|
||||
testLog := path.Join(d, "file.log")
|
||||
|
||||
t.Run("default", func(t *testing.T) {
|
||||
set := flag.NewFlagSet("flagSet", flag.ExitOnError)
|
||||
ctx := cli.NewContext(cli.NewApp(), set, nil)
|
||||
cfg := config.ApplicationConfiguration{
|
||||
LogPath: testLog.Name(),
|
||||
LogPath: testLog,
|
||||
}
|
||||
logger, err := handleLoggingParams(ctx, cfg)
|
||||
require.NoError(t, err)
|
||||
|
@ -50,7 +58,7 @@ func TestHandleLoggingParams(t *testing.T) {
|
|||
set.Bool("debug", true, "")
|
||||
ctx := cli.NewContext(cli.NewApp(), set, nil)
|
||||
cfg := config.ApplicationConfiguration{
|
||||
LogPath: testLog.Name(),
|
||||
LogPath: testLog,
|
||||
}
|
||||
logger, err := handleLoggingParams(ctx, cfg)
|
||||
require.NoError(t, err)
|
||||
|
@ -60,18 +68,13 @@ func TestHandleLoggingParams(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestInitBCWithMetrics(t *testing.T) {
|
||||
d, err := ioutil.TempDir("./", "")
|
||||
d := t.TempDir()
|
||||
err := os.Chdir(d)
|
||||
require.NoError(t, err)
|
||||
err = os.Chdir(d)
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
err = os.Chdir("..")
|
||||
require.NoError(t, err)
|
||||
os.RemoveAll(d)
|
||||
})
|
||||
t.Cleanup(func() { require.NoError(t, os.Chdir(serverTestWD)) })
|
||||
|
||||
set := flag.NewFlagSet("flagSet", flag.ExitOnError)
|
||||
set.String("config-path", "../../../config", "")
|
||||
set.String("config-path", path.Join(serverTestWD, "../../config"), "")
|
||||
set.Bool("testnet", true, "")
|
||||
set.Bool("debug", true, "")
|
||||
ctx := cli.NewContext(cli.NewApp(), set, nil)
|
||||
|
@ -90,19 +93,15 @@ func TestInitBCWithMetrics(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestDumpDB(t *testing.T) {
|
||||
testDump := "file.acc"
|
||||
|
||||
t.Run("too low chain", func(t *testing.T) {
|
||||
d, err := ioutil.TempDir("./", "")
|
||||
d := t.TempDir()
|
||||
err := os.Chdir(d)
|
||||
require.NoError(t, err)
|
||||
err = os.Chdir(d)
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
err = os.Chdir("..")
|
||||
require.NoError(t, err)
|
||||
os.RemoveAll(d)
|
||||
})
|
||||
testDump := "file.acc"
|
||||
t.Cleanup(func() { require.NoError(t, os.Chdir(serverTestWD)) })
|
||||
set := flag.NewFlagSet("flagSet", flag.ExitOnError)
|
||||
set.String("config-path", "../../../config", "")
|
||||
set.String("config-path", path.Join(serverTestWD, "../../config"), "")
|
||||
set.Bool("privnet", true, "")
|
||||
set.Bool("debug", true, "")
|
||||
set.Int("start", 0, "")
|
||||
|
@ -114,18 +113,12 @@ func TestDumpDB(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("positive", func(t *testing.T) {
|
||||
d, err := ioutil.TempDir("./", "")
|
||||
d := t.TempDir()
|
||||
err := os.Chdir(d)
|
||||
require.NoError(t, err)
|
||||
err = os.Chdir(d)
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
err = os.Chdir("..")
|
||||
require.NoError(t, err)
|
||||
os.RemoveAll(d)
|
||||
})
|
||||
testDump := "file.acc"
|
||||
t.Cleanup(func() { require.NoError(t, os.Chdir(serverTestWD)) })
|
||||
set := flag.NewFlagSet("flagSet", flag.ExitOnError)
|
||||
set.String("config-path", "../../../config", "")
|
||||
set.String("config-path", path.Join(serverTestWD, "../../config"), "")
|
||||
set.Bool("privnet", true, "")
|
||||
set.Bool("debug", true, "")
|
||||
set.Int("start", 0, "")
|
||||
|
@ -138,21 +131,16 @@ func TestDumpDB(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestRestoreDB(t *testing.T) {
|
||||
d, err := ioutil.TempDir("./", "")
|
||||
require.NoError(t, err)
|
||||
d := t.TempDir()
|
||||
testDump := "file1.acc"
|
||||
saveDump := "file2.acc"
|
||||
err = os.Chdir(d)
|
||||
err := os.Chdir(d)
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
err = os.Chdir("..")
|
||||
require.NoError(t, err)
|
||||
os.RemoveAll(d)
|
||||
})
|
||||
t.Cleanup(func() { require.NoError(t, os.Chdir(serverTestWD)) })
|
||||
|
||||
//dump first
|
||||
set := flag.NewFlagSet("flagSet", flag.ExitOnError)
|
||||
set.String("config-path", "../../../config", "")
|
||||
set.String("config-path", path.Join(serverTestWD, "../../config"), "")
|
||||
set.Bool("privnet", true, "")
|
||||
set.Bool("debug", true, "")
|
||||
set.Int("start", 0, "")
|
||||
|
|
|
@ -16,15 +16,12 @@ import (
|
|||
)
|
||||
|
||||
func TestInitSmartContract(t *testing.T) {
|
||||
d, err := ioutil.TempDir("./", "")
|
||||
d := t.TempDir()
|
||||
testWD, err := os.Getwd()
|
||||
require.NoError(t, err)
|
||||
err = os.Chdir(d)
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
err = os.Chdir("..")
|
||||
require.NoError(t, err)
|
||||
os.RemoveAll(d)
|
||||
})
|
||||
t.Cleanup(func() { require.NoError(t, os.Chdir(testWD)) })
|
||||
contractName := "testContract"
|
||||
|
||||
set := flag.NewFlagSet("flagSet", flag.ExitOnError)
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"math/big"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
"testing"
|
||||
|
@ -20,12 +19,7 @@ import (
|
|||
)
|
||||
|
||||
func TestWalletAccountRemove(t *testing.T) {
|
||||
tmpDir, err := ioutil.TempDir("", "neogo.test.walletinit")
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
os.RemoveAll(tmpDir)
|
||||
})
|
||||
|
||||
tmpDir := t.TempDir()
|
||||
e := newExecutor(t, false)
|
||||
|
||||
walletPath := path.Join(tmpDir, "wallet.json")
|
||||
|
@ -52,12 +46,7 @@ func TestWalletAccountRemove(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestWalletInit(t *testing.T) {
|
||||
tmpDir, err := ioutil.TempDir("", "neogo.test.walletinit")
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
os.RemoveAll(tmpDir)
|
||||
})
|
||||
|
||||
tmpDir := t.TempDir()
|
||||
e := newExecutor(t, false)
|
||||
|
||||
walletPath := path.Join(tmpDir, "wallet.json")
|
||||
|
@ -268,15 +257,11 @@ func TestClaimGas(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestImportDeployed(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
e := newExecutor(t, true)
|
||||
|
||||
h := deployVerifyContract(t, e)
|
||||
tmpDir, err := ioutil.TempDir("", "neogo.importdeployed")
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
os.Remove(tmpDir)
|
||||
})
|
||||
walletPath := path.Join(tmpDir, "wallet.json")
|
||||
|
||||
e.Run(t, "neo-go", "wallet", "init", "--wallet", walletPath)
|
||||
|
||||
priv, err := keys.NewPrivateKey()
|
||||
|
@ -402,12 +387,7 @@ func TestDumpKeys(t *testing.T) {
|
|||
|
||||
// Testcase is the wallet of privnet validator.
|
||||
func TestWalletConvert(t *testing.T) {
|
||||
tmpDir, err := ioutil.TempDir("", "neogo.test.convert")
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
os.RemoveAll(tmpDir)
|
||||
})
|
||||
|
||||
tmpDir := t.TempDir()
|
||||
e := newExecutor(t, false)
|
||||
|
||||
outPath := path.Join(tmpDir, "wallet.json")
|
||||
|
|
|
@ -2,8 +2,6 @@ package core
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"sort"
|
||||
"testing"
|
||||
|
@ -79,11 +77,7 @@ func TestStateRoot(t *testing.T) {
|
|||
updateIndex := bc.BlockHeight()
|
||||
transferTokenFromMultisigAccount(t, bc, h, bc.contracts.GAS.Hash, 1_0000_0000)
|
||||
|
||||
tmpDir, err := ioutil.TempDir("", "neogo.test.stateroot")
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
os.RemoveAll(tmpDir)
|
||||
})
|
||||
tmpDir := t.TempDir()
|
||||
w := createAndWriteWallet(t, accs[0], path.Join(tmpDir, "w"), "pass")
|
||||
cfg := createStateRootConfig(w.Path(), "pass")
|
||||
srv, err := stateroot.New(cfg, zaptest.NewLogger(t), bc, nil)
|
||||
|
@ -151,11 +145,7 @@ func TestStateRootInitNonZeroHeight(t *testing.T) {
|
|||
|
||||
_, err := persistBlock(bc)
|
||||
require.NoError(t, err)
|
||||
tmpDir, err := ioutil.TempDir("", "neogo.initsnz")
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
os.RemoveAll(tmpDir)
|
||||
})
|
||||
tmpDir := t.TempDir()
|
||||
w := createAndWriteWallet(t, accs[0], path.Join(tmpDir, "w"), "pass")
|
||||
cfg := createStateRootConfig(w.Path(), "pass")
|
||||
srv, err := stateroot.New(cfg, zaptest.NewLogger(t), bc, nil)
|
||||
|
@ -195,12 +185,7 @@ func createStateRootConfig(walletPath, password string) config.StateRoot {
|
|||
}
|
||||
|
||||
func TestStateRootFull(t *testing.T) {
|
||||
tmpDir, err := ioutil.TempDir("", "neogo.stateroot4")
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
os.RemoveAll(tmpDir)
|
||||
})
|
||||
|
||||
tmpDir := t.TempDir()
|
||||
bc := newTestChain(t)
|
||||
|
||||
h, pubs, accs := newMajorityMultisigWithGAS(t, 2)
|
||||
|
|
|
@ -1,33 +1,13 @@
|
|||
package storage
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
type tempBadgerDB struct {
|
||||
*BadgerDBStore
|
||||
dir string
|
||||
}
|
||||
|
||||
func (tbdb *tempBadgerDB) Close() error {
|
||||
err := tbdb.BadgerDBStore.Close()
|
||||
// Make test fail if failed to cleanup, even though technically it's
|
||||
// not a BadgerDBStore problem.
|
||||
osErr := os.RemoveAll(tbdb.dir)
|
||||
if osErr != nil {
|
||||
return osErr
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func newBadgerDBForTesting(t *testing.T) Store {
|
||||
bdbDir, err := ioutil.TempDir(os.TempDir(), "testbadgerdb")
|
||||
require.Nil(t, err, "failed to setup temporary directory")
|
||||
|
||||
bdbDir := t.TempDir()
|
||||
dbConfig := DBConfiguration{
|
||||
Type: "badgerdb",
|
||||
BadgerDBOptions: BadgerDBOptions{
|
||||
|
@ -36,9 +16,5 @@ func newBadgerDBForTesting(t *testing.T) Store {
|
|||
}
|
||||
newBadgerStore, err := NewBadgerDBStore(dbConfig.BadgerDBOptions)
|
||||
require.Nil(t, err, "NewBadgerDBStore error")
|
||||
tbdb := &tempBadgerDB{
|
||||
BadgerDBStore: newBadgerStore,
|
||||
dir: bdbDir,
|
||||
}
|
||||
return tbdb
|
||||
return newBadgerStore
|
||||
}
|
||||
|
|
|
@ -1,23 +1,16 @@
|
|||
package storage
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func newBoltStoreForTesting(t *testing.T) Store {
|
||||
testFileName := "test_bolt_db"
|
||||
file, err := ioutil.TempFile("", testFileName)
|
||||
t.Cleanup(func() {
|
||||
err := os.RemoveAll(file.Name())
|
||||
require.NoError(t, err)
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, file.Close())
|
||||
boltDBStore, err := NewBoltDBStore(BoltDBOptions{FilePath: file.Name()})
|
||||
d := t.TempDir()
|
||||
testFileName := path.Join(d, "test_bolt_db")
|
||||
boltDBStore, err := NewBoltDBStore(BoltDBOptions{FilePath: testFileName})
|
||||
require.NoError(t, err)
|
||||
return boltDBStore
|
||||
}
|
||||
|
|
|
@ -1,33 +1,13 @@
|
|||
package storage
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
type tempLevelDB struct {
|
||||
LevelDBStore
|
||||
dir string
|
||||
}
|
||||
|
||||
func (tldb *tempLevelDB) Close() error {
|
||||
err := tldb.LevelDBStore.Close()
|
||||
// Make test fail if failed to cleanup, even though technically it's
|
||||
// not a LevelDBStore problem.
|
||||
osErr := os.RemoveAll(tldb.dir)
|
||||
if osErr != nil {
|
||||
return osErr
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func newLevelDBForTesting(t *testing.T) Store {
|
||||
ldbDir, err := ioutil.TempDir(os.TempDir(), "testleveldb")
|
||||
require.Nil(t, err, "failed to setup temporary directory")
|
||||
|
||||
ldbDir := t.TempDir()
|
||||
dbConfig := DBConfiguration{
|
||||
Type: "leveldb",
|
||||
LevelDBOptions: LevelDBOptions{
|
||||
|
@ -36,6 +16,5 @@ func newLevelDBForTesting(t *testing.T) Store {
|
|||
}
|
||||
newLevelStore, err := NewLevelDBStore(dbConfig.LevelDBOptions)
|
||||
require.Nil(t, err, "NewLevelDBStore error")
|
||||
tldb := &tempLevelDB{LevelDBStore: *newLevelStore, dir: ldbDir}
|
||||
return tldb
|
||||
return newLevelStore
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package io
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
|
@ -10,34 +9,22 @@ import (
|
|||
)
|
||||
|
||||
func TestMakeDirForFile_HappyPath(t *testing.T) {
|
||||
tempDir, err := ioutil.TempDir("", "test")
|
||||
require.NoError(t, err)
|
||||
|
||||
filePath := tempDir + "/testDir/testFile.test"
|
||||
err = MakeDirForFile(filePath, "test")
|
||||
t.Cleanup(func() {
|
||||
removeDir(t, tempDir)
|
||||
})
|
||||
tempDir := t.TempDir()
|
||||
filePath := path.Join(tempDir, "testDir/testFile.test")
|
||||
err := MakeDirForFile(filePath, "test")
|
||||
require.NoError(t, err)
|
||||
|
||||
_, errChDir := os.Create(filePath)
|
||||
require.NoError(t, errChDir)
|
||||
}
|
||||
|
||||
func removeDir(t *testing.T, dirName string) {
|
||||
err := os.RemoveAll(dirName)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestMakeDirForFile_Negative(t *testing.T) {
|
||||
file, err := ioutil.TempFile("", "test")
|
||||
tempDir := t.TempDir()
|
||||
filePath := path.Join(tempDir, "testFile.test")
|
||||
_, err := os.Create(filePath)
|
||||
require.NoError(t, err)
|
||||
|
||||
filePath := file.Name() + "/error"
|
||||
dir := path.Dir(filePath)
|
||||
filePath = path.Join(filePath, "error")
|
||||
err = MakeDirForFile(filePath, "test")
|
||||
t.Cleanup(func() {
|
||||
removeDir(t, dir)
|
||||
})
|
||||
require.Errorf(t, err, "could not create dir for test: mkdir %s : not a directory", filePath)
|
||||
}
|
||||
|
|
|
@ -162,11 +162,7 @@ func TestLoad(t *testing.T) {
|
|||
return a * b
|
||||
}
|
||||
}`
|
||||
tmpDir, err := ioutil.TempDir("", "neogo.vmcliloadtest")
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
os.RemoveAll(tmpDir)
|
||||
})
|
||||
tmpDir := t.TempDir()
|
||||
|
||||
t.Run("loadgo", func(t *testing.T) {
|
||||
filename := path.Join(tmpDir, "vmtestcontract.go")
|
||||
|
@ -262,11 +258,7 @@ func TestRunWithDifferentArguments(t *testing.T) {
|
|||
return arg
|
||||
}`
|
||||
|
||||
tmpDir, err := ioutil.TempDir("", "neogo.vmcliruntest")
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
os.RemoveAll(tmpDir)
|
||||
})
|
||||
tmpDir := t.TempDir()
|
||||
filename := path.Join(tmpDir, "run_vmtestcontract.go")
|
||||
require.NoError(t, ioutil.WriteFile(filename, []byte(src), os.ModePerm))
|
||||
|
||||
|
|
|
@ -2,8 +2,6 @@ package wallet
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
|
@ -75,10 +73,8 @@ func TestPath(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestSave(t *testing.T) {
|
||||
file, err := ioutil.TempFile("", walletTemplate)
|
||||
require.NoError(t, err)
|
||||
wallet, err := NewWallet(file.Name())
|
||||
require.NoError(t, err)
|
||||
wallet := checkWalletConstructor(t)
|
||||
|
||||
wallet.AddAccount(&Account{
|
||||
privateKey: nil,
|
||||
publicKey: nil,
|
||||
|
@ -91,9 +87,6 @@ func TestSave(t *testing.T) {
|
|||
Default: false,
|
||||
})
|
||||
|
||||
t.Cleanup(func() {
|
||||
removeWallet(t, file.Name())
|
||||
})
|
||||
errForSave := wallet.Save()
|
||||
require.NoError(t, errForSave)
|
||||
|
||||
|
@ -130,21 +123,13 @@ func TestJSONMarshallUnmarshal(t *testing.T) {
|
|||
}
|
||||
|
||||
func checkWalletConstructor(t *testing.T) *Wallet {
|
||||
file, err := ioutil.TempFile("", walletTemplate)
|
||||
require.NoError(t, err)
|
||||
wallet, err := NewWallet(file.Name())
|
||||
t.Cleanup(func() {
|
||||
removeWallet(t, file.Name())
|
||||
})
|
||||
tmpDir := t.TempDir()
|
||||
file := path.Join(tmpDir, walletTemplate)
|
||||
wallet, err := NewWallet(file)
|
||||
require.NoError(t, err)
|
||||
return wallet
|
||||
}
|
||||
|
||||
func removeWallet(t *testing.T, walletPath string) {
|
||||
err := os.RemoveAll(walletPath)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestWallet_AddToken(t *testing.T) {
|
||||
w := checkWalletConstructor(t)
|
||||
tok := NewToken(util.Uint160{1, 2, 3}, "Rubl", "RUB", 2, manifest.NEP17StandardName)
|
||||
|
|
Loading…
Reference in a new issue