mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-21 22:31:48 +01:00
pytest: Added simple pytest for the new JSON-RPC
This commit is contained in:
parent
b2ea4cfd66
commit
9c7c2a3f2f
2 changed files with 38 additions and 0 deletions
|
@ -101,6 +101,16 @@ class LightningRpc(UnixDomainSocketRpc):
|
||||||
def getnodes(self):
|
def getnodes(self):
|
||||||
return self._call("getnodes", [])
|
return self._call("getnodes", [])
|
||||||
|
|
||||||
|
def newaddr(self):
|
||||||
|
return self._call("newaddr", [])['address']
|
||||||
|
|
||||||
|
def addfunds(self, tx):
|
||||||
|
return self._call("addfunds", [tx])
|
||||||
|
|
||||||
|
def fundchannel(self, node_id, capacity):
|
||||||
|
return self._call("fundchannel", [node_id, capacity])
|
||||||
|
|
||||||
|
|
||||||
class LegacyLightningRpc(UnixDomainSocketRpc):
|
class LegacyLightningRpc(UnixDomainSocketRpc):
|
||||||
def getchannels(self):
|
def getchannels(self):
|
||||||
"""List all known channels.
|
"""List all known channels.
|
||||||
|
|
|
@ -126,6 +126,34 @@ class LightningDTests(BaseLightningDTests):
|
||||||
assert p1['condition'] == 'Exchanging gossip'
|
assert p1['condition'] == 'Exchanging gossip'
|
||||||
assert p2['condition'] == 'Exchanging gossip'
|
assert p2['condition'] == 'Exchanging gossip'
|
||||||
|
|
||||||
|
def test_gossip_jsonrpc(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']
|
||||||
|
|
||||||
|
addr = l1.rpc.newaddr()
|
||||||
|
|
||||||
|
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.daemon.wait_for_log('WIRE_HSMCTL_SIGN_FUNDING_REPLY')
|
||||||
|
|
||||||
|
time.sleep(1)
|
||||||
|
l1.bitcoin.rpc.generate(6)
|
||||||
|
|
||||||
|
l1.daemon.wait_for_log('Normal operation')
|
||||||
|
l2.daemon.wait_for_log('Normal operation')
|
||||||
|
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
nodes = l1.rpc.getnodes()['nodes']
|
||||||
|
assert set([n['nodeid'] for n in nodes]) == set([l1.info['id'], l2.info['id']])
|
||||||
|
|
||||||
class LegacyLightningDTests(BaseLightningDTests):
|
class LegacyLightningDTests(BaseLightningDTests):
|
||||||
|
|
||||||
def test_connect(self):
|
def test_connect(self):
|
||||||
|
|
Loading…
Add table
Reference in a new issue