Changeset View
Changeset View
Standalone View
Standalone View
test/functional/p2p_permissions.py
Show First 20 Lines • Show All 124 Lines • ▼ Show 20 Lines | class P2PPermissionsTests(BitcoinTestFramework): | ||||
def check_tx_relay(self): | def check_tx_relay(self): | ||||
address = self.nodes[0].get_deterministic_priv_key().address | address = self.nodes[0].get_deterministic_priv_key().address | ||||
block = self.nodes[0].getblock( | block = self.nodes[0].getblock( | ||||
self.nodes[0].generatetoaddress( | self.nodes[0].generatetoaddress( | ||||
100, address)[0]) | 100, address)[0]) | ||||
self.sync_all() | self.sync_all() | ||||
self.log.debug( | self.log.debug( | ||||
"Create a connection from a whitelisted wallet that rebroadcasts raw txs") | "Create a connection from a forcerelay peer that rebroadcasts raw txs") | ||||
# A python mininode is needed to send the raw transaction directly. | # A python mininode is needed to send the raw transaction directly. | ||||
# If a full node was used, it could only rebroadcast via the inv-getdata | # If a full node was used, it could only rebroadcast via the inv-getdata | ||||
# mechanism. However, even for whitelisted connections, a full node would | # mechanism. However, even for forcerelay connections, a full node would | ||||
# currently not request a txid that is already in the mempool. | # currently not request a txid that is already in the mempool. | ||||
self.restart_node(1, extra_args=["-whitelist=forcerelay@127.0.0.1"]) | self.restart_node(1, extra_args=["-whitelist=forcerelay@127.0.0.1"]) | ||||
p2p_rebroadcast_wallet = self.nodes[1].add_p2p_connection( | p2p_rebroadcast_wallet = self.nodes[1].add_p2p_connection( | ||||
P2PDataStore()) | P2PDataStore()) | ||||
self.log.debug("Send a tx from the wallet initially") | self.log.debug("Send a tx from the wallet initially") | ||||
tx = FromHex( | tx = FromHex( | ||||
CTransaction(), | CTransaction(), | ||||
Show All 10 Lines | def check_tx_relay(self): | ||||
self.log.debug("Wait until tx is in node[1]'s mempool") | self.log.debug("Wait until tx is in node[1]'s mempool") | ||||
p2p_rebroadcast_wallet.send_txs_and_test([tx], self.nodes[1]) | p2p_rebroadcast_wallet.send_txs_and_test([tx], self.nodes[1]) | ||||
self.log.debug( | self.log.debug( | ||||
"Check that node[1] will send the tx to node[0] even though it" | "Check that node[1] will send the tx to node[0] even though it" | ||||
" is already in the mempool") | " is already in the mempool") | ||||
connect_nodes(self.nodes[1], 0) | connect_nodes(self.nodes[1], 0) | ||||
with self.nodes[1].assert_debug_log( | with self.nodes[1].assert_debug_log( | ||||
["Force relaying tx {} from whitelisted peer=0".format(txid)]): | ["Force relaying tx {} from peer=0".format(txid)]): | ||||
p2p_rebroadcast_wallet.send_txs_and_test([tx], self.nodes[1]) | p2p_rebroadcast_wallet.send_txs_and_test([tx], self.nodes[1]) | ||||
wait_until(lambda: txid in self.nodes[0].getrawmempool()) | wait_until(lambda: txid in self.nodes[0].getrawmempool()) | ||||
self.log.debug( | self.log.debug( | ||||
"Check that node[1] will not send an invalid tx to node[0]") | "Check that node[1] will not send an invalid tx to node[0]") | ||||
tx.vout[0].nValue += 1 | tx.vout[0].nValue += 1 | ||||
txid = tx.rehash() | txid = tx.rehash() | ||||
p2p_rebroadcast_wallet.send_txs_and_test( | p2p_rebroadcast_wallet.send_txs_and_test( | ||||
[tx], | [tx], | ||||
self.nodes[1], | self.nodes[1], | ||||
success=False, | success=False, | ||||
reject_reason='Not relaying non-mempool transaction ' | reject_reason='Not relaying non-mempool transaction ' | ||||
'{} from whitelisted peer=0'.format(txid), | '{} from forcerelay peer=0'.format(txid), | ||||
) | ) | ||||
def checkpermission(self, args, expectedPermissions, whitelisted): | def checkpermission(self, args, expectedPermissions, whitelisted): | ||||
self.restart_node(1, args) | self.restart_node(1, args) | ||||
connect_nodes(self.nodes[0], self.nodes[1]) | connect_nodes(self.nodes[0], self.nodes[1]) | ||||
peerinfo = self.nodes[1].getpeerinfo()[0] | peerinfo = self.nodes[1].getpeerinfo()[0] | ||||
assert_equal(peerinfo['whitelisted'], whitelisted) | assert_equal(peerinfo['whitelisted'], whitelisted) | ||||
assert_equal(len(expectedPermissions), len(peerinfo['permissions'])) | assert_equal(len(expectedPermissions), len(peerinfo['permissions'])) | ||||
Show All 14 Lines |