#! /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 if lcli1 connect localhost $PORT2 $ID1; then echo Connected OK with wrong ID? >&2 exit 1 fi lcli1 connect localhost $PORT2 $ID2 # 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"' # 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' # Now fund a channel. lcli1 fundchannel $ID2 1000000 # Now wait for it to reach depth lcli1 getpeers info | $FGREP "Waiting for our funding tx" [ `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 ] $CLI generate 10 check "lcli1 getpeers info | $FGREP 'Funding tx reached depth'" check "lcli2 getpeers info | $FGREP 'Funding tx reached depth'" check "lcli1 getpeers | tr -s '\012\011\" ' ' ' | $FGREP 'condition : Normal operation'" check "lcli2 getpeers | tr -s '\012\011\" ' ' ' | $FGREP 'condition : Normal operation'" SECRET=1de08917a61cb2b62ed5937d38577f6a7bfe59c176781c6d8128018e8b5ccdfd RHASH=`lcli1 dev-rhash $SECRET | sed 's/.*"\([0-9a-f]*\)".*/\1/'` # This is actually dust lcli1 dev-newhtlc $ID2 100000 $(( $(blockheight) + 10 )) $RHASH check "lcli1 getlog debug | $FGREP 'Sending commit_sig with 0 htlc sigs'" check "lcli2 getlog debug | $FGREP 'their htlc 0 locked'" check "lcli2 getpeers info | $FGREP 'failed htlc 0 code 0x400f'" check "lcli1 getpeers info | $FGREP 'htlc 0 failed with code 0x400f'" # 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 ] 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 ] 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 lcli1 stop lcli2 stop all_ok