test-cli/scripts/test.sh: send_after_delay()

Extract and generalize: we're about to get more.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2015-07-24 16:00:10 +09:30
parent 6a5ba591ee
commit 114161a6a5

View File

@ -14,6 +14,28 @@ getprivkey()
$CLI dumpprivkey $1
}
send_after_delay()
{
# For bitcoin testing, OP_CHECKSEQUENCEVERIFY is a NOP.
if [ $STYLE = alpha ]; then
# Alpha has a median time bug (which can't be triggered in bitcoin),
# triggered if we have < 11 blocks. Generate them now.
for i in `seq 11`; do scripts/generate-block.sh; done
# OP_CHECKSEQUENCEVERIFY will stop us spending for 60 seconds.
if $CLI sendrawtransaction $1 2>/dev/null; then
echo OP_CHECKSEQUENCEVERIFY broken! >&2
exit 1
fi
# Mine it.
scripts/generate-block.sh
echo Waiting for CSV timeout. >&2
sleep 61
# Move median time, for sure!
for i in `seq 11`; do scripts/generate-block.sh; done
fi
$CLI sendrawtransaction $1
}
if [ $# -lt 2 ]; then
echo Usage: "INPUT1" "INPUT2" "[--steal|--unilateral]" >&2
exit 1
@ -125,24 +147,7 @@ fi
if [ x"$1" = x--unilateral ]; then
$CLI sendrawtransaction `cut -d: -f1 A-commit-2.tx` > A-commit-2.txid
$PREFIX ./create-commit-spend-tx A-commit-2.tx A-open.pb B-open.pb $A_FINALKEY $A_CHANGEPUBKEY A-update-1.pb A-update-2.pb > A-spend.tx
# For bitcoin testing, OP_CHECKSEQUENCEVERIFY is a NOP.
if [ $STYLE = alpha ]; then
# Alpha has a median time bug (which can't be triggered in bitcoin),
# triggered if we have < 11 blocks. Generate them now.
for i in `seq 11`; do scripts/generate-block.sh; done
# OP_CHECKSEQUENCEVERIFY will stop us spending for 60 seconds.
if $CLI sendrawtransaction `cut -d: -f1 A-spend.tx` 2>/dev/null; then
echo OP_CHECKSEQUENCEVERIFY broken! >&2
exit 1
fi
# Mine it.
scripts/generate-block.sh
echo Waiting for CSV timeout. >&2
sleep 61
# Move median time, for sure!
for i in `seq 11`; do scripts/generate-block.sh; done
fi
$CLI sendrawtransaction `cut -d: -f1 A-spend.tx` > A-spend.txid
send_after_delay `cut -d: -f1 A-spend.tx` > A-spend.txid
exit 0
fi