Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14864548
D12477.id36258.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
21 KB
Subscribers
None
D12477.id36258.diff
View Options
diff --git a/test/functional/abc_feature_proof_cleanup.py b/test/functional/abc_feature_proof_cleanup.py
--- a/test/functional/abc_feature_proof_cleanup.py
+++ b/test/functional/abc_feature_proof_cleanup.py
@@ -43,7 +43,7 @@
def run_test(self):
node = self.nodes[0]
- master_key, local_proof = gen_proof(node)
+ master_key, local_proof = gen_proof(self, node)
self.restart_node(0, self.extra_args[0] + [
"-avaproof={}".format(local_proof.serialize().hex()),
@@ -61,14 +61,14 @@
peers = []
# The first 5 peers have a node attached
for _ in range(5):
- peer = get_ava_p2p_interface(node)
+ peer = get_ava_p2p_interface(self, node)
proofs.append(peer.proof)
keys.append(peer.master_privkey)
peers.append(peer)
# The last 5 peers have no node attached
for _ in range(5):
- _, proof = gen_proof(node)
+ _, proof = gen_proof(self, node)
node.sendavalancheproof(proof.serialize().hex())
proofs.append(proof)
@@ -124,7 +124,7 @@
node.disconnect_p2ps()
assert_equal(len(node.p2ps), 0)
- avanode = get_ava_p2p_interface(node)
+ avanode = get_ava_p2p_interface(self, node)
avanode.wait_until(lambda: avanode.last_message.get(
"getdata") and avanode.last_message["getdata"].inv[-1].hash == avanode.proof.proofid)
diff --git a/test/functional/abc_p2p_avalanche_peer_discovery.py b/test/functional/abc_p2p_avalanche_peer_discovery.py
--- a/test/functional/abc_p2p_avalanche_peer_discovery.py
+++ b/test/functional/abc_p2p_avalanche_peer_discovery.py
@@ -221,7 +221,7 @@
peer = get_ava_p2p_interface_no_handshake(node, services=NODE_NETWORK)
# Build a new proof and only announce this one
- _, new_proof_obj = gen_proof(node)
+ _, new_proof_obj = gen_proof(self, node)
new_proof = new_proof_obj.serialize().hex()
new_proofid = new_proof_obj.proofid
diff --git a/test/functional/abc_p2p_avalanche_proof_voting.py b/test/functional/abc_p2p_avalanche_proof_voting.py
--- a/test/functional/abc_p2p_avalanche_proof_voting.py
+++ b/test/functional/abc_p2p_avalanche_proof_voting.py
@@ -56,7 +56,7 @@
# Build a fake quorum of nodes.
def get_quorum(self, node):
- return [get_ava_p2p_interface(node, stake_utxo_confirmations=self.avaproof_stake_utxo_confirmations)
+ return [get_ava_p2p_interface(self, node, stake_utxo_confirmations=self.avaproof_stake_utxo_confirmations)
for _ in range(0, QUORUM_NODE_COUNT)]
def can_find_proof_in_poll(self, hash, response):
@@ -136,7 +136,7 @@
self.log.info("Trigger polling from the node...")
- peer = get_ava_p2p_interface(node)
+ peer = get_ava_p2p_interface(self, node)
mock_time = int(time.time())
node.setmocktime(mock_time)
@@ -183,7 +183,7 @@
self.restart_node(0)
self.quorum = self.get_quorum(node)
- peer = get_ava_p2p_interface(node)
+ peer = get_ava_p2p_interface(self, node)
mock_time = int(time.time())
node.setmocktime(mock_time)
@@ -300,7 +300,7 @@
self.get_quorum(node)
ava_node = get_ava_p2p_interface(
- node, stake_utxo_confirmations=self.avaproof_stake_utxo_confirmations)
+ self, node, stake_utxo_confirmations=self.avaproof_stake_utxo_confirmations)
# Generate coinbases to use for stakes
stakes_key = node.get_deterministic_priv_key()
@@ -418,7 +418,7 @@
self.restart_node(0)
self.quorum = self.get_quorum(node)
- peer = get_ava_p2p_interface(node)
+ peer = get_ava_p2p_interface(self, node)
mock_time = int(time.time())
node.setmocktime(mock_time)
@@ -478,9 +478,9 @@
self.quorum = self.get_quorum(node)
peer = get_ava_p2p_interface(
- node, stake_utxo_confirmations=self.avaproof_stake_utxo_confirmations)
+ self, node, stake_utxo_confirmations=self.avaproof_stake_utxo_confirmations)
- _, immature_proof = gen_proof(node)
+ _, immature_proof = gen_proof(self, node)
self.log.info("Immature proofs are not polled")
diff --git a/test/functional/abc_p2p_avalanche_quorum.py b/test/functional/abc_p2p_avalanche_quorum.py
--- a/test/functional/abc_p2p_avalanche_quorum.py
+++ b/test/functional/abc_p2p_avalanche_quorum.py
@@ -48,7 +48,7 @@
def run_test(self):
# Initially all nodes start with 8 nodes attached to a single proof
- privkey, proof = gen_proof(self.nodes[0])
+ privkey, proof = gen_proof(self, self.nodes[0])
for node in self.nodes:
for _ in range(8):
n = get_ava_p2p_interface_no_handshake(node)
@@ -63,7 +63,7 @@
# Prepare peers proofs
peers = []
for i in range(0, self.min_avaproofs_node_count + 1):
- key, proof = gen_proof(self.nodes[0])
+ key, proof = gen_proof(self, self.nodes[0])
peers.append({'key': key, 'proof': proof})
# Let the nodes known about all the blocks then disconnect them so we're
@@ -243,7 +243,7 @@
poll_and_assert_response(node, AvalancheVoteError.UNKNOWN)
# Add a node back and check it resumes the quorum status
- avapeer = AvaP2PInterface(node)
+ avapeer = AvaP2PInterface(self, node)
node.add_p2p_connection(avapeer)
wait_for_proof(node, uint256_hex(avapeer.proof.proofid))
poll_and_assert_response(node, AvalancheVoteError.ACCEPTED)
diff --git a/test/functional/abc_p2p_avalanche_transaction_voting.py b/test/functional/abc_p2p_avalanche_transaction_voting.py
--- a/test/functional/abc_p2p_avalanche_transaction_voting.py
+++ b/test/functional/abc_p2p_avalanche_transaction_voting.py
@@ -23,7 +23,7 @@
def run_test(self):
node = self.nodes[0]
- poll_node = get_ava_p2p_interface(node)
+ poll_node = get_ava_p2p_interface(self, node)
# Create helper to check expected poll responses
avakey = ECPubKey()
diff --git a/test/functional/abc_p2p_avalanche_voting.py b/test/functional/abc_p2p_avalanche_voting.py
--- a/test/functional/abc_p2p_avalanche_voting.py
+++ b/test/functional/abc_p2p_avalanche_voting.py
@@ -47,7 +47,7 @@
# Build a fake quorum of nodes.
def get_quorum():
- return [get_ava_p2p_interface(node)
+ return [get_ava_p2p_interface(self, node)
for _ in range(0, QUORUM_NODE_COUNT)]
# Pick one node from the quorum for polling.
diff --git a/test/functional/abc_p2p_compactproofs.py b/test/functional/abc_p2p_compactproofs.py
--- a/test/functional/abc_p2p_compactproofs.py
+++ b/test/functional/abc_p2p_compactproofs.py
@@ -93,7 +93,7 @@
outbound_avapeers = []
# With a proof and the service bit set
for _ in range(4):
- peer = AvaP2PInterface(node)
+ peer = AvaP2PInterface(self, node)
node.add_outbound_p2p_connection(
peer,
p2p_idx=p2p_idx,
@@ -152,7 +152,7 @@
self.log.info(
"After the first avaproofs has been received, all the peers are requested periodically")
- responding_outbound_avapeer = AvaP2PInterface(node)
+ responding_outbound_avapeer = AvaP2PInterface(self, node)
node.add_outbound_p2p_connection(
responding_outbound_avapeer,
p2p_idx=p2p_idx,
@@ -164,7 +164,7 @@
self.wait_until(all_peers_received_getavaproofs)
- _, proof = gen_proof(node)
+ _, proof = gen_proof(self, node)
# Send the avaproofs message
avaproofs = build_msg_avaproofs([proof])
@@ -212,7 +212,7 @@
def connect_callback(address, port):
self.log.debug("Connecting to {}:{}".format(address, port))
- p = AvaP2PInterface(node)
+ p = AvaP2PInterface(self, node)
p2p_idx = 1
p.peer_accept_connection(
connect_cb=connect_callback,
@@ -256,7 +256,7 @@
# Add some proofs
sending_peer = node.add_p2p_connection(NoHandshakeAvaP2PInterface())
for _ in range(50):
- _, proof = gen_proof(node)
+ _, proof = gen_proof(self, node)
sending_peer.send_avaproof(proof)
wait_for_proof(node, uint256_hex(proof.proofid))
@@ -287,7 +287,7 @@
key0 = random.randint(0, 2**64 - 1)
key1 = random.randint(0, 2**64 - 1)
- proofs = [gen_proof(node)[1] for _ in range(10)]
+ proofs = [gen_proof(self, node)[1] for _ in range(10)]
# Build a map from proofid to shortid. Use sorted proofids so we don't
# have the same indices than the `proofs` list.
@@ -298,7 +298,7 @@
self.log.info("The node ignores unsollicited avaproofs")
- spam_peer = get_ava_p2p_interface(node)
+ spam_peer = get_ava_p2p_interface(self, node)
msg = build_msg_avaproofs(
proofs, prefilled_proofs=[], key_pair=[
@@ -316,7 +316,7 @@
def add_avalanche_p2p_outbound():
nonlocal p2p_idx
- peer = AvaP2PInterface(node)
+ peer = AvaP2PInterface(self, node)
node.add_outbound_p2p_connection(
peer,
p2p_idx=p2p_idx,
@@ -414,7 +414,7 @@
msg = build_msg_avaproofs([], prefilled_proofs=[
AvalanchePrefilledProof(
len(shortid_map) + 1,
- gen_proof(node)[1])], key_pair=[key0, key1])
+ gen_proof(self, node)[1])], key_pair=[key0, key1])
msg.shortids = list(shortid_map.values())
with node.assert_debug_log(["Misbehaving", "avaproofs-bad-indexes"]):
@@ -423,7 +423,7 @@
self.log.info("An invalid prefilled proof will trigger a ban")
- _, no_stake = gen_proof(node)
+ _, no_stake = gen_proof(self, node)
no_stake.stakes = []
bad_peer = add_avalanche_p2p_outbound()
@@ -445,7 +445,7 @@
self.restart_node(0)
numof_proof = 10
- proofs = [gen_proof(node)[1] for _ in range(numof_proof)]
+ proofs = [gen_proof(self, node)[1] for _ in range(numof_proof)]
for proof in proofs:
node.sendavalancheproof(proof.serialize().hex())
@@ -566,7 +566,7 @@
self.restart_node(0)
numof_proof = 10
- proofs = [gen_proof(requestee)[1] for _ in range(numof_proof)]
+ proofs = [gen_proof(self, requestee)[1] for _ in range(numof_proof)]
for proof in proofs:
requestee.sendavalancheproof(proof.serialize().hex())
@@ -653,7 +653,7 @@
# Connect the minimum amount of stake and nodes
for _ in range(8):
- node.add_p2p_connection(AvaP2PInterface(node))
+ node.add_p2p_connection(AvaP2PInterface(self, node))
self.wait_until(lambda: node.getavalancheinfo()
['ready_to_poll'] is True)
diff --git a/test/functional/abc_p2p_getavaaddr.py b/test/functional/abc_p2p_getavaaddr.py
--- a/test/functional/abc_p2p_getavaaddr.py
+++ b/test/functional/abc_p2p_getavaaddr.py
@@ -55,8 +55,8 @@
class MutedAvaP2PInterface(AvaP2PInterface):
- def __init__(self, node=None):
- super().__init__(node)
+ def __init__(self, test_framework=None, node=None):
+ super().__init__(test_framework, node)
self.is_responding = False
self.privkey = None
self.addr = None
@@ -70,8 +70,8 @@
class AllYesAvaP2PInterface(MutedAvaP2PInterface):
- def __init__(self, node=None):
- super().__init__(node)
+ def __init__(self, test_framework=None, node=None):
+ super().__init__(test_framework, node)
self.is_responding = True
def on_avapoll(self, message):
@@ -128,7 +128,7 @@
# Add some avalanche peers to the node
for _ in range(10):
- node.add_p2p_connection(AllYesAvaP2PInterface(node))
+ node.add_p2p_connection(AllYesAvaP2PInterface(self, node))
# Build some statistics to ensure some addresses will be returned
def all_peers_received_poll():
@@ -179,7 +179,7 @@
# Create a bunch of proofs and associate each a bunch of nodes.
avanodes = []
for _ in range(num_proof):
- master_privkey, proof = gen_proof(node)
+ master_privkey, proof = gen_proof(self, node)
for n in range(num_avanode):
avanode = AllYesAvaP2PInterface() if n % 2 else MutedAvaP2PInterface()
avanode.master_privkey = master_privkey
@@ -339,7 +339,7 @@
avapeers = []
for i in range(16):
- avapeer = AllYesAvaP2PInterface(node)
+ avapeer = AllYesAvaP2PInterface(self, node)
node.add_outbound_p2p_connection(
avapeer,
p2p_idx=i,
@@ -390,7 +390,7 @@
# Add more nodes so we reach the mininum quorum stake amount.
for _ in range(4):
- avapeer = AllYesAvaP2PInterface(node)
+ avapeer = AllYesAvaP2PInterface(self, node)
node.add_p2p_connection(avapeer)
self.wait_until(lambda: node.getavalancheinfo()
['ready_to_poll'] is True)
@@ -457,7 +457,7 @@
# Connect the minimum amount of stake and nodes
for _ in range(8):
- node.add_p2p_connection(AvaP2PInterface(node))
+ node.add_p2p_connection(AvaP2PInterface(self, node))
self.wait_until(lambda: node.getavalancheinfo()
['ready_to_poll'] is True)
diff --git a/test/functional/abc_p2p_proof_inventory.py b/test/functional/abc_p2p_proof_inventory.py
--- a/test/functional/abc_p2p_proof_inventory.py
+++ b/test/functional/abc_p2p_proof_inventory.py
@@ -63,7 +63,7 @@
]] * self.num_nodes
def generate_proof(self, node, mature=True):
- privkey, proof = gen_proof(node)
+ privkey, proof = gen_proof(self, node)
if mature:
node.generate(1)
diff --git a/test/functional/abc_rpc_avalancheproof.py b/test/functional/abc_rpc_avalancheproof.py
--- a/test/functional/abc_rpc_avalancheproof.py
+++ b/test/functional/abc_rpc_avalancheproof.py
@@ -394,7 +394,7 @@
# confirm the coinbase UTXOs
node.generate(101)
too_many_stakes = create_stakes(
- node, new_blocks, AVALANCHE_MAX_PROOF_STAKES + 1)
+ self, node, new_blocks, AVALANCHE_MAX_PROOF_STAKES + 1)
# Make the newly split UTXOs mature
node.generate(stake_age)
diff --git a/test/functional/abc_rpc_getavalancheinfo.py b/test/functional/abc_rpc_getavalancheinfo.py
--- a/test/functional/abc_rpc_getavalancheinfo.py
+++ b/test/functional/abc_rpc_getavalancheinfo.py
@@ -40,7 +40,7 @@
def run_test(self):
node = self.nodes[0]
- privkey, proof = gen_proof(node)
+ privkey, proof = gen_proof(self, node)
# Make the proof mature
node.generate(1)
@@ -181,7 +181,7 @@
quorum = []
N = 13
for _ in range(N):
- _privkey, _proof = gen_proof(node)
+ _privkey, _proof = gen_proof(self, node)
proofs.append(_proof)
privkeys.append(_privkey)
@@ -210,7 +210,7 @@
n.send_avaproof(conflicting_proof)
# Generate an immature proof
- _, immature_proof = gen_proof(node)
+ _, immature_proof = gen_proof(self, node)
n.send_avaproof(immature_proof)
self.wait_until(
@@ -287,7 +287,7 @@
dg_priv.generate()
dg_pub = dg_priv.get_pubkey().get_bytes().hex()
- _privkey, _proof = gen_proof(node)
+ _privkey, _proof = gen_proof(self, node)
# Make the proof mature
node.generate(1)
diff --git a/test/functional/abc_rpc_getavalancheproofs.py b/test/functional/abc_rpc_getavalancheproofs.py
--- a/test/functional/abc_rpc_getavalancheproofs.py
+++ b/test/functional/abc_rpc_getavalancheproofs.py
@@ -36,7 +36,7 @@
def run_test(self):
node = self.nodes[0]
- privkey, proof = gen_proof(node)
+ privkey, proof = gen_proof(self, node)
# Make the proof mature
node.generate(1)
@@ -92,7 +92,7 @@
quorum = []
N = 13
for _ in range(N):
- _privkey, _proof = gen_proof(node)
+ _privkey, _proof = gen_proof(self, node)
proofs.append(_proof)
privkeys.append(_privkey)
@@ -121,7 +121,7 @@
n.send_avaproof(conflicting_proof)
# Generate an immature proof
- _, immature_proof = gen_proof(node)
+ _, immature_proof = gen_proof(self, node)
n.send_avaproof(immature_proof)
self.wait_until(
diff --git a/test/functional/abc_rpc_isfinal.py b/test/functional/abc_rpc_isfinal.py
--- a/test/functional/abc_rpc_isfinal.py
+++ b/test/functional/abc_rpc_isfinal.py
@@ -61,7 +61,7 @@
# Build a fake quorum of nodes.
def get_quorum():
- return [node.add_p2p_connection(AvaP2PInterface(node))
+ return [node.add_p2p_connection(AvaP2PInterface(self, node))
for _ in range(0, QUORUM_NODE_COUNT)]
# Pick one node from the quorum for polling.
diff --git a/test/functional/p2p_inv_download.py b/test/functional/p2p_inv_download.py
--- a/test/functional/p2p_inv_download.py
+++ b/test/functional/p2p_inv_download.py
@@ -383,7 +383,7 @@
node = self.nodes[0]
# Build a proof with immature utxos
- privkey, immature = gen_proof(node)
+ privkey, immature = gen_proof(self, node)
proofid_hex = "{:064x}".format(immature.proofid)
self.restart_node(0, extra_args=self.extra_args[0] + [
diff --git a/test/functional/rpc_deprecated.py b/test/functional/rpc_deprecated.py
--- a/test/functional/rpc_deprecated.py
+++ b/test/functional/rpc_deprecated.py
@@ -73,7 +73,7 @@
)
assert not self.nodes[1].isfinaltransaction(cb_txid, blockhash)
- [[node.add_p2p_connection(AvaP2PInterface(node))
+ [[node.add_p2p_connection(AvaP2PInterface(self, node))
for _ in range(0, QUORUM_NODE_COUNT)] for node in self.nodes]
self.wait_until(lambda: all(
diff --git a/test/functional/test_framework/avatools.py b/test/functional/test_framework/avatools.py
--- a/test/functional/test_framework/avatools.py
+++ b/test/functional/test_framework/avatools.py
@@ -6,7 +6,7 @@
import random
import struct
-from typing import Any, Dict, List, Optional
+from typing import TYPE_CHECKING, Any, Dict, List, Optional
from .authproxy import JSONRPCException
from .key import ECKey
@@ -33,6 +33,10 @@
msg_tcpavaresponse,
)
from .p2p import P2PInterface, p2p_lock
+
+if TYPE_CHECKING:
+ from .test_framework import BitcoinTestFramework
+
from .test_node import TestNode
from .util import satoshi_round, uint256_hex, wait_until_helper
from .wallet_util import bytes_to_wif
@@ -88,8 +92,10 @@
def create_stakes(
- node: TestNode, blockhashes: List[str], count: int
-) -> List[Dict[str, Any]]:
+ test_framework: 'BitcoinTestFramework',
+ node: TestNode,
+ blockhashes: List[str],
+ count: int) -> List[Dict[str, Any]]:
"""
Create a list of stakes by splitting existing UTXOs from a specified list
of blocks into 10 new coins.
@@ -121,7 +127,7 @@
# confirm the transactions
new_blocks = []
while node.getmempoolinfo()['size'] > 0:
- new_blocks += node.generate(1)
+ new_blocks += test_framework.generate(node, 1)
utxos = get_utxos_in_blocks(node, new_blocks)
stakes = []
@@ -279,7 +285,12 @@
class AvaP2PInterface(NoHandshakeAvaP2PInterface):
- def __init__(self, node=None):
+ def __init__(self, test_framework=None, node=None):
+ if (test_framework is not None and node is None) or (
+ node is not None and test_framework is None):
+ raise AssertionError(
+ "test_framework and node should both be either set or None")
+
super().__init__()
self.master_privkey = None
@@ -289,8 +300,8 @@
self.delegated_privkey.generate()
self.delegation = None
- if node is not None:
- self.master_privkey, self.proof = gen_proof(node)
+ if test_framework is not None and node is not None:
+ self.master_privkey, self.proof = gen_proof(test_framework, node)
delegation_hex = node.delegateavalancheproof(
f"{self.proof.limited_proofid:0{64}x}",
bytes_to_wif(self.master_privkey.get_bytes()),
@@ -346,16 +357,17 @@
def get_ava_p2p_interface(
+ test_framework: 'BitcoinTestFramework',
node: TestNode,
services=NODE_NETWORK | NODE_AVALANCHE,
stake_utxo_confirmations=1) -> AvaP2PInterface:
"""Build and return an AvaP2PInterface connected to the specified TestNode.
"""
- n = AvaP2PInterface(node)
+ n = AvaP2PInterface(test_framework, node)
# Make sure the proof utxos are mature
if stake_utxo_confirmations > 1:
- node.generate(stake_utxo_confirmations - 1)
+ test_framework.generate(node, stake_utxo_confirmations - 1)
assert node.verifyavalancheproof(n.proof.serialize().hex())
@@ -377,8 +389,8 @@
return n
-def gen_proof(node, coinbase_utxos=1):
- blockhashes = node.generate(coinbase_utxos)
+def gen_proof(test_framework, node, coinbase_utxos=1):
+ blockhashes = test_framework.generate(node, coinbase_utxos)
privkey = ECKey()
privkey.generate()
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, May 20, 20:28 (9 h, 17 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5865881
Default Alt Text
D12477.id36258.diff (21 KB)
Attached To
D12477: [avalanche] Use the generate* functions from test_framework in avatools
Event Timeline
Log In to Comment