Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc_rpc_avalancheproof.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 building avalanche proofs and using them to add avalanche peers.""" | """Test building avalanche proofs and using them to add avalanche peers.""" | ||||
import base64 | import base64 | ||||
from decimal import Decimal | from decimal import Decimal | ||||
from test_framework.address import ADDRESS_BCHREG_UNSPENDABLE | |||||
from test_framework.avatools import ( | from test_framework.avatools import ( | ||||
create_coinbase_stakes, | create_coinbase_stakes, | ||||
create_stakes, | create_stakes, | ||||
get_proof_ids, | get_proof_ids, | ||||
) | ) | ||||
from test_framework.key import ECKey, bytes_to_wif | from test_framework.key import ECKey, bytes_to_wif | ||||
from test_framework.messages import ( | from test_framework.messages import ( | ||||
AvalancheDelegation, | AvalancheDelegation, | ||||
▲ Show 20 Lines • Show All 262 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
assert proofid in get_proof_ids(node) | assert proofid in get_proof_ids(node) | ||||
def inv_found(): | def inv_found(): | ||||
with p2p_lock: | with p2p_lock: | ||||
return peer.last_message.get( | return peer.last_message.get( | ||||
"inv") and peer.last_message["inv"].inv[-1].hash == proofid | "inv") and peer.last_message["inv"].inv[-1].hash == proofid | ||||
wait_until(inv_found) | wait_until(inv_found) | ||||
self.log.info("Check the getrawproof RPC") | |||||
raw_proof = node.getrawavalancheproof("{:064x}".format(proofid)) | |||||
assert_equal(raw_proof['proof'], proof) | |||||
assert_equal(raw_proof['orphan'], False) | |||||
assert_raises_rpc_error(-8, "Proof not found", | |||||
node.getrawavalancheproof, '0' * 64) | |||||
# Orphan the proof by sending the stake | |||||
raw_tx = node.createrawtransaction( | |||||
[{"txid": stakes[-1]["txid"], "vout": 0}], | |||||
{ADDRESS_BCHREG_UNSPENDABLE: stakes[-1] | |||||
["amount"] - Decimal('0.01')} | |||||
) | |||||
signed_tx = node.signrawtransactionwithkey(raw_tx, [addrkey0.key]) | |||||
node.sendrawtransaction(signed_tx["hex"]) | |||||
node.generate(1) | |||||
wait_until(lambda: proofid not in get_proof_ids(node)) | |||||
raw_proof = node.getrawavalancheproof("{:064x}".format(proofid)) | |||||
assert_equal(raw_proof['proof'], proof) | |||||
assert_equal(raw_proof['orphan'], True) | |||||
self.log.info("Bad proof should be rejected at startup") | self.log.info("Bad proof should be rejected at startup") | ||||
self.stop_node(0) | self.stop_node(0) | ||||
node.assert_start_raises_init_error( | node.assert_start_raises_init_error( | ||||
self.extra_args[0] + [ | self.extra_args[0] + [ | ||||
"-avasessionkey=0", | "-avasessionkey=0", | ||||
], | ], | ||||
▲ Show 20 Lines • Show All 52 Lines • Show Last 20 Lines |