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.""" | ||||
from test_framework.avatools import get_stakes | from test_framework.avatools import get_stakes | ||||
from test_framework.key import ECKey, bytes_to_wif | from test_framework.key import ECKey, bytes_to_wif | ||||
from test_framework.messages import AvalancheDelegation | from test_framework.messages import AvalancheDelegation, FromHex | ||||
from test_framework.mininode import P2PInterface | from test_framework.mininode import P2PInterface | ||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.test_node import ErrorMatch | from test_framework.test_node import ErrorMatch | ||||
from test_framework.util import ( | from test_framework.util import ( | ||||
append_config, | append_config, | ||||
wait_until, | wait_until, | ||||
assert_raises_rpc_error, | assert_raises_rpc_error, | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 192 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
node.assert_start_raises_init_error( | node.assert_start_raises_init_error( | ||||
self.extra_args[0] + [ | self.extra_args[0] + [ | ||||
"-avamasterkey=cND2ZvtabDbJ1gucx9GWH6XT9kgTAqfb6cotPt5Q5CyxVDhid2EN", | "-avamasterkey=cND2ZvtabDbJ1gucx9GWH6XT9kgTAqfb6cotPt5Q5CyxVDhid2EN", | ||||
], | ], | ||||
expected_msg="Error: the avalanche proof has too many utxos", | expected_msg="Error: the avalanche proof has too many utxos", | ||||
match=ErrorMatch.PARTIAL_REGEX, | match=ErrorMatch.PARTIAL_REGEX, | ||||
) | ) | ||||
self.log.info("Bad delegation should be rejected at startup") | |||||
def check_delegation_init_error(delegation, message): | |||||
node.assert_start_raises_init_error( | |||||
self.extra_args[0] + [ | |||||
"-avadelegation={}".format(delegation), | |||||
"-avaproof={}".format(proof), | |||||
"-avamasterkey={}".format( | |||||
deadalnix: You get it right in the test, so just set descriptions accordingly. | |||||
bytes_to_wif(privkey.get_bytes())), | |||||
], | |||||
expected_msg="Error: " + message, | |||||
) | |||||
bad_proof_id = AvalancheDelegation() | |||||
check_delegation_init_error(bad_proof_id.serialize().hex(), | |||||
"the avalanche delegation does not match the proof") | |||||
bad_level_sig = FromHex(AvalancheDelegation(), delegation) | |||||
bad_level_sig.levels[-1].pubkey = bytes.fromhex(proof_master) | |||||
check_delegation_init_error(bad_level_sig.serialize().hex(), | |||||
"the avalanche delegation has invalid signatures") | |||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
AvalancheProofTest().main() | AvalancheProofTest().main() |
You get it right in the test, so just set descriptions accordingly.