Browse Source

daemon/test: test stealing.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 9 years ago
parent
commit
d6603adc2f
  1. 2
      Makefile
  2. 1
      daemon/peer.c
  3. 29
      daemon/test/test.sh

2
Makefile

@ -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 # These don't work in parallel, so we open-code them
daemon-tests: daemon-all daemon-tests: daemon-all
daemon/test/scripts/shutdown.sh 2>/dev/null || true 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 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 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

1
daemon/peer.c

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

29
daemon/test/test.sh

@ -52,6 +52,9 @@ while [ $# != 0 ]; do
x"--dump-onchain") x"--dump-onchain")
DUMP_ONCHAIN=1 DUMP_ONCHAIN=1
;; ;;
x"--steal")
STEAL=1
;;
x"--verbose") x"--verbose")
VERBOSE=1 VERBOSE=1
;; ;;
@ -354,6 +357,11 @@ check_status_single lcli2 $B_AMOUNT $B_FEE "" $A_AMOUNT $A_FEE '{ "msatoshis" :
lcli2 commit $ID1 lcli2 commit $ID1
check_status $A_AMOUNT $A_FEE '{ "msatoshis" : '$HTLC_AMOUNT', "expiry" : { "second" : '$EXPIRY' }, "rhash" : "'$RHASH'" } ' $B_AMOUNT $B_FEE "" 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 if [ -n "$DUMP_ONCHAIN" ]; then
# make node1 disconnect with node2. # make node1 disconnect with node2.
lcli1 dev-disconnect $ID2 lcli1 dev-disconnect $ID2
@ -456,6 +464,27 @@ A_AMOUNT=$(($A_AMOUNT + $EXTRA_FEE + $HTLC_AMOUNT))
A_FEE=$(($A_FEE - $EXTRA_FEE)) A_FEE=$(($A_FEE - $EXTRA_FEE))
check_status $A_AMOUNT $A_FEE "" $B_AMOUNT $B_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 lcli1 close $ID2
# They should be waiting for close. # They should be waiting for close.

Loading…
Cancel
Save