From 97bc4ed0cb97b71aeb7ee4367094fddfa2e330ab Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 26 May 2016 15:25:24 +0930 Subject: [PATCH] daemon/test: test mutual close with outstanding HTLCS. Signed-off-by: Rusty Russell --- Makefile | 3 ++- daemon/test/test.sh | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 4ba037b31..d87a3556b 100644 --- a/Makefile +++ b/Makefile @@ -198,7 +198,8 @@ daemon-test-steal: daemon-test-dump-onchain daemon-test-dump-onchain: daemon-test-timeout-anchor daemon-test-timeout-anchor: daemon-test-normal daemon-test-normal: daemon-test-manual-commit -daemon-test-manual-commit: daemon-all +daemon-test-manual-commit: daemon-test-mutual-close-with-htlcs +daemon-test-mutual-close-with-htlcs: daemon-all daemon-tests: daemon-test-steal diff --git a/daemon/test/test.sh b/daemon/test/test.sh index 83fd34816..450728a87 100755 --- a/daemon/test/test.sh +++ b/daemon/test/test.sh @@ -58,6 +58,9 @@ while [ $# != 0 ]; do x"--manual-commit") MANUALCOMMIT=1 ;; + x"--mutual-close-with-htlcs") + CLOSE_WITH_HTLCS=1 + ;; x"--normal") ;; x"--verbose") @@ -544,6 +547,41 @@ lcli2 newhtlc $ID1 $HTLC_AMOUNT $EXPIRY $RHASH2 check_status $(($A_AMOUNT - $HTLC_AMOUNT - $EXTRA_FEE)) $(($A_FEE + $EXTRA_FEE)) '{ "msatoshis" : '$HTLC_AMOUNT', "expiry" : { "second" : '$EXPIRY' }, "rhash" : "'$RHASH'" } ' $(($B_AMOUNT - $HTLC_AMOUNT - $EXTRA_FEE)) $(($B_FEE + $EXTRA_FEE)) '{ "msatoshis" : '$HTLC_AMOUNT', "expiry" : { "second" : '$EXPIRY' }, "rhash" : "'$RHASH2'" } ' +if [ -n "$CLOSE_WITH_HTLCS" ]; then + # Now begin close + lcli1 close $ID2 + + # They should be waiting for it to clear up. + check_peerstate lcli1 STATE_CLEARING + check_peerstate lcli2 STATE_CLEARING + + # Fail one, still waiting. + lcli2 failhtlc $ID1 $RHASH + check_peerstate lcli1 STATE_CLEARING + check_peerstate lcli2 STATE_CLEARING + + # Fulfill the other causes them to actually complete the close. + lcli1 fulfillhtlc $ID2 $SECRET2 + check_peerstate lcli1 STATE_MUTUAL_CLOSING + check_peerstate lcli2 STATE_MUTUAL_CLOSING + + $CLI generate 1 + + check_peerstate lcli1 STATE_CLOSE_ONCHAIN_MUTUAL + check_peerstate lcli2 STATE_CLOSE_ONCHAIN_MUTUAL + + # Give it 100 blocks. + $CLI generate 99 + + check_no_peers lcli1 + check_no_peers lcli2 + + lcli1 stop + lcli2 stop + + all_ok +fi + lcli2 failhtlc $ID1 $RHASH lcli1 fulfillhtlc $ID2 $SECRET2 [ ! -n "$MANUALCOMMIT" ] || lcli2 commit $ID1