Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc_p2p_proof_inventory.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2021 The Bitcoin developers | # Copyright (c) 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 proof inventory relaying | Test proof inventory relaying | ||||
""" | """ | ||||
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 gen_proof, get_proof_ids, wait_for_proof | from test_framework.avatools import ( | ||||
avalanche_proof_from_hex, | |||||
gen_proof, | |||||
get_proof_ids, | |||||
wait_for_proof, | |||||
) | |||||
from test_framework.messages import ( | from test_framework.messages import ( | ||||
MSG_AVA_PROOF, | MSG_AVA_PROOF, | ||||
MSG_TYPE_MASK, | MSG_TYPE_MASK, | ||||
CInv, | CInv, | ||||
msg_avaproof, | msg_avaproof, | ||||
msg_getdata, | msg_getdata, | ||||
) | ) | ||||
from test_framework.p2p import P2PInterface, p2p_lock | from test_framework.p2p import P2PInterface, p2p_lock | ||||
▲ Show 20 Lines • Show All 103 Lines • ▼ Show 20 Lines | def test_receive_proof(self): | ||||
wait_for_proof(node, orphan_proofid, expect_status="orphan") | wait_for_proof(node, orphan_proofid, expect_status="orphan") | ||||
def test_ban_invalid_proof(self): | def test_ban_invalid_proof(self): | ||||
node = self.nodes[0] | node = self.nodes[0] | ||||
_, bad_proof = self.generate_proof(node) | _, bad_proof = self.generate_proof(node) | ||||
bad_proof.stakes = [] | bad_proof.stakes = [] | ||||
privkey = node.get_deterministic_priv_key().key | |||||
missing_stake = node.buildavalancheproof( | |||||
1, 0, privkey, [{ | |||||
'txid': '0' * 64, | |||||
'vout': 0, | |||||
'amount': 10000000, | |||||
'height': 42, | |||||
'iscoinbase': False, | |||||
'privatekey': privkey, | |||||
}] | |||||
) | |||||
self.restart_node(0, ['-enableavalanche=1']) | self.restart_node(0, ['-enableavalanche=1']) | ||||
peer = node.add_p2p_connection(P2PInterface()) | peer = node.add_p2p_connection(P2PInterface()) | ||||
msg = msg_avaproof() | msg = msg_avaproof() | ||||
# Sending a proof with a missing utxo doesn't trigger a ban | |||||
msg.proof = avalanche_proof_from_hex(missing_stake) | |||||
with node.assert_debug_log(["received: avaproof"], ["Misbehaving"]): | |||||
peer.send_message(msg) | |||||
peer.sync_with_ping() | |||||
msg.proof = bad_proof | msg.proof = bad_proof | ||||
with node.assert_debug_log([ | with node.assert_debug_log([ | ||||
'Misbehaving', | 'Misbehaving', | ||||
'invalid-proof', | 'invalid-proof', | ||||
]): | ]): | ||||
peer.send_message(msg) | peer.send_message(msg) | ||||
peer.wait_for_disconnect() | peer.wait_for_disconnect() | ||||
▲ Show 20 Lines • Show All 163 Lines • Show Last 20 Lines |