Skip to content
This repository has been archived by the owner on Sep 8, 2020. It is now read-only.

Commit

Permalink
Merge branch 'deprecate_generate'
Browse files Browse the repository at this point in the history
RPC command is retired
  • Loading branch information
willcl-ark committed Sep 27, 2019
2 parents 5b46355 + f4f6907 commit 75bf423
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 37 deletions.
4 changes: 2 additions & 2 deletions lnd_grpc/invoices.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ def __init__(
def invoice_stub(self) -> invrpc.InvoicesStub:
if self._inv_stub is None:
ssl_creds = grpc.ssl_channel_credentials(self.tls_cert)
_inv_channel = grpc.secure_channel(
self._inv_channel = grpc.secure_channel(
target=self.grpc_address,
credentials=self.combined_credentials,
options=self.grpc_options,
)
self._inv_stub = invrpc.InvoicesStub(_inv_channel)
self._inv_stub = invrpc.InvoicesStub(self._inv_channel)
return self._inv_stub

def subscribe_single_invoice(
Expand Down
4 changes: 2 additions & 2 deletions lnd_grpc/wallet_unlocker.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ def __init__(
def wallet_unlocker_stub(self) -> lnrpc.WalletUnlockerStub:
if self._w_stub is None:
ssl_creds = grpc.ssl_channel_credentials(self.tls_cert)
_w_channel = grpc.secure_channel(
self._w_channel = grpc.secure_channel(
target=self.grpc_address,
credentials=ssl_creds,
options=self.grpc_options,
)
self._w_stub = lnrpc.WalletUnlockerStub(_w_channel)
self._w_stub = lnrpc.WalletUnlockerStub(self._w_channel)

# simulate connection status change after wallet stub used (typically wallet unlock) which
# stimulates lightning stub regeneration when necessary
Expand Down
64 changes: 36 additions & 28 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ def transact_and_mine(btc):
Generate some transactions and blocks.
To make bitcoind's `estimatesmartfee` succeeded.
"""
addr = btc.rpc.getnewaddress()
addr = btc.rpc.getnewaddress("", "bech32")
for i in range(10):
for j in range(10):
txid = btc.rpc.sendtoaddress(addr, 0.5)
btc.rpc.generate(1)
btc.rpc.generatetoaddress(1, addr)


def wait_for(success, timeout=30, interval=0.25):
Expand Down Expand Up @@ -82,11 +82,12 @@ def generate_until(btc, success, blocks=30, interval=1):
be delayed and we don't want to add a long waiting time to all
tests just because some are slow.
"""
addr = btc.rpc.getnewaddress("", "bech32")
for i in range(blocks):
time.sleep(interval)
if success():
return
btc.rpc.generate(1)
generate(bitcoind, 1)
time.sleep(interval)
if not success():
raise ValueError("Generated %d blocks, but still no success", blocks)
Expand All @@ -96,13 +97,18 @@ def gen_and_sync_lnd(bitcoind, nodes):
"""
generate a few blocks and wait for lnd nodes to sync
"""
bitcoind.rpc.generate(3)
generate(bitcoind, 3)
sync_blockheight(bitcoind, nodes=nodes)
for node in nodes:
wait_for(lambda: node.get_info().synced_to_chain, interval=0.25)
time.sleep(0.25)


def generate(bitcoind, blocks):
addr = bitcoind.rpc.getnewaddress("", "bech32")
bitcoind.rpc.generatetoaddress(blocks, addr)


def close_all_channels(bitcoind, nodes):
"""
Recursively close each channel for each node in the list of nodes passed in and assert
Expand Down Expand Up @@ -146,7 +152,7 @@ def setup_nodes(bitcoind, nodes, delay=0):
:return: the setup nodes
"""
# Needed by lnd in order to have at least one block in the last 2 hours
bitcoind.rpc.generate(1)
generate(bitcoind, 1)

# First break down nodes. This avoids situations where a test fails and breakdown is not called
break_down_nodes(bitcoind, nodes, delay)
Expand Down Expand Up @@ -178,7 +184,7 @@ def setup_channels(bitcoind, nodes, delay):
spend_unconfirmed=True,
)
time.sleep(delay)
bitcoind.rpc.generate(3)
generate(bitcoind, 3)
gen_and_sync_lnd(bitcoind, [nodes[i], nodes[i + 1]])

assert confirm_channel(bitcoind, nodes[i], nodes[i + 1])
Expand All @@ -201,7 +207,8 @@ def confirm_channel(bitcoind, n1, n2):
time.sleep(0.5)
if n1.check_channel(n2) and n2.check_channel(n1):
return True
bhash = bitcoind.rpc.generate(1)[0]
addr = bitcoind.rpc.getnewaddress("", "bech32")
bhash = bitcoind.rpc.generatetoaddress(1, addr)[0]
n1.block_sync(bhash)
n2.block_sync(bhash)

Expand Down Expand Up @@ -277,7 +284,7 @@ def test_send_coins(self, alice):

# test passes
send1 = alice.send_coins(addr=p2wkh_address, amount=100000)
alice.bitcoin.rpc.generate(1)
generate(alice.bitcoin, 1)
time.sleep(0.5)
send2 = alice.send_coins(addr=np2wkh_address, amount=100000)

Expand Down Expand Up @@ -305,7 +312,7 @@ def test_send_many(self, alice):
send_dict = {p2wkh_address: 100000, np2wkh_address: 100000}

send = alice.send_many(addr_to_amount=send_dict)
alice.bitcoin.rpc.generate(1)
alice.bitcoin.rpc.generatetoaddress(1, p2wkh_address)
time.sleep(0.5)
assert isinstance(send, rpc_pb2.SendManyResponse)

Expand Down Expand Up @@ -476,7 +483,7 @@ def test_lightning_stub(self, alice):
class TestInteractiveLightning:
def test_peer_connection(self, bob, carol, dave, bitcoind):
# Needed by lnd in order to have at least one block in the last 2 hours
bitcoind.rpc.generate(1)
generate(bitcoind, 1)

# connection tests
connection1 = bob.connect(
Expand All @@ -503,7 +510,7 @@ def test_peer_connection(self, bob, carol, dave, bitcoind):
assert carol.id() in [p.pub_key for p in dave.list_peers()]
assert dave.id() in [p.pub_key for p in carol.list_peers()]

bob.bitcoin.rpc.generate(1)
generate(bob.bitcoin, 1)
gen_and_sync_lnd(bitcoind, [bob, carol])

# Disconnection tests
Expand All @@ -526,7 +533,8 @@ def test_peer_connection(self, bob, carol, dave, bitcoind):

def test_open_channel_sync(self, bob, carol, bitcoind):
# Needed by lnd in order to have at least one block in the last 2 hours
bitcoind.rpc.generate(1)
generate(bitcoind, 1)
disconnect_all_peers(bitcoind, [bob, carol])

bob.connect(str(carol.id() + "@localhost:" + str(carol.daemon.port)), perm=1)

Expand All @@ -547,7 +555,7 @@ def test_open_channel_sync(self, bob, carol, bitcoind):

def test_open_channel(self, bob, carol, bitcoind):
# Needed by lnd in order to have at least one block in the last 2 hours
bitcoind.rpc.generate(1)
generate(bitcoind, 1)
break_down_nodes(bitcoind, nodes=[bob, carol])

bob.connect(str(carol.id() + "@localhost:" + str(carol.daemon.port)), perm=1)
Expand All @@ -560,7 +568,7 @@ def test_open_channel(self, bob, carol, bitcoind):
bob.open_channel(
node_pubkey_string=carol.id(), local_funding_amount=FUND_AMT
).__next__()
bitcoind.rpc.generate(3)
generate(bitcoind, 3)
gen_and_sync_lnd(bitcoind, [bob, carol])

assert confirm_channel(bitcoind, bob, carol)
Expand All @@ -573,7 +581,7 @@ def test_close_channel(self, bob, carol, bitcoind):

channel_point = bob.list_channels()[0].channel_point
bob.close_channel(channel_point=channel_point).__next__()
bitcoind.rpc.generate(6)
generate(bitcoind, 6)
gen_and_sync_lnd(bitcoind, [bob, carol])

assert bob.check_channel(carol) is False
Expand All @@ -585,7 +593,7 @@ def test_send_payment_sync(self, bitcoind, bob, carol):
# test payment request method
invoice = carol.add_invoice(value=SEND_AMT)
bob.send_payment_sync(payment_request=invoice.payment_request)
bitcoind.rpc.generate(3)
generate(bitcoind, 3)
gen_and_sync_lnd(bitcoind, [bob, carol])

payment_hash = carol.decode_pay_req(invoice.payment_request).payment_hash
Expand All @@ -600,7 +608,7 @@ def test_send_payment_sync(self, bitcoind, bob, carol):
payment_hash=invoice2.r_hash,
final_cltv_delta=144,
)
bitcoind.rpc.generate(3)
generate(bitcoind, 3)
gen_and_sync_lnd(bitcoind, [bob, carol])

payment_hash2 = carol.decode_pay_req(invoice2.payment_request).payment_hash
Expand All @@ -610,7 +618,7 @@ def test_send_payment_sync(self, bitcoind, bob, carol):
# test sending any amount to an invoice which requested 0
invoice3 = carol.add_invoice(value=0)
bob.send_payment_sync(payment_request=invoice3.payment_request, amt=SEND_AMT)
bitcoind.rpc.generate(3)
generate(bitcoind, 3)
gen_and_sync_lnd(bitcoind, [bob, carol])

payment_hash = carol.decode_pay_req(invoice3.payment_request).payment_hash
Expand All @@ -630,7 +638,7 @@ def test_send_payment(self, bitcoind, bob, carol):
except StopIteration:
pass
bob.daemon.wait_for_log("Closed completed SETTLE circuit", timeout=60)
bitcoind.rpc.generate(3)
generate(bitcoind, 3)
gen_and_sync_lnd(bitcoind, [bob, carol])

payment_hash = carol.decode_pay_req(invoice.payment_request).payment_hash
Expand All @@ -649,7 +657,7 @@ def test_send_payment(self, bitcoind, bob, carol):
except StopIteration:
pass
bob.daemon.wait_for_log("Closed completed SETTLE circuit", timeout=60)
bitcoind.rpc.generate(3)
generate(bitcoind, 3)
gen_and_sync_lnd(bitcoind, [bob, carol])

payment_hash2 = carol.decode_pay_req(invoice2.payment_request).payment_hash
Expand All @@ -665,7 +673,7 @@ def test_send_payment(self, bitcoind, bob, carol):
except StopIteration:
pass
bob.daemon.wait_for_log("Closed completed SETTLE circuit", timeout=60)
bitcoind.rpc.generate(3)
generate(bitcoind, 3)
gen_and_sync_lnd(bitcoind, [bob, carol])

payment_hash = carol.decode_pay_req(invoice.payment_request).payment_hash
Expand All @@ -680,7 +688,7 @@ def test_send_to_route_sync(self, bitcoind, bob, carol, dave):
invoice = dave.add_invoice(value=SEND_AMT)
route = bob.query_routes(pub_key=dave.id(), amt=SEND_AMT, final_cltv_delta=144)
bob.send_to_route_sync(payment_hash=invoice.r_hash, route=route[0])
bitcoind.rpc.generate(3)
generate(bitcoind, 3)
gen_and_sync_lnd(bitcoind, [bob, carol, dave])
payment_hash = dave.decode_pay_req(invoice.payment_request).payment_hash

Expand All @@ -697,7 +705,7 @@ def test_send_to_route(self, bitcoind, bob, carol, dave):
except StopIteration:
pass
bob.daemon.wait_for_log("Closed completed SETTLE circuit", timeout=60)
bitcoind.rpc.generate(3)
generate(bitcoind, 3)
gen_and_sync_lnd(bitcoind, [bob, carol, dave])
payment_hash = dave.decode_pay_req(invoice.payment_request).payment_hash

Expand All @@ -724,7 +732,7 @@ def sub_channel_events():
channel_point = bob.list_channels()[0].channel_point

bob.close_channel(channel_point=channel_point).__next__()
bitcoind.rpc.generate(6)
generate(bitcoind, 3)
gen_and_sync_lnd(bitcoind, [bob, carol])
assert any(
update.closed_channel is not None for update in get_updates(chan_updates)
Expand Down Expand Up @@ -780,9 +788,9 @@ def test_export_verify_restore_multi(self, bitcoind, bob, carol):

bob.daemon.wait_for_log("Inserting 1 SCB channel shells into DB")
carol.daemon.wait_for_log("Broadcasting force close transaction")
bitcoind.rpc.generate(6)
generate(bitcoind, 6)
bob.daemon.wait_for_log("Publishing sweep tx", timeout=120)
bitcoind.rpc.generate(6)
generate(bitcoind, 6)
assert bob.daemon.wait_for_log(
"a contract has been fully resolved!", timeout=120
)
Expand All @@ -809,9 +817,9 @@ def test_export_verify_restore_single(self, bitcoind, bob, carol):

bob.daemon.wait_for_log("Inserting 1 SCB channel shells into DB")
carol.daemon.wait_for_log("Broadcasting force close transaction")
bitcoind.rpc.generate(6)
generate(bitcoind, 6)
bob.daemon.wait_for_log("Publishing sweep tx", timeout=120)
bitcoind.rpc.generate(6)
generate(bitcoind, 6)
assert bob.daemon.wait_for_log(
"a contract has been fully resolved!", timeout=120
)
Expand Down
5 changes: 3 additions & 2 deletions tests/test_utils/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,15 @@ def bitcoind(directory):
)
btc.start()
bch_info = btc.rpc.getblockchaininfo()
addr = btc.rpc.getnewaddress("", "bech32")
w_info = btc.rpc.getwalletinfo()
# Make sure we have segwit and some funds
if bch_info["blocks"] < 120:
logging.debug("SegWit not active, generating some more blocks")
btc.rpc.generate(120 - bch_info["blocks"])
btc.rpc.generatetoaddress(120 - bch_info["blocks"], addr)
elif w_info["balance"] < 1:
logging.debug("Insufficient balance, generating 1 block")
btc.rpc.generate(1)
btc.rpc.generatetoaddress(1, addr)

yield btc

Expand Down
2 changes: 1 addition & 1 deletion tests/test_utils/lnd.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def add_funds(self, bitcoind, amount):
addr = self.new_address("p2wkh").address
bitcoind.rpc.sendtoaddress(addr, amount)
self.daemon.wait_for_log("Inserting unconfirmed transaction")
bitcoind.rpc.generate(3)
bitcoind.rpc.generatetoaddress(3, addr)
self.daemon.wait_for_log("Marking unconfirmed transaction")

# The above still doesn't mean the wallet balance is updated,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ def __init__(self, bitcoin_dir="/tmp/bitcoind-test", rpcport=None):
"-rpcpassword=rpcpass",
"-zmqpubrawblock=tcp://127.0.0.1:{}".format(self.zmqpubrawblock_port),
"-zmqpubrawtx=tcp://127.0.0.1:{}".format(self.zmqpubrawtx_port),
"-zmqpubrawblockhwm=0",
"-zmqpubrawtxhwm=0",
# "-zmqpubrawblockhwm=0",
# "-zmqpubrawtxhwm=0",
]
BITCOIND_CONFIG["rpcport"] = rpcport
write_config(os.path.join(bitcoin_dir, self.CONF_NAME), BITCOIND_CONFIG)
Expand Down

0 comments on commit 75bf423

Please sign in to comment.