github.com/tri-stone/burrow@v0.25.0/tests/dump/test.sh (about)

     1  #! /bin/bash
     2  
     3  # Test the dump restore functionality
     4  # 
     5  # Steps taken:
     6  # - Create a chain
     7  # - Create some code and events
     8  # - Dump chain
     9  # - Stop chain and delete
    10  # - Restore chain from dump
    11  # - Check all bits are present (account, namereg, code, events)
    12  #
    13  
    14  set -e
    15  
    16  burrow_dump="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
    17  tmp_dir=$(mktemp -d 2>/dev/null || mktemp -d -t 'tmpdumpXXX')
    18  trap "rm -f $tmp_dir" EXIT
    19  cd $tmp_dir
    20  rm -rf .burrow genesis.json burrow.toml burrow.log
    21  
    22  burrow_bin=${burrow_bin:-burrow}
    23  
    24  echo "------------------------------------"
    25  echo "Creating new chain..."
    26  echo "------------------------------------"
    27  
    28  $burrow_bin spec -n "Fresh Chain" -v1 | $burrow_bin configure -m BurrowTestDumpNode -s- -w genesis.json > burrow.toml
    29  
    30  $burrow_bin start 2>> burrow.log &
    31  burrow_pid=$!
    32  function kill_burrow {
    33  	kill -KILL $burrow_pid
    34  	rm -rf $tmp_dir
    35  }
    36  trap kill_burrow EXIT
    37  
    38  sleep 1
    39  
    40  echo "------------------------------------"
    41  echo "Creating code, events and names..."
    42  echo "------------------------------------"
    43  
    44  $burrow_bin deploy -o '' -a Validator_0 --dir $burrow_dump deploy.yaml
    45  
    46  
    47  echo "------------------------------------"
    48  echo "Dumping chain..."
    49  echo "------------------------------------"
    50  
    51  $burrow_bin dump dump.bin
    52  $burrow_bin dump -j dump.json
    53  height=$(head -1  dump.json | jq .Height)
    54  
    55  kill $burrow_pid
    56  
    57  # Now we have a dump with out stuff in it. Delete everything apart from
    58  # the dump and the keys
    59  mv genesis.json genesis-original.json
    60  rm -rf .burrow burrow.toml
    61  
    62  echo "------------------------------------"
    63  echo "Create new chain based of dump with new name..."
    64  echo "------------------------------------"
    65  
    66  $burrow_bin configure -m BurrowTestRestoreNode -n "Restored Chain" -g genesis-original.json -w genesis.json --restore-dump dump.json > burrow.toml
    67  
    68  $burrow_bin restore dump.json
    69  $burrow_bin start 2>> burrow.log &
    70  burrow_pid=$!
    71  sleep 13
    72  
    73  echo "------------------------------------"
    74  echo "Dumping restored chain for comparison..."
    75  echo "------------------------------------"
    76  
    77  burrow dump -j --height $height dump-after-restore.json
    78  
    79  kill $burrow_pid
    80  
    81  if cmp dump.json dump-after-restore.json
    82  then
    83  	echo "------------------------------------"
    84  	echo "Done."
    85  	echo "------------------------------------"
    86  else
    87  	echo "RESTORE FAILURE"
    88  	echo "restored dump is different"
    89  	diff -u dump.json dump-after-restore.json
    90  	exit 1
    91  fi