2017-01-10 06:08:33 +01:00
|
|
|
#! /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 lightningd/lightningd
|
|
|
|
|
2017-01-10 06:08:33 +01:00
|
|
|
if lcli1 connect localhost $PORT2 $ID1; then
|
|
|
|
echo Connected OK with wrong ID? >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
lcli1 connect localhost $PORT2 $ID2
|
2017-01-10 06:08:33 +01:00
|
|
|
|
2017-01-10 06:08:34 +01:00
|
|
|
# Should now be exchanging gossip
|
|
|
|
lcli1 getpeers | $FGREP '"condition" : "Exchanging gossip"'
|
|
|
|
|
|
|
|
# It should have gone through these steps
|
|
|
|
lcli1 getpeers info | $FGREP "Starting handshake as initiator"
|
|
|
|
lcli1 getpeers info | $FGREP "Beginning gossip"
|
|
|
|
lcli1 getpeers info | $FGREP "Exchanging gossip"
|
|
|
|
|
|
|
|
# Both should still be owned by gossip
|
|
|
|
lcli1 getpeers | $FGREP '"owner" : "lightningd_gossip"'
|
|
|
|
lcli2 getpeers | $FGREP '"owner" : "lightningd_gossip"'
|
2017-01-10 06:08:33 +01:00
|
|
|
|
2017-02-21 05:49:02 +01:00
|
|
|
# Add some funds.
|
|
|
|
NEWADDR=`lcli1 newaddr | get_field address`
|
|
|
|
FUND_INPUT_TXID=`$CLI sendtoaddress $NEWADDR 0.10000002`
|
|
|
|
FUND_INPUT_TX=`$CLI getrawtransaction $FUND_INPUT_TXID`
|
|
|
|
|
|
|
|
lcli1 addfunds $FUND_INPUT_TX | $FGREP '"satoshis" : 10000002'
|
|
|
|
|
2017-02-24 06:52:56 +01:00
|
|
|
# Now fund a channel.
|
2017-04-01 12:58:30 +02:00
|
|
|
lcli1 fundchannel $ID2 1000000
|
2017-02-24 06:52:56 +01:00
|
|
|
|
2017-03-07 02:03:55 +01:00
|
|
|
# Now wait for it to reach depth
|
|
|
|
lcli1 getpeers info | $FGREP "Waiting for our funding tx"
|
2017-04-01 12:58:30 +02:00
|
|
|
[ `lcli1 getpeers | get_field msatoshi_to_us` = 1000000000 ]
|
|
|
|
[ `lcli1 getpeers | get_field msatoshi_to_them` = 0 ]
|
|
|
|
[ `lcli2 getpeers | get_field msatoshi_to_them` = 1000000000 ]
|
|
|
|
[ `lcli2 getpeers | get_field msatoshi_to_us` = 0 ]
|
2017-03-07 02:03:55 +01:00
|
|
|
|
|
|
|
$CLI generate 10
|
|
|
|
check "lcli1 getpeers info | $FGREP 'Funding tx reached depth'"
|
|
|
|
check "lcli2 getpeers info | $FGREP 'Funding tx reached depth'"
|
|
|
|
|
2017-03-07 02:26:12 +01:00
|
|
|
check "lcli1 getpeers | tr -s '\012\011\" ' ' ' | $FGREP 'condition : Normal operation'"
|
|
|
|
check "lcli2 getpeers | tr -s '\012\011\" ' ' ' | $FGREP 'condition : Normal operation'"
|
|
|
|
|
2017-04-01 12:24:59 +02:00
|
|
|
SECRET=1de08917a61cb2b62ed5937d38577f6a7bfe59c176781c6d8128018e8b5ccdfd
|
|
|
|
RHASH=`lcli1 dev-rhash $SECRET | sed 's/.*"\([0-9a-f]*\)".*/\1/'`
|
|
|
|
|
2017-04-01 12:58:30 +02:00
|
|
|
# This is actually dust
|
2017-04-01 12:24:59 +02:00
|
|
|
lcli1 dev-newhtlc $ID2 100000 $(( $(blockheight) + 10 )) $RHASH
|
2017-04-01 12:58:30 +02:00
|
|
|
check "lcli1 getlog debug | $FGREP 'Sending commit_sig with 0 htlc sigs'"
|
2017-04-01 12:24:59 +02:00
|
|
|
|
2017-04-01 12:58:30 +02:00
|
|
|
check "lcli2 getlog debug | $FGREP 'their htlc 0 locked'"
|
2017-04-01 12:58:30 +02:00
|
|
|
check "lcli2 getpeers info | $FGREP 'failed htlc 0 code 0x400f'"
|
2017-04-01 13:01:13 +02:00
|
|
|
check "lcli1 getpeers info | $FGREP 'htlc 0 failed with code 0x400f'"
|
2017-04-01 12:58:30 +02:00
|
|
|
|
|
|
|
# This one isn't dust.
|
|
|
|
RHASH=`lcli2 invoice 100000000 testpayment1 | get_field rhash`
|
|
|
|
[ `lcli2 listinvoice testpayment1 | get_field complete` = false ]
|
|
|
|
|
|
|
|
lcli1 dev-newhtlc $ID2 100000000 $(( $(blockheight) + 10 )) $RHASH
|
|
|
|
check "lcli1 getlog debug | $FGREP 'Sending commit_sig with 1 htlc sigs'"
|
|
|
|
|
|
|
|
check "lcli2 getlog debug | $FGREP 'Resolving invoice '\'testpayment1\'' with HTLC 1'"
|
|
|
|
[ `lcli2 listinvoice testpayment1 | get_field complete` = true ]
|
2017-04-01 12:26:07 +02:00
|
|
|
|
2017-04-01 13:01:13 +02:00
|
|
|
check "lcli1 getpeers | get_field msatoshi_to_us | $FGREP -w 900000000"
|
|
|
|
[ `lcli1 getpeers | get_field msatoshi_to_us` = 900000000 ]
|
|
|
|
[ `lcli1 getpeers | get_field msatoshi_to_them` = 100000000 ]
|
|
|
|
[ `lcli2 getpeers | get_field msatoshi_to_them` = 900000000 ]
|
|
|
|
[ `lcli2 getpeers | get_field msatoshi_to_us` = 100000000 ]
|
2017-04-01 13:01:13 +02:00
|
|
|
|
2017-04-01 15:05:29 +02:00
|
|
|
RHASH=`lcli2 invoice 200000000 testpayment2 | get_field rhash`
|
|
|
|
[ `lcli2 listinvoice testpayment2 | get_field complete` = false ]
|
|
|
|
|
|
|
|
# Not enough delay.
|
|
|
|
if lcli1 sendpay '[ { "msatoshi" : 200000000, "id" : "'$ID2'", "delay" : 3 } ]' $RHASH; then
|
|
|
|
echo Infufficient delay succeeded? >&2
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Insufficient funds.
|
|
|
|
if lcli1 sendpay '[ { "msatoshi" : 199999999, "id" : "'$ID2'", "delay" : 5 } ]' $RHASH; then
|
|
|
|
echo Infufficient funds succeeded? >&2
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Bad ID.
|
|
|
|
if lcli1 sendpay '[ { "msatoshi" : 200000000,, "id" : "'$ID2'", "delay" : 5 } ]' 00000000000000000000000000000000; then
|
|
|
|
echo Bad ID succeeded? >&2
|
|
|
|
fi
|
|
|
|
|
|
|
|
# This works
|
|
|
|
lcli1 sendpay '[ { "msatoshi" : 200000000, "id" : "'$ID2'", "delay" : 5 } ]' $RHASH
|
|
|
|
[ `lcli2 listinvoice testpayment2 | get_field complete` = true ]
|
|
|
|
|
|
|
|
# This will "succeed", but won't actually send anything (duplicate)
|
|
|
|
if lcli1 getlog debug | $FGREP 'json_sendpay: found previous... succeeded'; then
|
|
|
|
echo Already had found previous? >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
lcli1 sendpay '[ { "msatoshi" : 200000000, "id" : "'$ID2'", "delay" : 5 } ]' $RHASH
|
|
|
|
lcli1 getlog debug | $FGREP 'json_sendpay: found previous... succeeded'
|
|
|
|
|
|
|
|
# FIXME: test paying via another node, should fail to pay twice.
|
|
|
|
|
|
|
|
# Overpay.
|
|
|
|
RHASH=`lcli2 invoice 200000000 testpayment3 | get_field rhash`
|
|
|
|
lcli1 sendpay '[ { "msatoshi" : 200000001, "id" : "'$ID2'", "delay" : 5 } ]' $RHASH
|
|
|
|
|
2017-01-10 06:08:33 +01:00
|
|
|
lcli1 stop
|
|
|
|
lcli2 stop
|
|
|
|
|
|
|
|
all_ok
|