def test_static_output_counterparty_payment(): outpoint = OutPoint.from_bytes(get_random_bytes(34)) txout = TxOut(get_random_int(8), Script(get_random_bytes(30))) key_derivation_params = (get_random_int(8), get_random_int(8)) descriptor = SpendableOutputDescriptor.static_output_counterparty_payment( outpoint, txout, key_derivation_params) assert isinstance( descriptor, SpendableOutputDescriptor ) and descriptor.type == "StaticOutputCounterpartyPayment"
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"
def test_static_output_counterparty_payment_getters(): outpoint = OutPoint.from_bytes(get_random_bytes(34)) txout = TxOut(get_random_int(8), Script(get_random_bytes(30))) key_derivation_params = (get_random_int(8), get_random_int(8)) descriptor = SpendableOutputDescriptor.static_output_counterparty_payment( outpoint, txout, key_derivation_params) assert descriptor.outpoint == outpoint assert descriptor.output == txout assert descriptor.key_derivation_params == key_derivation_params # Check no other getters are available local_attributes = ["outpoint", "output", "key_derivation_params"] check_not_available_getters(descriptor, local_attributes, all_attributes)
def test_pending_htlcs_forwardable(): secs = get_random_int(8) nanos = get_random_int(4) # Make sure nanos does not go all the way to seconds while nanos > 100000000: secs = +1 nanos -= 100000000 event = Event.pending_htlcs_forwardable(secs, nanos) assert event.time_forwardable == (secs, nanos) # Check no other getters are available local_attributes = ["time_forwardable"] check_not_available_getters(event, local_attributes, all_attributes)
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
def test_static_output(): outpoint = OutPoint.from_bytes(get_random_bytes(34)) txout = TxOut(get_random_int(8), Script(get_random_bytes(30))) descriptor = SpendableOutputDescriptor.static_output(outpoint, txout) assert isinstance( descriptor, SpendableOutputDescriptor) and descriptor.type == "StaticOutput"
def test_funding_generation_ready(): temporary_channel_id = get_random_bytes(32) channel_value_satoshis = 42 output_script = Script(get_random_bytes(50)) user_channel_id = get_random_int(8) event = Event.funding_generation_ready(temporary_channel_id, channel_value_satoshis, output_script, user_channel_id) assert isinstance(event, Event) and event.type == "FundingGenerationReady"
def directional_channel_info_data(): last_update = get_random_int(4) enabled = True cltv_expiry_delta = get_random_int(2) htlc_minimum_msat = get_random_int(8) htlc_maximum_msat = get_random_int(8) fees = RoutingFees(42, 21) last_update_message = None return { "last_update": last_update, "enabled": enabled, "cltv_expiry_delta": cltv_expiry_delta, "htlc_minimum_msat": htlc_minimum_msat, "htlc_maximum_msat": htlc_maximum_msat, "fees": fees, "last_update_message": last_update_message, }
def test_spendable_outputs_getters(): outpoint = OutPoint.from_bytes(get_random_bytes(34)) output = TxOut(get_random_int(8), Script(get_random_bytes(50))) descriptor = SpendableOutputDescriptor.static_output(outpoint, output) event = Event.spendable_outputs([descriptor]) for local_output, binded_output in zip(event.outputs, [descriptor]): assert local_output.type == binded_output.type assert local_output.outpoint == binded_output.outpoint assert local_output.output == binded_output.output
def node_info_data(routing_fees_bytes, node_announcement_info_bytes): channels = [get_random_int(8)] lowest_inbound_channel_fees = RoutingFees.from_bytes(routing_fees_bytes) announcement_info = NodeAnnouncementInfo.from_bytes(node_announcement_info_bytes) return { "channels": channels, "lowest_inbound_channel_fees": lowest_inbound_channel_fees, "announcement_info": announcement_info, }
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)
def test_funding_broadcasting_safe_getters(): outpoint = OutPoint.from_bytes(get_random_bytes(34)) user_channel_id = get_random_int(8) event = Event.funding_broadcasting_safe(outpoint, user_channel_id) assert event.funding_txo == outpoint assert event.user_channel_id == user_channel_id # Check no other getters are available local_attributes = ["funding_txo", "user_channel_id"] check_not_available_getters(event, local_attributes, all_attributes)
def test_static_output_getters(): outpoint = OutPoint.from_bytes(get_random_bytes(34)) txout = TxOut(get_random_int(8), Script(get_random_bytes(30))) descriptor = SpendableOutputDescriptor.static_output(outpoint, txout) assert descriptor.outpoint == outpoint assert descriptor.output == txout # Check no other getters are available local_attributes = ["outpoint", "output"] check_not_available_getters(descriptor, local_attributes, all_attributes)
def test_payment_received_getters(): payment_hash = PaymentHash(get_random_bytes(32)) payment_secret = None amt = get_random_int(8) event = Event.payment_received(payment_hash, payment_secret, amt) assert event.payment_hash == payment_hash assert event.payment_secret == payment_secret assert event.amt == amt # Check no other getters are available local_attributes = ["payment_hash", "payment_secret", "amt"] check_not_available_getters(event, local_attributes, all_attributes)
def node_announcement_info_data(node_announcement_bytes): features = NodeFeatures.known() last_update = get_random_int(4) rgb = get_random_bytes(3) alias = get_random_bytes(32) addresses = [NetAddress.ipv4([127, 0, 0, 1], 1234)] announcement_message = NodeAnnouncement.from_bytes(node_announcement_bytes) return { "features": features, "last_update": last_update, "rgb": rgb, "alias": alias, "addresses": addresses, "announcement_message": announcement_message, }
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
def test_funding_generation_ready_getters(): temporary_channel_id = get_random_bytes(32) channel_value_satoshis = 42 output_script = Script(get_random_bytes(50)) user_channel_id = get_random_int(8) event = Event.funding_generation_ready(temporary_channel_id, channel_value_satoshis, output_script, user_channel_id) assert event.temporary_channel_id == temporary_channel_id assert event.channel_value_satoshis == channel_value_satoshis assert event.output_script == output_script assert event.user_channel_id == user_channel_id # Check no other getters are available local_attributes = [ "temporary_channel_id", "channel_value_satoshis", "output_script", "user_channel_id" ] check_not_available_getters(event, local_attributes, all_attributes)
def routing_fees_data(): base_msat = get_random_int(4) proportional_millionths = get_random_int(4) return {"base_msat": base_msat, "proportional_millionths": proportional_millionths}
def test_payment_received(): payment_hash = PaymentHash(get_random_bytes(32)) payment_secret = None amt = get_random_int(8) event = Event.payment_received(payment_hash, payment_secret, amt) assert isinstance(event, Event) and event.type == "PaymentReceived"
def test_funding_broadcasting_safe(): outpoint = OutPoint.from_bytes(get_random_bytes(34)) user_channel_id = get_random_int(8) event = Event.funding_broadcasting_safe(outpoint, user_channel_id) assert isinstance(event, Event) and event.type == "FundingBroadcastSafe"
def test_pending_htlcs_forwardable(): secs = get_random_int(8) nanos = get_random_int(4) event = Event.pending_htlcs_forwardable(secs, nanos) assert isinstance(event, Event) and event.type == "PendingHTLCsForwardable"
def test_spendable_outputs(): outpoint = OutPoint.from_bytes(get_random_bytes(34)) output = TxOut(get_random_int(8), Script(get_random_bytes(50))) descriptor = SpendableOutputDescriptor.static_output(outpoint, output) event = Event.spendable_outputs([descriptor]) assert isinstance(event, Event) and event.type == "SpendableOutputs"