mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-01 03:24:41 +01:00
e8e7c4719f
This only happens when a deletion is added by a running gossipd, so we put a deletion at the end of the store to test it. mypy noticed that this code was nonsensical, so clearly untested. The testing noticed that making a nodeid from a string was also buggy. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
75 lines
2.3 KiB
Python
75 lines
2.3 KiB
Python
from pyln.client import Gossmap, GossmapNode, GossmapNodeId
|
|
|
|
import os.path
|
|
import lzma
|
|
|
|
|
|
def unxz_data_tmp(src, tmp_path, dst, wmode):
|
|
fulldst = os.path.join(tmp_path, dst)
|
|
with open(fulldst, wmode) as out:
|
|
with lzma.open(os.path.join(os.path.dirname(__file__), "data", src), "rb")as f:
|
|
out.write(f.read())
|
|
return fulldst
|
|
|
|
|
|
def test_gossmap(tmp_path):
|
|
sfile = unxz_data_tmp("gossip_store-part1.xz", tmp_path, "gossip_store", "xb")
|
|
g = Gossmap(sfile)
|
|
|
|
chans = len(g.channels)
|
|
nodes = len(g.nodes)
|
|
|
|
g.refresh()
|
|
assert chans == len(g.channels)
|
|
assert nodes == len(g.nodes)
|
|
|
|
# Now append.
|
|
unxz_data_tmp("gossip_store-part2.xz", tmp_path, "gossip_store", "ab")
|
|
|
|
g.refresh()
|
|
|
|
# This actually deletes a channel, which deletes a node.
|
|
assert g.get_channel("686386x1093x1") is None
|
|
assert g.get_node('029deaf9d2fba868fe0a124050f0a13e021519a12f41bea34f391fe7533fb3166d') is None
|
|
# The other node is untouched
|
|
assert g.get_node('02e0af3c70bf42343316513e54683b10c01d906c04a05dfcd9479b90d7beed9129')
|
|
|
|
# It will notice the new ones.
|
|
assert chans < len(g.channels)
|
|
assert nodes < len(g.nodes)
|
|
|
|
# Whole load at the same time gives the same results.
|
|
g2 = Gossmap(sfile)
|
|
assert set(g.channels.keys()) == set(g2.channels.keys())
|
|
assert set(g.nodes.keys()) == set(g2.nodes.keys())
|
|
|
|
# Check some details
|
|
channel2 = g.get_channel("686200x1137x0")
|
|
assert g.get_channel("686386x1093x1") is None
|
|
assert channel2.satoshis == 3000000
|
|
|
|
|
|
def test_objects():
|
|
boltz = "026165850492521f4ac8abd9bd8088123446d126f648ca35e60f88177dc149ceb2"
|
|
acinq = "03864ef025fde8fb587d989186ce6a4a186895ee44a926bfc370e2c366597a3f8f"
|
|
|
|
boltz_id = GossmapNodeId(bytes.fromhex(boltz))
|
|
acinq_id = GossmapNodeId(bytes.fromhex(acinq))
|
|
assert boltz_id == GossmapNodeId(boltz)
|
|
|
|
assert boltz_id < acinq_id
|
|
assert acinq_id > boltz_id
|
|
assert boltz_id != acinq_id
|
|
assert acinq_id != boltz_id
|
|
assert not boltz_id > acinq_id
|
|
assert not acinq_id < boltz_id
|
|
assert not boltz_id == acinq_id
|
|
assert not acinq_id == boltz_id
|
|
|
|
boltz_node = GossmapNode(boltz_id)
|
|
acinq_node = GossmapNode(acinq_id)
|
|
assert boltz_node == GossmapNode(boltz)
|
|
assert boltz_node < acinq_node
|
|
assert acinq_node > boltz_node
|
|
assert boltz_node != acinq_node
|