Browse Source

ping: move test to python.

Faster and neater.

Before:
	real	0m11.200s

After:
	real	0m9.101s

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 8 years ago
committed by Christian Decker
parent
commit
056f93e2d2
  1. 75
      lightningd/test/test-ping
  2. 48
      tests/test_lightningd.py

75
lightningd/test/test-ping

@ -1,75 +0,0 @@
#! /bin/sh -e
# Wherever we are, we want to be in daemon/test dir.
cd `git rev-parse --show-toplevel`/daemon/test
add_funds()
{
local NEWADDR=`$1 newaddr | get_field address`
local FUND_INPUT_TXID=`$CLI sendtoaddress $NEWADDR $2`
local FUND_INPUT_TX=`$CLI getrawtransaction $FUND_INPUT_TXID`
$1 addfunds $FUND_INPUT_TX
}
. scripts/vars.sh
. scripts/helpers.sh
parse_cmdline 2 "$@"
setup_lightning 2
start_lightningd 2 lightningd/lightningd
lcli1 connect localhost $PORT2 $ID2
# Gossipd pings.
# 0-byte pong gives just type + length field.
[ `lcli1 dev-ping $ID2 0 0 | get_field totlen` = 4 ]
# 1000-byte ping, 0-byte pong.
[ `lcli1 dev-ping $ID2 1000 0 | get_field totlen` = 4 ]
# 1000 byte pong.
[ `lcli1 dev-ping $ID2 1000 1000 | get_field totlen` = 1004 ]
# Maximum length pong.
[ `lcli1 dev-ping $ID2 1000 65531 | get_field totlen` = 65535 ]
# Overlength -> no reply.
[ `lcli1 dev-ping $ID2 1000 65532 | get_field totlen` = 0 ]
[ `lcli1 dev-ping $ID2 1000 65533 | get_field totlen` = 0 ]
[ `lcli1 dev-ping $ID2 1000 65534 | get_field totlen` = 0 ]
[ `lcli1 dev-ping $ID2 1000 65535 | get_field totlen` = 0 ]
add_funds lcli1 0.2
# Now fund the channels
CHANNEL_SAT=10000000
CHANNEL_MSAT=$(($CHANNEL_SAT * 1000))
lcli1 fundchannel $ID2 $CHANNEL_SAT
# Lock them in.
$CLI generate 10
check "lcli1 getpeers info | $FGREP 'Funding tx reached depth'"
# 0-byte pong gives just type + length field.
[ `lcli1 dev-ping $ID2 0 0 | get_field totlen` = 4 ]
# 1000-byte ping, 0-byte pong.
[ `lcli1 dev-ping $ID2 1000 0 | get_field totlen` = 4 ]
# 1000 byte pong.
[ `lcli1 dev-ping $ID2 1000 1000 | get_field totlen` = 1004 ]
# Maximum length pong.
[ `lcli1 dev-ping $ID2 1000 65531 | get_field totlen` = 65535 ]
# Overlength -> no reply.
[ `lcli1 dev-ping $ID2 1000 65532 | get_field totlen` = 0 ]
[ `lcli1 dev-ping $ID2 1000 65533 | get_field totlen` = 0 ]
[ `lcli1 dev-ping $ID2 1000 65534 | get_field totlen` = 0 ]
[ `lcli1 dev-ping $ID2 1000 65535 | get_field totlen` = 0 ]
lcli1 stop
lcli2 stop
all_ok

48
tests/test_lightningd.py

@ -162,6 +162,54 @@ class LightningDTests(BaseLightningDTests):
assert len(channels) == 2 assert len(channels) == 2
assert [c['active'] for c in channels] == [True, True] assert [c['active'] for c in channels] == [True, True]
def ping_tests(self, l1, l2):
# 0-byte pong gives just type + length field.
ret = l1.rpc.dev_ping(l2.info['id'], 0, 0)
assert ret['totlen'] == 4
# 1000-byte ping, 0-byte pong.
ret = l1.rpc.dev_ping(l2.info['id'], 1000, 0)
assert ret['totlen'] == 4
# 1000 byte pong.
ret = l1.rpc.dev_ping(l2.info['id'], 1000, 1000)
assert ret['totlen'] == 1004
# Maximum length pong.
ret = l1.rpc.dev_ping(l2.info['id'], 1000, 65531)
assert ret['totlen'] == 65535
# Overlength -> no reply.
for s in range(65532, 65536):
ret = l1.rpc.dev_ping(l2.info['id'], 1000, s)
assert ret['totlen'] == 0
def test_ping(self):
l1 = self.node_factory.get_node(legacy=False)
l2 = self.node_factory.get_node(legacy=False)
ret = l1.rpc.connect('localhost', l2.info['port'], l2.info['id'])
assert ret['id'] == l2.info['id']
# Test gossip pinging.
self.ping_tests(l1, l2)
# Now fund the channels
addr = l1.rpc.newaddr()['address']
txid = l1.bitcoin.rpc.sendtoaddress(addr, 0.02)
tx = l1.bitcoin.rpc.getrawtransaction(txid)
l1.rpc.addfunds(tx)
l1.rpc.fundchannel(l2.info['id'], 10**5)
l1.bitcoin.rpc.generate(6)
l1.daemon.wait_for_log('Normal operation')
l2.daemon.wait_for_log('Normal operation')
# channeld pinging
self.ping_tests(l1, l2)
class LegacyLightningDTests(BaseLightningDTests): class LegacyLightningDTests(BaseLightningDTests):
def test_connect(self): def test_connect(self):

Loading…
Cancel
Save