Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/mininode.py
Show All 26 Lines | from test_framework.messages import ( | ||||
msg_addr, | msg_addr, | ||||
msg_avapoll, | msg_avapoll, | ||||
msg_tcpavaresponse, | msg_tcpavaresponse, | ||||
msg_block, | msg_block, | ||||
MSG_BLOCK, | MSG_BLOCK, | ||||
msg_blocktxn, | msg_blocktxn, | ||||
msg_cmpctblock, | msg_cmpctblock, | ||||
msg_feefilter, | msg_feefilter, | ||||
msg_filterload, | |||||
msg_getaddr, | msg_getaddr, | ||||
msg_getblocks, | msg_getblocks, | ||||
msg_getblocktxn, | msg_getblocktxn, | ||||
msg_getdata, | msg_getdata, | ||||
msg_getheaders, | msg_getheaders, | ||||
msg_headers, | msg_headers, | ||||
msg_inv, | msg_inv, | ||||
msg_mempool, | msg_mempool, | ||||
msg_merkleblock, | |||||
msg_notfound, | msg_notfound, | ||||
msg_ping, | msg_ping, | ||||
msg_pong, | msg_pong, | ||||
msg_reject, | msg_reject, | ||||
msg_sendcmpct, | msg_sendcmpct, | ||||
msg_sendheaders, | msg_sendheaders, | ||||
msg_tx, | msg_tx, | ||||
MSG_TX, | MSG_TX, | ||||
Show All 10 Lines | |||||
MESSAGEMAP = { | MESSAGEMAP = { | ||||
b"addr": msg_addr, | b"addr": msg_addr, | ||||
b"avapoll": msg_avapoll, | b"avapoll": msg_avapoll, | ||||
b"avaresponse": msg_tcpavaresponse, | b"avaresponse": msg_tcpavaresponse, | ||||
b"block": msg_block, | b"block": msg_block, | ||||
b"blocktxn": msg_blocktxn, | b"blocktxn": msg_blocktxn, | ||||
b"cmpctblock": msg_cmpctblock, | b"cmpctblock": msg_cmpctblock, | ||||
b"feefilter": msg_feefilter, | b"feefilter": msg_feefilter, | ||||
b"filterload": msg_filterload, | |||||
b"getaddr": msg_getaddr, | b"getaddr": msg_getaddr, | ||||
b"getblocks": msg_getblocks, | b"getblocks": msg_getblocks, | ||||
b"getblocktxn": msg_getblocktxn, | b"getblocktxn": msg_getblocktxn, | ||||
b"getdata": msg_getdata, | b"getdata": msg_getdata, | ||||
b"getheaders": msg_getheaders, | b"getheaders": msg_getheaders, | ||||
b"headers": msg_headers, | b"headers": msg_headers, | ||||
b"inv": msg_inv, | b"inv": msg_inv, | ||||
b"mempool": msg_mempool, | b"mempool": msg_mempool, | ||||
b"merkleblock": msg_merkleblock, | |||||
b"notfound": msg_notfound, | b"notfound": msg_notfound, | ||||
b"ping": msg_ping, | b"ping": msg_ping, | ||||
b"pong": msg_pong, | b"pong": msg_pong, | ||||
b"reject": msg_reject, | b"reject": msg_reject, | ||||
b"sendcmpct": msg_sendcmpct, | b"sendcmpct": msg_sendcmpct, | ||||
b"sendheaders": msg_sendheaders, | b"sendheaders": msg_sendheaders, | ||||
b"tx": msg_tx, | b"tx": msg_tx, | ||||
b"verack": msg_verack, | b"verack": msg_verack, | ||||
▲ Show 20 Lines • Show All 275 Lines • ▼ Show 20 Lines | class P2PInterface(P2PConnection): | ||||
def on_block(self, message): pass | def on_block(self, message): pass | ||||
def on_blocktxn(self, message): pass | def on_blocktxn(self, message): pass | ||||
def on_cmpctblock(self, message): pass | def on_cmpctblock(self, message): pass | ||||
def on_feefilter(self, message): pass | def on_feefilter(self, message): pass | ||||
def on_filterload(self, message): pass | |||||
def on_getaddr(self, message): pass | def on_getaddr(self, message): pass | ||||
def on_getblocks(self, message): pass | def on_getblocks(self, message): pass | ||||
def on_getblocktxn(self, message): pass | def on_getblocktxn(self, message): pass | ||||
def on_getdata(self, message): pass | def on_getdata(self, message): pass | ||||
def on_getheaders(self, message): pass | def on_getheaders(self, message): pass | ||||
def on_headers(self, message): pass | def on_headers(self, message): pass | ||||
def on_mempool(self, message): pass | def on_mempool(self, message): pass | ||||
def on_merkleblock(self, message): pass | |||||
def on_notfound(self, message): pass | def on_notfound(self, message): pass | ||||
def on_pong(self, message): pass | def on_pong(self, message): pass | ||||
def on_reject(self, message): pass | def on_reject(self, message): pass | ||||
def on_sendcmpct(self, message): pass | def on_sendcmpct(self, message): pass | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | def wait_for_header(self, blockhash, timeout=60): | ||||
def test_function(): | def test_function(): | ||||
last_headers = self.last_message.get('headers') | last_headers = self.last_message.get('headers') | ||||
if not last_headers: | if not last_headers: | ||||
return False | return False | ||||
return last_headers.headers[0].rehash() == blockhash | return last_headers.headers[0].rehash() == blockhash | ||||
wait_until(test_function, timeout=timeout, lock=mininode_lock) | wait_until(test_function, timeout=timeout, lock=mininode_lock) | ||||
def wait_for_merkleblock(self, timeout=60): | |||||
def test_function(): | |||||
assert self.is_connected | |||||
last_filtered_block = self.last_message.get('merkleblock') | |||||
if not last_filtered_block: | |||||
return False | |||||
# TODO change this method to take a hash value and only return true | |||||
# if the correct block has been received | |||||
return True | |||||
wait_until(test_function, timeout=timeout, lock=mininode_lock) | |||||
def wait_for_getdata(self, timeout=60): | def wait_for_getdata(self, timeout=60): | ||||
"""Waits for a getdata message. | """Waits for a getdata message. | ||||
Receiving any getdata message will satisfy the predicate. the last_message["getdata"] | Receiving any getdata message will satisfy the predicate. the last_message["getdata"] | ||||
value must be explicitly cleared before calling this method, or this will return | value must be explicitly cleared before calling this method, or this will return | ||||
immediately with success. TODO: change this method to take a hash value and only | immediately with success. TODO: change this method to take a hash value and only | ||||
return true if the correct block/tx has been requested.""" | return true if the correct block/tx has been requested.""" | ||||
def test_function(): return self.last_message.get("getdata") | def test_function(): return self.last_message.get("getdata") | ||||
▲ Show 20 Lines • Show All 223 Lines • Show Last 20 Lines |