mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-25 13:47:19 +00:00
*: do not call wallet.Close() explicitly
NewWallet and NewWalletFromFile close underlying io.Closer by itself, no need to close it manually. Introduced in #2184.
This commit is contained in:
parent
b2f188f8f0
commit
5f36a7ca0f
13 changed files with 4 additions and 41 deletions
|
@ -447,9 +447,8 @@ func TestContractManifestGroups(t *testing.T) {
|
|||
config.Version = "0.90.0-test"
|
||||
tmpDir := t.TempDir()
|
||||
|
||||
w, err := wallet.NewWalletFromFile(testWalletPath)
|
||||
_, err := wallet.NewWalletFromFile(testWalletPath)
|
||||
require.NoError(t, err)
|
||||
defer w.Close()
|
||||
|
||||
nefName := filepath.Join(tmpDir, "deploy.nef")
|
||||
manifestName := filepath.Join(tmpDir, "deploy.manifest.json")
|
||||
|
|
|
@ -113,7 +113,6 @@ func TestNEP17Balance(t *testing.T) {
|
|||
func TestNEP17Transfer(t *testing.T) {
|
||||
w, err := wallet.NewWalletFromFile("testdata/testwallet.json")
|
||||
require.NoError(t, err)
|
||||
defer w.Close()
|
||||
|
||||
e := newExecutor(t, true)
|
||||
args := []string{
|
||||
|
|
|
@ -25,7 +25,6 @@ func TestQueryTx(t *testing.T) {
|
|||
|
||||
w, err := wallet.NewWalletFromFile("testdata/testwallet.json")
|
||||
require.NoError(t, err)
|
||||
defer w.Close()
|
||||
|
||||
transferArgs := []string{
|
||||
"neo-go", "wallet", "nep17", "transfer",
|
||||
|
|
|
@ -16,7 +16,6 @@ func signStoredTransaction(ctx *cli.Context) error {
|
|||
if err != nil {
|
||||
return cli.NewExitError(err, 1)
|
||||
}
|
||||
defer wall.Close()
|
||||
|
||||
c, err := paramcontext.Read(ctx.String("in"))
|
||||
if err != nil {
|
||||
|
|
|
@ -167,7 +167,6 @@ func getNEP11Balance(ctx *cli.Context) error {
|
|||
if err != nil {
|
||||
return cli.NewExitError(fmt.Errorf("bad wallet: %w", err), 1)
|
||||
}
|
||||
defer wall.Close()
|
||||
|
||||
addrFlag := ctx.Generic("address").(*flags.Address)
|
||||
if addrFlag.IsSet {
|
||||
|
|
|
@ -155,7 +155,6 @@ func getNEP17Balance(ctx *cli.Context) error {
|
|||
if err != nil {
|
||||
return cli.NewExitError(fmt.Errorf("bad wallet: %w", err), 1)
|
||||
}
|
||||
defer wall.Close()
|
||||
|
||||
addrFlag := ctx.Generic("address").(*flags.Address)
|
||||
if addrFlag.IsSet {
|
||||
|
@ -354,7 +353,6 @@ func importNEPToken(ctx *cli.Context, standard string) error {
|
|||
if err != nil {
|
||||
return cli.NewExitError(err, 1)
|
||||
}
|
||||
defer wall.Close()
|
||||
|
||||
tokenHashFlag := ctx.Generic("token").(*flags.Address)
|
||||
if !tokenHashFlag.IsSet {
|
||||
|
@ -417,7 +415,6 @@ func printNEPInfo(ctx *cli.Context, standard string) error {
|
|||
if err != nil {
|
||||
return cli.NewExitError(err, 1)
|
||||
}
|
||||
defer wall.Close()
|
||||
|
||||
if name := ctx.String("token"); name != "" {
|
||||
token, err := getMatchingToken(ctx, wall, name, standard)
|
||||
|
@ -450,7 +447,6 @@ func removeNEPToken(ctx *cli.Context, standard string) error {
|
|||
if err != nil {
|
||||
return cli.NewExitError(err, 1)
|
||||
}
|
||||
defer wall.Close()
|
||||
|
||||
token, err := getMatchingToken(ctx, wall, ctx.String("token"), standard)
|
||||
if err != nil {
|
||||
|
@ -474,7 +470,6 @@ func multiTransferNEP17(ctx *cli.Context) error {
|
|||
if err != nil {
|
||||
return cli.NewExitError(err, 1)
|
||||
}
|
||||
defer wall.Close()
|
||||
|
||||
fromFlag := ctx.Generic("from").(*flags.Address)
|
||||
from, err := getDefaultAddress(fromFlag, wall)
|
||||
|
@ -560,7 +555,6 @@ func transferNEP(ctx *cli.Context, standard string) error {
|
|||
if err != nil {
|
||||
return cli.NewExitError(err, 1)
|
||||
}
|
||||
defer wall.Close()
|
||||
|
||||
fromFlag := ctx.Generic("from").(*flags.Address)
|
||||
from, err := getDefaultAddress(fromFlag, wall)
|
||||
|
|
|
@ -90,7 +90,6 @@ func handleCandidate(ctx *cli.Context, method string, sysGas int64) error {
|
|||
if err != nil {
|
||||
return cli.NewExitError(err, 1)
|
||||
}
|
||||
defer wall.Close()
|
||||
|
||||
addrFlag := ctx.Generic("address").(*flags.Address)
|
||||
if !addrFlag.IsSet {
|
||||
|
@ -145,7 +144,6 @@ func handleVote(ctx *cli.Context) error {
|
|||
if err != nil {
|
||||
return cli.NewExitError(err, 1)
|
||||
}
|
||||
defer wall.Close()
|
||||
|
||||
addrFlag := ctx.Generic("address").(*flags.Address)
|
||||
if !addrFlag.IsSet {
|
||||
|
|
|
@ -299,7 +299,6 @@ func claimGas(ctx *cli.Context) error {
|
|||
if err != nil {
|
||||
return cli.NewExitError(err, 1)
|
||||
}
|
||||
defer wall.Close()
|
||||
|
||||
addrFlag := ctx.Generic("address").(*flags.Address)
|
||||
if !addrFlag.IsSet {
|
||||
|
@ -398,7 +397,6 @@ func convertWallet(ctx *cli.Context) error {
|
|||
if err != nil {
|
||||
return cli.NewExitError(err, 1)
|
||||
}
|
||||
defer newWallet.Close()
|
||||
newWallet.Scrypt = wall.Scrypt
|
||||
|
||||
for _, acc := range wall.Accounts {
|
||||
|
@ -428,8 +426,6 @@ func addAccount(ctx *cli.Context) error {
|
|||
return cli.NewExitError(err, 1)
|
||||
}
|
||||
|
||||
defer wall.Close()
|
||||
|
||||
if err := createAccount(wall, pass); err != nil {
|
||||
return cli.NewExitError(err, 1)
|
||||
}
|
||||
|
@ -504,8 +500,6 @@ func importMultisig(ctx *cli.Context) error {
|
|||
return cli.NewExitError(err, 1)
|
||||
}
|
||||
|
||||
defer wall.Close()
|
||||
|
||||
m := ctx.Int("min")
|
||||
if ctx.NArg() < m {
|
||||
return cli.NewExitError(errors.New("insufficient number of public keys"), 1)
|
||||
|
@ -546,8 +540,6 @@ func importDeployed(ctx *cli.Context) error {
|
|||
return cli.NewExitError(err, 1)
|
||||
}
|
||||
|
||||
defer wall.Close()
|
||||
|
||||
rawHash := ctx.Generic("contract").(*flags.Address)
|
||||
if !rawHash.IsSet {
|
||||
return cli.NewExitError("contract hash was not provided", 1)
|
||||
|
@ -600,7 +592,6 @@ func importWallet(ctx *cli.Context) error {
|
|||
if err != nil {
|
||||
return cli.NewExitError(err, 1)
|
||||
}
|
||||
defer wall.Close()
|
||||
|
||||
acc, err := newAccountFromWIF(ctx.App.Writer, ctx.String("wif"), wall.Scrypt)
|
||||
if err != nil {
|
||||
|
@ -630,7 +621,6 @@ func removeAccount(ctx *cli.Context) error {
|
|||
if err != nil {
|
||||
return cli.NewExitError(err, 1)
|
||||
}
|
||||
defer wall.Close()
|
||||
|
||||
addr := ctx.Generic("address").(*flags.Address)
|
||||
if !addr.IsSet {
|
||||
|
|
|
@ -221,7 +221,6 @@ func TestWalletInit(t *testing.T) {
|
|||
require.Len(t, w.Accounts, 1)
|
||||
require.Equal(t, "букandmore", w.Accounts[0].Label)
|
||||
require.NoError(t, w.Accounts[0].Decrypt("пароль", w.Scrypt))
|
||||
w.Close()
|
||||
})
|
||||
|
||||
t.Run("CreateAccount", func(t *testing.T) {
|
||||
|
@ -244,7 +243,6 @@ func TestWalletInit(t *testing.T) {
|
|||
require.Len(t, w.Accounts, 1)
|
||||
require.Equal(t, w.Accounts[0].Label, "testname")
|
||||
require.NoError(t, w.Accounts[0].Decrypt("testpass", w.Scrypt))
|
||||
w.Close()
|
||||
|
||||
t.Run("RemoveAccount", func(t *testing.T) {
|
||||
sh := w.Accounts[0].Contract.ScriptHash()
|
||||
|
@ -255,7 +253,6 @@ func TestWalletInit(t *testing.T) {
|
|||
w, err := wallet.NewWalletFromFile(walletPath)
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, w.GetAccount(sh))
|
||||
w.Close()
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -274,7 +271,6 @@ func TestWalletInit(t *testing.T) {
|
|||
|
||||
w, err := wallet.NewWalletFromFile(walletPath)
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(w.Close)
|
||||
acc := w.GetAccount(priv.GetScriptHash())
|
||||
require.NotNil(t, acc)
|
||||
require.Equal(t, "test_account", acc.Label)
|
||||
|
@ -302,7 +298,6 @@ func TestWalletInit(t *testing.T) {
|
|||
check := func(t *testing.T, expectedLabel string, pass string) {
|
||||
w, err := wallet.NewWalletFromFile(walletPath)
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(w.Close)
|
||||
acc := w.GetAccount(priv.GetScriptHash())
|
||||
require.NotNil(t, acc)
|
||||
require.Equal(t, expectedLabel, acc.Label)
|
||||
|
@ -355,7 +350,6 @@ func TestWalletInit(t *testing.T) {
|
|||
|
||||
w, err := wallet.NewWalletFromFile(walletPath)
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(w.Close)
|
||||
actual := w.GetAccount(acc.PrivateKey().GetScriptHash())
|
||||
require.NotNil(t, actual)
|
||||
require.NoError(t, actual.Decrypt("somepass", w.Scrypt))
|
||||
|
@ -410,7 +404,6 @@ func TestWalletInit(t *testing.T) {
|
|||
|
||||
w, err := wallet.NewWalletFromFile(walletPath)
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(w.Close)
|
||||
actual := w.GetAccount(hash.Hash160(script))
|
||||
require.NotNil(t, actual)
|
||||
require.NoError(t, actual.Decrypt("multipass", w.Scrypt))
|
||||
|
@ -595,9 +588,6 @@ func TestWalletImportDeployed(t *testing.T) {
|
|||
"--contract", h.StringLE())
|
||||
|
||||
w, err := wallet.NewWalletFromFile(walletPath)
|
||||
t.Cleanup(func() {
|
||||
w.Close()
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 1, len(w.Accounts))
|
||||
contractAddr := w.Accounts[0].Address
|
||||
|
|
|
@ -168,8 +168,6 @@ func NewService(cfg Config) (Service, error) {
|
|||
return nil, errors.New("no account with provided password was found")
|
||||
}
|
||||
|
||||
defer srv.wallet.Close()
|
||||
|
||||
srv.dbft = dbft.New(
|
||||
dbft.WithLogger(srv.log),
|
||||
dbft.WithSecondsPerBlock(cfg.TimePerBlock),
|
||||
|
|
|
@ -197,7 +197,6 @@ func createAndWriteWallet(t *testing.T, acc *wallet.Account, path, password stri
|
|||
require.NoError(t, acc.Encrypt(password, w.Scrypt))
|
||||
w.AddAccount(acc)
|
||||
require.NoError(t, w.Save())
|
||||
w.Close()
|
||||
return w
|
||||
}
|
||||
|
||||
|
|
|
@ -202,7 +202,6 @@ func createWallet(t *testing.T, path string, accs ...*Account) {
|
|||
w.AddAccount(acc)
|
||||
}
|
||||
require.NoError(t, w.SavePretty())
|
||||
w.Close()
|
||||
}
|
||||
|
||||
func TestRegenerateCLIWallet1_solo(t *testing.T) {
|
||||
|
|
|
@ -168,9 +168,9 @@ func (w *Wallet) JSON() ([]byte, error) {
|
|||
return json.MarshalIndent(w, " ", " ")
|
||||
}
|
||||
|
||||
// Close closes the internal rw if its an io.ReadCloser.
|
||||
func (w *Wallet) Close() {
|
||||
}
|
||||
// Deprecated: Close is deprecated.
|
||||
// Close performs nothing and is left for backwards compatibility.
|
||||
func (w *Wallet) Close() {}
|
||||
|
||||
// GetAccount returns an account corresponding to the provided scripthash.
|
||||
func (w *Wallet) GetAccount(h util.Uint160) *Account {
|
||||
|
|
Loading…
Reference in a new issue