Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc-schnorr.py
Show First 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | |||||
class SchnorrTest(BitcoinTestFramework): | class SchnorrTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.num_nodes = 1 | self.num_nodes = 1 | ||||
self.block_heights = {} | self.block_heights = {} | ||||
self.extra_args = [[ | self.extra_args = [[ | ||||
"-acceptnonstdtxn=1"]] | "-acceptnonstdtxn=1"]] | ||||
def bootstrap_p2p(self, *, num_connections=1): | def reconnect_p2p(self): | ||||
"""Add a P2P connection to the node. | |||||
Helper to connect and wait for version handshake.""" | |||||
for _ in range(num_connections): | |||||
self.nodes[0].add_p2p_connection(P2PDataStore()) | |||||
def reconnect_p2p(self, **kwargs): | |||||
"""Tear down and bootstrap the P2P connection to the node. | """Tear down and bootstrap the P2P connection to the node. | ||||
The node gets disconnected several times in this test. This helper | The node gets disconnected several times in this test. This helper | ||||
method reconnects the p2p and restarts the network thread.""" | method reconnects the p2p and restarts the network thread.""" | ||||
self.nodes[0].disconnect_p2ps() | self.nodes[0].disconnect_p2ps() | ||||
self.bootstrap_p2p(**kwargs) | self.peer = self.nodes[0].add_p2p_connection(P2PDataStore()) | ||||
def getbestblock(self, node): | def getbestblock(self, node): | ||||
"""Get the best block. Register its height so we can use build_block.""" | """Get the best block. Register its height so we can use build_block.""" | ||||
block_height = node.getblockcount() | block_height = node.getblockcount() | ||||
blockhash = node.getblockhash(block_height) | blockhash = node.getblockhash(block_height) | ||||
block = FromHex(CBlock(), node.getblock(blockhash, 0)) | block = FromHex(CBlock(), node.getblock(blockhash, 0)) | ||||
block.calc_sha256() | block.calc_sha256() | ||||
self.block_heights[block.sha256] = block_height | self.block_heights[block.sha256] = block_height | ||||
Show All 15 Lines | def build_block(self, parent, transactions=(), nTime=None): | ||||
block.solve() | block.solve() | ||||
self.block_heights[block.sha256] = block_height | self.block_heights[block.sha256] = block_height | ||||
return block | return block | ||||
def check_for_ban_on_rejected_tx(self, tx, reject_reason=None): | def check_for_ban_on_rejected_tx(self, tx, reject_reason=None): | ||||
"""Check we are disconnected when sending a txn that the node rejects. | """Check we are disconnected when sending a txn that the node rejects. | ||||
(Can't actually get banned, since bitcoind won't ban local peers.)""" | (Can't actually get banned, since bitcoind won't ban local peers.)""" | ||||
self.nodes[0].p2p.send_txs_and_test( | self.peer.send_txs_and_test( | ||||
[tx], self.nodes[0], success=False, reject_reason=reject_reason, expect_disconnect=True) | [tx], self.nodes[0], success=False, reject_reason=reject_reason, expect_disconnect=True) | ||||
self.reconnect_p2p() | self.reconnect_p2p() | ||||
def check_for_ban_on_rejected_block(self, block, reject_reason=None): | def check_for_ban_on_rejected_block(self, block, reject_reason=None): | ||||
"""Check we are disconnected when sending a block that the node rejects. | """Check we are disconnected when sending a block that the node rejects. | ||||
(Can't actually get banned, since bitcoind won't ban local peers.)""" | (Can't actually get banned, since bitcoind won't ban local peers.)""" | ||||
self.nodes[0].p2p.send_blocks_and_test( | self.peer.send_blocks_and_test( | ||||
[block], self.nodes[0], success=False, reject_reason=reject_reason, expect_disconnect=True) | [block], self.nodes[0], success=False, reject_reason=reject_reason, expect_disconnect=True) | ||||
self.reconnect_p2p() | self.reconnect_p2p() | ||||
def run_test(self): | def run_test(self): | ||||
node, = self.nodes | node, = self.nodes | ||||
self.bootstrap_p2p() | self.peer = self.nodes[0].add_p2p_connection(P2PDataStore()) | ||||
tip = self.getbestblock(node) | tip = self.getbestblock(node) | ||||
self.log.info("Create some blocks with OP_1 coinbase for spending.") | self.log.info("Create some blocks with OP_1 coinbase for spending.") | ||||
blocks = [] | blocks = [] | ||||
for _ in range(10): | for _ in range(10): | ||||
tip = self.build_block(tip) | tip = self.build_block(tip) | ||||
blocks.append(tip) | blocks.append(tip) | ||||
▲ Show 20 Lines • Show All 108 Lines • Show Last 20 Lines |