github.com/ethereumproject/go-ethereum@v5.5.2+incompatible/tests/bats/cli.bats (about) 1 #!/usr/bin/env bats 2 3 : ${GETH_CMD:=$GOPATH/bin/geth} 4 5 setup() { 6 DATA_DIR=`mktemp -d` 7 } 8 9 teardown() { 10 rm -fr $DATA_DIR 11 } 12 13 # Invalid flags exit with exit code 1. 14 # Invalid commands and subcommands exit with exit code 3. 15 @test "runs with valid command" { 16 run $GETH_CMD version 17 [ "$status" -eq 0 ] 18 [[ "$output" == *"Geth"* ]] 19 [[ "$output" == *"Version: "* ]] 20 [[ "$output" == *"Go Version: "* ]] 21 [[ "$output" == *"OS: "* ]] 22 [[ "$output" == *"GOPATH="* ]] 23 [[ "$output" == *"GOROOT="* ]] 24 } 25 26 @test "displays help with invalid command" { 27 run $GETH_CMD verison 28 [ "$status" -eq 3 ] 29 [[ "$output" == *"Invalid command"* ]] 30 [[ "$output" == *"USAGE"* ]] 31 } 32 33 @test "displays help with invalid flag" { 34 run $GETH_CMD --fat 35 [ "$status" -eq 1 ] 36 [[ "$output" == *"flag provided but not defined"* ]] 37 } 38 39 @test "runs with valid flag and valid command" { 40 run $GETH_CMD --datadir $DATA_DIR --maxpeers 0 --nodiscover --nat none --ipcdisable --exec 'exit' console 41 echo "$output" 42 43 [ "$status" -eq 0 ] 44 [[ "$output" == *"Blockchain"* ]] 45 [[ "$output" == *"Local head"* ]] 46 [[ "$output" == *"Starting server"* ]] 47 } 48 49 @test "displays help with invalid flag and valid command" { 50 # --nodisco 51 run $GETH_CMD --datadir $DATA_DIR --maxpeers 0 --nodisco --nat none --ipcdisable --exec 'exit' console 52 echo "$output" 53 54 [ "$status" -eq 1 ] 55 [[ "$output" == *"flag provided but not defined"* ]] 56 [[ "$output" == *"USAGE"* ]] 57 } 58 59 @test "displays help with valid flag and invalid command" { 60 # conso 61 run $GETH_CMD --datadir $DATA_DIR --maxpeers 0 --nodiscover --nat none --ipcdisable --exec 'exit' conso 62 echo "$output" 63 64 [ "$status" -eq 3 ] 65 [[ "$output" == *"Invalid command"* ]] 66 [[ "$output" == *"USAGE"* ]] 67 } 68 69 @test "exactly overlapping flags not allowed: --chain=morden --testnet" { 70 run $GETH_CMD --data-dir $DATA_DIR --testnet --chain=morden --maxpeers 0 --nodiscover --nat none --ipcdisable --exec 'exit' console 71 echo "$output" 72 [ "$status" -ne 0 ] 73 } 74 75 @test "custom testnet subdir --testnet --chain=morden2 | exit !=0" { 76 run $GETH_CMD --data-dir $DATA_DIR --testnet --chain=morden2 --maxpeers 0 --nodiscover --nat none --ipcdisable --exec 'exit' console 77 echo "$output" 78 [ "$status" -ne 0 ] 79 [[ "$output" == *"invalid flag "* ]] 80 } 81 82 # TODO 83 # This doesn't pass, and that's an issue. 84 # @test "displays help with valid command and invalid subcommand" { 85 # # lisr 86 # run $GETH_CMD account lisr 87 # echo "$output" 88 89 # [ "$status" -eq 3 ] 90 # [[ "$output" == *"SUBCOMMANDS"* ]] 91 # } 92 93 @test "aliasing directory flags: --data-dir==--datadir, --ipc-path==--ipcpath" { 94 95 # keystore not hyphenated 96 run $GETH_CMD --datadir $DATA_DIR --keystore $DATA_DIR/keyhere --exec 'exit;' console 97 [ "$status" -eq 0 ] 98 [ -d $DATA_DIR/keyhere ] 99 100 # data-dir/datadir 101 run $GETH_CMD --datadir $DATA_DIR --exec 'exit;' console 102 [ "$status" -eq 0 ] 103 [ -d $DATA_DIR ] 104 105 run $GETH_CMD --data-dir $DATA_DIR --exec 'exit;' console 106 [ "$status" -eq 0 ] 107 [ -d $DATA_DIR ] 108 109 # # ipc-path/ipcpath 110 run $GETH_CMD --data-dir $DATA_DIR --ipc-path abc.ipc --exec 'exit;' console 111 [ "$status" -eq 0 ] 112 echo "$output" 113 [[ "$output" == *"IPC endpoint opened"* ]] 114 [[ "$output" == *"$DATA_DIR/mainnet/abc.ipc"* ]] 115 116 run $GETH_CMD --data-dir $DATA_DIR --ipcpath $DATA_DIR/mainnet/abc.ipc --exec 'exit;' console 117 [ "$status" -eq 0 ] 118 echo "$output" 119 [[ "$output" == *"IPC endpoint opened"* ]] 120 [[ "$output" == *"$DATA_DIR/mainnet/abc.ipc"* ]] 121 122 run $GETH_CMD --data-dir $DATA_DIR --ipc-path $DATA_DIR/mainnet/abc --exec 'exit;' console 123 [ "$status" -eq 0 ] 124 echo "$output" 125 [[ "$output" == *"IPC endpoint opened"* ]] 126 [[ "$output" == *"$DATA_DIR/mainnet/abc"* ]] 127 128 run $GETH_CMD --data-dir $DATA_DIR --ipcpath $DATA_DIR/mainnet/abc --exec 'exit;' console 129 [ "$status" -eq 0 ] 130 echo "$output" 131 [[ "$output" == *"IPC endpoint opened"* ]] 132 [[ "$output" == *"$DATA_DIR/mainnet/abc"* ]] 133 134 } 135 136 # ... assuming that if two work, the rest will work. 137 @test "aliasing hyphenated flags: --no-discover==--nodiscover, --ipc-disable==--ipcdisable | exit 0" { 138 old_command_names=(nodiscover ipcdisable) 139 new_command_names=(no-discover ipc-disable) 140 141 for var in "${old_command_names[@]}" 142 do 143 # hardcode --datadir/--data-dir 144 run $GETH_CMD --datadir $DATA_DIR --$var --exec 'exit' console 145 [ "$status" -eq 0 ] 146 [[ "$output" == *"Blockchain"* ]] 147 [[ "$output" == *"Local head"* ]] 148 [[ "$output" == *"Starting server"* ]] 149 done 150 151 for var in "${new_command_names[@]}" 152 do 153 run $GETH_CMD --data-dir $DATA_DIR --$var --exec 'exit' console 154 [ "$status" -eq 0 ] 155 [[ "$output" == *"Blockchain"* ]] 156 [[ "$output" == *"Local head"* ]] 157 [[ "$output" == *"Starting server"* ]] 158 done 159 } 160 161 @test "--cache 16 | exit 0" { 162 run $GETH_CMD --data-dir $DATA_DIR --cache 17 --exec 'exit;' console 163 [ "$status" -eq 0 ] 164 [[ "$output" == *"Allotted"* ]] 165 [[ "$output" == *"17MB"* ]] 166 [[ "$output" == *"cache"* ]] 167 } 168 169 # Test `dump` command. 170 # All tests copy testdata/testdatadir to $DATA_DIR to ensure we're consistently testing against a not-only-init'ed chaindb. 171 @test "dump [noargs] | exit >0" { 172 cp -a $BATS_TEST_DIRNAME/../../cmd/geth/testdata/testdatadir/. $DATA_DIR/ 173 run $GETH_CMD --data-dir $DATA_DIR dump 174 echo "$output" 175 [ "$status" -gt 0 ] 176 [[ "$output" == *"invalid"* ]] # invalid use 177 } 178 @test "dump 0 [noaddress] | exit 0" { 179 cp -a $BATS_TEST_DIRNAME/../../cmd/geth/testdata/testdatadir/. $DATA_DIR/ 180 run $GETH_CMD --data-dir $DATA_DIR dump 0 181 echo "$output" 182 [ "$status" -eq 0 ] 183 [[ "$output" == *"root"* ]] # block state root 184 [[ "$output" == *"balance"* ]] 185 [[ "$output" == *"accounts"* ]] 186 [[ "$output" == *"d7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544"* ]] # block state root 187 [[ "$output" == *"ffec0913c635baca2f5e57a37aa9fb7b6c9b6e26"* ]] # random hex address existing in genesis 188 [[ "$output" == *"253319000000000000000"* ]] # random address balance existing in genesis 189 } 190 @test "dump 0 fff7ac99c8e4feb60c9750054bdc14ce1857f181 | exit 0" { 191 cp -a $BATS_TEST_DIRNAME/../../cmd/geth/testdata/testdatadir/. $DATA_DIR/ 192 run $GETH_CMD --data-dir $DATA_DIR dump 0 fff7ac99c8e4feb60c9750054bdc14ce1857f181 193 echo "$output" 194 [ "$status" -eq 0 ] 195 [[ "$output" == *"root"* ]] # block state root 196 [[ "$output" == *"balance"* ]] 197 [[ "$output" == *"accounts"* ]] 198 [[ "$output" == *"d7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544"* ]] # block state root 199 [[ "$output" == *"fff7ac99c8e4feb60c9750054bdc14ce1857f181"* ]] # hex address 200 [[ "$output" == *"1000000000000000000000"* ]] # address balance 201 } 202 @test "dump 0 fff7ac99c8e4feb60c9750054bdc14ce1857f181,0xffe8cbc1681e5e9db74a0f93f8ed25897519120f | exit 0" { 203 cp -a $BATS_TEST_DIRNAME/../../cmd/geth/testdata/testdatadir/. $DATA_DIR/ 204 run $GETH_CMD --data-dir $DATA_DIR dump 0 fff7ac99c8e4feb60c9750054bdc14ce1857f181,0xffe8cbc1681e5e9db74a0f93f8ed25897519120f 205 echo "$output" 206 [ "$status" -eq 0 ] 207 [[ "$output" == *"root"* ]] # block state root 208 [[ "$output" == *"balance"* ]] 209 [[ "$output" == *"accounts"* ]] 210 [[ "$output" == *"d7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544"* ]] # block 0 state root 211 212 [[ "$output" == *"fff7ac99c8e4feb60c9750054bdc14ce1857f181"* ]] # hex address 213 [[ "$output" == *"1000000000000000000000"* ]] # address balance 214 215 [[ "$output" == *"ffe8cbc1681e5e9db74a0f93f8ed25897519120f"* ]] # hex address 216 [[ "$output" == *"1507000000000000000000"* ]] # address balance 217 } 218 219 @test "dump 0,1 fff7ac99c8e4feb60c9750054bdc14ce1857f181,0xffe8cbc1681e5e9db74a0f93f8ed25897519120f | exit 0" { 220 cp -a $BATS_TEST_DIRNAME/../../cmd/geth/testdata/testdatadir/. $DATA_DIR/ 221 run $GETH_CMD --data-dir $DATA_DIR dump 0,1 fff7ac99c8e4feb60c9750054bdc14ce1857f181,0xffe8cbc1681e5e9db74a0f93f8ed25897519120f 222 echo "$output" 223 [ "$status" -eq 0 ] 224 [[ "$output" == *"root"* ]] # block state root 225 [[ "$output" == *"balance"* ]] 226 [[ "$output" == *"accounts"* ]] 227 228 [[ "$output" == *"d7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544"* ]] # block 0 state root 229 [[ "$output" == *"d67e4d450343046425ae4271474353857ab860dbc0a1dde64b41b5cd3a532bf3"* ]] # block 1 state root 230 231 [[ "$output" == *"fff7ac99c8e4feb60c9750054bdc14ce1857f181"* ]] # hex address 232 [[ "$output" == *"1000000000000000000000"* ]] # address balance 233 234 [[ "$output" == *"ffe8cbc1681e5e9db74a0f93f8ed25897519120f"* ]] # hex address 235 [[ "$output" == *"1507000000000000000000"* ]] # address balance 236 } 237 @test "dump 0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3 fff7ac99c8e4feb60c9750054bdc14ce1857f181,0xffe8cbc1681e5e9db74a0f93f8ed25897519120f | exit 0" { 238 cp -a $BATS_TEST_DIRNAME/../../cmd/geth/testdata/testdatadir/. $DATA_DIR/ 239 run $GETH_CMD --data-dir $DATA_DIR dump 0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3 fff7ac99c8e4feb60c9750054bdc14ce1857f181,0xffe8cbc1681e5e9db74a0f93f8ed25897519120f 240 echo "$output" 241 [ "$status" -eq 0 ] 242 [[ "$output" == *"root"* ]] # block state root 243 [[ "$output" == *"balance"* ]] 244 [[ "$output" == *"accounts"* ]] 245 246 [[ "$output" == *"d7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544"* ]] # block 0 state root 247 248 [[ "$output" == *"fff7ac99c8e4feb60c9750054bdc14ce1857f181"* ]] # hex address 249 [[ "$output" == *"1000000000000000000000"* ]] # address balance 250 251 [[ "$output" == *"ffe8cbc1681e5e9db74a0f93f8ed25897519120f"* ]] # hex address 252 [[ "$output" == *"1507000000000000000000"* ]] # address balance 253 } 254 255 # Ensure --testnet and --chain=morden/testnet set up respective subdirs with default 'morden' 256 @test "--chain=testnet creates /morden subdir, activating testnet genesis" { # This is kind of weird, but it is expected. 257 run $GETH_CMD --data-dir $DATA_DIR --chain=testnet --exec 'eth.getBlock(0).hash' console 258 [ "$status" -eq 0 ] 259 260 [[ "$output" == *"0x0cd786a2425d16f152c658316c423e6ce1181e15c3295826d7c9904cba9ce303"* ]] 261 262 [ -d $DATA_DIR/morden ] 263 } 264 265 @test "--testnet creates /morden subdir, activating testnet genesis" { 266 run $GETH_CMD --data-dir $DATA_DIR --testnet --exec 'eth.getBlock(0).hash' console 267 [ "$status" -eq 0 ] 268 [[ "$output" == *"0x0cd786a2425d16f152c658316c423e6ce1181e15c3295826d7c9904cba9ce303"* ]] 269 270 [ -d $DATA_DIR/morden ] 271 } 272 273 @test "--chain=morden creates /morden subdir, activating testnet genesis" { 274 run $GETH_CMD --data-dir $DATA_DIR --chain=morden --exec 'eth.getBlock(0).hash' console 275 [ "$status" -eq 0 ] 276 [[ "$output" == *"0x0cd786a2425d16f152c658316c423e6ce1181e15c3295826d7c9904cba9ce303"* ]] 277 278 [ -d $DATA_DIR/morden ] 279 } 280 281 # Command: status 282 @test "status command present and true for mainnet" { 283 run $GETH_CMD --data-dir $DATA_DIR status 284 [ "$status" -eq 0 ] 285 286 # bug(whilei): warning: command substitution: ignored null byte in input 287 # When I tried using heredoc and other more elegant solutions than line-by-line checking. 288 289 # Chain Configuration Genesis 290 echo "$output" 291 [[ "$output" == *"mainnet"* ]] 292 [[ "$output" == *"Ethereum Classic Mainnet"* ]] 293 [[ "$output" == *"Genesis"* ]] 294 [[ "$output" == *"0x0000000000000042"* ]] 295 [[ "$output" == *"0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa"* ]] 296 [[ "$output" == *"0x1388"* ]] 297 [[ "$output" == *"0x0400000000"* ]] 298 [[ "$output" == *"8893"* ]] 299 300 # Run twice, because the second time will have set up database. 301 run $GETH_CMD --data-dir $DATA_DIR --exec 'exit' console # set up db 302 [ "$status" -eq 0 ] 303 run $GETH_CMD --data-dir $DATA_DIR status 304 [ "$status" -eq 0 ] 305 306 # Chain database Genesis 307 echo "$output" 308 [[ "$output" == *"Genesis"* ]] 309 [[ "$output" == *"0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3"* ]] 310 [[ "$output" == *"0x0000000000000000000000000000000000000000000000000000000000000000"* ]] 311 [[ "$output" == *"66"* ]] 312 [[ "$output" == *"17179869184"* ]] 313 [[ "$output" == *"0x0000000000000000000000000000000000000000"* ]] 314 [[ "$output" == *"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"* ]] 315 [[ "$output" == *"5000"* ]] 316 [[ "$output" == *"0"* ]] 317 [[ "$output" == *"[17 187 232 219 78 52 123 78 140 147 124 28 131 112 228 181 237 51 173 179 219 105 203 219 122 56 225 229 11 27 130 250]"* ]] 318 } 319 320 @test "status command present and true for morden" { 321 run $GETH_CMD --data-dir $DATA_DIR --chain morden status 322 [ "$status" -eq 0 ] 323 324 # bug(whilei): warning: command substitution: ignored null byte in input 325 # When I tried using heredoc and other more elegant solutions than line-by-line checking. 326 327 # Chain Configuration Genesis 328 [[ "$output" == *"Genesis"* ]] 329 [[ "$output" == *"morden"* ]] 330 [[ "$output" == *"Morden Testnet"* ]] 331 [[ "$output" == *"0x2FEFD8"* ]] 332 [[ "$output" == *"0x020000"* ]] 333 [[ "$output" == *"5"* ]] 334 335 # Run twice, because the second time will have set up database. 336 run $GETH_CMD --data-dir $DATA_DIR --chain morden --exec 'exit' console # set up db 337 [ "$status" -eq 0 ] 338 run $GETH_CMD --data-dir $DATA_DIR --chain morden status 339 [ "$status" -eq 0 ] 340 341 # Chain database Genesis 342 [[ "$output" == *"Genesis"* ]] 343 [[ "$output" == *"0x0cd786a2425d16f152c658316c423e6ce1181e15c3295826d7c9904cba9ce303"* ]] 344 [[ "$output" == *"0x0000000000000000000000000000000000000000000000000000000000000000"* ]] 345 [[ "$output" == *"120325427979630"* ]] 346 [[ "$output" == *"131072"* ]] 347 [[ "$output" == *"0x0000000000000000000000000000000000000000"* ]] 348 [[ "$output" == *"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"* ]] 349 [[ "$output" == *"3141592"* ]] 350 [[ "$output" == *"0"* ]] 351 [[ "$output" == *"[]"* ]] 352 }