Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc_p2p_avalanche.py
Show All 11 Lines | from test_framework.messages import ( | ||||
CInv, | CInv, | ||||
msg_avapoll, | msg_avapoll, | ||||
msg_tcpavaresponse, | msg_tcpavaresponse, | ||||
TCPAvalancheResponse, | TCPAvalancheResponse, | ||||
) | ) | ||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import ( | from test_framework.util import ( | ||||
assert_equal, | assert_equal, | ||||
sync_blocks, | |||||
wait_until, | wait_until, | ||||
) | ) | ||||
from test_framework import schnorr | from test_framework import schnorr | ||||
BLOCK_ACCEPTED = 0 | BLOCK_ACCEPTED = 0 | ||||
BLOCK_REJECTED = 1 | BLOCK_REJECTED = 1 | ||||
BLOCK_UNKNOWN = -1 | BLOCK_UNKNOWN = -1 | ||||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
nodeid = node.getpeerinfo()[-1]['id'] | nodeid = node.getpeerinfo()[-1]['id'] | ||||
# Generate many block and poll for them. | # Generate many block and poll for them. | ||||
address = node.get_deterministic_priv_key().address | address = node.get_deterministic_priv_key().address | ||||
node.generatetoaddress(100, address) | node.generatetoaddress(100, address) | ||||
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 | ||||
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 = bytes.fromhex(node.getavalanchekey()) | avakey = bytes.fromhex(node.getavalanchekey()) | ||||
self.log.info("Poll for the chain tip...") | self.log.info("Poll for the chain tip...") | ||||
best_block_hash = int(node.getbestblockhash(), 16) | best_block_hash = int(node.getbestblockhash(), 16) | ||||
poll_node.send_poll([best_block_hash]) | poll_node.send_poll([best_block_hash]) | ||||
▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
# duplicate the deterministic sig test from src/test/key_tests.cpp | # duplicate the deterministic sig test from src/test/key_tests.cpp | ||||
privkey = bytes.fromhex( | privkey = bytes.fromhex( | ||||
"12b004fff7f4b69ef8650e767f18f11ede158148b425660723b9f9a66e61f747") | "12b004fff7f4b69ef8650e767f18f11ede158148b425660723b9f9a66e61f747") | ||||
pubkey = schnorr.getpubkey(privkey, compressed=True) | pubkey = schnorr.getpubkey(privkey, compressed=True) | ||||
node.addavalanchepeer(nodeid, pubkey.hex()) | node.addavalanchepeer(nodeid, pubkey.hex()) | ||||
# Make sure the fork node has synced the blocks | # Make sure the fork node has synced the blocks | ||||
sync_blocks([node, fork_node]) | self.sync_blocks([node, fork_node]) | ||||
# Create a fork 2 blocks deep. This should trigger polling. | # Create a fork 2 blocks deep. This should trigger polling. | ||||
fork_node.invalidateblock(fork_node.getblockhash(100)) | fork_node.invalidateblock(fork_node.getblockhash(100)) | ||||
fork_address = fork_node.get_deterministic_priv_key().address | fork_address = fork_node.get_deterministic_priv_key().address | ||||
fork_node.generatetoaddress(2, fork_address) | fork_node.generatetoaddress(2, fork_address) | ||||
def can_find_block_in_poll(hash): | def can_find_block_in_poll(hash): | ||||
poll = poll_node.wait_for_avapoll() | poll = poll_node.wait_for_avapoll() | ||||
Show All 26 Lines |