-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from vincenzopalazzo/macros/coop_close
bolt2: add coop close test
- Loading branch information
Showing
14 changed files
with
581 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ on: | |
branches: [master] | ||
pull_request: | ||
branches: [master] | ||
schedule: | ||
- cron: '30 1 1,15 * *' | ||
|
||
jobs: | ||
test: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,8 +59,7 @@ RUN pip3 install -U pip && \ | |
RUN git config --global user.name "John Doe" && \ | ||
git config --global user.email [email protected] && \ | ||
git clone https://github.com/ElementsProject/lightning.git && \ | ||
cd lightning && \ | ||
git checkout v$CLIGHTNING_VERSION && \ | ||
cd lightning && \ | ||
poetry config virtualenvs.create false && \ | ||
poetry install && \ | ||
./configure --enable-developer && \ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
""" | ||
Bitcoin utils is a collection of methods that helps to | ||
work with bitcoin primitive. | ||
""" | ||
import hashlib | ||
from enum import Enum | ||
|
||
from bitcoin.core import Hash160, x | ||
from bitcoin.core.script import OP_0, OP_CHECKSIG, CScript | ||
from bitcoin.wallet import CBitcoinSecret | ||
|
||
|
||
class ScriptType(Enum): | ||
""" | ||
Type of Script used in the Runner. | ||
In particular, during the testing we need to have | ||
two type of script, the valid one and the invalid one. | ||
This is useful when is needed to send an invalid script. | ||
FIXME: naming is too simple. | ||
""" | ||
|
||
VALID_CLOSE_SCRIPT = 1 | ||
INVALID_CLOSE_SCRIPT = 2 | ||
|
||
|
||
class BitcoinUtils: | ||
"""Main implementation class of the lightning networks utils. | ||
The implementation class contains only static methods that | ||
apply the rules specified by the BIP.""" | ||
|
||
@staticmethod | ||
def blockchain_hash() -> str: | ||
"""Return the chain transaction hash. | ||
That in this case is the regtest transaction hash.""" | ||
return "06226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f" | ||
|
||
@staticmethod | ||
def build_valid_script( | ||
script_type: ScriptType = ScriptType.VALID_CLOSE_SCRIPT, | ||
word: str = "lnprototest", | ||
) -> str: | ||
"""Build a valid bitcoin script and hide the primitive of the library""" | ||
secret_str = f"correct horse battery staple {word}" | ||
h = hashlib.sha256(secret_str.encode("ascii")).digest() | ||
seckey = CBitcoinSecret.from_secret_bytes(h) | ||
if script_type is ScriptType.VALID_CLOSE_SCRIPT: | ||
return CScript([OP_0, Hash160(seckey.pub)]).hex() | ||
elif script_type is ScriptType.INVALID_CLOSE_SCRIPT: | ||
return CScript([seckey.pub, OP_CHECKSIG]).hex() | ||
|
||
@staticmethod | ||
def build_script(hex: str) -> CScript: | ||
return CScript(x(hex)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
""" | ||
Lightning network Speck utils, is a collection of methods that helps to | ||
work with some concept of lightning network RFC | ||
""" | ||
|
||
|
||
class LightningUtils: | ||
""" | ||
Main implementation class of the lightning networks utils. | ||
The implementation class contains only static methods that | ||
apply the rules specified in the lightning network RFC. | ||
""" | ||
|
||
@staticmethod | ||
def derive_short_channel_id(block_height: int, tx_idx: int, tx_output) -> str: | ||
""" | ||
Derive the short channel id with the specified | ||
parameters, and return the result as string. | ||
RFC definition: https://github.com/lightning/bolts/blob/93909f67f6a48ee3f155a6224c182e612dd5f187/07-routing-gossip.md#definition-of-short_channel_id | ||
The short_channel_id is the unique description of the funding transaction. It is constructed as follows: | ||
- the most significant 3 bytes: indicating the block height | ||
- the next 3 bytes: indicating the transaction index within the block | ||
- the least significant 2 bytes: indicating the output index that pays to the channel. | ||
e.g: a short_channel_id might be written as 539268x845x1, indicating a channel on the | ||
output 1 of the transaction at index 845 of the block at height 539268. | ||
block_height: str | ||
Block height. | ||
tx_idx: int | ||
Transaction index inside the block. | ||
tx_output: int | ||
Output index inside the transaction. | ||
""" | ||
return f"{block_height}x{tx_idx}x{tx_output}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.