github.com/ethereumproject/go-ethereum@v5.5.2+incompatible/tests/bats/accountdb.bats (about)

     1  #!/usr/bin/env bats
     2  
     3  : ${GETH_CMD:=$GOPATH/bin/geth}
     4  
     5  setup() {
     6  	DATA_DIR=`mktemp -d`
     7  	mkdir "$DATA_DIR/mainnet"
     8  }
     9  
    10  teardown() {
    11  	rm -fr $DATA_DIR
    12  }
    13  
    14  @test "account <no command> yields help/usage" {
    15  	run $GETH_CMD --datadir $DATA_DIR account
    16  	echo "$output"
    17  
    18  	[ "$status" -eq 0 ]
    19  	[[ "$output" == *"USAGE"* ]]
    20  }
    21  
    22  @test "account list yields <blank> (no accounts)" {
    23  	run $GETH_CMD --datadir $DATA_DIR account list
    24  	echo "$output"
    25  
    26  	[ "$status" -eq 0 ]
    27  	[ "$output" = "" ]
    28  }
    29  
    30  @test "account list testdata keystore (db)" {
    31  	cp -R $BATS_TEST_DIRNAME/../../accounts/testdata/keystore $DATA_DIR/mainnet
    32  
    33  	# Create index.
    34  	run $GETH_CMD --data-dir $DATA_DIR --index-accounts account index
    35  	[ "$status" -eq 0 ]
    36  
    37  	run $GETH_CMD --datadir $DATA_DIR --index-accounts account list
    38  	echo "$output"
    39  
    40  	[ "$status" -eq 0 ]
    41  	# Note: cachedb stores files relative to keystore dir, while mem stores absolute paths.
    42  	# (whilei): I prefer relative to dir in case user wants to move keystore then paths will remain stable and not need to be reindexed.
    43  	# Also, both mem and cache implementations only scan 1 level (not recursively) and thus absolute path is unnecessarily verbose.
    44  	[ "${lines[0]}" == "Account #0: {7ef5a6135f1fd6a02593eedc869c6d41d934aef8} UTC--2016-03-22T12-57-55.920751759Z--7ef5a6135f1fd6a02593eedc869c6d41d934aef8" ]
    45  	[ "${lines[1]}" == "Account #1: {f466859ead1932d743d622cb74fc058882e8648a} aaa" ]
    46  	[ "${lines[2]}" == "Account #2: {289d485d9771714cce91d3393d764e1311907acc} zzz" ]
    47  }
    48  
    49  @test "account create (db)" {
    50  	run $GETH_CMD --datadir $DATA_DIR --lightkdf --index-accounts account new <<< $'secret\nsecret\n'
    51  	echo "$output"
    52  
    53  	[ "$status" -eq 0 ]
    54  	[[ "$output" =~ Address:.\{[0-9a-f]{40}\}$ ]]
    55  }
    56  
    57  @test "account create pass mismatch (db)" {
    58  	run $GETH_CMD --datadir $DATA_DIR --lightkdf --index-accounts account new <<< $'secret\nother\n'
    59  	echo "$output"
    60  
    61  	[ "$status" -ne 0 ]
    62  	[[ "$output" == *"Passphrases do not match" ]]
    63  }
    64  
    65  @test "account update pass (db)" {
    66  	cp -R $BATS_TEST_DIRNAME/../../accounts/testdata/keystore $DATA_DIR/mainnet
    67  	run $GETH_CMD --keystore $DATA_DIR/mainnet/keystore --index-accounts account index
    68  	[ "$status" -eq 0 ]
    69  
    70  	# Create index.
    71  	run $GETH_CMD --data-dir $DATA_DIR --index-accounts account index
    72  	[ "$status" -eq 0 ]
    73  
    74  	run $GETH_CMD --datadir $DATA_DIR --lightkdf --index-accounts account update f466859ead1932d743d622cb74fc058882e8648a <<< $'foobar\nother\nother\n'
    75  	echo "$output"
    76  
    77  	[ "$status" -eq 0 ]
    78  }
    79  
    80  @test "account import (db)" {
    81  	run $GETH_CMD --datadir $DATA_DIR --lightkdf --index-accounts wallet import $GOPATH/src/github.com/ethereumproject/go-ethereum/cmd/geth/testdata/guswallet.json <<< $'foo\n'
    82  	echo "$output"
    83  
    84  	[ "$status" -eq 0 ]
    85  	[[ "$output" == *"Address: {d4584b5f6229b7be90727b0fc8c6b91bb427821f}" ]]
    86  
    87  	echo "=== data dir files:"
    88  	ls $DATA_DIR/mainnet/keystore
    89  	[ $(ls $DATA_DIR/mainnet/keystore | wc -l) -eq 2 ] # keyfile + accounts.db
    90  }
    91  
    92  @test "account import pass mismatch (db)" {
    93  	run $GETH_CMD --datadir $DATA_DIR --lightkdf --index-accounts wallet import $GOPATH/src/github.com/ethereumproject/go-ethereum/cmd/geth/testdata/guswallet.json <<< $'wrong\n'
    94  	echo "$output"
    95  
    96  	[ "$status" -ne 0 ]
    97  	[[ "$output" == *"could not decrypt key with given passphrase" ]]
    98  }
    99  
   100  @test "account unlock (db)" {
   101  	cp -R $BATS_TEST_DIRNAME/../../accounts/testdata/keystore $DATA_DIR/mainnet
   102  	run $GETH_CMD --keystore $DATA_DIR/mainnet/keystore --index-accounts account index
   103  	[ "$status" -eq 0 ]
   104  	touch $DATA_DIR/empty.js
   105  
   106  	# Create index.
   107  	run $GETH_CMD --data-dir $DATA_DIR --index-accounts account index
   108  	[ "$status" -eq 0 ]
   109  
   110  	run $GETH_CMD --datadir $DATA_DIR --index-accounts --keystore="$DATA_DIR"/mainnet/keystore\
   111  	 --nat none --nodiscover --dev --unlock f466859ead1932d743d622cb74fc058882e8648a js $DATA_DIR/empty.js <<< $'foobar\n'
   112  	echo "$output"
   113  
   114  	[ "$status" -eq 0 ]
   115  	[[ "$output" == *"Unlocked account f466859ead1932d743d622cb74fc058882e8648a"* ]]
   116  }
   117  
   118  @test "account unlock pass mismatch (db)" {
   119  	cp -R $BATS_TEST_DIRNAME/../../accounts/testdata/keystore $DATA_DIR/mainnet
   120  	run $GETH_CMD --keystore $DATA_DIR/mainnet/keystore --index-accounts account index
   121  	[ "$status" -eq 0 ]
   122  	touch $DATA_DIR/empty.js
   123  
   124  	# Create index.
   125  	run $GETH_CMD --data-dir $DATA_DIR --index-accounts account index
   126  	[ "$status" -eq 0 ]
   127  
   128  	run $GETH_CMD --datadir $DATA_DIR --index-accounts --keystore="$DATA_DIR"/mainnet/keystore\
   129  	 --nat none --nodiscover --dev --unlock f466859ead1932d743d622cb74fc058882e8648a js $DATA_DIR/empty.js <<< $'wrong1\nwrong2\nwrong3\n'
   130  	echo "$output"
   131  
   132  	[ "$status" -ne 0 ]
   133  	[[ "$output" == *"Failed to unlock account f466859ead1932d743d622cb74fc058882e8648a (could not decrypt key with given passphrase)" ]]
   134  }
   135  
   136  @test "account unlock multiple (db)" {
   137  	cp -R $BATS_TEST_DIRNAME/../../accounts/testdata/keystore $DATA_DIR/mainnet
   138  	run $GETH_CMD --keystore $DATA_DIR/mainnet/keystore --index-accounts account index
   139  	[ "$status" -eq 0 ]
   140  	touch $DATA_DIR/empty.js
   141  
   142  	# Create index.
   143  	run $GETH_CMD --data-dir $DATA_DIR --index-accounts account index
   144  	[ "$status" -eq 0 ]
   145  
   146  	run $GETH_CMD --datadir $DATA_DIR --index-accounts --keystore="$DATA_DIR"/mainnet/keystore\
   147  	 --nat none --nodiscover --dev --unlock 0,2 js $DATA_DIR/empty.js <<< $'foobar\nfoobar\n'
   148  	echo "$output"
   149  
   150  	[ "$status" -eq 0 ]
   151  	[[ "$output" == *"Unlocked account 7ef5a6135f1fd6a02593eedc869c6d41d934aef8"* ]]
   152  	[[ "$output" == *"Unlocked account 289d485d9771714cce91d3393d764e1311907acc"* ]]
   153  }
   154  
   155  @test "account unlock multiple with pass file (db)" {
   156  	cp -R $BATS_TEST_DIRNAME/../../accounts/testdata/keystore $DATA_DIR/mainnet
   157  	run $GETH_CMD --keystore $DATA_DIR/mainnet/keystore --index-accounts account index
   158  	[ "$status" -eq 0 ]
   159  	touch $DATA_DIR/empty.js
   160  
   161  	# Create index.
   162  	run $GETH_CMD --data-dir $DATA_DIR --index-accounts account index
   163  	[ "$status" -eq 0 ]
   164  
   165  	echo $'foobar\nfoobar\nfoobar\n' > $DATA_DIR/pass.txt
   166  
   167  	run $GETH_CMD --datadir $DATA_DIR --index-accounts --keystore="$DATA_DIR"/mainnet/keystore\
   168  	 --nat none --nodiscover --dev --password $DATA_DIR/pass.txt --unlock 0,2 js $DATA_DIR/empty.js
   169  	echo "$output"
   170  
   171  	[ "$status" -eq 0 ]
   172  	[[ "$output" == *"Unlocked account 7ef5a6135f1fd6a02593eedc869c6d41d934aef8"* ]]
   173  	[[ "$output" == *"Unlocked account 289d485d9771714cce91d3393d764e1311907acc"* ]]
   174  }
   175  
   176  @test "account unlock multiple with wrong pass file (db)" {
   177  	cp -R $BATS_TEST_DIRNAME/../../accounts/testdata/keystore $DATA_DIR/mainnet
   178  	run $GETH_CMD --keystore $DATA_DIR/mainnet/keystore --index-accounts account index
   179  	[ "$status" -eq 0 ]
   180  	touch $DATA_DIR/empty.js
   181  
   182  	# Create index.
   183  	run $GETH_CMD --data-dir $DATA_DIR --index-accounts account index
   184  	[ "$status" -eq 0 ]
   185  
   186  	echo $'wrong\nwrong\nwrong\n' > $DATA_DIR/pass.txt
   187  
   188  	run $GETH_CMD --datadir $DATA_DIR --nat none --index-accounts --keystore="$DATA_DIR"/mainnet/keystore\
   189  	 --nat none --nodiscover --dev --password $DATA_DIR/pass.txt --unlock 0,2 js $DATA_DIR/empty.js
   190  	echo "$output"
   191  
   192  	[ "$status" -ne 0 ]
   193  	[[ "$output" == *"Failed to unlock account 0 (could not decrypt key with given passphrase)" ]]
   194  }
   195  
   196  @test "account unlock ambiguous (db)" {
   197  	cp -R $BATS_TEST_DIRNAME/../../accounts/testdata/dupes $DATA_DIR/mainnet/store
   198  	touch $DATA_DIR/empty.js
   199  
   200  	run $GETH_CMD --keystore $DATA_DIR/mainnet/store --index-accounts account index
   201  	[ "$status" -eq 0 ]
   202  
   203  	run $GETH_CMD --datadir $DATA_DIR --keystore $DATA_DIR/mainnet/store --index-accounts --keystore="$DATA_DIR"/mainnet/store\
   204  	 --nat none --nodiscover --dev --unlock f466859ead1932d743d622cb74fc058882e8648a js $DATA_DIR/empty.js <<< $'foobar\n'$DATA_DIR/store/1
   205  	echo "$output"
   206  
   207  	[ "$status" -eq 0 ]
   208  	[[ "$output" == *"Multiple key files exist for address f466859ead1932d743d622cb74fc058882e8648a:"* ]]
   209  	[[ "$output" == *"Your passphrase unlocked 1"* ]]
   210  	[[ "$output" == *"Unlocked account f466859ead1932d743d622cb74fc058882e8648a"* ]]
   211  }
   212  
   213  @test "account unlock ambiguous pass mismatch (db)" {
   214  	cp -R $BATS_TEST_DIRNAME/../../accounts/testdata/dupes $DATA_DIR/mainnet/store
   215  	touch $DATA_DIR/empty.js
   216  
   217  	run $GETH_CMD --keystore $DATA_DIR/mainnet/store --index-accounts account index
   218  	[ "$status" -eq 0 ]
   219  
   220  	run $GETH_CMD --datadir $DATA_DIR --keystore $DATA_DIR/mainnet/store --index-accounts --keystore="$DATA_DIR"/mainnet/store\
   221  	 --nat none --nodiscover --dev --unlock f466859ead1932d743d622cb74fc058882e8648a js $DATA_DIR/empty.js <<< $'wrong\n'$DATA_DIR/store/1
   222  	echo "$output"
   223  
   224  	[ "$status" -ne 0 ]
   225  	[[ "$output" == *"Multiple key files exist for address f466859ead1932d743d622cb74fc058882e8648a:"* ]]
   226  	[[ "$output" == *"None of the listed files could be unlocked."* ]]
   227  }