Changeset View
Changeset View
Standalone View
Standalone View
test/functional/p2p_inv_download.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2019 The Bitcoin Core developers | # Copyright (c) 2019 The Bitcoin Core 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 inventory download behavior | Test inventory download behavior | ||||
""" | """ | ||||
import functools | import functools | ||||
import time | import time | ||||
from test_framework.address import ADDRESS_ECREG_UNSPENDABLE | from test_framework.address import ADDRESS_ECREG_UNSPENDABLE | ||||
from test_framework.avatools import avalanche_proof_from_hex, wait_for_proof | from test_framework.avatools import ( | ||||
avalanche_proof_from_hex, | |||||
gen_proof, | |||||
wait_for_proof, | |||||
) | |||||
from test_framework.key import ECKey | from test_framework.key import ECKey | ||||
from test_framework.messages import ( | from test_framework.messages import ( | ||||
MSG_AVA_PROOF, | MSG_AVA_PROOF, | ||||
MSG_TX, | MSG_TX, | ||||
MSG_TYPE_MASK, | MSG_TYPE_MASK, | ||||
CInv, | CInv, | ||||
CTransaction, | CTransaction, | ||||
FromHex, | FromHex, | ||||
▲ Show 20 Lines • Show All 349 Lines • ▼ Show 20 Lines | class InventoryDownloadTest(BitcoinTestFramework): | ||||
def test_spurious_notfound(self, context): | def test_spurious_notfound(self, context): | ||||
self.log.info('Check that spurious notfound is ignored') | self.log.info('Check that spurious notfound is ignored') | ||||
self.nodes[0].p2ps[0].send_message( | self.nodes[0].p2ps[0].send_message( | ||||
msg_notfound(vec=[CInv(context.inv_type, 1)])) | msg_notfound(vec=[CInv(context.inv_type, 1)])) | ||||
@skip(TX_TEST_CONTEXT) | @skip(TX_TEST_CONTEXT) | ||||
def test_orphan_download(self, context): | def test_orphan_download(self, context): | ||||
node = self.nodes[0] | node = self.nodes[0] | ||||
privkey = ECKey() | |||||
privkey.generate() | |||||
privkey_wif = bytes_to_wif(privkey.get_bytes()) | |||||
# Build a proof with missing utxos so it will be orphaned | # Build a proof with immature utxos so it will be orphaned | ||||
orphan = node.buildavalancheproof( | privkey, orphan = gen_proof(node) | ||||
42, 2000000000, bytes_to_wif(privkey.get_bytes()), [{ | proofid_hex = "{:064x}".format(orphan.proofid) | ||||
'txid': '0' * 64, | |||||
'vout': 0, | |||||
'amount': 10e6, | |||||
'height': 42, | |||||
'iscoinbase': False, | |||||
'privatekey': privkey_wif, | |||||
}] | |||||
) | |||||
proofid = avalanche_proof_from_hex(orphan).proofid | |||||
proofid_hex = "{:064x}".format(proofid) | |||||
self.restart_node(0, extra_args=self.extra_args[0] + [ | self.restart_node(0, extra_args=self.extra_args[0] + [ | ||||
"-avaproof={}".format(orphan), | "-avaproofstakeutxoconfirmations=3", | ||||
"-avamasterkey={}".format(privkey_wif), | "-avaproof={}".format(orphan.serialize().hex()), | ||||
"-avamasterkey={}".format(bytes_to_wif(privkey.get_bytes())), | |||||
]) | ]) | ||||
node.generate(1) | node.generate(1) | ||||
wait_for_proof(node, proofid_hex, expect_orphan=True) | wait_for_proof(node, proofid_hex, expect_orphan=True) | ||||
peer = node.add_p2p_connection(context.p2p_conn()) | peer = node.add_p2p_connection(context.p2p_conn()) | ||||
peer.send_message(msg_inv([CInv(t=context.inv_type, h=proofid)])) | peer.send_message( | ||||
msg_inv([CInv(t=context.inv_type, h=orphan.proofid)])) | |||||
# Give enough time for the node to eventually request the proof. | # Give enough time for the node to eventually request the proof. | ||||
node.setmocktime(int(time.time()) + | node.setmocktime(int(time.time()) + | ||||
context.constants.getdata_interval + 1) | context.constants.getdata_interval + 1) | ||||
peer.sync_with_ping() | peer.sync_with_ping() | ||||
assert_equal(peer.getdata_count, 0) | assert_equal(peer.getdata_count, 0) | ||||
▲ Show 20 Lines • Show All 73 Lines • Show Last 20 Lines |