mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-19 05:45:05 +01:00
test: use test_framework.p2p P2P_SERVICES in functional tests
This commit is contained in:
parent
de2af19dc8
commit
b69a106bcd
@ -6,22 +6,22 @@
|
||||
Test addr relay
|
||||
"""
|
||||
|
||||
import random
|
||||
import time
|
||||
|
||||
from test_framework.messages import (
|
||||
CAddress,
|
||||
NODE_NETWORK,
|
||||
NODE_WITNESS,
|
||||
msg_addr,
|
||||
msg_getaddr,
|
||||
msg_verack
|
||||
msg_verack,
|
||||
)
|
||||
from test_framework.p2p import (
|
||||
P2PInterface,
|
||||
p2p_lock,
|
||||
P2P_SERVICES,
|
||||
)
|
||||
from test_framework.test_framework import BitcoinTestFramework
|
||||
from test_framework.util import assert_equal, assert_greater_than
|
||||
import random
|
||||
import time
|
||||
|
||||
|
||||
class AddrReceiver(P2PInterface):
|
||||
@ -96,7 +96,7 @@ class AddrTest(BitcoinTestFramework):
|
||||
for i in range(num):
|
||||
addr = CAddress()
|
||||
addr.time = self.mocktime + i
|
||||
addr.nServices = NODE_NETWORK | NODE_WITNESS
|
||||
addr.nServices = P2P_SERVICES
|
||||
addr.ip = f"123.123.123.{self.counter % 256}"
|
||||
addr.port = 8333 + i
|
||||
addrs.append(addr)
|
||||
@ -111,7 +111,7 @@ class AddrTest(BitcoinTestFramework):
|
||||
for i in range(num):
|
||||
addr = CAddress()
|
||||
addr.time = self.mocktime + i
|
||||
addr.nServices = NODE_NETWORK | NODE_WITNESS
|
||||
addr.nServices = P2P_SERVICES
|
||||
addr.ip = f"{random.randrange(128,169)}.{random.randrange(1,255)}.{random.randrange(1,255)}.{random.randrange(1,255)}"
|
||||
addr.port = 8333
|
||||
addrs.append(addr)
|
||||
|
@ -8,14 +8,21 @@ Test p2p addr-fetch connections
|
||||
|
||||
import time
|
||||
|
||||
from test_framework.messages import msg_addr, CAddress, NODE_NETWORK, NODE_WITNESS
|
||||
from test_framework.p2p import P2PInterface, p2p_lock
|
||||
from test_framework.messages import (
|
||||
CAddress,
|
||||
msg_addr,
|
||||
)
|
||||
from test_framework.p2p import (
|
||||
P2PInterface,
|
||||
p2p_lock,
|
||||
P2P_SERVICES,
|
||||
)
|
||||
from test_framework.test_framework import BitcoinTestFramework
|
||||
from test_framework.util import assert_equal
|
||||
|
||||
ADDR = CAddress()
|
||||
ADDR.time = int(time.time())
|
||||
ADDR.nServices = NODE_NETWORK | NODE_WITNESS
|
||||
ADDR.nServices = P2P_SERVICES
|
||||
ADDR.ip = "192.0.0.8"
|
||||
ADDR.port = 18444
|
||||
|
||||
|
@ -11,10 +11,11 @@ import time
|
||||
from test_framework.messages import (
|
||||
CAddress,
|
||||
msg_addrv2,
|
||||
NODE_NETWORK,
|
||||
NODE_WITNESS,
|
||||
)
|
||||
from test_framework.p2p import P2PInterface
|
||||
from test_framework.p2p import (
|
||||
P2PInterface,
|
||||
P2P_SERVICES,
|
||||
)
|
||||
from test_framework.test_framework import BitcoinTestFramework
|
||||
from test_framework.util import assert_equal
|
||||
|
||||
@ -24,7 +25,7 @@ ADDRS = []
|
||||
for i in range(10):
|
||||
addr = CAddress()
|
||||
addr.time = int(time.time()) + i
|
||||
addr.nServices = NODE_NETWORK | NODE_WITNESS
|
||||
addr.nServices = P2P_SERVICES
|
||||
# Add one I2P address at an arbitrary position.
|
||||
if i == 5:
|
||||
addr.net = addr.NET_I2P
|
||||
|
@ -43,6 +43,7 @@ from test_framework.messages import (
|
||||
from test_framework.p2p import (
|
||||
P2PInterface,
|
||||
p2p_lock,
|
||||
P2P_SERVICES,
|
||||
)
|
||||
from test_framework.script import (
|
||||
CScript,
|
||||
@ -224,14 +225,14 @@ class SegWitTest(BitcoinTestFramework):
|
||||
|
||||
def run_test(self):
|
||||
# Setup the p2p connections
|
||||
# self.test_node sets NODE_WITNESS|NODE_NETWORK
|
||||
self.test_node = self.nodes[0].add_p2p_connection(TestP2PConn(), services=NODE_NETWORK | NODE_WITNESS)
|
||||
# self.test_node sets P2P_SERVICES, i.e. NODE_WITNESS | NODE_NETWORK
|
||||
self.test_node = self.nodes[0].add_p2p_connection(TestP2PConn(), services=P2P_SERVICES)
|
||||
# self.old_node sets only NODE_NETWORK
|
||||
self.old_node = self.nodes[0].add_p2p_connection(TestP2PConn(), services=NODE_NETWORK)
|
||||
# self.std_node is for testing node1 (fRequireStandard=true)
|
||||
self.std_node = self.nodes[1].add_p2p_connection(TestP2PConn(), services=NODE_NETWORK | NODE_WITNESS)
|
||||
self.std_node = self.nodes[1].add_p2p_connection(TestP2PConn(), services=P2P_SERVICES)
|
||||
# self.std_wtx_node is for testing node1 with wtxid relay
|
||||
self.std_wtx_node = self.nodes[1].add_p2p_connection(TestP2PConn(wtxidrelay=True), services=NODE_NETWORK | NODE_WITNESS)
|
||||
self.std_wtx_node = self.nodes[1].add_p2p_connection(TestP2PConn(wtxidrelay=True), services=P2P_SERVICES)
|
||||
|
||||
assert self.test_node.nServices & NODE_WITNESS != 0
|
||||
|
||||
@ -2017,8 +2018,8 @@ class SegWitTest(BitcoinTestFramework):
|
||||
@subtest # type: ignore
|
||||
def test_wtxid_relay(self):
|
||||
# Use brand new nodes to avoid contamination from earlier tests
|
||||
self.wtx_node = self.nodes[0].add_p2p_connection(TestP2PConn(wtxidrelay=True), services=NODE_NETWORK | NODE_WITNESS)
|
||||
self.tx_node = self.nodes[0].add_p2p_connection(TestP2PConn(wtxidrelay=False), services=NODE_NETWORK | NODE_WITNESS)
|
||||
self.wtx_node = self.nodes[0].add_p2p_connection(TestP2PConn(wtxidrelay=True), services=P2P_SERVICES)
|
||||
self.tx_node = self.nodes[0].add_p2p_connection(TestP2PConn(wtxidrelay=False), services=P2P_SERVICES)
|
||||
|
||||
# Check wtxidrelay feature negotiation message through connecting a new peer
|
||||
def received_wtxidrelay():
|
||||
|
@ -12,11 +12,10 @@ from itertools import product
|
||||
import time
|
||||
|
||||
from test_framework.blocktools import COINBASE_MATURITY
|
||||
from test_framework.p2p import P2PInterface
|
||||
import test_framework.messages
|
||||
from test_framework.messages import (
|
||||
NODE_NETWORK,
|
||||
NODE_WITNESS,
|
||||
from test_framework.p2p import (
|
||||
P2PInterface,
|
||||
P2P_SERVICES,
|
||||
)
|
||||
from test_framework.test_framework import BitcoinTestFramework
|
||||
from test_framework.util import (
|
||||
@ -189,7 +188,6 @@ class NetTest(BitcoinTestFramework):
|
||||
def test_getnodeaddresses(self):
|
||||
self.log.info("Test getnodeaddresses")
|
||||
self.nodes[0].add_p2p_connection(P2PInterface())
|
||||
services = NODE_NETWORK | NODE_WITNESS
|
||||
|
||||
# Add an IPv6 address to the address manager.
|
||||
ipv6_addr = "1233:3432:2434:2343:3234:2345:6546:4534"
|
||||
@ -217,7 +215,7 @@ class NetTest(BitcoinTestFramework):
|
||||
assert_greater_than(10000, len(node_addresses))
|
||||
for a in node_addresses:
|
||||
assert_greater_than(a["time"], 1527811200) # 1st June 2018
|
||||
assert_equal(a["services"], services)
|
||||
assert_equal(a["services"], P2P_SERVICES)
|
||||
assert a["address"] in imported_addrs
|
||||
assert_equal(a["port"], 8333)
|
||||
assert_equal(a["network"], "ipv4")
|
||||
@ -228,7 +226,7 @@ class NetTest(BitcoinTestFramework):
|
||||
assert_equal(res[0]["address"], ipv6_addr)
|
||||
assert_equal(res[0]["network"], "ipv6")
|
||||
assert_equal(res[0]["port"], 8333)
|
||||
assert_equal(res[0]["services"], services)
|
||||
assert_equal(res[0]["services"], P2P_SERVICES)
|
||||
|
||||
# Test for the absence of onion and I2P addresses.
|
||||
for network in ["onion", "i2p"]:
|
||||
|
@ -356,7 +356,7 @@ class P2PInterface(P2PConnection):
|
||||
|
||||
return create_conn
|
||||
|
||||
def peer_accept_connection(self, *args, services=NODE_NETWORK | NODE_WITNESS, **kwargs):
|
||||
def peer_accept_connection(self, *args, services=P2P_SERVICES, **kwargs):
|
||||
create_conn = super().peer_accept_connection(*args, **kwargs)
|
||||
self.peer_connect_send_version(services)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user