mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-20 10:39:49 +01:00
ce96812ef0
This significantly reduces re-testing of the same paths, and simplifies the addition of new tests. make check -j12 times: Before: 9m24.973s After: 7m52.005s Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
96 lines
2.7 KiB
Bash
Executable File
96 lines
2.7 KiB
Bash
Executable File
#! /bin/sh -e
|
|
|
|
# Wherever we are, we want to be in daemon/test dir.
|
|
cd `git rev-parse --show-toplevel`/daemon/test
|
|
|
|
. scripts/vars.sh
|
|
. scripts/helpers.sh
|
|
|
|
parse_cmdline 2 "$@"
|
|
setup_lightning 2
|
|
start_lightningd 2
|
|
|
|
lcli1 connect localhost $PORT2 $FUND_INPUT_TX &
|
|
|
|
# Now make it pass anchor (should be in mempool: one block to bury it)
|
|
check_tx_spend
|
|
$CLI generate 1
|
|
|
|
DO_RECONNECT=$RECONNECT
|
|
|
|
check_peerstate lcli1 STATE_NORMAL
|
|
check_peerstate lcli2 STATE_NORMAL
|
|
|
|
A_AMOUNT=$(($AMOUNT - $NO_HTLCS_FEE))
|
|
A_FEE=$NO_HTLCS_FEE
|
|
B_AMOUNT=0
|
|
B_FEE=0
|
|
|
|
# Send funds to 2 so it can offer HTLCS
|
|
HTLC_AMOUNT=100000000
|
|
RHASH=`lcli2 invoice $HTLC_AMOUNT RHASH3 | sed 's/.*"\([0-9a-f]*\)".*/\1/'`
|
|
ROUTE=`lcli1 getroute $ID2 $HTLC_AMOUNT 1`
|
|
ROUTE=`echo $ROUTE | sed 's/^{ "route" : \(.*\) }$/\1/'`
|
|
lcli1 sendpay "$ROUTE" $RHASH
|
|
|
|
# They pay half fees each.
|
|
A_AMOUNT=$(($A_AMOUNT - $HTLC_AMOUNT + $NO_HTLCS_FEE / 2))
|
|
A_FEE=$(($NO_HTLCS_FEE / 2))
|
|
B_AMOUNT=$(($B_AMOUNT + $HTLC_AMOUNT - $NO_HTLCS_FEE / 2))
|
|
B_FEE=$(($NO_HTLCS_FEE / 2))
|
|
check_status $A_AMOUNT $A_FEE "" $B_AMOUNT $B_FEE ""
|
|
|
|
# For next step, make sure neither node fails HTLCs we're about to set up.
|
|
lcli1 dev-routefail false
|
|
lcli2 dev-routefail false
|
|
|
|
# Set up HTLCs both ways.
|
|
|
|
# This is 10,000 satoshi, so not dust!
|
|
HTLC_AMOUNT=10000000
|
|
|
|
EXPIRY=$(( $(blockheight) + 10))
|
|
SECRET=1de08917a61cb2b62ed5937d38577f6a7bfe59c176781c6d8128018e8b5ccdfd
|
|
RHASH=`lcli1 dev-rhash $SECRET | sed 's/.*"\([0-9a-f]*\)".*/\1/'`
|
|
|
|
HTLCID1=`lcli1 dev-newhtlc $ID2 $HTLC_AMOUNT $EXPIRY $RHASH | extract_id`
|
|
|
|
# FIXME: Test with dust htlc, too.
|
|
HTLCID2=`lcli2 dev-newhtlc $ID1 $HTLC_AMOUNT $EXPIRY $RHASH | extract_id`
|
|
|
|
check_status $(($A_AMOUNT - $HTLC_AMOUNT - $EXTRA_FEE)) $(($A_FEE + $EXTRA_FEE)) "{ msatoshi : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : SENT_ADD_ACK_REVOCATION } " $(($B_AMOUNT - $HTLC_AMOUNT - $EXTRA_FEE)) $(($B_FEE + $EXTRA_FEE)) "{ msatoshi : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : RCVD_ADD_ACK_REVOCATION } "
|
|
|
|
# Now begin close
|
|
lcli1 close $ID2
|
|
|
|
# They should be waiting for it to clear up.
|
|
check_peerstate lcli1 STATE_SHUTDOWN
|
|
check_peerstate lcli2 STATE_SHUTDOWN
|
|
|
|
# Fail one, still waiting.
|
|
lcli2 dev-failhtlc $ID1 $HTLCID1 800
|
|
check_peerstate lcli1 STATE_SHUTDOWN
|
|
check_peerstate lcli2 STATE_SHUTDOWN
|
|
|
|
# Fulfill the other causes them to actually complete the close.
|
|
lcli1 dev-fulfillhtlc $ID2 $HTLCID2 $SECRET
|
|
check_peerstate lcli1 STATE_MUTUAL_CLOSING
|
|
check_peerstate lcli2 STATE_MUTUAL_CLOSING
|
|
|
|
check_tx_spend
|
|
$CLI generate 1
|
|
|
|
check_peerstate lcli1 STATE_CLOSE_ONCHAIN_MUTUAL
|
|
check_peerstate lcli2 STATE_CLOSE_ONCHAIN_MUTUAL
|
|
|
|
# Give it "forever" blocks.
|
|
$CLI generate 9
|
|
|
|
check_no_peers lcli1
|
|
check_no_peers lcli2
|
|
|
|
lcli1 stop
|
|
lcli2 stop
|
|
|
|
all_ok
|