Changeset View
Changeset View
Standalone View
Standalone View
test/functional/p2p_invalid_block.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2015-2016 The Bitcoin Core developers | # Copyright (c) 2015-2016 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 node responses to invalid blocks. | |||||
In this test we connect to one node over p2p, and test block requests: | |||||
1) Valid blocks should be requested and become chain tip. | |||||
2) Invalid block with duplicated transaction should be re-requested. | |||||
3) Invalid block with bad coinbase value should be rejected and not | |||||
re-requested. | |||||
""" | |||||
import copy | import copy | ||||
import time | import time | ||||
from test_framework.blocktools import ( | from test_framework.blocktools import ( | ||||
create_block, | create_block, | ||||
create_coinbase, | create_coinbase, | ||||
create_transaction, | create_transaction, | ||||
) | ) | ||||
from test_framework.comptool import RejectResult, TestInstance, TestManager | from test_framework.comptool import RejectResult, TestInstance, TestManager | ||||
from test_framework.messages import COIN | from test_framework.messages import COIN | ||||
from test_framework.mininode import network_thread_start | from test_framework.mininode import network_thread_start | ||||
from test_framework.test_framework import ComparisonTestFramework | from test_framework.test_framework import ComparisonTestFramework | ||||
from test_framework.util import assert_equal | from test_framework.util import assert_equal | ||||
''' | |||||
In this test we connect to one node over p2p, and test block requests: | |||||
1) Valid blocks should be requested and become chain tip. | |||||
2) Invalid block with duplicated transaction should be re-requested. | |||||
3) Invalid block with bad coinbase value should be rejected and not | |||||
re-requested. | |||||
''' | |||||
# Use the ComparisonTestFramework with 1 node: only use --testbinary. | # Use the ComparisonTestFramework with 1 node: only use --testbinary. | ||||
class InvalidBlockRequestTest(ComparisonTestFramework): | class InvalidBlockRequestTest(ComparisonTestFramework): | ||||
''' Can either run this test as 1 node with expected answers, or two and compare them. | ''' Can either run this test as 1 node with expected answers, or two and compare them. | ||||
Change the "outcome" variable from each TestInstance object to only do the comparison. ''' | Change the "outcome" variable from each TestInstance object to only do the comparison. ''' | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.num_nodes = 1 | self.num_nodes = 1 | ||||
self.setup_clean_chain = True | self.setup_clean_chain = True | ||||
▲ Show 20 Lines • Show All 111 Lines • Show Last 20 Lines |