def channel_monitor_data(in_mem_chan_keys, holder_commitment_tx):
    shutdown_pk = PublicKey(get_random_pk_bytes())
    on_counterparty_tx_csv = 20
    destination_script = Script(get_random_bytes((40)))
    funding_info = (OutPoint.from_bytes(get_random_bytes(34)), Script(get_random_bytes(50)))
    counterparty_htlc_base_key = PublicKey(get_random_pk_bytes())
    counterparty_delayed_payment_base_key = PublicKey(get_random_pk_bytes())
    on_holder_tx_csv = 30
    funding_redeemscript = Script(get_random_bytes(40))
    channel_value_satoshis = 42
    commitment_transaction_number_obscure_factor = 10

    return {
        "in_mem_chan_keys": in_mem_chan_keys,
        "shutdown_pk": shutdown_pk,
        "on_counterparty_tx_csv": on_counterparty_tx_csv,
        "destination_script": destination_script,
        "funding_info": funding_info,
        "counterparty_htlc_base_key": counterparty_htlc_base_key,
        "counterparty_delayed_payment_base_key": counterparty_delayed_payment_base_key,
        "on_holder_tx_csv": on_holder_tx_csv,
        "funding_redeemscript": funding_redeemscript,
        "channel_value_satoshis": channel_value_satoshis,
        "commitment_transaction_number_obscure_factor": commitment_transaction_number_obscure_factor,
        "holder_commitment_tx": holder_commitment_tx,
    }
Beispiel #2
0
def test_tx_creation_keys():
    tx_creation_keys = TxCreationKeys(
        PublicKey(get_random_pk_bytes()),
        PublicKey(get_random_pk_bytes()),
        PublicKey(get_random_pk_bytes()),
        PublicKey(get_random_pk_bytes()),
        PublicKey(get_random_pk_bytes()),
    )
    assert isinstance(tx_creation_keys, TxCreationKeys)
Beispiel #3
0
def test_channel_public_keys():
    chan_pks = ChannelPublicKeys(
        PublicKey(get_random_pk_bytes()),
        PublicKey(get_random_pk_bytes()),
        PublicKey(get_random_pk_bytes()),
        PublicKey(get_random_pk_bytes()),
        PublicKey(get_random_pk_bytes()),
    )

    assert isinstance(chan_pks, ChannelPublicKeys)
Beispiel #4
0
def test_dynamic_output_pwsh():
    outpoint = OutPoint.from_bytes(get_random_bytes(34))
    per_commitment_point = PublicKey(get_random_pk_bytes())
    to_self_delay = 20
    txout = TxOut(get_random_int(8), Script(get_random_bytes(30)))
    key_derivation_params = (get_random_int(8), get_random_int(8))
    revocation_pubkey = PublicKey(get_random_pk_bytes())
    descriptor = SpendableOutputDescriptor.dynamic_output_pwsh(
        outpoint, per_commitment_point, to_self_delay, txout,
        key_derivation_params, revocation_pubkey)

    assert isinstance(
        descriptor,
        SpendableOutputDescriptor) and descriptor.type == "DynamicOutputP2WSH"
Beispiel #5
0
def test_test_channel_public_keys_getters():
    funding_pk = PublicKey(get_random_pk_bytes())
    revocation_basepoint = PublicKey(get_random_pk_bytes())
    payment_point = PublicKey(get_random_pk_bytes())
    delayed_payment_basepoint = PublicKey(get_random_pk_bytes())
    htlc_basepoint = PublicKey(get_random_pk_bytes())

    chan_pks = ChannelPublicKeys(
        funding_pk, revocation_basepoint, payment_point, delayed_payment_basepoint, htlc_basepoint
    )

    assert chan_pks.funding_pubkey == funding_pk
    assert chan_pks.revocation_basepoint == revocation_basepoint
    assert chan_pks.payment_point == payment_point
    assert chan_pks.delayed_payment_basepoint == delayed_payment_basepoint
    assert chan_pks.htlc_basepoint == htlc_basepoint
Beispiel #6
0
def test_dynamic_output_pwsh_getters():
    outpoint = OutPoint.from_bytes(get_random_bytes(34))
    per_commitment_point = PublicKey(get_random_pk_bytes())
    to_self_delay = 20
    txout = TxOut(get_random_int(8), Script(get_random_bytes(30)))
    key_derivation_params = (get_random_int(8), get_random_int(8))
    revocation_pubkey = PublicKey(get_random_pk_bytes())
    descriptor = SpendableOutputDescriptor.dynamic_output_pwsh(
        outpoint, per_commitment_point, to_self_delay, txout,
        key_derivation_params, revocation_pubkey)

    assert descriptor.outpoint == outpoint
    assert descriptor.per_commitment_point == per_commitment_point
    assert descriptor.to_self_delay == to_self_delay
    assert descriptor.output == txout
    assert descriptor.key_derivation_params == key_derivation_params
    assert descriptor.revocation_pubkey == revocation_pubkey
Beispiel #7
0
def test_network_graph_getters():
    net_graph = NetworkGraph()

    assert net_graph.channels == {}
    assert net_graph.nodes == {}

    # This is not exactly a getter perse (like getting an attribute), but its a Rust getter, so let's add it here too.
    pk = PublicKey(get_random_pk_bytes())
    assert net_graph.get_addresses(pk) is None
