Skip to content

Commit

Permalink
Make softfork test script more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
bip-42 committed Nov 26, 2019
1 parent 05d87de commit 6a499ec
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions test/softfork_test.sh
@@ -1,19 +1,22 @@
#!/bin/bash

# this testing script requires jq

cleanup () {
rm -rf /path/to/datadir/regtest
agt_cli stop
rm -rf "$datadir"
}

mine_block () {
agt_cli generatetoaddress 1 "$1" 1>/dev/null
agt_cli generatetoaddress 1 "$1" 1>/dev/null
(( "timestamp+=10" ))
agt_cli setmocktime "$timestamp"
}

dummy_mine () {
mine_block "$other_address" > /dev/null 2>&1
}

agt_cli () {
src/argentumnt-cli -regtest -datadir=/path/to/datadir "$@"
src/argentumnt-cli -regtest -datadir="$datadir" "$@"
}

get_status () {
Expand All @@ -25,7 +28,7 @@ get_height () {
}

start_server () {
src/argentumntd -daemon -regtest -datadir=/path/to/datadir -txindex -blockversion="$1"
src/argentumntd -daemon -regtest -datadir="$datadir" -txindex -blockversion="$1"
sleep 3
}

Expand All @@ -41,6 +44,15 @@ assert_string_eql () {
fi
}

if ! command -v jq > /dev/null; then
echo please install jq
exit 1
fi

trap cleanup EXIT

datadir=$(mktemp -d)

# 0X20000000
bip9_flag_unset=536870912
# 0X20000004 (third bit)
Expand Down Expand Up @@ -81,10 +93,10 @@ start_server $bip9_flag_unset
# for any but the first server startups, the first generatetoaddress
# mine fails ("time-too-old").
# It is likely connected to the hacky use of setmocktime, which is itself
# necessitated by the validation rule that block times must strictly
# necessitated by the validation rule that block times must strictly
# monotonically increase.
# We therefore call mine_block once whenever we restart the server.
mine_block $other_address
dummy_mine

end=$((miner_confirmation_window - change_activation_threshold + 1))
for _ in $(seq 1 $end); do
Expand All @@ -95,7 +107,7 @@ assert_string_eql '"started"' "$(get_status)"

stop_server
start_server $bip9_flag_set
mine_block $other_address
dummy_mine

##### Mine enough blocks to lock in
end=$((change_activation_threshold))
Expand All @@ -105,7 +117,7 @@ done

stop_server
start_server $bip9_flag_unset
mine_block $other_address
dummy_mine

##### Mine all but one of the rest of the blocks of activation window
end=$((miner_confirmation_window - change_activation_threshold - 1))
Expand All @@ -130,11 +142,8 @@ mine_block $other_address
assert_string_eql '"active"' "$(get_status)"

assert_string_eql '575' "$(get_height)"
mine_block $other_address
mine_block $other_address > /dev/null 2>&1
assert_string_eql '575' "$(get_height)"

mine_block $whitelisted_address
assert_string_eql '576' "$(get_height)"

stop_server
cleanup

0 comments on commit 6a499ec

Please sign in to comment.