From 114161a6a5f538d674b1e3c1a81aa20a20495999 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 24 Jul 2015 16:00:10 +0930 Subject: [PATCH] test-cli/scripts/test.sh: send_after_delay() Extract and generalize: we're about to get more. Signed-off-by: Rusty Russell --- test-cli/scripts/test.sh | 41 ++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/test-cli/scripts/test.sh b/test-cli/scripts/test.sh index 72e9fa4a7..fdf363e75 100755 --- a/test-cli/scripts/test.sh +++ b/test-cli/scripts/test.sh @@ -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