Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc_rpc_getavalancheinfo.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2022 The Bitcoin developers | # Copyright (c) 2022 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 the getavalancheinfo RPC.""" | """Test the getavalancheinfo RPC.""" | ||||
import time | import time | ||||
from decimal import Decimal | from decimal import Decimal | ||||
from test_framework.address import ADDRESS_ECREG_UNSPENDABLE | from test_framework.address import ADDRESS_ECREG_UNSPENDABLE | ||||
from test_framework.avatools import ( | from test_framework.avatools import ( | ||||
AvaP2PInterface, | AvaP2PInterface, | ||||
avalanche_proof_from_hex, | avalanche_proof_from_hex, | ||||
create_coinbase_stakes, | create_coinbase_stakes, | ||||
gen_proof, | gen_proof, | ||||
get_ava_p2p_interface, | get_ava_p2p_interface_no_handshake, | ||||
wait_for_proof, | wait_for_proof, | ||||
) | ) | ||||
from test_framework.key import ECKey | from test_framework.key import ECKey | ||||
from test_framework.messages import AvalancheProofVoteResponse, AvalancheVote | from test_framework.messages import AvalancheProofVoteResponse, AvalancheVote | ||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import assert_equal, try_rpc, uint256_hex | from test_framework.util import assert_equal, try_rpc, uint256_hex | ||||
from test_framework.wallet_util import bytes_to_wif | from test_framework.wallet_util import bytes_to_wif | ||||
▲ Show 20 Lines • Show All 77 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
"node_count": 0, | "node_count": 0, | ||||
"connected_node_count": 0, | "connected_node_count": 0, | ||||
"pending_node_count": 0, | "pending_node_count": 0, | ||||
} | } | ||||
}) | }) | ||||
# Make sure receiving our own proof from the network before validating | # Make sure receiving our own proof from the network before validating | ||||
# the local proof doesn't change our proof count. | # the local proof doesn't change our proof count. | ||||
sender = get_ava_p2p_interface(node) | sender = get_ava_p2p_interface_no_handshake(node) | ||||
sender.send_avaproof(proof) | sender.send_avaproof(proof) | ||||
# Make sure getting the proof via RPC doesn't change our proof count | # Make sure getting the proof via RPC doesn't change our proof count | ||||
# either. | # either. | ||||
node.sendavalancheproof(proof.serialize().hex()) | node.sendavalancheproof(proof.serialize().hex()) | ||||
assert_avalancheinfo({ | assert_avalancheinfo({ | ||||
"ready_to_poll": False, | "ready_to_poll": False, | ||||
"local": { | "local": { | ||||
▲ Show 20 Lines • Show All 176 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
delegation = node.delegateavalancheproof( | delegation = node.delegateavalancheproof( | ||||
uint256_hex(_proof.limited_proofid), | uint256_hex(_proof.limited_proofid), | ||||
bytes_to_wif(_privkey.get_bytes()), | bytes_to_wif(_privkey.get_bytes()), | ||||
dg_pub, | dg_pub, | ||||
None | None | ||||
) | ) | ||||
n = get_ava_p2p_interface(node) | # It would be much simpler to just use get_ava_p2p_interface here | ||||
# but the node would be able to download the proof, so the node | |||||
# won't be pending. | |||||
n = get_ava_p2p_interface_no_handshake(node) | |||||
n.send_avahello(delegation, dg_priv) | n.send_avahello(delegation, dg_priv) | ||||
# Make sure we completed at least one time the ProcessMessage or we | # Make sure we completed at least one time the ProcessMessage or we | ||||
# might miss the last pending node for the following assert | # might miss the last pending node for the following assert | ||||
n.sync_with_ping() | n.sync_with_ping() | ||||
# Immature became mature | # Immature became mature | ||||
proofs.append(immature_proof) | proofs.append(immature_proof) | ||||
▲ Show 20 Lines • Show All 101 Lines • Show Last 20 Lines |