diff --git a/daemon/test/test.sh b/daemon/test/test.sh index 0475f8eea..ad098d888 100755 --- a/daemon/test/test.sh +++ b/daemon/test/test.sh @@ -110,9 +110,8 @@ check() # Try making time pass for the nodes (if on mocktime), then sleeping. if [ -n "$MOCKTIME" ]; then MOCKTIME=$(($MOCKTIME + 1)) - # Some tests kill nodes, so ignore failure here. - lcli1 dev-mocktime $MOCKTIME > /dev/null 2>&1 || true - lcli2 dev-mocktime $MOCKTIME > /dev/null 2>&1 || true + lcli1 dev-mocktime $MOCKTIME + lcli2 dev-mocktime $MOCKTIME fi sleep 1 i=$(($i + 1)) @@ -599,6 +598,38 @@ A_AMOUNT=$(($A_AMOUNT + $HTLC_AMOUNT)) B_AMOUNT=$(($B_AMOUNT - $HTLC_AMOUNT)) check_status $A_AMOUNT $A_FEE "" $B_AMOUNT $B_FEE "" +# Now, test making more changes before receiving commit reply. +lcli2 dev-output $ID1 false +lcli1 newhtlc $ID2 $HTLC_AMOUNT $EXPIRY $RHASH + +# Make sure node1 sends commit (in the background, since it will block!) +[ ! -n "$MANUALCOMMIT" ] || lcli1 commit $ID2 & +# node2 will consider this committed. +check_status_single lcli2 $(($B_AMOUNT - $EXTRA_FEE/2)) $(($B_FEE + $EXTRA_FEE/2)) "" $(($A_AMOUNT - $HTLC_AMOUNT - $EXTRA_FEE/2)) $(($A_FEE + $EXTRA_FEE/2)) '{ "msatoshis" : '$HTLC_AMOUNT', "expiry" : { "second" : '$EXPIRY' }, "rhash" : "'$RHASH'" } ' + +# Now send another offer, and enable node2 output. +lcli1 newhtlc $ID2 $HTLC_AMOUNT $EXPIRY $RHASH2 +lcli2 dev-output $ID1 true + +[ ! -n "$MANUALCOMMIT" ] || lcli2 commit $ID1 +[ ! -n "$MANUALCOMMIT" ] || lcli1 commit $ID2 +[ ! -n "$MANUALCOMMIT" ] || lcli2 commit $ID1 + +# Both sides should be committed to htlcs +check_status $(($A_AMOUNT - $HTLC_AMOUNT*2 - $EXTRA_FEE)) $(($A_FEE + $EXTRA_FEE)) '{ "msatoshis" : '$HTLC_AMOUNT', "expiry" : { "second" : '$EXPIRY' }, "rhash" : "'$RHASH'" }, { "msatoshis" : '$HTLC_AMOUNT', "expiry" : { "second" : '$EXPIRY' }, "rhash" : "'$RHASH2'" } ' $(($B_AMOUNT - $EXTRA_FEE)) $(($B_FEE + $EXTRA_FEE)) "" + +# Node2 collects the HTLCs. +lcli2 fulfillhtlc $ID1 $SECRET +lcli2 fulfillhtlc $ID1 $SECRET2 + +[ ! -n "$MANUALCOMMIT" ] || lcli2 commit $ID1 +[ ! -n "$MANUALCOMMIT" ] || lcli1 commit $ID2 + +# We transferred 2 * amount from A to B. +A_AMOUNT=$(($A_AMOUNT - $HTLC_AMOUNT * 2)) +B_AMOUNT=$(($B_AMOUNT + $HTLC_AMOUNT * 2)) +check_status $A_AMOUNT $A_FEE "" $B_AMOUNT $B_FEE "" + lcli1 close $ID2 # They should be negotiating the close. diff --git a/test/commits/06-change-while-commit-outstanding.script b/test/commits/06-change-while-commit-outstanding.script new file mode 100644 index 000000000..65268b2e4 --- /dev/null +++ b/test/commits/06-change-while-commit-outstanding.script @@ -0,0 +1,28 @@ +# Test changes after committing but before receiving revocation. +A:offer 1 +B:recvoffer +A:commit +A:offer 3 + +# Now B receives that commitment and counter-commits. +B:recvcommit +B:commit + +A:recvrevoke +A:recvcommit +A:commit + +B:recvoffer +B:recvrevoke +B:recvcommit + +B:commit +A:recvrevoke +A:recvcommit +B:recvrevoke + +checksync +echo ***A*** +A:dump +echo ***B*** +B:dump diff --git a/test/commits/06-change-while-commit-outstanding.script.expected b/test/commits/06-change-while-commit-outstanding.script.expected new file mode 100644 index 000000000..e924275aa --- /dev/null +++ b/test/commits/06-change-while-commit-outstanding.script.expected @@ -0,0 +1,22 @@ +***A*** +LOCAL COMMITS: + Commit 2: + Offered htlcs: 1 3 + Received htlcs: + SIGNED +REMOTE COMMITS: + Commit 2: + Offered htlcs: + Received htlcs: 1 3 + SIGNED +***B*** +LOCAL COMMITS: + Commit 2: + Offered htlcs: + Received htlcs: 1 3 + SIGNED +REMOTE COMMITS: + Commit 2: + Offered htlcs: 1 3 + Received htlcs: + SIGNED