2016-03-18 01:35:03 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								// 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 <http://www.gnu.org/licenses/>.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								package main
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import (
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									"io/ioutil"
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									"path/filepath"
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-03 01:15:42 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									"runtime"
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-18 01:35:03 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
									"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")
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-24 11:49:20 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									source := filepath.Join("..", "..", "accounts", "keystore", "testdata", "keystore")
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-18 01:35:03 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
									if err := cp.CopyAll(keystore, source); err != nil {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										t.Fatal(err)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									return datadir
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								func TestAccountListEmpty(t *testing.T) {
							 | 
						
					
						
							
								
									
										
										
										
											2017-04-28 12:38:49 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									geth := runGeth(t, "account", "list")
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-21 14:54:23 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									geth.ExpectExit()
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-18 01:35:03 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								func TestAccountList(t *testing.T) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									datadir := tmpDatadirWithKeystore(t)
							 | 
						
					
						
							
								
									
										
										
										
											2017-04-28 12:38:49 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									geth := runGeth(t, "account", "list", "--datadir", datadir)
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-21 14:54:23 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									defer geth.ExpectExit()
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-03 01:15:42 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									if runtime.GOOS == "windows" {
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-21 14:54:23 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										geth.Expect(`
							 | 
						
					
						
							
								
									
										
										
										
											2017-02-08 15:53:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								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
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-03 01:15:42 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								`)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									} else {
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-21 14:54:23 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										geth.Expect(`
							 | 
						
					
						
							
								
									
										
										
										
											2017-02-08 15:53:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								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
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-18 01:35:03 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								`)
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-03 01:15:42 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									}
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-18 01:35:03 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								func TestAccountNew(t *testing.T) {
							 | 
						
					
						
							
								
									
										
										
										
											2017-04-28 12:38:49 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									geth := runGeth(t, "account", "new", "--lightkdf")
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-21 14:54:23 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									defer geth.ExpectExit()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									geth.Expect(`
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-18 01:35:03 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								Your new account is locked with a password. Please give a password. Do not forget this password.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								!! Unsupported terminal, password will be echoed.
							 | 
						
					
						
							
								
									
										
										
										
											2019-08-12 11:00:38 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								Password: {{.InputLine "foobar"}}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								Repeat password: {{.InputLine "foobar"}}
							 | 
						
					
						
							
								
									
										
										
										
											2019-05-07 15:49:51 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								Your new key was generated
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								`)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									geth.ExpectRegexp(`
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								Public address of the key:   0x[0-9a-fA-F]{40}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								Path of the secret key file: .*UTC--.+--[0-9a-f]{40}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								- You can share your public address with anyone. Others need it to interact with you.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								- You must NEVER share the secret key with anyone! The key controls access to your funds!
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								- You must BACKUP your key file! Without the key, it's impossible to access account funds!
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								- You must REMEMBER your password! Without the password, it's impossible to decrypt the key!
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-18 01:35:03 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								`)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-04-08 16:01:11 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								func TestAccountImport(t *testing.T) {
							 | 
						
					
						
							
								
									
										
										
										
											2020-04-22 11:52:29 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									tests := []struct{ name, key, output string }{
							 | 
						
					
						
							
								
									
										
										
										
											2020-04-08 16:01:11 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										{
							 | 
						
					
						
							
								
									
										
										
										
											2020-04-22 11:52:29 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											name:   "correct account",
							 | 
						
					
						
							
								
									
										
										
										
											2020-04-08 16:01:11 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											key:    "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											output: "Address: {fcad0b19bb29d4674531d6f115237e16afce377c}\n",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										},
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										{
							 | 
						
					
						
							
								
									
										
										
										
											2020-04-22 11:52:29 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											name:   "invalid character",
							 | 
						
					
						
							
								
									
										
										
										
											2020-04-08 16:01:11 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											key:    "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef1",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											output: "Fatal: Failed to load the private key: invalid character '1' at end of key file\n",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										},
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									for _, test := range tests {
							 | 
						
					
						
							
								
									
										
										
										
											2020-04-22 11:52:29 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										t.Run(test.name, func(t *testing.T) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											t.Parallel()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											importAccountWithExpect(t, test.key, test.output)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										})
							 | 
						
					
						
							
								
									
										
										
										
											2020-04-08 16:01:11 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								func importAccountWithExpect(t *testing.T, key string, expected string) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									dir := tmpdir(t)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									keyfile := filepath.Join(dir, "key.prv")
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									if err := ioutil.WriteFile(keyfile, []byte(key), 0600); err != nil {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										t.Error(err)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									passwordFile := filepath.Join(dir, "password.txt")
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									if err := ioutil.WriteFile(passwordFile, []byte("foobar"), 0600); err != nil {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										t.Error(err)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									geth := runGeth(t, "account", "import", keyfile, "-password", passwordFile)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									defer geth.ExpectExit()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									geth.Expect(expected)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-18 01:35:03 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								func TestAccountNewBadRepeat(t *testing.T) {
							 | 
						
					
						
							
								
									
										
										
										
											2017-04-28 12:38:49 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									geth := runGeth(t, "account", "new", "--lightkdf")
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-21 14:54:23 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									defer geth.ExpectExit()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									geth.Expect(`
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-18 01:35:03 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								Your new account is locked with a password. Please give a password. Do not forget this password.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								!! Unsupported terminal, password will be echoed.
							 | 
						
					
						
							
								
									
										
										
										
											2019-08-12 11:00:38 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								Password: {{.InputLine "something"}}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								Repeat password: {{.InputLine "something else"}}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								Fatal: Passwords do not match
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-18 01:35:03 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								`)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								func TestAccountUpdate(t *testing.T) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									datadir := tmpDatadirWithKeystore(t)
							 | 
						
					
						
							
								
									
										
										
										
											2017-04-28 12:38:49 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									geth := runGeth(t, "account", "update",
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-18 01:35:03 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
										"--datadir", datadir, "--lightkdf",
							 | 
						
					
						
							
								
									
										
										
										
											2017-04-28 12:38:49 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										"f466859ead1932d743d622cb74fc058882e8648a")
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-21 14:54:23 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									defer geth.ExpectExit()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									geth.Expect(`
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-18 01:35:03 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								Unlocking account f466859ead1932d743d622cb74fc058882e8648a | Attempt 1/3
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								!! Unsupported terminal, password will be echoed.
							 | 
						
					
						
							
								
									
										
										
										
											2019-08-12 11:00:38 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								Password: {{.InputLine "foobar"}}
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-18 01:35:03 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								Please give a new password. Do not forget this password.
							 | 
						
					
						
							
								
									
										
										
										
											2019-08-12 11:00:38 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								Password: {{.InputLine "foobar2"}}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								Repeat password: {{.InputLine "foobar2"}}
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-18 01:35:03 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								`)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								func TestWalletImport(t *testing.T) {
							 | 
						
					
						
							
								
									
										
										
										
											2017-04-28 12:38:49 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									geth := runGeth(t, "wallet", "import", "--lightkdf", "testdata/guswallet.json")
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-21 14:54:23 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									defer geth.ExpectExit()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									geth.Expect(`
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-18 01:35:03 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								!! Unsupported terminal, password will be echoed.
							 | 
						
					
						
							
								
									
										
										
										
											2019-08-12 11:00:38 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								Password: {{.InputLine "foo"}}
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-18 01:35:03 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								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) {
							 | 
						
					
						
							
								
									
										
										
										
											2017-04-28 12:38:49 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									geth := runGeth(t, "wallet", "import", "--lightkdf", "testdata/guswallet.json")
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-21 14:54:23 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									defer geth.ExpectExit()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									geth.Expect(`
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-18 01:35:03 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								!! Unsupported terminal, password will be echoed.
							 | 
						
					
						
							
								
									
										
										
										
											2019-08-12 11:00:38 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								Password: {{.InputLine "wrong"}}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								Fatal: could not decrypt key with given password
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-18 01:35:03 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								`)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								func TestUnlockFlag(t *testing.T) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									datadir := tmpDatadirWithKeystore(t)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									geth := runGeth(t,
							 | 
						
					
						
							
								
									
										
										
										
											2017-10-24 13:40:42 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										"--datadir", datadir, "--nat", "none", "--nodiscover", "--maxpeers", "0", "--port", "0",
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-18 01:35:03 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
										"--unlock", "f466859ead1932d743d622cb74fc058882e8648a",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										"js", "testdata/empty.js")
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-21 14:54:23 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									geth.Expect(`
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-18 01:35:03 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								Unlocking account f466859ead1932d743d622cb74fc058882e8648a | Attempt 1/3
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								!! Unsupported terminal, password will be echoed.
							 | 
						
					
						
							
								
									
										
										
										
											2019-08-12 11:00:38 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								Password: {{.InputLine "foobar"}}
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-18 01:35:03 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								`)
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-21 14:54:23 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									geth.ExpectExit()
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-18 01:35:03 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									wantMessages := []string{
							 | 
						
					
						
							
								
									
										
										
										
											2017-02-22 16:58:00 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										"Unlocked account",
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-16 13:29:20 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										"=0xf466859eAD1932D743d622CB74FC058882E8648A",
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-18 01:35:03 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
									}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									for _, m := range wantMessages {
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-21 14:54:23 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										if !strings.Contains(geth.StderrText(), m) {
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-18 01:35:03 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
											t.Errorf("stderr text does not contain %q", m)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								func TestUnlockFlagWrongPassword(t *testing.T) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									datadir := tmpDatadirWithKeystore(t)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									geth := runGeth(t,
							 | 
						
					
						
							
								
									
										
										
										
											2017-10-24 13:40:42 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										"--datadir", datadir, "--nat", "none", "--nodiscover", "--maxpeers", "0", "--port", "0",
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-18 01:35:03 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
										"--unlock", "f466859ead1932d743d622cb74fc058882e8648a")
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-21 14:54:23 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									defer geth.ExpectExit()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									geth.Expect(`
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-18 01:35:03 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								Unlocking account f466859ead1932d743d622cb74fc058882e8648a | Attempt 1/3
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								!! Unsupported terminal, password will be echoed.
							 | 
						
					
						
							
								
									
										
										
										
											2019-08-12 11:00:38 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								Password: {{.InputLine "wrong1"}}
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-18 01:35:03 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								Unlocking account f466859ead1932d743d622cb74fc058882e8648a | Attempt 2/3
							 | 
						
					
						
							
								
									
										
										
										
											2019-08-12 11:00:38 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								Password: {{.InputLine "wrong2"}}
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-18 01:35:03 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								Unlocking account f466859ead1932d743d622cb74fc058882e8648a | Attempt 3/3
							 | 
						
					
						
							
								
									
										
										
										
											2019-08-12 11:00:38 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								Password: {{.InputLine "wrong3"}}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								Fatal: Failed to unlock account f466859ead1932d743d622cb74fc058882e8648a (could not decrypt key with given password)
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-18 01:35:03 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								`)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								// https://github.com/ethereum/go-ethereum/issues/1785
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								func TestUnlockFlagMultiIndex(t *testing.T) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									datadir := tmpDatadirWithKeystore(t)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									geth := runGeth(t,
							 | 
						
					
						
							
								
									
										
										
										
											2017-10-24 13:40:42 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										"--datadir", datadir, "--nat", "none", "--nodiscover", "--maxpeers", "0", "--port", "0",
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-18 01:35:03 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
										"--unlock", "0,2",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										"js", "testdata/empty.js")
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-21 14:54:23 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									geth.Expect(`
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-18 01:35:03 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								Unlocking account 0 | Attempt 1/3
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								!! Unsupported terminal, password will be echoed.
							 | 
						
					
						
							
								
									
										
										
										
											2019-08-12 11:00:38 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								Password: {{.InputLine "foobar"}}
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-18 01:35:03 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								Unlocking account 2 | Attempt 1/3
							 | 
						
					
						
							
								
									
										
										
										
											2019-08-12 11:00:38 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								Password: {{.InputLine "foobar"}}
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-18 01:35:03 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								`)
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-21 14:54:23 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									geth.ExpectExit()
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-18 01:35:03 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									wantMessages := []string{
							 | 
						
					
						
							
								
									
										
										
										
											2017-02-22 16:58:00 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										"Unlocked account",
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-16 13:29:20 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										"=0x7EF5A6135f1FD6a02593eEdC869c6D41D934aef8",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										"=0x289d485D9771714CCe91D3393D764E1311907ACc",
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-18 01:35:03 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
									}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									for _, m := range wantMessages {
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-21 14:54:23 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										if !strings.Contains(geth.StderrText(), m) {
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-18 01:35:03 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
											t.Errorf("stderr text does not contain %q", m)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								func TestUnlockFlagPasswordFile(t *testing.T) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									datadir := tmpDatadirWithKeystore(t)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									geth := runGeth(t,
							 | 
						
					
						
							
								
									
										
										
										
											2017-10-24 13:40:42 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										"--datadir", datadir, "--nat", "none", "--nodiscover", "--maxpeers", "0", "--port", "0",
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-18 01:35:03 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
										"--password", "testdata/passwords.txt", "--unlock", "0,2",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										"js", "testdata/empty.js")
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-21 14:54:23 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									geth.ExpectExit()
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-18 01:35:03 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									wantMessages := []string{
							 | 
						
					
						
							
								
									
										
										
										
											2017-02-22 16:58:00 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										"Unlocked account",
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-16 13:29:20 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										"=0x7EF5A6135f1FD6a02593eEdC869c6D41D934aef8",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										"=0x289d485D9771714CCe91D3393D764E1311907ACc",
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-18 01:35:03 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
									}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									for _, m := range wantMessages {
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-21 14:54:23 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										if !strings.Contains(geth.StderrText(), m) {
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-18 01:35:03 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
											t.Errorf("stderr text does not contain %q", m)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								func TestUnlockFlagPasswordFileWrongPassword(t *testing.T) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									datadir := tmpDatadirWithKeystore(t)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									geth := runGeth(t,
							 | 
						
					
						
							
								
									
										
										
										
											2017-10-24 13:40:42 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										"--datadir", datadir, "--nat", "none", "--nodiscover", "--maxpeers", "0", "--port", "0",
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-18 01:35:03 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
										"--password", "testdata/wrong-passwords.txt", "--unlock", "0,2")
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-21 14:54:23 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									defer geth.ExpectExit()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									geth.Expect(`
							 | 
						
					
						
							
								
									
										
										
										
											2019-08-12 11:00:38 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								Fatal: Failed to unlock account 0 (could not decrypt key with given password)
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-18 01:35:03 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								`)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-01 18:10:58 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								func TestUnlockFlagAmbiguous(t *testing.T) {
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-24 11:49:20 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									store := filepath.Join("..", "..", "accounts", "keystore", "testdata", "dupes")
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-01 18:10:58 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									geth := runGeth(t,
							 | 
						
					
						
							
								
									
										
										
										
											2017-10-24 13:40:42 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										"--keystore", store, "--nat", "none", "--nodiscover", "--maxpeers", "0", "--port", "0",
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-01 18:10:58 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										"--unlock", "f466859ead1932d743d622cb74fc058882e8648a",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										"js", "testdata/empty.js")
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-21 14:54:23 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									defer geth.ExpectExit()
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-01 18:10:58 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									// Helper for the expect template, returns absolute keystore path.
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-21 14:54:23 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									geth.SetTemplateFunc("keypath", func(file string) string {
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-01 18:10:58 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										abs, _ := filepath.Abs(filepath.Join(store, file))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										return abs
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									})
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-21 14:54:23 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									geth.Expect(`
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-01 18:10:58 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								Unlocking account f466859ead1932d743d622cb74fc058882e8648a | Attempt 1/3
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								!! Unsupported terminal, password will be echoed.
							 | 
						
					
						
							
								
									
										
										
										
											2019-08-12 11:00:38 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								Password: {{.InputLine "foobar"}}
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-01 18:10:58 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								Multiple key files exist for address f466859ead1932d743d622cb74fc058882e8648a:
							 | 
						
					
						
							
								
									
										
										
										
											2017-02-08 15:53:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								   keystore://{{keypath "1"}}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								   keystore://{{keypath "2"}}
							 | 
						
					
						
							
								
									
										
										
										
											2019-08-12 11:00:38 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								Testing your password against all of them...
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								Your password unlocked keystore://{{keypath "1"}}
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-01 18:10:58 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								In order to avoid this warning, you need to remove the following duplicate key files:
							 | 
						
					
						
							
								
									
										
										
										
											2017-02-08 15:53:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								   keystore://{{keypath "2"}}
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-01 18:10:58 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								`)
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-21 14:54:23 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									geth.ExpectExit()
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-01 18:10:58 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									wantMessages := []string{
							 | 
						
					
						
							
								
									
										
										
										
											2017-02-22 16:58:00 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										"Unlocked account",
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-16 13:29:20 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										"=0xf466859eAD1932D743d622CB74FC058882E8648A",
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-01 18:10:58 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									for _, m := range wantMessages {
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-21 14:54:23 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										if !strings.Contains(geth.StderrText(), m) {
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-01 18:10:58 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											t.Errorf("stderr text does not contain %q", m)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								func TestUnlockFlagAmbiguousWrongPassword(t *testing.T) {
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-24 11:49:20 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									store := filepath.Join("..", "..", "accounts", "keystore", "testdata", "dupes")
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-01 18:10:58 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									geth := runGeth(t,
							 | 
						
					
						
							
								
									
										
										
										
											2017-10-24 13:40:42 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										"--keystore", store, "--nat", "none", "--nodiscover", "--maxpeers", "0", "--port", "0",
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-01 18:10:58 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										"--unlock", "f466859ead1932d743d622cb74fc058882e8648a")
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-21 14:54:23 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									defer geth.ExpectExit()
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-01 18:10:58 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									// Helper for the expect template, returns absolute keystore path.
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-21 14:54:23 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									geth.SetTemplateFunc("keypath", func(file string) string {
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-01 18:10:58 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										abs, _ := filepath.Abs(filepath.Join(store, file))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										return abs
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									})
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-21 14:54:23 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									geth.Expect(`
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-01 18:10:58 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								Unlocking account f466859ead1932d743d622cb74fc058882e8648a | Attempt 1/3
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								!! Unsupported terminal, password will be echoed.
							 | 
						
					
						
							
								
									
										
										
										
											2019-08-12 11:00:38 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								Password: {{.InputLine "wrong"}}
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-01 18:10:58 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								Multiple key files exist for address f466859ead1932d743d622cb74fc058882e8648a:
							 | 
						
					
						
							
								
									
										
										
										
											2017-02-08 15:53:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								   keystore://{{keypath "1"}}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								   keystore://{{keypath "2"}}
							 | 
						
					
						
							
								
									
										
										
										
											2019-08-12 11:00:38 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								Testing your password against all of them...
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-01 18:10:58 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								Fatal: None of the listed files could be unlocked.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								`)
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-21 14:54:23 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									geth.ExpectExit()
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-01 18:10:58 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 |