daemon/test: test stealing.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2016-05-06 12:00:30 +09:30
parent 5e40b264dd
commit d6603adc2f
3 changed files with 31 additions and 1 deletions

View File

@ -187,7 +187,7 @@ $(HELPER_OBJS) $(BITCOIN_OBJS) $(TEST_PROGRAMS:=.o): $(BITCOIN_HEADERS) $(CORE_H
# These don't work in parallel, so we open-code them
daemon-tests: daemon-all
daemon/test/scripts/shutdown.sh 2>/dev/null || true
set -e; for arg in "--dump-onchain" "" "--timeout-anchor"; do daemon/test/test.sh $$arg; done
set -e; for arg in "--steal" "--dump-onchain" "" "--timeout-anchor"; do daemon/test/test.sh $$arg; done
test-onion: test/test_onion test/onion_key
set -e; TMPF=/tmp/onion.$$$$; test/test_onion --generate $$(test/onion_key --pub `seq 20`) > $$TMPF; for k in `seq 20`; do test/test_onion --decode $$(test/onion_key --priv $$k) < $$TMPF > $$TMPF.unwrap; mv $$TMPF.unwrap $$TMPF; done; rm -f $$TMPF

View File

@ -945,6 +945,7 @@ static void resolve_cheating(struct peer *peer)
n = 0;
if (ci->map[0] != -1) {
connect_input(ci, &steal_tx->input[n], ci->map[0]);
peer->closing_onchain.resolved[0] = steal_tx;
wscripts[n++]
= bitcoin_redeem_secret_or_delay(wscripts,
&peer->them.finalkey,

View File

@ -52,6 +52,9 @@ while [ $# != 0 ]; do
x"--dump-onchain")
DUMP_ONCHAIN=1
;;
x"--steal")
STEAL=1
;;
x"--verbose")
VERBOSE=1
;;
@ -354,6 +357,11 @@ check_status_single lcli2 $B_AMOUNT $B_FEE "" $A_AMOUNT $A_FEE '{ "msatoshis" :
lcli2 commit $ID1
check_status $A_AMOUNT $A_FEE '{ "msatoshis" : '$HTLC_AMOUNT', "expiry" : { "second" : '$EXPIRY' }, "rhash" : "'$RHASH'" } ' $B_AMOUNT $B_FEE ""
if [ -n "$STEAL" ]; then
$LCLI1 dev-signcommit $ID2 >&2
STEAL_TX=`$LCLI1 dev-signcommit $ID2 | cut -d\" -f4`
fi
if [ -n "$DUMP_ONCHAIN" ]; then
# make node1 disconnect with node2.
lcli1 dev-disconnect $ID2
@ -456,6 +464,27 @@ A_AMOUNT=$(($A_AMOUNT + $EXTRA_FEE + $HTLC_AMOUNT))
A_FEE=$(($A_FEE - $EXTRA_FEE))
check_status $A_AMOUNT $A_FEE "" $B_AMOUNT $B_FEE ""
if [ -n "$STEAL" ]; then
# Send out old commit tx from peer 1.
$CLI sendrawtransaction $STEAL_TX
$CLI generate 1
# Node1 should get really upset; node2 should steal the transaction.
check_peerstate lcli1 STATE_ERR_INFORMATION_LEAK
check_peerstate lcli2 STATE_CLOSE_ONCHAIN_CHEATED
check_tx_spend
# Give it 100 blocks.
$CLI generate 100
check_no_peers lcli2
lcli1 stop
lcli2 stop
all_ok
fi
lcli1 close $ID2
# They should be waiting for close.