github.com/ethereumproject/go-ethereum@v5.5.2+incompatible/tests/bats/account.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" { 31 cp -R $BATS_TEST_DIRNAME/../../accounts/testdata/keystore $DATA_DIR/mainnet 32 33 run $GETH_CMD --datadir $DATA_DIR account list 34 echo "$output" 35 36 [ "$status" -eq 0 ] 37 [ "${lines[0]}" == "Account #0: {7ef5a6135f1fd6a02593eedc869c6d41d934aef8} $DATA_DIR/mainnet/keystore/UTC--2016-03-22T12-57-55.920751759Z--7ef5a6135f1fd6a02593eedc869c6d41d934aef8" ] 38 [ "${lines[1]}" == "Account #1: {f466859ead1932d743d622cb74fc058882e8648a} $DATA_DIR/mainnet/keystore/aaa" ] 39 [ "${lines[2]}" == "Account #2: {289d485d9771714cce91d3393d764e1311907acc} $DATA_DIR/mainnet/keystore/zzz" ] 40 } 41 42 @test "account create" { 43 run $GETH_CMD --datadir $DATA_DIR --lightkdf account new <<< $'secret\nsecret\n' 44 echo "$output" 45 46 [ "$status" -eq 0 ] 47 [[ "$output" =~ Address:.\{[0-9a-f]{40}\}$ ]] 48 } 49 50 @test "account create pass mismatch" { 51 run $GETH_CMD --datadir $DATA_DIR --lightkdf account new <<< $'secret\nother\n' 52 echo "$output" 53 54 [ "$status" -ne 0 ] 55 [[ "$output" == *"Passphrases do not match" ]] 56 } 57 58 @test "account update pass" { 59 cp -R $BATS_TEST_DIRNAME/../../accounts/testdata/keystore $DATA_DIR/mainnet 60 61 run $GETH_CMD --datadir $DATA_DIR --lightkdf account update f466859ead1932d743d622cb74fc058882e8648a <<< $'foobar\nother\nother\n' 62 echo "$output" 63 64 [ "$status" -eq 0 ] 65 } 66 67 @test "account import" { 68 run $GETH_CMD --datadir $DATA_DIR --lightkdf wallet import $GOPATH/src/github.com/ethereumproject/go-ethereum/cmd/geth/testdata/guswallet.json <<< $'foo\n' 69 echo "$output" 70 71 [ "$status" -eq 0 ] 72 [[ "$output" == *"Address: {d4584b5f6229b7be90727b0fc8c6b91bb427821f}" ]] 73 74 echo "=== data dir files:" 75 ls $DATA_DIR/mainnet/keystore 76 [ $(ls $DATA_DIR/mainnet/keystore | wc -l) -eq 1 ] 77 } 78 79 @test "account import pass mismatch" { 80 run $GETH_CMD --datadir $DATA_DIR --lightkdf wallet import $GOPATH/src/github.com/ethereumproject/go-ethereum/cmd/geth/testdata/guswallet.json <<< $'wrong\n' 81 echo "$output" 82 83 [ "$status" -ne 0 ] 84 [[ "$output" == *"could not decrypt key with given passphrase" ]] 85 } 86 87 @test "account unlock" { 88 cp -R $BATS_TEST_DIRNAME/../../accounts/testdata/keystore $DATA_DIR/mainnet 89 touch $DATA_DIR/empty.js 90 91 run $GETH_CMD --datadir $DATA_DIR --nat none --nodiscover --dev --keystore="$DATA_DIR"/mainnet/keystore --unlock f466859ead1932d743d622cb74fc058882e8648a js $DATA_DIR/empty.js <<< $'foobar\n' 92 echo "$output" 93 94 [ "$status" -eq 0 ] 95 [[ "$output" == *"Unlocked account f466859ead1932d743d622cb74fc058882e8648a"* ]] 96 } 97 98 @test "account unlock by index" { 99 cp -R $BATS_TEST_DIRNAME/../../accounts/testdata/keystore $DATA_DIR/mainnet 100 touch $DATA_DIR/empty.js 101 102 run $GETH_CMD --datadir $DATA_DIR --nat none --nodiscover --dev --keystore="$DATA_DIR"/mainnet/keystore --unlock 0 js $DATA_DIR/empty.js <<< $'foobar\n' 103 echo "$output" 104 105 [ "$status" -eq 0 ] 106 [[ "$output" == *"Unlocked account 7ef5a6135f1fd6a02593eedc869c6d41d934aef8"* ]] 107 } 108 109 @test "account unlock pass mismatch" { 110 cp -R $BATS_TEST_DIRNAME/../../accounts/testdata/keystore $DATA_DIR/mainnet 111 touch $DATA_DIR/empty.js 112 113 run $GETH_CMD --datadir $DATA_DIR --nat none --nodiscover --dev --keystore="$DATA_DIR"/mainnet/keystore --unlock f466859ead1932d743d622cb74fc058882e8648a js $DATA_DIR/empty.js <<< $'wrong1\nwrong2\nwrong3\n' 114 echo "$output" 115 116 [ "$status" -ne 0 ] 117 [[ "$output" == *"Failed to unlock account f466859ead1932d743d622cb74fc058882e8648a (could not decrypt key with given passphrase)" ]] 118 } 119 120 @test "account unlock multiple" { 121 cp -R $BATS_TEST_DIRNAME/../../accounts/testdata/keystore $DATA_DIR/mainnet 122 touch $DATA_DIR/empty.js 123 124 run $GETH_CMD --datadir $DATA_DIR --nat none --nodiscover --dev --keystore="$DATA_DIR"/mainnet/keystore --unlock 0,2 js $DATA_DIR/empty.js <<< $'foobar\nfoobar\n' 125 echo "$output" 126 127 [ "$status" -eq 0 ] 128 [[ "$output" == *"Unlocked account 7ef5a6135f1fd6a02593eedc869c6d41d934aef8"* ]] 129 [[ "$output" == *"Unlocked account 289d485d9771714cce91d3393d764e1311907acc"* ]] 130 } 131 132 @test "account unlock multiple with pass file" { 133 cp -R $BATS_TEST_DIRNAME/../../accounts/testdata/keystore $DATA_DIR/mainnet 134 touch $DATA_DIR/empty.js 135 echo $'foobar\nfoobar\nfoobar\n' > $DATA_DIR/pass.txt 136 137 run $GETH_CMD --datadir $DATA_DIR --nat none --nodiscover --dev --keystore="$DATA_DIR"/mainnet/keystore --password $DATA_DIR/pass.txt --unlock 0,2 js $DATA_DIR/empty.js 138 echo "$output" 139 140 [ "$status" -eq 0 ] 141 [[ "$output" == *"Unlocked account 7ef5a6135f1fd6a02593eedc869c6d41d934aef8"* ]] 142 [[ "$output" == *"Unlocked account 289d485d9771714cce91d3393d764e1311907acc"* ]] 143 } 144 145 @test "account unlock multiple with wrong pass file" { 146 cp -R $BATS_TEST_DIRNAME/../../accounts/testdata/keystore $DATA_DIR/mainnet 147 touch $DATA_DIR/empty.js 148 echo $'wrong\nwrong\nwrong\n' > $DATA_DIR/pass.txt 149 150 run $GETH_CMD --datadir $DATA_DIR --nat none --nodiscover --dev --keystore="$DATA_DIR"/mainnet/keystore --password $DATA_DIR/pass.txt --unlock 0,2 js $DATA_DIR/empty.js 151 echo "$output" 152 153 [ "$status" -ne 0 ] 154 [[ "$output" == *"Failed to unlock account 0 (could not decrypt key with given passphrase)" ]] 155 } 156 157 @test "account unlock ambiguous" { 158 cp -R $BATS_TEST_DIRNAME/../../accounts/testdata/dupes $DATA_DIR/mainnet/store 159 touch $DATA_DIR/empty.js 160 161 run $GETH_CMD --datadir $DATA_DIR --keystore $DATA_DIR/mainnet/store --nat none --nodiscover --dev --unlock f466859ead1932d743d622cb74fc058882e8648a js $DATA_DIR/empty.js <<< $'foobar\n'$DATA_DIR/store/1 162 echo "$output" 163 164 [ "$status" -eq 0 ] 165 [[ "$output" == *"Multiple key files exist for address f466859ead1932d743d622cb74fc058882e8648a:"* ]] 166 [[ "$output" == *"Your passphrase unlocked "$DATA_DIR"/mainnet/store/1"* ]] 167 [[ "$output" == *"Unlocked account f466859ead1932d743d622cb74fc058882e8648a"* ]] 168 } 169 170 @test "account unlock ambiguous pass mismatch" { 171 cp -R $BATS_TEST_DIRNAME/../../accounts/testdata/dupes $DATA_DIR/store 172 touch $DATA_DIR/empty.js 173 174 run $GETH_CMD --datadir $DATA_DIR --keystore $DATA_DIR/store --nat none --nodiscover --dev --unlock f466859ead1932d743d622cb74fc058882e8648a js $DATA_DIR/empty.js <<< $'wrong\n'$DATA_DIR/store/1 175 echo "$output" 176 177 [ "$status" -ne 0 ] 178 [[ "$output" == *"Multiple key files exist for address f466859ead1932d743d622cb74fc058882e8648a:"* ]] 179 [[ "$output" == *"None of the listed files could be unlocked."* ]] 180 }