mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-10 14:48:46 +02:00
test: make reusable filling of a node's addrman
Extract the part of `p2p_private_broadcast.py` that fills a given node's addrman and put it into `test_framework/test_framework.py`.
This commit is contained in:
@@ -48,116 +48,6 @@ from test_framework.wallet import (
|
||||
|
||||
NUM_PRIVATE_BROADCAST_PER_TX = 3
|
||||
|
||||
# Fill addrman with these addresses. Must have enough Tor addresses, so that even
|
||||
# if all 10 default connections are opened to a Tor address (!?) there must be more
|
||||
# for private broadcast.
|
||||
ADDRMAN_ADDRESSES = [
|
||||
"20.0.0.1",
|
||||
"30.0.0.1",
|
||||
"40.0.0.1",
|
||||
"50.0.0.1",
|
||||
"60.0.0.1",
|
||||
"70.0.0.1",
|
||||
"80.0.0.1",
|
||||
"90.0.0.1",
|
||||
"100.0.0.1",
|
||||
"110.0.0.1",
|
||||
"120.0.0.1",
|
||||
"130.0.0.1",
|
||||
"140.0.0.1",
|
||||
"150.0.0.1",
|
||||
"160.0.0.1",
|
||||
"170.0.0.1",
|
||||
"180.0.0.1",
|
||||
"190.0.0.1",
|
||||
"200.0.0.1",
|
||||
"210.0.0.1",
|
||||
|
||||
"[20::1]",
|
||||
"[30::1]",
|
||||
"[40::1]",
|
||||
"[50::1]",
|
||||
"[60::1]",
|
||||
"[70::1]",
|
||||
"[80::1]",
|
||||
"[90::1]",
|
||||
"[100::1]",
|
||||
"[110::1]",
|
||||
"[120::1]",
|
||||
"[130::1]",
|
||||
"[140::1]",
|
||||
"[150::1]",
|
||||
"[160::1]",
|
||||
"[170::1]",
|
||||
"[180::1]",
|
||||
"[190::1]",
|
||||
"[200::1]",
|
||||
"[210::1]",
|
||||
|
||||
"testonlyad777777777777777777777777777777777777777775b6qd.onion",
|
||||
"testonlyah77777777777777777777777777777777777777777z7ayd.onion",
|
||||
"testonlyal77777777777777777777777777777777777777777vp6qd.onion",
|
||||
"testonlyap77777777777777777777777777777777777777777r5qad.onion",
|
||||
"testonlyat77777777777777777777777777777777777777777udsid.onion",
|
||||
"testonlyax77777777777777777777777777777777777777777yciid.onion",
|
||||
"testonlya777777777777777777777777777777777777777777rhgyd.onion",
|
||||
"testonlybd77777777777777777777777777777777777777777rs4ad.onion",
|
||||
"testonlybp77777777777777777777777777777777777777777zs2ad.onion",
|
||||
"testonlybt777777777777777777777777777777777777777777x6id.onion",
|
||||
"testonlybx777777777777777777777777777777777777777775styd.onion",
|
||||
"testonlyb3777777777777777777777777777777777777777774ckid.onion",
|
||||
"testonlycd77777777777777777777777777777777777777777733id.onion",
|
||||
"testonlych77777777777777777777777777777777777777777t6kid.onion",
|
||||
"testonlycl77777777777777777777777777777777777777777tt3ad.onion",
|
||||
"testonlyct77777777777777777777777777777777777777777wvhyd.onion",
|
||||
"testonlycx7777777777777777777777777777777777777777774bad.onion",
|
||||
"testonlyc377777777777777777777777777777777777777777u6aid.onion",
|
||||
"testonlydd777777777777777777777777777777777777777777u5ad.onion",
|
||||
"testonlydh77777777777777777777777777777777777777777wgnyd.onion",
|
||||
|
||||
"testonlyad77777777777777777777777777777777777777777q.b32.i2p",
|
||||
"testonlyah77777777777777777777777777777777777777777q.b32.i2p",
|
||||
"testonlyap77777777777777777777777777777777777777777q.b32.i2p",
|
||||
"testonlyat77777777777777777777777777777777777777777q.b32.i2p",
|
||||
"testonlyax77777777777777777777777777777777777777777q.b32.i2p",
|
||||
"testonlya377777777777777777777777777777777777777777q.b32.i2p",
|
||||
"testonlya777777777777777777777777777777777777777777q.b32.i2p",
|
||||
"testonlybd77777777777777777777777777777777777777777q.b32.i2p",
|
||||
"testonlybh77777777777777777777777777777777777777777q.b32.i2p",
|
||||
"testonlybl77777777777777777777777777777777777777777q.b32.i2p",
|
||||
"testonlybp77777777777777777777777777777777777777777q.b32.i2p",
|
||||
"testonlybt77777777777777777777777777777777777777777q.b32.i2p",
|
||||
"testonlybx77777777777777777777777777777777777777777q.b32.i2p",
|
||||
"testonlyb777777777777777777777777777777777777777777q.b32.i2p",
|
||||
"testonlych77777777777777777777777777777777777777777q.b32.i2p",
|
||||
"testonlycp77777777777777777777777777777777777777777q.b32.i2p",
|
||||
"testonlyct77777777777777777777777777777777777777777q.b32.i2p",
|
||||
"testonlycx77777777777777777777777777777777777777777q.b32.i2p",
|
||||
"testonlyc377777777777777777777777777777777777777777q.b32.i2p",
|
||||
"testonlyc777777777777777777777777777777777777777777q.b32.i2p",
|
||||
|
||||
"[fc00::1]",
|
||||
"[fc00::2]",
|
||||
"[fc00::3]",
|
||||
"[fc00::5]",
|
||||
"[fc00::6]",
|
||||
"[fc00::7]",
|
||||
"[fc00::8]",
|
||||
"[fc00::9]",
|
||||
"[fc00::10]",
|
||||
"[fc00::11]",
|
||||
"[fc00::12]",
|
||||
"[fc00::13]",
|
||||
"[fc00::15]",
|
||||
"[fc00::16]",
|
||||
"[fc00::17]",
|
||||
"[fc00::18]",
|
||||
"[fc00::19]",
|
||||
"[fc00::20]",
|
||||
"[fc00::22]",
|
||||
"[fc00::23]",
|
||||
]
|
||||
|
||||
|
||||
class P2PPrivateBroadcast(BitcoinTestFramework):
|
||||
def set_test_params(self):
|
||||
@@ -333,13 +223,9 @@ class P2PPrivateBroadcast(BitcoinTestFramework):
|
||||
tx_receiver = self.nodes[1]
|
||||
far_observer = tx_receiver.add_p2p_connection(P2PInterface())
|
||||
|
||||
wallet = MiniWallet(tx_originator)
|
||||
self.fill_node_addrman(node_index=0, address_types_to_add=[CAddress.NET_IPV4, CAddress.NET_IPV6, CAddress.NET_TORV3, CAddress.NET_I2P, CAddress.NET_CJDNS])
|
||||
|
||||
# Fill tx_originator's addrman.
|
||||
for addr in ADDRMAN_ADDRESSES:
|
||||
res = tx_originator.addpeeraddress(address=addr, port=0 if addr.endswith(".i2p") else 8333, tried=False)
|
||||
if not res["success"]:
|
||||
self.log.debug(f"Could not add {addr} to tx_originator's addrman (collision?)")
|
||||
wallet = MiniWallet(tx_originator)
|
||||
|
||||
txs = wallet.create_self_transfer_chain(chain_length=3)
|
||||
self.log.info(f"Created txid={txs[0]['txid']}: for basic test")
|
||||
|
||||
@@ -24,6 +24,7 @@ import time
|
||||
from .address import create_deterministic_address_bcrt1_p2tr_op_true
|
||||
from .authproxy import JSONRPCException
|
||||
from . import coverage
|
||||
from .messages import CAddress
|
||||
from .p2p import NetworkThread
|
||||
from .test_node import TestNode
|
||||
from .util import (
|
||||
@@ -730,6 +731,125 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
|
||||
def wait_until(self, test_function, timeout=60, check_interval=0.05):
|
||||
return wait_until_helper_internal(test_function, timeout=timeout, timeout_factor=self.options.timeout_factor, check_interval=check_interval)
|
||||
|
||||
def fill_node_addrman(self, *, node_index, address_types_to_add):
|
||||
ADDRESSES = {
|
||||
CAddress.NET_IPV4: [
|
||||
"20.0.0.1",
|
||||
"30.0.0.1",
|
||||
"40.0.0.1",
|
||||
"50.0.0.1",
|
||||
"60.0.0.1",
|
||||
"70.0.0.1",
|
||||
"80.0.0.1",
|
||||
"90.0.0.1",
|
||||
"100.0.0.1",
|
||||
"110.0.0.1",
|
||||
"120.0.0.1",
|
||||
"130.0.0.1",
|
||||
"140.0.0.1",
|
||||
"150.0.0.1",
|
||||
"160.0.0.1",
|
||||
"170.0.0.1",
|
||||
"180.0.0.1",
|
||||
"190.0.0.1",
|
||||
"200.0.0.1",
|
||||
"210.0.0.1",
|
||||
],
|
||||
CAddress.NET_IPV6: [
|
||||
"[20::1]",
|
||||
"[30::1]",
|
||||
"[40::1]",
|
||||
"[50::1]",
|
||||
"[60::1]",
|
||||
"[70::1]",
|
||||
"[80::1]",
|
||||
"[90::1]",
|
||||
"[100::1]",
|
||||
"[110::1]",
|
||||
"[120::1]",
|
||||
"[130::1]",
|
||||
"[140::1]",
|
||||
"[150::1]",
|
||||
"[160::1]",
|
||||
"[170::1]",
|
||||
"[180::1]",
|
||||
"[190::1]",
|
||||
"[200::1]",
|
||||
"[210::1]",
|
||||
],
|
||||
CAddress.NET_TORV3: [
|
||||
"testonlyad777777777777777777777777777777777777777775b6qd.onion",
|
||||
"testonlyah77777777777777777777777777777777777777777z7ayd.onion",
|
||||
"testonlyal77777777777777777777777777777777777777777vp6qd.onion",
|
||||
"testonlyap77777777777777777777777777777777777777777r5qad.onion",
|
||||
"testonlyat77777777777777777777777777777777777777777udsid.onion",
|
||||
"testonlyax77777777777777777777777777777777777777777yciid.onion",
|
||||
"testonlya777777777777777777777777777777777777777777rhgyd.onion",
|
||||
"testonlybd77777777777777777777777777777777777777777rs4ad.onion",
|
||||
"testonlybp77777777777777777777777777777777777777777zs2ad.onion",
|
||||
"testonlybt777777777777777777777777777777777777777777x6id.onion",
|
||||
"testonlybx777777777777777777777777777777777777777775styd.onion",
|
||||
"testonlyb3777777777777777777777777777777777777777774ckid.onion",
|
||||
"testonlycd77777777777777777777777777777777777777777733id.onion",
|
||||
"testonlych77777777777777777777777777777777777777777t6kid.onion",
|
||||
"testonlycl77777777777777777777777777777777777777777tt3ad.onion",
|
||||
"testonlyct77777777777777777777777777777777777777777wvhyd.onion",
|
||||
"testonlycx7777777777777777777777777777777777777777774bad.onion",
|
||||
"testonlyc377777777777777777777777777777777777777777u6aid.onion",
|
||||
"testonlydd777777777777777777777777777777777777777777u5ad.onion",
|
||||
"testonlydh77777777777777777777777777777777777777777wgnyd.onion",
|
||||
],
|
||||
CAddress.NET_I2P: [
|
||||
"testonlyad77777777777777777777777777777777777777777q.b32.i2p",
|
||||
"testonlyah77777777777777777777777777777777777777777q.b32.i2p",
|
||||
"testonlyap77777777777777777777777777777777777777777q.b32.i2p",
|
||||
"testonlyat77777777777777777777777777777777777777777q.b32.i2p",
|
||||
"testonlyax77777777777777777777777777777777777777777q.b32.i2p",
|
||||
"testonlya377777777777777777777777777777777777777777q.b32.i2p",
|
||||
"testonlya777777777777777777777777777777777777777777q.b32.i2p",
|
||||
"testonlybd77777777777777777777777777777777777777777q.b32.i2p",
|
||||
"testonlybh77777777777777777777777777777777777777777q.b32.i2p",
|
||||
"testonlybl77777777777777777777777777777777777777777q.b32.i2p",
|
||||
"testonlybp77777777777777777777777777777777777777777q.b32.i2p",
|
||||
"testonlybt77777777777777777777777777777777777777777q.b32.i2p",
|
||||
"testonlybx77777777777777777777777777777777777777777q.b32.i2p",
|
||||
"testonlyb777777777777777777777777777777777777777777q.b32.i2p",
|
||||
"testonlych77777777777777777777777777777777777777777q.b32.i2p",
|
||||
"testonlycp77777777777777777777777777777777777777777q.b32.i2p",
|
||||
"testonlyct77777777777777777777777777777777777777777q.b32.i2p",
|
||||
"testonlycx77777777777777777777777777777777777777777q.b32.i2p",
|
||||
"testonlyc377777777777777777777777777777777777777777q.b32.i2p",
|
||||
"testonlyc777777777777777777777777777777777777777777q.b32.i2p",
|
||||
],
|
||||
CAddress.NET_CJDNS: [
|
||||
"[fc00::1]",
|
||||
"[fc00::2]",
|
||||
"[fc00::3]",
|
||||
"[fc00::5]",
|
||||
"[fc00::6]",
|
||||
"[fc00::7]",
|
||||
"[fc00::8]",
|
||||
"[fc00::9]",
|
||||
"[fc00::10]",
|
||||
"[fc00::11]",
|
||||
"[fc00::12]",
|
||||
"[fc00::13]",
|
||||
"[fc00::15]",
|
||||
"[fc00::16]",
|
||||
"[fc00::17]",
|
||||
"[fc00::18]",
|
||||
"[fc00::19]",
|
||||
"[fc00::20]",
|
||||
"[fc00::22]",
|
||||
"[fc00::23]",
|
||||
],
|
||||
}
|
||||
for addr_type in address_types_to_add:
|
||||
for addr in ADDRESSES[addr_type]:
|
||||
res = self.nodes[node_index].addpeeraddress(address=addr, port=0 if addr.endswith(".i2p") else 8333, tried=False)
|
||||
if not res["success"]:
|
||||
self.log.debug(f"Could not add {addr} to nodes[{node_index}]'s addrman (collision?)")
|
||||
|
||||
# Private helper methods. These should not be accessed by the subclass test scripts.
|
||||
|
||||
def _start_logging(self):
|
||||
|
||||
Reference in New Issue
Block a user