Changeset View
Changeset View
Standalone View
Standalone View
test/functional/p2p_permissions.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2015-2018 The Bitcoin Core developers | # Copyright (c) 2015-2018 The Bitcoin Core 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 p2p permission message. | """Test p2p permission message. | ||||
Test that permissions are correctly calculated and applied | Test that permissions are correctly calculated and applied | ||||
""" | """ | ||||
from test_framework.address import ADDRESS_ECREG_P2SH_OP_TRUE | |||||
from test_framework.messages import CTransaction, FromHex | from test_framework.messages import CTransaction, FromHex | ||||
from test_framework.p2p import P2PDataStore | from test_framework.p2p import P2PDataStore | ||||
from test_framework.script import OP_TRUE, CScript, CScriptOp | |||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.test_node import ErrorMatch | from test_framework.test_node import ErrorMatch | ||||
from test_framework.txtools import pad_tx | from test_framework.txtools import pad_tx | ||||
from test_framework.util import assert_equal, connect_nodes, p2p_port | from test_framework.util import assert_equal, connect_nodes, p2p_port | ||||
class P2PPermissionsTests(BitcoinTestFramework): | class P2PPermissionsTests(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
▲ Show 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
"Invalid netmask specified in", | "Invalid netmask specified in", | ||||
match=ErrorMatch.PARTIAL_REGEX) | match=ErrorMatch.PARTIAL_REGEX) | ||||
self.nodes[1].assert_start_raises_init_error( | self.nodes[1].assert_start_raises_init_error( | ||||
["-whitebind=noban@127.0.0.1/10"], | ["-whitebind=noban@127.0.0.1/10"], | ||||
"Cannot resolve -whitebind address", | "Cannot resolve -whitebind address", | ||||
match=ErrorMatch.PARTIAL_REGEX) | match=ErrorMatch.PARTIAL_REGEX) | ||||
def check_tx_relay(self): | def check_tx_relay(self): | ||||
address = self.nodes[0].get_deterministic_priv_key().address | block_op_true = self.nodes[0].getblock( | ||||
key = self.nodes[0].get_deterministic_priv_key().key | self.nodes[0].generatetoaddress(100, ADDRESS_ECREG_P2SH_OP_TRUE)[0]) | ||||
block = self.nodes[0].getblock( | |||||
self.nodes[0].generatetoaddress( | |||||
100, address)[0]) | |||||
self.sync_all() | self.sync_all() | ||||
self.log.debug( | self.log.debug( | ||||
"Create a connection from a forcerelay peer 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 forcerelay 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") | ||||
raw_tx = self.nodes[0].createrawtransaction( | tx = FromHex(CTransaction(), | ||||
inputs=[{'txid': block['tx'][0], 'vout': 0}], | self.nodes[0].createrawtransaction( | ||||
outputs=[{address: 50, }]) | inputs=[{'txid': block_op_true['tx'][0], 'vout': 0}], | ||||
signed_tx = self.nodes[0].signrawtransactionwithkey(raw_tx, | outputs=[{ADDRESS_ECREG_P2SH_OP_TRUE: 50}])) | ||||
[key])['hex'] | # push the one byte script to the stack | ||||
tx = FromHex(CTransaction(), signed_tx) | tx.vin[0].scriptSig = CScriptOp.encode_op_pushdata(CScript([OP_TRUE])) | ||||
pad_tx(tx) | pad_tx(tx) | ||||
txid = tx.rehash() | txid = tx.rehash() | ||||
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" | ||||
Show All 39 Lines |