Skip to content

Commit 8d6c848

Browse files
[test] Move MAGIC_BYTES to messages.py
This avoids circular dependency happening when importing MAGIC_BYTES. Before, p2p.py <--import for EncryptedP2PState-- v2_p2p.py | ^ | | └---------import for MAGIC_BYTES----------┘ Now, MAGIC_BYTES are kept separately in messages.py Co-authored-by: Martin Zumsande <[email protected]>
1 parent 595ad4b commit 8d6c848

File tree

5 files changed

+11
-12
lines changed

5 files changed

+11
-12
lines changed

test/functional/feature_addrman.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
import re
99
import struct
1010

11-
from test_framework.messages import ser_uint256, hash256
11+
from test_framework.messages import ser_uint256, hash256, MAGIC_BYTES
1212
from test_framework.netutil import ADDRMAN_NEW_BUCKET_COUNT, ADDRMAN_TRIED_BUCKET_COUNT, ADDRMAN_BUCKET_SIZE
13-
from test_framework.p2p import MAGIC_BYTES
1413
from test_framework.test_framework import BitcoinTestFramework
1514
from test_framework.test_node import ErrorMatch
1615
from test_framework.util import assert_equal

test/functional/feature_reindex.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"""
1212

1313
from test_framework.test_framework import BitcoinTestFramework
14-
from test_framework.p2p import MAGIC_BYTES
14+
from test_framework.messages import MAGIC_BYTES
1515
from test_framework.util import assert_equal
1616

1717

test/functional/p2p_v2_transport.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
"""
88
import socket
99

10-
from test_framework.messages import NODE_P2P_V2
11-
from test_framework.p2p import MAGIC_BYTES
10+
from test_framework.messages import MAGIC_BYTES, NODE_P2P_V2
1211
from test_framework.test_framework import BitcoinTestFramework
1312
from test_framework.util import (
1413
assert_equal,

test/functional/test_framework/messages.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@
7575

7676
DEFAULT_MEMPOOL_EXPIRY_HOURS = 336 # hours
7777

78+
MAGIC_BYTES = {
79+
"mainnet": b"\xf9\xbe\xb4\xd9", # mainnet
80+
"testnet3": b"\x0b\x11\x09\x07", # testnet3
81+
"regtest": b"\xfa\xbf\xb5\xda", # regtest
82+
"signet": b"\x0a\x03\xcf\x40", # signet
83+
}
84+
7885
def sha256(s):
7986
return hashlib.sha256(s).digest()
8087

test/functional/test_framework/p2p.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
msg_wtxidrelay,
7373
NODE_NETWORK,
7474
NODE_WITNESS,
75+
MAGIC_BYTES,
7576
sha256,
7677
)
7778
from test_framework.util import (
@@ -140,13 +141,6 @@
140141
b"wtxidrelay": msg_wtxidrelay,
141142
}
142143

143-
MAGIC_BYTES = {
144-
"mainnet": b"\xf9\xbe\xb4\xd9", # mainnet
145-
"testnet3": b"\x0b\x11\x09\x07", # testnet3
146-
"regtest": b"\xfa\xbf\xb5\xda", # regtest
147-
"signet": b"\x0a\x03\xcf\x40", # signet
148-
}
149-
150144

151145
class P2PConnection(asyncio.Protocol):
152146
"""A low-level connection object to a node's P2P interface.

0 commit comments

Comments
 (0)