Browse Source

lnbase online test: use random node key when making new channel, save node key, multiple actions per invocation

dependabot/pip/contrib/deterministic-build/ecdsa-0.13.3
Janus 7 years ago
committed by ThomasV
parent
commit
5da3820a28
  1. 2
      lib/lnbase.py
  2. 28
      lib/tests/test_lnbase_online.py

2
lib/lnbase.py

@ -1030,7 +1030,7 @@ class Peer(PrintError):
return chan._replace(short_channel_id=short_channel_id, remote_state=chan.remote_state._replace(next_per_commitment_point=remote_funding_locked_msg["next_per_commitment_point"])) return chan._replace(short_channel_id=short_channel_id, remote_state=chan.remote_state._replace(next_per_commitment_point=remote_funding_locked_msg["next_per_commitment_point"]))
async def pay(self, wallet, chan, sat, payment_hash): async def pay(self, wallet, chan, sat, payment_hash, pubkey_in_invoice):
def derive_and_incr(): def derive_and_incr():
nonlocal chan nonlocal chan
last_small_num = chan.local_state.ctn last_small_num = chan.local_state.ctn

28
lib/tests/test_lnbase_online.py

@ -7,6 +7,7 @@ import time
import os import os
from lib.bitcoin import sha256, COIN from lib.bitcoin import sha256, COIN
from lib.util import bh2u, bfh
from decimal import Decimal from decimal import Decimal
from lib.constants import set_testnet, set_simnet from lib.constants import set_testnet, set_simnet
from lib.simple_config import SimpleConfig from lib.simple_config import SimpleConfig
@ -77,8 +78,8 @@ if __name__ == "__main__":
host, port, pubkey = node_list[0] host, port, pubkey = node_list[0]
pubkey = binascii.unhexlify(pubkey) pubkey = binascii.unhexlify(pubkey)
port = int(port) port = int(port)
if sys.argv[1] not in ["new_channel", "reestablish_channel", "pay"]: if not any(x in sys.argv[1] for x in ["new_channel", "reestablish_channel"]):
raise Exception("first argument must be new_channel or reestablish_channel or pay") raise Exception("first argument must contain new_channel or reestablish_channel")
if sys.argv[2] not in ["simnet", "testnet"]: if sys.argv[2] not in ["simnet", "testnet"]:
raise Exception("second argument must be simnet or testnet") raise Exception("second argument must be simnet or testnet")
if sys.argv[2] == "simnet": if sys.argv[2] == "simnet":
@ -97,8 +98,15 @@ if __name__ == "__main__":
wallet = Wallet(storage) wallet = Wallet(storage)
wallet.start_threads(network) wallet.start_threads(network)
# start peer # start peer
privkey = sha256("0123456789") if "new_channel" in sys.argv[1]:
peer = Peer(host, port, pubkey, privkey, request_initial_sync=False, network=network) privkey = sha256(os.urandom(32))
wallet.storage.put("channels_privkey", bh2u(privkey))
wallet.storage.write()
elif "reestablish_channel" in sys.argv[1]:
privkey = wallet.storage.get("channels_privkey", None)
assert privkey is not None
privkey = bfh(privkey)
peer = Peer(host, port, pubkey, privkey, request_initial_sync=True, network=network)
network.futures.append(asyncio.run_coroutine_threadsafe(peer.main_loop(), network.asyncio_loop)) network.futures.append(asyncio.run_coroutine_threadsafe(peer.main_loop(), network.asyncio_loop))
funding_satoshis = 2000000 funding_satoshis = 2000000
@ -110,26 +118,26 @@ if __name__ == "__main__":
RHASH = sha256(payment_preimage) RHASH = sha256(payment_preimage)
channels = wallet.storage.get("channels", None) channels = wallet.storage.get("channels", None)
if sys.argv[1] == "new_channel": if "new_channel" in sys.argv[1]:
openingchannel = await peer.channel_establishment_flow(wallet, config, None, funding_satoshis, push_msat, temp_channel_id=os.urandom(32)) openingchannel = await peer.channel_establishment_flow(wallet, config, None, funding_satoshis, push_msat, temp_channel_id=os.urandom(32))
openchannel = await peer.wait_for_funding_locked(openingchannel, wallet) openchannel = await peer.wait_for_funding_locked(openingchannel, wallet)
dumped = serialize_channels([openchannel]) dumped = serialize_channels([openchannel])
wallet.storage.put("channels", dumped) wallet.storage.put("channels", dumped)
wallet.storage.write() wallet.storage.write()
return openchannel.channel_id elif "reestablish_channel" in sys.argv[1]:
if channels is None or len(channels) < 1: if channels is None or len(channels) < 1:
raise Exception("Can't reestablish: No channel saved") raise Exception("Can't reestablish: No channel saved")
openchannel = channels[0] openchannel = channels[0]
openchannel = reconstruct_namedtuples(openchannel) openchannel = reconstruct_namedtuples(openchannel)
openchannel = await peer.reestablish_channel(openchannel) openchannel = await peer.reestablish_channel(openchannel)
if sys.argv[1] == "pay": if "pay" in sys.argv[1]:
addr = lndecode(sys.argv[6], expected_hrp="sb" if sys.argv[2] == "simnet" else "tb") addr = lndecode(sys.argv[6], expected_hrp="sb" if sys.argv[2] == "simnet" else "tb")
payment_hash = addr.paymenthash payment_hash = addr.paymenthash
pubkey = addr.pubkey.serialize()
amt = int(addr.amount * COIN) amt = int(addr.amount * COIN)
advanced_channel = await peer.pay(wallet, openchannel, amt, payment_hash) advanced_channel = await peer.pay(wallet, openchannel, amt, payment_hash, pubkey)
else: elif "get_paid" in sys.argv[1]:
expected_received_sat = 200000 expected_received_sat = 200000
pay_req = lnencode(LnAddr(RHASH, amount=1/Decimal(COIN)*expected_received_sat, tags=[('d', 'one cup of coffee')]), peer.privkey[:32]) pay_req = lnencode(LnAddr(RHASH, amount=1/Decimal(COIN)*expected_received_sat, tags=[('d', 'one cup of coffee')]), peer.privkey[:32])
print("payment request", pay_req) print("payment request", pay_req)

Loading…
Cancel
Save