Beispiel #8
0
def channel_info_data(directional_channel_info, channel_announcement_bytes):
    features = ChannelFeatures.known()
    node_one = PublicKey(get_random_pk_bytes())
    one_to_two = directional_channel_info
    node_two = PublicKey(get_random_pk_bytes())
    two_to_one = directional_channel_info
    capacity_sats = 42000
    announcement_message = ChannelAnnouncement.from_bytes(channel_announcement_bytes)

    return {
        "features": features,
        "node_one": node_one,
        "one_to_two": one_to_two,
        "node_two": node_two,
        "two_to_one": two_to_one,
        "capacity_sats": capacity_sats,
        "announcement_message": announcement_message,
    }
Beispiel #9
0
def get_rand_route_hop():
    pubkey = PublicKey(get_random_pk_bytes())
    node_features = NodeFeatures()
    short_channel_id = get_random_int(2)
    channel_features = ChannelFeatures()
    fee_msat = 1000
    cltv_expiry_delta = 20

    return RouteHop(pubkey, node_features, short_channel_id, channel_features,
                    fee_msat, cltv_expiry_delta)
Beispiel #10
0
def test_tx_creation_keys_getters():
    per_commitment_point = PublicKey(get_random_pk_bytes())
    revocation_key = PublicKey(get_random_pk_bytes())
    broadcaster_htlc_key = PublicKey(get_random_pk_bytes())
    countersignatory_htlc_key = PublicKey(get_random_pk_bytes())
    broadcaster_delayed_payment_key = PublicKey(get_random_pk_bytes())

    tx_creation_keys = TxCreationKeys(
        per_commitment_point,
        revocation_key,
        broadcaster_htlc_key,
        countersignatory_htlc_key,
        broadcaster_delayed_payment_key,
    )

    assert tx_creation_keys.per_commitment_point == per_commitment_point
    assert tx_creation_keys.revocation_key == revocation_key
    assert tx_creation_keys.broadcaster_htlc_key == broadcaster_htlc_key
    assert tx_creation_keys.countersignatory_htlc_key == countersignatory_htlc_key
    assert tx_creation_keys.broadcaster_delayed_payment_key == broadcaster_delayed_payment_key
Beispiel #11
0
def holder_commitment_tx_data(tx):
    counterparty_sk = SecretKey(get_random_sk_bytes())

    counterparty_pk = PublicKey.from_secret_key(counterparty_sk)
    counterparty_sig = counterparty_sk.sign(tx.hex())
    holder_pk = PublicKey(get_random_pk_bytes())
    keys = TxCreationKeys(
        PublicKey(get_random_pk_bytes()),
        PublicKey(get_random_pk_bytes()),
        PublicKey(get_random_pk_bytes()),
        PublicKey(get_random_pk_bytes()),
        PublicKey(get_random_pk_bytes()),
    )
    feerate_kw = 1000

    # HTLC DATA
    offered = True
    amount_msat = 500000
    cltv_expiry = 30
    payment_hash = PaymentHash(get_random_bytes(32))
    tx_out_index = None

    htlc_out = HTLCOutputInCommitment(offered, amount_msat, cltv_expiry, payment_hash, tx_out_index)
    htlc_data = [(htlc_out, None)]

    return Transaction.from_bytes(tx), counterparty_sig, holder_pk, counterparty_pk, keys, feerate_kw, htlc_data
Beispiel #12
0
def test_route_hop_getters():
    # FIXME: Features content cannot be tested since it cannot be serialized and the flags cannot be accessed
    # Try back once bindings are switched to work with references intead of values
    pubkey = PublicKey(get_random_pk_bytes())
    node_features = NodeFeatures()
    short_channel_id = get_random_int(2)
    channel_features = ChannelFeatures()
    fee_msat = 1000
    cltv_expiry_delta = 20

    rh = RouteHop(pubkey, node_features, short_channel_id, channel_features,
                  fee_msat, cltv_expiry_delta)

    assert rh.pubkey == pubkey
    assert rh.short_channel_id == short_channel_id
    assert rh.fee_msat == fee_msat
    assert rh.cltv_expiry_delta == cltv_expiry_delta
Beispiel #13
0
def test_public_key_serialize():
    pk_bytes = get_random_pk_bytes()
    assert (PublicKey(pk_bytes).serialize()) == pk_bytes

    pk_bytes = get_random_pk_bytes(compressed=False)
    assert (PublicKey(pk_bytes).serialize(compressed=False)) == pk_bytes
Beispiel #14
0
def test_public_key_init():
    assert isinstance(PublicKey(get_random_pk_bytes()), PublicKey)
    assert isinstance(PublicKey(get_random_pk_bytes(compressed=False)), PublicKey)
Beispiel #15
0
def test_public_key_str():
    pk_bytes = get_random_pk_bytes()
    assert (str(PublicKey(pk_bytes))) == pk_bytes.hex()
Beispiel #16
0
def test_public_key_cmp():
    pk_bytes = get_random_pk_bytes()
    assert PublicKey(pk_bytes) == PublicKey(pk_bytes)
    assert PublicKey(get_random_pk_bytes()) != PublicKey(pk_bytes)
Beispiel #17
0
def test_peer_manager_new_outbound_connection(peer_manager, socket_descriptor):
    their_node_id = PublicKey(get_random_pk_bytes())

    r = peer_manager.new_outbound_connection(their_node_id, socket_descriptor)
    assert isinstance(r, bytes) and len(r) == 50