github.com/ethereumproject/go-ethereum@v5.5.2+incompatible/tests/bats/migrate_datadir.bats (about) 1 #!/usr/bin/env bats 2 3 # Current build. 4 : ${GETH_CMD:=$GOPATH/bin/geth} 5 6 setup() { 7 8 # A temporary place to hold current test datadir. 9 DATA_DIR=`mktemp -d` 10 11 # Create a static place to put different downloaded geth executable versions. 12 # We will remove this after the last test. 13 CMD_DIR="$HOME"/bats-tests-cmd 14 if ! [ -d "$CMD_DIR" ]; then 15 mkdir -p "$HOME"/bats-tests-cmd 16 fi 17 18 # Fake tempdir as home so geth defaults install in temporary place. 19 HOME_DEF="$HOME" 20 HOME="$DATA_DIR" 21 22 # Decide OS var for release download links. 23 TEST_OS_HF=placeholder 24 TEST_OS_C=placeholder 25 DATA_DIR_PARENT=placeholder 26 DATA_DIR_NAME=placeholder 27 DATA_DIR_NAME_EX=placeholder 28 # http://stackoverflow.com/questions/3466166/how-to-check-if-running-in-cygwin-mac-or-linux 29 if [ "$(uname)" == "Darwin" ]; then 30 # Do something under Mac OS X platform 31 TEST_OS_HF=darwin 32 TEST_OS_C=osx 33 DATA_DIR_PARENT="$HOME/Library" 34 DATA_DIR_NAME_EX="Ethereum" 35 DATA_DIR_NAME="EthereumClassic" 36 elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then 37 # Do something under GNU/Linux platform 38 TEST_OS_HF=linux 39 TEST_OS_C=linux 40 DATA_DIR_PARENT="$HOME" 41 DATA_DIR_NAME_EX=".ethereum" 42 DATA_DIR_NAME=".ethereum-classic" 43 elif [ "$(expr substr $(uname -s) 1 10)" == "MINGW32_NT" ]; then 44 # Do something under 32 bits Windows NT platform 45 echo "Win32 not supported." 46 exit 1 47 elif [ "$(expr substr $(uname -s) 1 10)" == "MINGW64_NT" ]; then 48 # Do something under 64 bits Windows NT platform 49 TEST_OS_HF=windows 50 TEST_OS_C=win64 51 DATA_DIR_PARENT="$HOME/AppData/Roaming" 52 DATA_DIR_NAME_EX="Ethereum" 53 DATA_DIR_NAME="EthereumClassic" 54 fi 55 56 # Only install everything once. 57 # BATS_TEST_NUMBER is 1-indexed. 58 if [ "$BATS_TEST_NUMBER" -eq 1 ]; then 59 60 TMP_DIR="$BATS_TMPDIR" 61 # Install 1.6 and 1.5 of Ethereum Geth 62 # Travis Linux+Mac, AppVeyor Windows all use amd64. 63 curl -o "$TMP_DIR/gethf1.6.tar.gz" https://gethstore.blob.core.windows.net/builds/geth-"$TEST_OS_HF"-amd64-1.6.0-facc47cb.tar.gz 64 curl -o "$TMP_DIR/gethf1.5.tar.gz" https://gethstore.blob.core.windows.net/builds/geth-"$TEST_OS_HF"-amd64-1.5.0-c3c58eb6.tar.gz 65 tar xf "$TMP_DIR/gethf1.6.tar.gz" -C "$TMP_DIR" 66 tar xf "$TMP_DIR/gethf1.5.tar.gz" -C "$TMP_DIR" 67 mv "$TMP_DIR/geth-$TEST_OS_HF-amd64-1.6.0-facc47cb/geth" "$CMD_DIR/gethf1.6" 68 mv "$TMP_DIR/geth-$TEST_OS_HF-amd64-1.5.0-c3c58eb6/geth" "$CMD_DIR/gethf1.5" 69 70 # Install 3.3 of EthereumClassic Geth 71 curl -L -o "$TMP_DIR/gethc3.3.zip" https://github.com/ethereumproject/go-ethereum/releases/download/v3.3.0/geth-classic-"$TEST_OS_C"-v3.3.0-1-gdd95f05.zip 72 unzip "$TMP_DIR/gethc3.3.zip" -d "$TMP_DIR" 73 mv "$TMP_DIR/geth" "$CMD_DIR/gethc3.3" 74 75 fi 76 } 77 78 teardown() { 79 rm -rf $DATA_DIR 80 81 # Put back original. 82 HOME="$HOME_DEF" 83 84 # 13 is last test. 85 # Important: You must update this number if the number of tests change. 86 if [ "$BATS_TEST_NUMBER" -eq 11 ]; then 87 # Remove downloaded executables. 88 rm -rf "$CMD_DIR" 89 90 unset TMP_DIR 91 unset CMD_DIR 92 fi 93 } 94 95 # Migrate ETC. 96 # mainnet 97 @test "should migrate datadir /Ethereum/ -> /EthereumClassic/ from ETC3.3 schema" { 98 # Should create $HOME/Ethereum/chaindata,keystore,nodes,... 99 run "$CMD_DIR/gethc3.3" --fast --exec='exit' console 100 echo "$output" 101 [ "$status" -eq 0 ] 102 103 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX" ] 104 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX"/chaindata ] # 3.3 schema 105 106 run $GETH_CMD --fast --verbosity 5 --exec='exit' console 107 echo "$output" 108 [ "$status" -eq 0 ] 109 110 # Ensure datadir is renamed. 111 ! [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX" ] 112 113 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME" ] 114 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME"/mainnet ] 115 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME"/mainnet/chaindata ] 116 ! [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME"/chaindata ] 117 118 [[ "$output" == *"Moving it from"* ]] 119 } 120 121 @test "should migrate datadir /Ethereum/ -> /EthereumClassic/ from ETC3.3 schema | --chain=mainnet" { 122 # Should create $HOME/Ethereum/testnet/chaindata,keystore,nodes,... 123 run "$CMD_DIR/gethc3.3" --fast --exec='exit' console 124 echo "$output" 125 [ "$status" -eq 0 ] 126 127 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX" ] 128 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX"/chaindata ] 129 130 run $GETH_CMD --fast --verbosity 5 --chain mainnet --exec='exit' console 131 echo "$output" 132 [ "$status" -eq 0 ] 133 134 # Ensure datadir is renamed. 135 ! [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX" ] 136 137 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME" ] 138 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME"/mainnet ] 139 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME"/mainnet/chaindata ] 140 141 [[ "$output" == *"Moving it from"* ]] 142 } 143 144 # testnet 145 @test "should migrate datadir /Ethereum/testnet -> /EthereumClassic/ from ETC3.3 schema | --chain=morden" { 146 # Should create $HOME/Ethereum/testnet/chaindata,keystore,nodes,... 147 run "$CMD_DIR/gethc3.3" --fast --testnet --exec='exit' console 148 echo "$output" 149 [ "$status" -eq 0 ] 150 151 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX" ] 152 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX"/testnet ] # 3.3 schema 153 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX"/testnet/chaindata ] 154 155 run $GETH_CMD --fast --verbosity 5 --chain morden --exec='exit' console 156 echo "$output" 157 [ "$status" -eq 0 ] 158 159 # Ensure datadir is renamed. 160 ! [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX" ] 161 162 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME" ] 163 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME"/morden ] 164 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME"/morden/chaindata ] 165 ! [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME"/testnet ] 166 167 [[ "$output" == *"Moving it from"* ]] 168 } 169 170 # testnet 171 @test "shouldnot migrate datadir /Ethereum/testnet -> /EthereumClassic/ from ETC3.3 schema | --chain=mainnet" { 172 # Should create $HOME/Ethereum/testnet/chaindata,keystore,nodes,... 173 run "$CMD_DIR/gethc3.3" --fast --testnet --exec='exit' console 174 echo "$output" 175 [ "$status" -eq 0 ] 176 177 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX" ] 178 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX"/testnet ] # 3.3 schema 179 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX"/testnet/chaindata ] 180 181 run $GETH_CMD --fast --verbosity 5 --chain mainnet --exec='exit' console 182 echo "$output" 183 [ "$status" -eq 0 ] 184 185 # Ensure datadir is NOT renamed. 186 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX" ] 187 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX"/testnet ] # 3.3 schema 188 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX"/testnet/chaindata ] 189 190 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME" ] 191 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME"/mainnet ] 192 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME"/mainnet/chaindata ] 193 ! [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME"/testnet ] 194 } 195 196 # customnet 197 @test "shouldnot migrate datadir /Ethereum/ -> /EthereumClassic/ from ETC3.3 schema | --chain kitty" { 198 199 # Should create $HOME/Ethereum/chaindata,keystore,nodes,... 200 run "$CMD_DIR/gethc3.3" --fast --exec='exit' console 201 echo "$output" 202 [ "$status" -eq 0 ] 203 204 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX" ] 205 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX"/chaindata ] # 3.3 schema 206 207 # Set up custom net config. 208 mkdir -p $DATA_DIR_PARENT/$DATA_DIR_NAME/kitty 209 cp $BATS_TEST_DIRNAME/../../core/config/mainnet.json $DATA_DIR_PARENT/$DATA_DIR_NAME/kitty/chain.json 210 cp $BATS_TEST_DIRNAME/../../core/config/mainnet_genesis.json $DATA_DIR_PARENT/$DATA_DIR_NAME/kitty/kitty_genesis.json 211 cp $BATS_TEST_DIRNAME/../../core/config/mainnet_bootnodes.json $DATA_DIR_PARENT/$DATA_DIR_NAME/kitty/kitty_bootnodes.json 212 cp $BATS_TEST_DIRNAME/../../core/config/mainnet_genesis_alloc.csv $DATA_DIR_PARENT/$DATA_DIR_NAME/kitty/kitty_genesis_alloc.csv 213 sed -i.bak s/mainnet/kitty/ $DATA_DIR_PARENT/$DATA_DIR_NAME/kitty/chain.json 214 sed -i.bak s/mainnet/kitty/ $DATA_DIR_PARENT/$DATA_DIR_NAME/kitty/kitty_genesis.json 215 216 run $GETH_CMD --fast --verbosity 5 --chain kitty --ipc-disable --exec='exit' console 217 echo "$output" 218 [ "$status" -eq 0 ] 219 220 # Ensure datadir is not renamed. 221 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX" ] 222 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX"/chaindata ] 223 224 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME" ] 225 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME"/kitty ] 226 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME"/kitty/chaindata ] 227 ! [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME"/chaindata ] 228 } 229 230 # datadir 231 @test "shouldnot migrate datadir /Ethereum/ -> /EthereumClassic/ from ETC3.3 schema | --datadir data" { 232 run "$CMD_DIR/gethc3.3" --fast --exec='exit' console 233 echo "$output" 234 [ "$status" -eq 0 ] 235 236 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX" ] 237 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX"/chaindata ] 238 239 run $GETH_CMD --fast --verbosity 5 --datadir "$DATA_DIR/data" --exec='exit' console 240 echo "$output" 241 [ "$status" -eq 0 ] 242 243 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX" ] 244 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX"/chaindata ] 245 246 [ -d "$DATA_DIR"/data ] 247 [ -d "$DATA_DIR"/data/mainnet ] 248 [ -d "$DATA_DIR"/data/mainnet/chaindata ] 249 } 250 251 # chainconfig INVALID 252 @test "shouldnot migrate datadir /Ethereum/ -> /EthereumClassic/ from ETC3.3 schema | --chain kitty (invalid config)" { 253 run "$CMD_DIR/gethc3.3" --fast --exec='exit' console 254 echo "$output" 255 [ "$status" -eq 0 ] 256 257 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX" ] 258 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX"/chaindata ] 259 260 # Set up custom net config. 261 mkdir -p $DATA_DIR_PARENT/$DATA_DIR_NAME/kitty 262 cp "$GOPATH/src/github.com/ethereumproject/go-ethereum/cmd/geth/testdata/chain_config_dump-invalid-coinbase.json" $DATA_DIR_PARENT/$DATA_DIR_NAME/kitty/chain.json 263 sed -i.bak s/mainnet/kitty/ $DATA_DIR_PARENT/$DATA_DIR_NAME/kitty/chain.json 264 265 run $GETH_CMD --fast --verbosity 5 --chain kitty --exec='exit' console 266 echo "$output" 267 [ "$status" -gt 0 ] 268 269 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX" ] 270 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX"/chaindata ] 271 272 ! [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME" ] 273 ! [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME"/mainnet ] 274 ! [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME"/mainnet/chaindata ] 275 } 276 277 # Don't migrate ETHF. 278 @test "shouldnot migrate datadir /Ethereum/ -> /EthereumClassic/ from ETHF1.5 schema" { 279 run "$CMD_DIR/gethf1.5" --fast --verbosity 5 --exec='exit' console 280 echo "$output" 281 [ "$status" -eq 0 ] 282 283 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX" ] 284 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX"/geth ] 285 286 run $GETH_CMD --fast --verbosity 5 --exec='exit' console 287 echo "$output" 288 [ "$status" -eq 0 ] 289 290 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX" ] 291 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX"/geth ] 292 293 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME" ] 294 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME"/mainnet ] 295 } 296 297 @test "shouldnot migrate datadir /Ethereum/ -> /EthereumClassic/ from ETHF1.6 schema" { 298 run "$CMD_DIR/gethf1.6" --fast --verbosity 5 --exec='exit' console 299 echo "$output" 300 [ "$status" -eq 0 ] 301 302 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX" ] 303 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX"/geth ] 304 305 run $GETH_CMD --fast --verbosity 5 --exec='exit' console 306 echo "$output" 307 [ "$status" -eq 0 ] 308 309 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX" ] 310 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX"/geth ] 311 312 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME" ] 313 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME"/mainnet ] 314 } 315 316 @test "shouldnot migrate datadir /Ethereum/ -> /EthereumClassic/ from ETC3.3 schema without any ETC data in it" { 317 318 mkdir -p "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX"/{chaindata,nodes,dapp,keystore} # We're on Bash 4.0, right? 319 echo "bellow word" > "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX"/nodekey 320 321 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX" ] 322 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX"/chaindata ] 323 324 run $GETH_CMD --fast --verbosity 5 --exec='exit' console 325 echo "$output" 326 [ "$status" -eq 0 ] 327 328 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX" ] 329 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX"/chaindata ] 330 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX"/nodes ] 331 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX"/dapp ] 332 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX"/keystore ] 333 [ -f "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX"/nodekey ] 334 335 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME" ] 336 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME"/mainnet ] 337 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME"/mainnet/chaindata ] 338 } 339 340 @test "shouldnot migrate datadir /Ethereum/ -> /EthereumClassic/ from ETHF schema without any ETH data in it" { 341 342 mkdir -p "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX"/geth # We're on Bash 4.0, right? 343 echo "bellow word" > "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX"/geth.ipc 344 345 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX" ] 346 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX"/geth ] 347 348 run $GETH_CMD --fast --verbosity 5 --exec='exit' console 349 echo "$output" 350 [ "$status" -eq 0 ] 351 352 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX" ] 353 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX"/geth ] 354 [ -f "$DATA_DIR_PARENT"/"$DATA_DIR_NAME_EX"/geth.ipc ] 355 356 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME" ] 357 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME"/mainnet ] 358 [ -d "$DATA_DIR_PARENT"/"$DATA_DIR_NAME"/mainnet/chaindata ] 359 }