diff --git a/cmd/XDC/accountcmd.go b/cmd/XDC/accountcmd.go
new file mode 100644
index 0000000000..38bb3dce2e
--- /dev/null
+++ b/cmd/XDC/accountcmd.go
@@ -0,0 +1,379 @@
+// Copyright 2016 The go-ethereum Authors
+// This file is part of go-ethereum.
+//
+// go-ethereum is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// go-ethereum is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with go-ethereum. If not, see .
+
+package main
+
+import (
+ "fmt"
+ "io/ioutil"
+
+ "github.com/ethereum/go-ethereum/accounts"
+ "github.com/ethereum/go-ethereum/accounts/keystore"
+ "github.com/ethereum/go-ethereum/cmd/utils"
+ "github.com/ethereum/go-ethereum/console"
+ "github.com/ethereum/go-ethereum/crypto"
+ "github.com/ethereum/go-ethereum/log"
+ "gopkg.in/urfave/cli.v1"
+)
+
+var (
+ walletCommand = cli.Command{
+ Name: "wallet",
+ Usage: "Manage Ethereum presale wallets",
+ ArgsUsage: "",
+ Category: "ACCOUNT COMMANDS",
+ Description: `
+ XDC wallet import /path/to/my/presale.wallet
+
+will prompt for your password and imports your ether presale account.
+It can be used non-interactively with the --password option taking a
+passwordfile as argument containing the wallet password in plaintext.`,
+ Subcommands: []cli.Command{
+ {
+
+ Name: "import",
+ Usage: "Import Ethereum presale wallet",
+ ArgsUsage: "",
+ Action: utils.MigrateFlags(importWallet),
+ Category: "ACCOUNT COMMANDS",
+ Flags: []cli.Flag{
+ utils.DataDirFlag,
+ utils.KeyStoreDirFlag,
+ utils.PasswordFileFlag,
+ utils.LightKDFFlag,
+ },
+ Description: `
+ XDC wallet [options] /path/to/my/presale.wallet
+
+will prompt for your password and imports your ether presale account.
+It can be used non-interactively with the --password option taking a
+passwordfile as argument containing the wallet password in plaintext.`,
+ },
+ },
+ }
+
+ accountCommand = cli.Command{
+ Name: "account",
+ Usage: "Manage accounts",
+ Category: "ACCOUNT COMMANDS",
+ Description: `
+
+Manage accounts, list all existing accounts, import a private key into a new
+account, create a new account or update an existing account.
+
+It supports interactive mode, when you are prompted for password as well as
+non-interactive mode where passwords are supplied via a given password file.
+Non-interactive mode is only meant for scripted use on test networks or known
+safe environments.
+
+Make sure you remember the password you gave when creating a new account (with
+either new or import). Without it you are not able to unlock your account.
+
+Note that exporting your key in unencrypted format is NOT supported.
+
+Keys are stored under /keystore.
+It is safe to transfer the entire directory or the individual keys therein
+between ethereum nodes by simply copying.
+
+Make sure you backup your keys regularly.`,
+ Subcommands: []cli.Command{
+ {
+ Name: "list",
+ Usage: "Print summary of existing accounts",
+ Action: utils.MigrateFlags(accountList),
+ Flags: []cli.Flag{
+ utils.DataDirFlag,
+ utils.KeyStoreDirFlag,
+ },
+ Description: `
+Print a short summary of all accounts`,
+ },
+ {
+ Name: "new",
+ Usage: "Create a new account",
+ Action: utils.MigrateFlags(accountCreate),
+ Flags: []cli.Flag{
+ utils.DataDirFlag,
+ utils.KeyStoreDirFlag,
+ utils.PasswordFileFlag,
+ utils.LightKDFFlag,
+ },
+ Description: `
+ XDC account new
+
+Creates a new account and prints the address.
+
+The account is saved in encrypted format, you are prompted for a passphrase.
+
+You must remember this passphrase to unlock your account in the future.
+
+For non-interactive use the passphrase can be specified with the --password flag:
+
+Note, this is meant to be used for testing only, it is a bad idea to save your
+password to file or expose in any other way.
+`,
+ },
+ {
+ Name: "update",
+ Usage: "Update an existing account",
+ Action: utils.MigrateFlags(accountUpdate),
+ ArgsUsage: "",
+ Flags: []cli.Flag{
+ utils.DataDirFlag,
+ utils.KeyStoreDirFlag,
+ utils.LightKDFFlag,
+ },
+ Description: `
+ XDC account update
+
+Update an existing account.
+
+The account is saved in the newest version in encrypted format, you are prompted
+for a passphrase to unlock the account and another to save the updated file.
+
+This same command can therefore be used to migrate an account of a deprecated
+format to the newest format or change the password for an account.
+
+For non-interactive use the passphrase can be specified with the --password flag:
+
+ XDC account update [options]
+
+Since only one password can be given, only format update can be performed,
+changing your password is only possible interactively.
+`,
+ },
+ {
+ Name: "import",
+ Usage: "Import a private key into a new account",
+ Action: utils.MigrateFlags(accountImport),
+ Flags: []cli.Flag{
+ utils.DataDirFlag,
+ utils.KeyStoreDirFlag,
+ utils.PasswordFileFlag,
+ utils.LightKDFFlag,
+ },
+ ArgsUsage: "",
+ Description: `
+ XDC account import
+
+Imports an unencrypted private key from and creates a new account.
+Prints the address.
+
+The keyfile is assumed to contain an unencrypted private key in hexadecimal format.
+
+The account is saved in encrypted format, you are prompted for a passphrase.
+
+You must remember this passphrase to unlock your account in the future.
+
+For non-interactive use the passphrase can be specified with the -password flag:
+
+ XDC account import [options]
+
+Note:
+As you can directly copy your encrypted accounts to another ethereum instance,
+this import mechanism is not needed when you transfer an account between
+nodes.
+`,
+ },
+ },
+ }
+)
+
+func accountList(ctx *cli.Context) error {
+ stack, _ := makeConfigNode(ctx)
+ var index int
+ for _, wallet := range stack.AccountManager().Wallets() {
+ for _, account := range wallet.Accounts() {
+ fmt.Printf("Account #%d: {%x} %s\n", index, account.Address, &account.URL)
+ index++
+ }
+ }
+ return nil
+}
+
+// tries unlocking the specified account a few times.
+func unlockAccount(ctx *cli.Context, ks *keystore.KeyStore, address string, i int, passwords []string) (accounts.Account, string) {
+ account, err := utils.MakeAddress(ks, address)
+ if err != nil {
+ utils.Fatalf("Could not list accounts: %v", err)
+ }
+ for trials := 0; trials < 3; trials++ {
+ prompt := fmt.Sprintf("Unlocking account %s | Attempt %d/%d", address, trials+1, 3)
+ password := getPassPhrase(prompt, false, i, passwords)
+ err = ks.Unlock(account, password)
+ if err == nil {
+ log.Info("Unlocked account", "address", account.Address.Hex())
+ return account, password
+ }
+ if err, ok := err.(*keystore.AmbiguousAddrError); ok {
+ log.Info("Unlocked account", "address", account.Address.Hex())
+ return ambiguousAddrRecovery(ks, err, password), password
+ }
+ if err != keystore.ErrDecrypt {
+ // No need to prompt again if the error is not decryption-related.
+ break
+ }
+ }
+ // All trials expended to unlock account, bail out
+ utils.Fatalf("Failed to unlock account %s (%v)", address, err)
+
+ return accounts.Account{}, ""
+}
+
+// getPassPhrase retrieves the password associated with an account, either fetched
+// from a list of preloaded passphrases, or requested interactively from the user.
+func getPassPhrase(prompt string, confirmation bool, i int, passwords []string) string {
+ // If a list of passwords was supplied, retrieve from them
+ if len(passwords) > 0 {
+ if i < len(passwords) {
+ return passwords[i]
+ }
+ return passwords[len(passwords)-1]
+ }
+ // Otherwise prompt the user for the password
+ if prompt != "" {
+ fmt.Println(prompt)
+ }
+ password, err := console.Stdin.PromptPassword("Passphrase: ")
+ if err != nil {
+ utils.Fatalf("Failed to read passphrase: %v", err)
+ }
+ if confirmation {
+ confirm, err := console.Stdin.PromptPassword("Repeat passphrase: ")
+ if err != nil {
+ utils.Fatalf("Failed to read passphrase confirmation: %v", err)
+ }
+ if password != confirm {
+ utils.Fatalf("Passphrases do not match")
+ }
+ }
+ return password
+}
+
+func ambiguousAddrRecovery(ks *keystore.KeyStore, err *keystore.AmbiguousAddrError, auth string) accounts.Account {
+ fmt.Printf("Multiple key files exist for address %x:\n", err.Addr)
+ for _, a := range err.Matches {
+ fmt.Println(" ", a.URL)
+ }
+ fmt.Println("Testing your passphrase against all of them...")
+ var match *accounts.Account
+ for _, a := range err.Matches {
+ if err := ks.Unlock(a, auth); err == nil {
+ match = &a
+ break
+ }
+ }
+ if match == nil {
+ utils.Fatalf("None of the listed files could be unlocked.")
+ }
+ fmt.Printf("Your passphrase unlocked %s\n", match.URL)
+ fmt.Println("In order to avoid this warning, you need to remove the following duplicate key files:")
+ for _, a := range err.Matches {
+ if a != *match {
+ fmt.Println(" ", a.URL)
+ }
+ }
+ return *match
+}
+
+// accountCreate creates a new account into the keystore defined by the CLI flags.
+func accountCreate(ctx *cli.Context) error {
+ cfg := XDCConfig{Node: defaultNodeConfig()}
+ // Load config file.
+ if file := ctx.GlobalString(configFileFlag.Name); file != "" {
+ if err := loadConfig(file, &cfg); err != nil {
+ utils.Fatalf("%v", err)
+ }
+ }
+ utils.SetNodeConfig(ctx, &cfg.Node)
+ scryptN, scryptP, keydir, err := cfg.Node.AccountConfig()
+
+ if err != nil {
+ utils.Fatalf("Failed to read configuration: %v", err)
+ }
+
+ password := getPassPhrase("Your new account is locked with a password. Please give a password. Do not forget this password.", true, 0, utils.MakePasswordList(ctx))
+
+ address, err := keystore.StoreKey(keydir, password, scryptN, scryptP)
+
+ if err != nil {
+ utils.Fatalf("Failed to create account: %v", err)
+ }
+ fmt.Printf("Address: {%x}\n", address)
+ return nil
+}
+
+// accountUpdate transitions an account from a previous format to the current
+// one, also providing the possibility to change the pass-phrase.
+func accountUpdate(ctx *cli.Context) error {
+ if len(ctx.Args()) == 0 {
+ utils.Fatalf("No accounts specified to update")
+ }
+ stack, _ := makeConfigNode(ctx)
+ ks := stack.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore)
+
+ for _, addr := range ctx.Args() {
+ account, oldPassword := unlockAccount(ctx, ks, addr, 0, nil)
+ newPassword := getPassPhrase("Please give a new password. Do not forget this password.", true, 0, nil)
+ if err := ks.Update(account, oldPassword, newPassword); err != nil {
+ utils.Fatalf("Could not update the account: %v", err)
+ }
+ }
+ return nil
+}
+
+func importWallet(ctx *cli.Context) error {
+ keyfile := ctx.Args().First()
+ if len(keyfile) == 0 {
+ utils.Fatalf("keyfile must be given as argument")
+ }
+ keyJson, err := ioutil.ReadFile(keyfile)
+ if err != nil {
+ utils.Fatalf("Could not read wallet file: %v", err)
+ }
+
+ stack, _ := makeConfigNode(ctx)
+ passphrase := getPassPhrase("", false, 0, utils.MakePasswordList(ctx))
+
+ ks := stack.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore)
+ acct, err := ks.ImportPreSaleKey(keyJson, passphrase)
+ if err != nil {
+ utils.Fatalf("%v", err)
+ }
+ fmt.Printf("Address: {%x}\n", acct.Address)
+ return nil
+}
+
+func accountImport(ctx *cli.Context) error {
+ keyfile := ctx.Args().First()
+ if len(keyfile) == 0 {
+ utils.Fatalf("keyfile must be given as argument")
+ }
+ key, err := crypto.LoadECDSA(keyfile)
+ if err != nil {
+ utils.Fatalf("Failed to load the private key: %v", err)
+ }
+ stack, _ := makeConfigNode(ctx)
+ passphrase := getPassPhrase("Your new account is locked with a password. Please give a password. Do not forget this password.", true, 0, utils.MakePasswordList(ctx))
+
+ ks := stack.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore)
+ acct, err := ks.ImportECDSA(key, passphrase)
+ if err != nil {
+ utils.Fatalf("Could not create the account: %v", err)
+ }
+ fmt.Printf("Address: {%x}\n", acct.Address)
+ return nil
+}
diff --git a/cmd/XDC/accountcmd_test.go b/cmd/XDC/accountcmd_test.go
new file mode 100644
index 0000000000..3ea22ccfab
--- /dev/null
+++ b/cmd/XDC/accountcmd_test.go
@@ -0,0 +1,296 @@
+// Copyright 2016 The go-ethereum Authors
+// This file is part of go-ethereum.
+//
+// go-ethereum is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// go-ethereum is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with go-ethereum. If not, see .
+
+package main
+
+import (
+ "io/ioutil"
+ "path/filepath"
+ "runtime"
+ "strings"
+ "testing"
+
+ "github.com/cespare/cp"
+)
+
+// These tests are 'smoke tests' for the account related
+// subcommands and flags.
+//
+// For most tests, the test files from package accounts
+// are copied into a temporary keystore directory.
+
+func tmpDatadirWithKeystore(t *testing.T) string {
+ datadir := tmpdir(t)
+ keystore := filepath.Join(datadir, "keystore")
+ source := filepath.Join("..", "..", "accounts", "keystore", "testdata", "keystore")
+ if err := cp.CopyAll(keystore, source); err != nil {
+ t.Fatal(err)
+ }
+ return datadir
+}
+
+func TestAccountListEmpty(t *testing.T) {
+ geth := runGeth(t, "account", "list")
+ geth.ExpectExit()
+}
+
+func TestAccountList(t *testing.T) {
+ datadir := tmpDatadirWithKeystore(t)
+ geth := runGeth(t, "account", "list", "--datadir", datadir)
+ defer geth.ExpectExit()
+ if runtime.GOOS == "windows" {
+ geth.Expect(`
+Account #0: {7ef5a6135f1fd6a02593eedc869c6d41d934aef8} keystore://{{.Datadir}}\keystore\UTC--2016-03-22T12-57-55.920751759Z--7ef5a6135f1fd6a02593eedc869c6d41d934aef8
+Account #1: {f466859ead1932d743d622cb74fc058882e8648a} keystore://{{.Datadir}}\keystore\aaa
+Account #2: {289d485d9771714cce91d3393d764e1311907acc} keystore://{{.Datadir}}\keystore\zzz
+`)
+ } else {
+ geth.Expect(`
+Account #0: {7ef5a6135f1fd6a02593eedc869c6d41d934aef8} keystore://{{.Datadir}}/keystore/UTC--2016-03-22T12-57-55.920751759Z--7ef5a6135f1fd6a02593eedc869c6d41d934aef8
+Account #1: {f466859ead1932d743d622cb74fc058882e8648a} keystore://{{.Datadir}}/keystore/aaa
+Account #2: {289d485d9771714cce91d3393d764e1311907acc} keystore://{{.Datadir}}/keystore/zzz
+`)
+ }
+}
+
+func TestAccountNew(t *testing.T) {
+ geth := runGeth(t, "account", "new", "--lightkdf")
+ defer geth.ExpectExit()
+ geth.Expect(`
+Your new account is locked with a password. Please give a password. Do not forget this password.
+!! Unsupported terminal, password will be echoed.
+Passphrase: {{.InputLine "foobar"}}
+Repeat passphrase: {{.InputLine "foobar"}}
+`)
+ geth.ExpectRegexp(`Address: \{[0-9a-f]{40}\}\n`)
+}
+
+func TestAccountNewBadRepeat(t *testing.T) {
+ geth := runGeth(t, "account", "new", "--lightkdf")
+ defer geth.ExpectExit()
+ geth.Expect(`
+Your new account is locked with a password. Please give a password. Do not forget this password.
+!! Unsupported terminal, password will be echoed.
+Passphrase: {{.InputLine "something"}}
+Repeat passphrase: {{.InputLine "something else"}}
+Fatal: Passphrases do not match
+`)
+}
+
+func TestAccountUpdate(t *testing.T) {
+ datadir := tmpDatadirWithKeystore(t)
+ geth := runGeth(t, "account", "update",
+ "--datadir", datadir, "--lightkdf",
+ "f466859ead1932d743d622cb74fc058882e8648a")
+ defer geth.ExpectExit()
+ geth.Expect(`
+Unlocking account f466859ead1932d743d622cb74fc058882e8648a | Attempt 1/3
+!! Unsupported terminal, password will be echoed.
+Passphrase: {{.InputLine "foobar"}}
+Please give a new password. Do not forget this password.
+Passphrase: {{.InputLine "foobar2"}}
+Repeat passphrase: {{.InputLine "foobar2"}}
+`)
+}
+
+func TestWalletImport(t *testing.T) {
+ geth := runGeth(t, "wallet", "import", "--lightkdf", "testdata/guswallet.json")
+ defer geth.ExpectExit()
+ geth.Expect(`
+!! Unsupported terminal, password will be echoed.
+Passphrase: {{.InputLine "foo"}}
+Address: {d4584b5f6229b7be90727b0fc8c6b91bb427821f}
+`)
+
+ files, err := ioutil.ReadDir(filepath.Join(geth.Datadir, "keystore"))
+ if len(files) != 1 {
+ t.Errorf("expected one key file in keystore directory, found %d files (error: %v)", len(files), err)
+ }
+}
+
+func TestWalletImportBadPassword(t *testing.T) {
+ geth := runGeth(t, "wallet", "import", "--lightkdf", "testdata/guswallet.json")
+ defer geth.ExpectExit()
+ geth.Expect(`
+!! Unsupported terminal, password will be echoed.
+Passphrase: {{.InputLine "wrong"}}
+Fatal: could not decrypt key with given passphrase
+`)
+}
+
+func TestUnlockFlag(t *testing.T) {
+ datadir := tmpDatadirWithKeystore(t)
+ geth := runGeth(t,
+ "--datadir", datadir, "--nat", "none", "--nodiscover", "--maxpeers", "0", "--port", "0",
+ "--unlock", "f466859ead1932d743d622cb74fc058882e8648a",
+ "js", "testdata/empty.js")
+ geth.Expect(`
+Unlocking account f466859ead1932d743d622cb74fc058882e8648a | Attempt 1/3
+!! Unsupported terminal, password will be echoed.
+Passphrase: {{.InputLine "foobar"}}
+`)
+ geth.ExpectExit()
+
+ wantMessages := []string{
+ "Unlocked account",
+ "=0xf466859eAD1932D743d622CB74FC058882E8648A",
+ }
+ for _, m := range wantMessages {
+ if !strings.Contains(geth.StderrText(), m) {
+ t.Errorf("stderr text does not contain %q", m)
+ }
+ }
+}
+
+func TestUnlockFlagWrongPassword(t *testing.T) {
+ datadir := tmpDatadirWithKeystore(t)
+ geth := runGeth(t,
+ "--datadir", datadir, "--nat", "none", "--nodiscover", "--maxpeers", "0", "--port", "0",
+ "--unlock", "f466859ead1932d743d622cb74fc058882e8648a")
+ defer geth.ExpectExit()
+ geth.Expect(`
+Unlocking account f466859ead1932d743d622cb74fc058882e8648a | Attempt 1/3
+!! Unsupported terminal, password will be echoed.
+Passphrase: {{.InputLine "wrong1"}}
+Unlocking account f466859ead1932d743d622cb74fc058882e8648a | Attempt 2/3
+Passphrase: {{.InputLine "wrong2"}}
+Unlocking account f466859ead1932d743d622cb74fc058882e8648a | Attempt 3/3
+Passphrase: {{.InputLine "wrong3"}}
+Fatal: Failed to unlock account f466859ead1932d743d622cb74fc058882e8648a (could not decrypt key with given passphrase)
+`)
+}
+
+// https://github.com/ethereum/go-ethereum/issues/1785
+func TestUnlockFlagMultiIndex(t *testing.T) {
+ datadir := tmpDatadirWithKeystore(t)
+ geth := runGeth(t,
+ "--datadir", datadir, "--nat", "none", "--nodiscover", "--maxpeers", "0", "--port", "0",
+ "--unlock", "0,2",
+ "js", "testdata/empty.js")
+ geth.Expect(`
+Unlocking account 0 | Attempt 1/3
+!! Unsupported terminal, password will be echoed.
+Passphrase: {{.InputLine "foobar"}}
+Unlocking account 2 | Attempt 1/3
+Passphrase: {{.InputLine "foobar"}}
+`)
+ geth.ExpectExit()
+
+ wantMessages := []string{
+ "Unlocked account",
+ "=0x7EF5A6135f1FD6a02593eEdC869c6D41D934aef8",
+ "=0x289d485D9771714CCe91D3393D764E1311907ACc",
+ }
+ for _, m := range wantMessages {
+ if !strings.Contains(geth.StderrText(), m) {
+ t.Errorf("stderr text does not contain %q", m)
+ }
+ }
+}
+
+func TestUnlockFlagPasswordFile(t *testing.T) {
+ datadir := tmpDatadirWithKeystore(t)
+ geth := runGeth(t,
+ "--datadir", datadir, "--nat", "none", "--nodiscover", "--maxpeers", "0", "--port", "0",
+ "--password", "testdata/passwords.txt", "--unlock", "0,2",
+ "js", "testdata/empty.js")
+ geth.ExpectExit()
+
+ wantMessages := []string{
+ "Unlocked account",
+ "=0x7EF5A6135f1FD6a02593eEdC869c6D41D934aef8",
+ "=0x289d485D9771714CCe91D3393D764E1311907ACc",
+ }
+ for _, m := range wantMessages {
+ if !strings.Contains(geth.StderrText(), m) {
+ t.Errorf("stderr text does not contain %q", m)
+ }
+ }
+}
+
+func TestUnlockFlagPasswordFileWrongPassword(t *testing.T) {
+ datadir := tmpDatadirWithKeystore(t)
+ geth := runGeth(t,
+ "--datadir", datadir, "--nat", "none", "--nodiscover", "--maxpeers", "0", "--port", "0",
+ "--password", "testdata/wrong-passwords.txt", "--unlock", "0,2")
+ defer geth.ExpectExit()
+ geth.Expect(`
+Fatal: Failed to unlock account 0 (could not decrypt key with given passphrase)
+`)
+}
+
+func TestUnlockFlagAmbiguous(t *testing.T) {
+ store := filepath.Join("..", "..", "accounts", "keystore", "testdata", "dupes")
+ geth := runGeth(t,
+ "--keystore", store, "--nat", "none", "--nodiscover", "--maxpeers", "0", "--port", "0",
+ "--unlock", "f466859ead1932d743d622cb74fc058882e8648a",
+ "js", "testdata/empty.js")
+ defer geth.ExpectExit()
+
+ // Helper for the expect template, returns absolute keystore path.
+ geth.SetTemplateFunc("keypath", func(file string) string {
+ abs, _ := filepath.Abs(filepath.Join(store, file))
+ return abs
+ })
+ geth.Expect(`
+Unlocking account f466859ead1932d743d622cb74fc058882e8648a | Attempt 1/3
+!! Unsupported terminal, password will be echoed.
+Passphrase: {{.InputLine "foobar"}}
+Multiple key files exist for address f466859ead1932d743d622cb74fc058882e8648a:
+ keystore://{{keypath "1"}}
+ keystore://{{keypath "2"}}
+Testing your passphrase against all of them...
+Your passphrase unlocked keystore://{{keypath "1"}}
+In order to avoid this warning, you need to remove the following duplicate key files:
+ keystore://{{keypath "2"}}
+`)
+ geth.ExpectExit()
+
+ wantMessages := []string{
+ "Unlocked account",
+ "=0xf466859eAD1932D743d622CB74FC058882E8648A",
+ }
+ for _, m := range wantMessages {
+ if !strings.Contains(geth.StderrText(), m) {
+ t.Errorf("stderr text does not contain %q", m)
+ }
+ }
+}
+
+func TestUnlockFlagAmbiguousWrongPassword(t *testing.T) {
+ store := filepath.Join("..", "..", "accounts", "keystore", "testdata", "dupes")
+ geth := runGeth(t,
+ "--keystore", store, "--nat", "none", "--nodiscover", "--maxpeers", "0", "--port", "0",
+ "--unlock", "f466859ead1932d743d622cb74fc058882e8648a")
+ defer geth.ExpectExit()
+
+ // Helper for the expect template, returns absolute keystore path.
+ geth.SetTemplateFunc("keypath", func(file string) string {
+ abs, _ := filepath.Abs(filepath.Join(store, file))
+ return abs
+ })
+ geth.Expect(`
+Unlocking account f466859ead1932d743d622cb74fc058882e8648a | Attempt 1/3
+!! Unsupported terminal, password will be echoed.
+Passphrase: {{.InputLine "wrong"}}
+Multiple key files exist for address f466859ead1932d743d622cb74fc058882e8648a:
+ keystore://{{keypath "1"}}
+ keystore://{{keypath "2"}}
+Testing your passphrase against all of them...
+Fatal: None of the listed files could be unlocked.
+`)
+ geth.ExpectExit()
+}