Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc_p2p_avalanche.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2020-2021 The Bitcoin developers | # Copyright (c) 2020-2021 The Bitcoin developers | ||||
# Distributed under the MIT software license, see the accompanying | # Distributed under the MIT software license, see the accompanying | ||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
"""Test the resolution of forks via avalanche.""" | """Test the resolution of forks via avalanche.""" | ||||
import random | import random | ||||
from test_framework.avatools import get_stakes | from test_framework.avatools import create_coinbase_stakes | ||||
from test_framework.key import ( | from test_framework.key import ( | ||||
ECKey, | ECKey, | ||||
ECPubKey, | ECPubKey, | ||||
) | ) | ||||
from test_framework.mininode import P2PInterface, mininode_lock | from test_framework.mininode import P2PInterface, mininode_lock | ||||
from test_framework.messages import ( | from test_framework.messages import ( | ||||
AvalancheResponse, | AvalancheResponse, | ||||
AvalancheVote, | AvalancheVote, | ||||
▲ Show 20 Lines • Show All 125 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
# Pick on node from the quorum for polling. | # Pick on node from the quorum for polling. | ||||
quorum = get_quorum() | quorum = get_quorum() | ||||
poll_node = quorum[0] | poll_node = quorum[0] | ||||
# Generate many block and poll for them. | # Generate many block and poll for them. | ||||
addrkey0 = node.get_deterministic_priv_key() | addrkey0 = node.get_deterministic_priv_key() | ||||
blockhashes = node.generatetoaddress(100, addrkey0.address) | blockhashes = node.generatetoaddress(100, addrkey0.address) | ||||
# Use the first coinbase to create a stake | # Use the first coinbase to create a stake | ||||
stakes = get_stakes(node, [blockhashes[0]], addrkey0.key) | stakes = create_coinbase_stakes(node, [blockhashes[0]], addrkey0.key) | ||||
fork_node = self.nodes[1] | fork_node = self.nodes[1] | ||||
# Make sure the fork node has synced the blocks | # Make sure the fork node has synced the blocks | ||||
self.sync_blocks([node, fork_node]) | self.sync_blocks([node, fork_node]) | ||||
# Get the key so we can verify signatures. | # Get the key so we can verify signatures. | ||||
avakey = ECPubKey() | avakey = ECPubKey() | ||||
avakey.set(bytes.fromhex(node.getavalanchekey())) | avakey.set(bytes.fromhex(node.getavalanchekey())) | ||||
▲ Show 20 Lines • Show All 208 Lines • Show Last 20 Lines |