Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc_p2p_avalanche.py
Show All 29 Lines | |||||
BLOCK_ACCEPTED = 0 | BLOCK_ACCEPTED = 0 | ||||
BLOCK_INVALID = 1 | BLOCK_INVALID = 1 | ||||
BLOCK_PARKED = 2 | BLOCK_PARKED = 2 | ||||
BLOCK_FORK = 3 | BLOCK_FORK = 3 | ||||
BLOCK_UNKNOWN = -1 | BLOCK_UNKNOWN = -1 | ||||
BLOCK_MISSING = -2 | BLOCK_MISSING = -2 | ||||
BLOCK_PENDING = -3 | BLOCK_PENDING = -3 | ||||
QUORUM_NODE_COUNT = 16 | |||||
class TestNode(P2PInterface): | class TestNode(P2PInterface): | ||||
def __init__(self): | def __init__(self): | ||||
self.round = 0 | self.round = 0 | ||||
self.avahello = None | self.avahello = None | ||||
self.avaresponses = [] | self.avaresponses = [] | ||||
self.avapolls = [] | self.avapolls = [] | ||||
▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
n, services=NODE_NETWORK | NODE_AVALANCHE) | n, services=NODE_NETWORK | NODE_AVALANCHE) | ||||
n.wait_for_verack() | n.wait_for_verack() | ||||
# Get our own node id so we can use it later. | # Get our own node id so we can use it later. | ||||
n.nodeid = node.getpeerinfo()[-1]['id'] | n.nodeid = node.getpeerinfo()[-1]['id'] | ||||
return n | return n | ||||
return [get_node() for _ in range(0, 16)] | return [get_node() for _ in range(0, QUORUM_NODE_COUNT)] | ||||
# Pick on node from the quorum for polling. | # Pick on node from the quorum for polling. | ||||
quorum = get_quorum() | quorum = get_quorum() | ||||
poll_node = quorum[0] | poll_node = quorum[0] | ||||
# Generate many block and poll for them. | # Generate many block and poll for them. | ||||
address = node.get_deterministic_priv_key().address | address = node.get_deterministic_priv_key().address | ||||
blocks = node.generatetoaddress(100, address) | blocks = node.generatetoaddress(100, address) | ||||
▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
self.log.info("Trigger polling from the node...") | self.log.info("Trigger polling from the node...") | ||||
# duplicate the deterministic sig test from src/test/key_tests.cpp | # duplicate the deterministic sig test from src/test/key_tests.cpp | ||||
privkey = ECKey() | privkey = ECKey() | ||||
privkey.set(bytes.fromhex( | privkey.set(bytes.fromhex( | ||||
"12b004fff7f4b69ef8650e767f18f11ede158148b425660723b9f9a66e61f747"), True) | "12b004fff7f4b69ef8650e767f18f11ede158148b425660723b9f9a66e61f747"), True) | ||||
pubkey = privkey.get_pubkey() | pubkey = privkey.get_pubkey() | ||||
privatekey = node.get_deterministic_priv_key().key | privatekey = node.get_deterministic_priv_key().key | ||||
proof = node.buildavalancheproof(11, 12, pubkey.get_bytes().hex(), [{ | proof_sequence = 11 | ||||
proof_expiration = 12 | |||||
proof = node.buildavalancheproof( | |||||
proof_sequence, proof_expiration, pubkey.get_bytes().hex(), | |||||
[{ | |||||
'txid': coinbases[0]['txid'], | 'txid': coinbases[0]['txid'], | ||||
'vout': coinbases[0]['n'], | 'vout': coinbases[0]['n'], | ||||
'amount': coinbases[0]['value'], | 'amount': coinbases[0]['value'], | ||||
'height': coinbases[0]['height'], | 'height': coinbases[0]['height'], | ||||
'iscoinbase': True, | 'iscoinbase': True, | ||||
'privatekey': privatekey, | 'privatekey': privatekey, | ||||
}]) | }]) | ||||
# Activate the quorum. | # Activate the quorum. | ||||
for n in quorum: | for n in quorum: | ||||
success = node.addavalanchenode( | success = node.addavalanchenode( | ||||
n.nodeid, pubkey.get_bytes().hex(), proof) | n.nodeid, pubkey.get_bytes().hex(), proof) | ||||
assert success is True | assert success is True | ||||
self.log.info("Testing getavalanchepeerinfo...") | |||||
avapeerinfo = node.getavalanchepeerinfo() | |||||
# There is a single peer because all nodes share the same proof. | |||||
assert_equal(len(avapeerinfo), 1) | |||||
assert_equal(avapeerinfo[0]["peerid"], 0) | |||||
assert_equal(avapeerinfo[0]["nodecount"], len(quorum)) | |||||
# The first avalanche node index is 1, because 0 is self.nodes[1]. | |||||
assert_equal(sorted(avapeerinfo[0]["nodes"]), | |||||
list(range(1, QUORUM_NODE_COUNT + 1))) | |||||
assert_equal(avapeerinfo[0]["sequence"], proof_sequence) | |||||
assert_equal(avapeerinfo[0]["expiration"], proof_expiration) | |||||
assert_equal(avapeerinfo[0]["master"], pubkey.get_bytes().hex()) | |||||
assert_equal(avapeerinfo[0]["proof"], proof) | |||||
assert_equal(len(avapeerinfo[0]["stakes"]), 1) | |||||
assert_equal(avapeerinfo[0]["stakes"][0]["txid"], coinbases[0]['txid']) | |||||
def can_find_block_in_poll(hash, resp=BLOCK_ACCEPTED): | def can_find_block_in_poll(hash, resp=BLOCK_ACCEPTED): | ||||
found_hash = False | found_hash = False | ||||
for n in quorum: | for n in quorum: | ||||
poll = n.get_avapoll_if_available() | poll = n.get_avapoll_if_available() | ||||
# That node has not received a poll | # That node has not received a poll | ||||
if poll is None: | if poll is None: | ||||
continue | continue | ||||
▲ Show 20 Lines • Show All 87 Lines • Show Last 20 Lines |