Skip to content

Commit 40a4d83

Browse files
committed
pytest: don't assume gossip order in test_gossip_query_channel_range
``` # reply_channel_range == 264 > assert msgs == ['0108' # blockhash + genesis_blockhash # first_blocknum, number_of_blocks, complete + format(0, '08x') + format(1000000, '08x') + '01' # encoded_short_ids + format(len(encoded) // 2, '04x') + encoded] E AssertionError: assert ['010806226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f00000000000f42400100110000006900000100000000680000010000'] == ['010806226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f00000000000f42400100110000006800000100000000690000010000'] E At index 0 diff: '010806226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f00000000000f42400100110000006900000100000000680000010000' != '010806226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f00000000000f42400100110000006800000100000000690000010000' E Full diff: E - ['010806226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f00000000000f42400100110000006800000100000000690000010000'] E ? ^ ^ E + ['010806226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f00000000000f42400100110000006900000100000000680000010000'] E ? ^ ^ ``` Signed-off-by: Rusty Russell <[email protected]>
1 parent a5ba3f8 commit 40a4d83

File tree

1 file changed

+60
-29
lines changed

1 file changed

+60
-29
lines changed

tests/test_gossip.py

Lines changed: 60 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -748,19 +748,32 @@ def test_gossip_query_channel_range(node_factory, bitcoind, chainparams):
748748
chainparams['chain_hash'],
749749
0, 1000000,
750750
filters=['0109', '0107', '0012'])
751-
encoded = subprocess.run(['devtools/mkencoded', '--scids', '00', scid12, scid23],
752-
check=True,
753-
timeout=TIMEOUT,
754-
stdout=subprocess.PIPE).stdout.strip().decode()
751+
# Either order!
752+
encoded1 = subprocess.run(['devtools/mkencoded', '--scids', '00', scid12, scid23],
753+
check=True,
754+
timeout=TIMEOUT,
755+
stdout=subprocess.PIPE).stdout.strip().decode()
756+
encoded2 = subprocess.run(['devtools/mkencoded', '--scids', '00', scid23, scid12],
757+
check=True,
758+
timeout=TIMEOUT,
759+
stdout=subprocess.PIPE).stdout.strip().decode()
755760
# reply_channel_range == 264
756-
assert msgs == ['0108'
757-
# blockhash
758-
+ genesis_blockhash
759-
# first_blocknum, number_of_blocks, complete
760-
+ format(0, '08x') + format(1000000, '08x') + '01'
761-
# encoded_short_ids
762-
+ format(len(encoded) // 2, '04x')
763-
+ encoded]
761+
assert msgs in (['0108'
762+
# blockhash
763+
+ genesis_blockhash
764+
# first_blocknum, number_of_blocks, complete
765+
+ format(0, '08x') + format(1000000, '08x') + '01'
766+
# encoded_short_ids
767+
+ format(len(encoded1) // 2, '04x')
768+
+ encoded1],
769+
['0108'
770+
# blockhash
771+
+ genesis_blockhash
772+
# first_blocknum, number_of_blocks, complete
773+
+ format(0, '08x') + format(1000000, '08x') + '01'
774+
# encoded_short_ids
775+
+ format(len(encoded2) // 2, '04x')
776+
+ encoded2])
764777

765778
# Does not include scid12
766779
msgs = l4.query_gossip('query_channel_range',
@@ -819,19 +832,32 @@ def test_gossip_query_channel_range(node_factory, bitcoind, chainparams):
819832
genesis_blockhash,
820833
block12, block23 - block12 + 1,
821834
filters=['0109', '0107', '0012'])
822-
encoded = subprocess.run(['devtools/mkencoded', '--scids', '00', scid12, scid23],
823-
check=True,
824-
timeout=TIMEOUT,
825-
stdout=subprocess.PIPE).stdout.strip().decode()
835+
# Either order
836+
encoded1 = subprocess.run(['devtools/mkencoded', '--scids', '00', scid12, scid23],
837+
check=True,
838+
timeout=TIMEOUT,
839+
stdout=subprocess.PIPE).stdout.strip().decode()
840+
encoded2 = subprocess.run(['devtools/mkencoded', '--scids', '00', scid23, scid12],
841+
check=True,
842+
timeout=TIMEOUT,
843+
stdout=subprocess.PIPE).stdout.strip().decode()
826844
# reply_channel_range == 264
827-
assert msgs == ['0108'
828-
# blockhash
829-
+ genesis_blockhash
830-
# first_blocknum, number_of_blocks, complete
831-
+ format(block12, '08x') + format(block23 - block12 + 1, '08x') + '01'
832-
# encoded_short_ids
833-
+ format(len(encoded) // 2, '04x')
834-
+ encoded]
845+
assert msgs in (['0108'
846+
# blockhash
847+
+ genesis_blockhash
848+
# first_blocknum, number_of_blocks, complete
849+
+ format(block12, '08x') + format(block23 - block12 + 1, '08x') + '01'
850+
# encoded_short_ids
851+
+ format(len(encoded1) // 2, '04x')
852+
+ encoded1],
853+
['0108'
854+
# blockhash
855+
+ genesis_blockhash
856+
# first_blocknum, number_of_blocks, complete
857+
+ format(block12, '08x') + format(block23 - block12 + 1, '08x') + '01'
858+
# encoded_short_ids
859+
+ format(len(encoded2) // 2, '04x')
860+
+ encoded2])
835861

836862
# Only includes scid23
837863
msgs = l4.query_gossip('query_channel_range',
@@ -888,11 +914,16 @@ def test_gossip_query_channel_range(node_factory, bitcoind, chainparams):
888914
assert this_start == start
889915
start += num
890916

891-
encoded = subprocess.run(['devtools/mkencoded', '--scids', '00', scid12, scid23],
892-
check=True,
893-
timeout=TIMEOUT,
894-
stdout=subprocess.PIPE).stdout.strip().decode()
895-
assert scids == encoded
917+
# Either order
918+
encoded1 = subprocess.run(['devtools/mkencoded', '--scids', '00', scid12, scid23],
919+
check=True,
920+
timeout=TIMEOUT,
921+
stdout=subprocess.PIPE).stdout.strip().decode()
922+
encoded2 = subprocess.run(['devtools/mkencoded', '--scids', '00', scid23, scid12],
923+
check=True,
924+
timeout=TIMEOUT,
925+
stdout=subprocess.PIPE).stdout.strip().decode()
926+
assert scids in (encoded1, encoded2)
896927

897928
# Test overflow case doesn't split forever; should still only get 2 for this
898929
msgs = l4.query_gossip('query_channel_range',

0 commit comments

Comments
 (0)