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.avatools import ( | from test_framework.avatools import ( | ||||
create_coinbase_stakes, | create_coinbase_stakes, | ||||
create_stakes, | create_stakes, | ||||
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, | ||||
AvalancheDelegationLevel, | AvalancheDelegationLevel, | ||||
AvalancheProof, | AvalancheProof, | ||||
FromHex, | FromHex, | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 207 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
bad_sig = ("0b000000000000000c0000000000000021030b4c866585dd868a9d62348" | bad_sig = ("0b000000000000000c0000000000000021030b4c866585dd868a9d62348" | ||||
"a9cd008d6a312937048fff31670e7e920cfc7a7440105c5f72f5d6da3085" | "a9cd008d6a312937048fff31670e7e920cfc7a7440105c5f72f5d6da3085" | ||||
"583e75ee79340eb4eff208c89988e7ed0efb30b87298fa30000000000f20" | "583e75ee79340eb4eff208c89988e7ed0efb30b87298fa30000000000f20" | ||||
"52a0100000003000000210227d85ba011276cf25b51df6a188b75e604b3" | "52a0100000003000000210227d85ba011276cf25b51df6a188b75e604b3" | ||||
"8770a462b2d0e9fb2fc839ef5d3faf07f001dd38e9b4a43d07d5d449cc0" | "8770a462b2d0e9fb2fc839ef5d3faf07f001dd38e9b4a43d07d5d449cc0" | ||||
"f7d2888d96b82962b3ce516d1083c0e031773487fc3c4f2e38acd1db974" | "f7d2888d96b82962b3ce516d1083c0e031773487fc3c4f2e38acd1db974" | ||||
"1321b91a79b82d1c2cfd47793261e4ba003cf5") | "1321b91a79b82d1c2cfd47793261e4ba003cf5") | ||||
self.log.info("Check the verifyavalancheproof RPC") | self.log.info( | ||||
"Check the verifyavalancheproof and sendavalancheproof RPCs") | |||||
for rpc in [node.verifyavalancheproof, node.sendavalancheproof]: | |||||
assert_raises_rpc_error(-22, "Proof must be an hexadecimal string", | assert_raises_rpc_error(-22, "Proof must be an hexadecimal string", | ||||
node.verifyavalancheproof, "f00") | rpc, "f00") | ||||
assert_raises_rpc_error(-22, "Proof has invalid format", | assert_raises_rpc_error(-22, "Proof has invalid format", | ||||
node.verifyavalancheproof, "f00d") | rpc, "f00d") | ||||
def check_verifyavalancheproof_failure(proof, message): | def check_rpc_failure(proof, message): | ||||
assert_raises_rpc_error(-8, "The proof is invalid: " + message, | assert_raises_rpc_error(-8, "The proof is invalid: " + message, | ||||
node.verifyavalancheproof, proof) | rpc, proof) | ||||
check_verifyavalancheproof_failure(no_stake, "no-stake") | check_rpc_failure(no_stake, "no-stake") | ||||
check_verifyavalancheproof_failure(dust, "amount-below-dust-threshold") | check_rpc_failure(dust, "amount-below-dust-threshold") | ||||
check_verifyavalancheproof_failure(duplicate_stake, "duplicated-stake") | check_rpc_failure(duplicate_stake, "duplicated-stake") | ||||
check_verifyavalancheproof_failure(bad_sig, "invalid-signature") | check_rpc_failure(bad_sig, "invalid-signature") | ||||
if self.is_wallet_compiled(): | if self.is_wallet_compiled(): | ||||
check_verifyavalancheproof_failure( | check_rpc_failure(too_many_utxos, "too-many-utxos") | ||||
too_many_utxos, "too-many-utxos") | |||||
conflicting_utxo = node.buildavalancheproof( | |||||
proof_sequence + 1, proof_expiration, proof_master, stakes) | |||||
assert_raises_rpc_error(-8, "The proof has conflicting utxo with an existing proof", | |||||
node.sendavalancheproof, conflicting_utxo) | |||||
# Good proof | # Good proof | ||||
assert node.verifyavalancheproof(proof) | assert node.verifyavalancheproof(proof) | ||||
proofid = FromHex(AvalancheProof(), proof).proofid | |||||
node.sendavalancheproof(proof) | |||||
assert proofid in get_proof_ids(node) | |||||
# TODO Once implemented we expect the sendavalancheproof to trigger the | |||||
# sending of an inv message with our proof: | |||||
# | |||||
# def inv_found(): | |||||
# with p2p_lock: | |||||
# return peer.last_message.get( | |||||
# "inv") and peer.last_message["inv"].inv[-1].hash == proofid | |||||
# wait_until(inv_found) | |||||
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 |