Skip to content

Commit

Permalink
reformatting python code
Browse files Browse the repository at this point in the history
Signed-off-by: Vincenzo Palazzo <[email protected]>
  • Loading branch information
vincenzopalazzo committed Apr 6, 2022
1 parent a9a5ac5 commit 127fd9f
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 15 deletions.
3 changes: 2 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[flake8]
max-line-length = 88
extend-ignore = E203
extend-ignore = E203
per-file-ignores = __init__.py:F401
10 changes: 9 additions & 1 deletion lnprototest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lnprototest/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -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
from .bitcoin_utils import ScriptType, BitcoinUtils
7 changes: 5 additions & 2 deletions lnprototest/utils/bitcoin_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand All @@ -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)
Expand Down
1 change: 0 additions & 1 deletion lnprototest/utils/ln_spec_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"

12 changes: 7 additions & 5 deletions tests/spec_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
Commit,
Side,
msat,
CreateFunding, OneOf,
CreateFunding,
)
from helpers import (
utxo,
Expand Down Expand Up @@ -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",
),
]
11 changes: 7 additions & 4 deletions tests/test_bolt2-01-close_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
| |<-(2)----- shutdown --------| |
| | | |
| | <complete all pending HTLCs> | |
| | <must not add HTLCs> | |
| A | ... | B |
| | | |
| |--(3)-- closing_signed F1--->| |
Expand Down Expand Up @@ -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 |
-------------------------------------------------------
"""

Expand Down Expand Up @@ -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?
],
),
Expand Down

0 comments on commit 127fd9f

Please sign in to comment.