Skip to content

Commit

Permalink
pytest: add filters arg to query_gossip()
Browse files Browse the repository at this point in the history
Code changes mean we're going to get gossip_timestamp_filter messages from
peers.

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell authored and niftynei committed Oct 11, 2019
1 parent 9d33676 commit a3f6ce1
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ def wait_for_onchaind_broadcast(self, name, resolve=None):

wait_for(lambda: txid in self.bitcoin.rpc.getrawmempool())

def query_gossip(self, querytype, *args):
def query_gossip(self, querytype, *args, filters=[]):
"""Generate a gossip query, feed it into this node and get responses
in hex"""
query = subprocess.run(['devtools/mkquery',
Expand All @@ -825,10 +825,18 @@ def query_gossip(self, querytype, *args):
check=True,
timeout=TIMEOUT, stdout=subprocess.PIPE).stdout

def passes_filters(hmsg, filters):
for f in filters:
if hmsg.startswith(f):
return False
return True

msgs = []
while len(out):
length = struct.unpack('>H', out[0:2])[0]
msgs.append(out[2:2 + length].hex())
hmsg = out[2:2 + length].hex()
if passes_filters(hmsg, filters):
msgs.append(out[2:2 + length].hex())
out = out[2 + length:]
return msgs

Expand Down

0 comments on commit a3f6ce1

Please sign in to comment.