From 127fd9f5dd15ee72d0e80a9448877bae9743201d Mon Sep 17 00:00:00 2001 From: Vincenzo Palazzo Date: Wed, 6 Apr 2022 16:31:55 +0200 Subject: [PATCH] reformatting python code Signed-off-by: Vincenzo Palazzo --- .flake8 | 3 ++- lnprototest/__init__.py | 10 +++++++++- lnprototest/utils/__init__.py | 2 +- lnprototest/utils/bitcoin_utils.py | 7 +++++-- lnprototest/utils/ln_spec_utils.py | 1 - tests/spec_helper.py | 12 +++++++----- tests/test_bolt2-01-close_channel.py | 11 +++++++---- 7 files changed, 31 insertions(+), 15 deletions(-) diff --git a/.flake8 b/.flake8 index e0ea542..5411088 100644 --- a/.flake8 +++ b/.flake8 @@ -1,3 +1,4 @@ [flake8] max-line-length = 88 -extend-ignore = E203 \ No newline at end of file +extend-ignore = E203 +per-file-ignores = __init__.py:F401 \ No newline at end of file diff --git a/lnprototest/__init__.py b/lnprototest/__init__.py index 4da4a7a..9ea164e 100644 --- a/lnprototest/__init__.py +++ b/lnprototest/__init__.py @@ -61,7 +61,15 @@ from .signature import SigType, Sig from .keyset import KeySet from .commit_tx import Commit, HTLC, UpdateCommit -from .utils import Side, regtest_hash, privkey_expand, wait_for, LightningUtils, ScriptType, BitcoinUtils +from .utils import ( + Side, + regtest_hash, + privkey_expand, + wait_for, + LightningUtils, + ScriptType, + BitcoinUtils, +) from .funding import ( AcceptFunding, CreateFunding, diff --git a/lnprototest/utils/__init__.py b/lnprototest/utils/__init__.py index 9ed0922..19456a3 100644 --- a/lnprototest/utils/__init__.py +++ b/lnprototest/utils/__init__.py @@ -1,3 +1,3 @@ from .ln_spec_utils import LightningUtils from .utils import Side, regtest_hash, privkey_expand, wait_for, check_hex -from .bitcoin_utils import ScriptType, BitcoinUtils \ No newline at end of file +from .bitcoin_utils import ScriptType, BitcoinUtils diff --git a/lnprototest/utils/bitcoin_utils.py b/lnprototest/utils/bitcoin_utils.py index 6f1dbbc..77efcb6 100644 --- a/lnprototest/utils/bitcoin_utils.py +++ b/lnprototest/utils/bitcoin_utils.py @@ -20,12 +20,13 @@ class ScriptType(Enum): FIXME: naming is too simple. """ + VALID_CLOSE_SCRIPT = 1 INVALID_CLOSE_SCRIPT = 2 class BitcoinUtils: - """ Main implementation class of the lightning networks utils. + """Main implementation class of the lightning networks utils. The implementation class contains only static methods that apply the rules specified by the BIP.""" @@ -37,7 +38,9 @@ def blockchain_hash() -> str: return "06226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f" @staticmethod - def build_valid_script(script_type: ScriptType = ScriptType.VALID_CLOSE_SCRIPT) -> str: + def build_valid_script( + script_type: ScriptType = ScriptType.VALID_CLOSE_SCRIPT, + ) -> str: """Build a valid bitcoin script and hide the primitive of the library""" h = hashlib.sha256(b"correct horse battery staple").digest() seckey = CBitcoinSecret.from_secret_bytes(h) diff --git a/lnprototest/utils/ln_spec_utils.py b/lnprototest/utils/ln_spec_utils.py index ffba453..58a9883 100644 --- a/lnprototest/utils/ln_spec_utils.py +++ b/lnprototest/utils/ln_spec_utils.py @@ -36,4 +36,3 @@ def derive_short_channel_id(block_height: int, tx_idx: int, tx_output) -> str: Output index inside the transaction. """ return f"{block_height}x{tx_idx}x{tx_output}" - diff --git a/tests/spec_helper.py b/tests/spec_helper.py index 32610b2..d3e34dc 100644 --- a/tests/spec_helper.py +++ b/tests/spec_helper.py @@ -28,7 +28,7 @@ Commit, Side, msat, - CreateFunding, OneOf, + CreateFunding, ) from helpers import ( utxo, @@ -160,18 +160,20 @@ def open_and_announce_channel_helper( # wait confirmations Block(blockheight=103, number=6), # FIXME: implement all the utils function for the announcement_signatures - ExpectMsg("announcement_signatures", + ExpectMsg( + "announcement_signatures", channel_id=channel_id(), short_channel_id=short_channel_id, # TODO: How build signatures without hard coding it here? node_signature="5ffb05bfb1ef2941cd26e02eea9bfcd6862a08dcfd58473cd1e7da879c2127d6650159c731ae07cd07ff00f4fe7d344aef7997384465f34d7c57add4795a7b09", - bitcoin_signature="138c93afb2013c39f959e70a163c3d6d8128cf72f8ae143f87b9d1fd6bb0ad30321116b9c58d69fca9fb33c214f681b664e53d5640abc2fdb972dc62a5571053" + bitcoin_signature="138c93afb2013c39f959e70a163c3d6d8128cf72f8ae143f87b9d1fd6bb0ad30321116b9c58d69fca9fb33c214f681b664e53d5640abc2fdb972dc62a5571053", ), - Msg("announcement_signatures", + Msg( + "announcement_signatures", channel_id=channel_id(), short_channel_id=short_channel_id, # TODO: How build signatures without hard coding it here? node_signature="5ffb05bfb1ef2941cd26e02eea9bfcd6862a08dcfd58473cd1e7da879c2127d6650159c731ae07cd07ff00f4fe7d344aef7997384465f34d7c57add4795a7b09", - bitcoin_signature="138c93afb2013c39f959e70a163c3d6d8128cf72f8ae143f87b9d1fd6bb0ad30321116b9c58d69fca9fb33c214f681b664e53d5640abc2fdb972dc62a5571053" + bitcoin_signature="138c93afb2013c39f959e70a163c3d6d8128cf72f8ae143f87b9d1fd6bb0ad30321116b9c58d69fca9fb33c214f681b664e53d5640abc2fdb972dc62a5571053", ), ] diff --git a/tests/test_bolt2-01-close_channel.py b/tests/test_bolt2-01-close_channel.py index 2021b3c..3fe0ca5 100644 --- a/tests/test_bolt2-01-close_channel.py +++ b/tests/test_bolt2-01-close_channel.py @@ -11,6 +11,7 @@ | |<-(2)----- shutdown --------| | | | | | | | | | + | | | | | A | ... | B | | | | | | |--(3)-- closing_signed F1--->| | @@ -81,12 +82,14 @@ def test_close_channel_shutdown_msg_normal_case_received_side(runner: Runner) -> run_runner(runner, merge_events_sequences(pre=pre_events, post=test)) -def test_close_channel_shutdown_msg_wrong_script_pubkey_received_side(runner: Runner) -> None: +def test_close_channel_shutdown_msg_wrong_script_pubkey_received_side( + runner: Runner, +) -> None: """Test close operation from the receiver view point, in the case when the sender set a wrong script pub key not specified in the spec. ______________________________________________________ | runner -> shutdown (wrong script pub key) -> ln-node | - | runner <- error msg <- ln-node | + | runner <- warning msg <- ln-node | ------------------------------------------------------- """ @@ -114,8 +117,8 @@ def test_close_channel_shutdown_msg_wrong_script_pubkey_received_side(runner: Ru channel_id=channel_idx, scriptpubkey=script, ), - MustNotMsg('shutdown'), - MustNotMsg('add_htlc'), + MustNotMsg("shutdown"), + MustNotMsg("add_htlc"), # FIXME: add support for warning messages in pyln package? ], ),