Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc-p2p-avalanche.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2018 The Bitcoin developers | # Copyright (c) 2018 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.mininode import P2PInterface, mininode_lock | from test_framework.mininode import P2PInterface, mininode_lock | ||||
from test_framework.messages import AvalancheVote, CInv, msg_avapoll | from test_framework.messages import ( | ||||
AvalancheVote, | |||||
CInv, | |||||
msg_avapoll, | |||||
) | |||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import assert_equal, wait_until | from test_framework.util import assert_equal, 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 133 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
poll_node.send_poll(various_block_hashes) | poll_node.send_poll(various_block_hashes) | ||||
poll_node.wait_for_avaresponse() | poll_node.wait_for_avaresponse() | ||||
assert_response(poll_node.last_avaresponse, | assert_response(poll_node.last_avaresponse, | ||||
[AvalancheVote(BLOCK_ACCEPTED, h) for h in various_block_hashes[:3]] + | [AvalancheVote(BLOCK_ACCEPTED, h) for h in various_block_hashes[:3]] + | ||||
[AvalancheVote(BLOCK_REJECTED, h) for h in various_block_hashes[3:6]] + | [AvalancheVote(BLOCK_REJECTED, h) for h in various_block_hashes[3:6]] + | ||||
[AvalancheVote(BLOCK_UNKNOWN, h) for h in various_block_hashes[-3:]]) | [AvalancheVote(BLOCK_UNKNOWN, h) for h in various_block_hashes[-3:]]) | ||||
self.log.info("Trigger polling from the node...") | self.log.info("Trigger polling from the node...") | ||||
node.addavalanchepeer(nodeid) | # duplicate the deterministic sig test from src/test/key_tests.cpp | ||||
privkey = bytes.fromhex( | |||||
"12b004fff7f4b69ef8650e767f18f11ede158148b425660723b9f9a66e61f747") | |||||
pubkey = schnorr.getpubkey(privkey, compressed=True) | |||||
node.addavalanchepeer(nodeid, pubkey.hex()) | |||||
# Sanity check | # Sanity check | ||||
fork_node = self.nodes[1] | fork_node = self.nodes[1] | ||||
assert_equal(node.getbestblockhash(), fork_node.getbestblockhash()) | assert_equal(node.getbestblockhash(), fork_node.getbestblockhash()) | ||||
# 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_node.generate(2) | fork_node.generate(2) | ||||
Show All 24 Lines |