Changeset View
Changeset View
Standalone View
Standalone View
test/functional/p2p-compactblocks.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2016 The Bitcoin Core developers | # Copyright (c) 2016 The Bitcoin Core developers | ||||
# Copyright (c) 2017 The Bitcoin developers | # Copyright (c) 2017 The Bitcoin 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. | ||||
from test_framework.mininode import * | from test_framework.mininode import * | ||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import * | from test_framework.util import * | ||||
from test_framework.blocktools import create_block, create_coinbase | from test_framework.blocktools import create_block, create_coinbase, magnetic_anomaly_block | ||||
from test_framework.script import CScript, OP_TRUE | from test_framework.script import CScript, OP_TRUE | ||||
''' | ''' | ||||
CompactBlocksTest -- test compact blocks (BIP 152) | CompactBlocksTest -- test compact blocks (BIP 152) | ||||
Only testing Version 1 compact blocks (txids) | Only testing Version 1 compact blocks (txids) | ||||
''' | ''' | ||||
# TestNode: A peer we use to send messages to bitcoind, and store responses. | # TestNode: A peer we use to send messages to bitcoind, and store responses. | ||||
# Defer magnetic anomaly until far in the future, so this test can operate | |||||
# normally | |||||
MAGNETIC_ANOMALY_START_TIME = 2000000000 | |||||
class TestNode(NodeConnCB): | class TestNode(NodeConnCB): | ||||
def __init__(self): | def __init__(self): | ||||
super().__init__() | super().__init__() | ||||
self.last_sendcmpct = [] | self.last_sendcmpct = [] | ||||
self.block_announced = False | self.block_announced = False | ||||
# Store the hashes of blocks we've seen announced. | # Store the hashes of blocks we've seen announced. | ||||
# This is for synchronizing the p2p message traffic, | # This is for synchronizing the p2p message traffic, | ||||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | def send_await_disconnect(self, message, timeout=30): | ||||
wait_until(lambda: not self.connected, | wait_until(lambda: not self.connected, | ||||
timeout=timeout, lock=mininode_lock) | timeout=timeout, lock=mininode_lock) | ||||
class CompactBlocksTest(BitcoinTestFramework): | class CompactBlocksTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.setup_clean_chain = True | self.setup_clean_chain = True | ||||
self.num_nodes = 2 | self.num_nodes = 2 | ||||
self.extra_args = [[], ["-txindex"]] | self.extra_args = [['-magneticanomalyactivationtime=%d' % MAGNETIC_ANOMALY_START_TIME], | ||||
["-txindex", '-magneticanomalyactivationtime=%d' % MAGNETIC_ANOMALY_START_TIME]] | |||||
self.utxos = [] | self.utxos = [] | ||||
def build_block_on_tip(self, node): | def build_block_on_tip(self, node): | ||||
height = node.getblockcount() | height = node.getblockcount() | ||||
tip = node.getbestblockhash() | tip = node.getbestblockhash() | ||||
mtp = node.getblockheader(tip)['mediantime'] | mtp = node.getblockheader(tip)['mediantime'] | ||||
block = create_block( | block = create_block( | ||||
int(tip, 16), create_coinbase(height + 1), mtp + 1) | int(tip, 16), create_coinbase(height + 1), mtp + 1) | ||||
▲ Show 20 Lines • Show All 782 Lines • Show Last 20 Lines |