Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc-p2p-fullblocktest.py
Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | class FullBlockTest(ComparisonTestFramework): | ||||
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 | ||||
self.block_heights = {} | self.block_heights = {} | ||||
self.tip = None | self.tip = None | ||||
self.blocks = {} | self.blocks = {} | ||||
self.excessive_block_size = 100 * ONE_MEGABYTE | self.excessive_block_size = 100 * ONE_MEGABYTE | ||||
self.extra_args = [['-whitelist=127.0.0.1', | self.extra_args = [['-whitelist=127.0.0.1', | ||||
"-monolithactivationtime=%d" % MONOLITH_START_TIME, | |||||
"-excessiveblocksize=%d" | "-excessiveblocksize=%d" | ||||
% self.excessive_block_size]] | % self.excessive_block_size]] | ||||
def add_options(self, parser): | def add_options(self, parser): | ||||
super().add_options(parser) | super().add_options(parser) | ||||
parser.add_option( | parser.add_option( | ||||
"--runbarelyexpensive", dest="runbarelyexpensive", default=True) | "--runbarelyexpensive", dest="runbarelyexpensive", default=True) | ||||
▲ Show 20 Lines • Show All 117 Lines • ▼ Show 20 Lines | def next_block(self, number, spend=None, script=CScript([OP_TRUE]), block_size=0, extra_sigops=0): | ||||
block.solve() | block.solve() | ||||
self.tip = block | self.tip = block | ||||
self.block_heights[block.sha256] = height | self.block_heights[block.sha256] = height | ||||
assert number not in self.blocks | assert number not in self.blocks | ||||
self.blocks[number] = block | self.blocks[number] = block | ||||
return block | return block | ||||
def get_tests(self): | def get_tests(self): | ||||
self.genesis_hash = int(self.nodes[0].getbestblockhash(), 16) | node = self.nodes[0] | ||||
self.genesis_hash = int(node.getbestblockhash(), 16) | |||||
self.block_heights[self.genesis_hash] = 0 | self.block_heights[self.genesis_hash] = 0 | ||||
spendable_outputs = [] | spendable_outputs = [] | ||||
# save the current tip so it can be spent by a later block | # save the current tip so it can be spent by a later block | ||||
def save_spendable_output(): | def save_spendable_output(): | ||||
spendable_outputs.append(self.tip) | spendable_outputs.append(self.tip) | ||||
# get an output that we previously marked as spendable | # get an output that we previously marked as spendable | ||||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | def get_tests(self): | ||||
out.append(get_spendable_output()) | out.append(get_spendable_output()) | ||||
# Let's build some blocks and test them. | # Let's build some blocks and test them. | ||||
for i in range(15): | for i in range(15): | ||||
n = i + 1 | n = i + 1 | ||||
block(n, spend=out[i], block_size=n * ONE_MEGABYTE // 2) | block(n, spend=out[i], block_size=n * ONE_MEGABYTE // 2) | ||||
yield accepted() | yield accepted() | ||||
# Fork block | # Start moving MTP forward | ||||
bfork = block(5555, out[15], block_size=8 * ONE_MEGABYTE) | bfork = block(5555, out[15], block_size=8 * ONE_MEGABYTE) | ||||
bfork.nTime = MONOLITH_START_TIME | bfork.nTime = MONOLITH_START_TIME - 1 | ||||
update_block(5555, []) | update_block(5555, []) | ||||
yield accepted() | yield accepted() | ||||
# Get to one block of the May 15, 2018 HF activation | # Get to one block of the May 15, 2018 HF activation | ||||
for i in range(4): | for i in range(5): | ||||
block(5100 + i) | block(5100 + i) | ||||
test.blocks_and_transactions.append([self.tip, True]) | test.blocks_and_transactions.append([self.tip, True]) | ||||
yield test | yield test | ||||
# Check that the MTP is just before the configured fork point. | |||||
assert_equal(node.getblockheader(node.getbestblockhash())['mediantime'], | |||||
MONOLITH_START_TIME - 1) | |||||
# Before we acivate the May 15, 2018 HF, 8MB is the limit. | # Before we acivate the May 15, 2018 HF, 8MB is the limit. | ||||
block(4444, spend=out[16], block_size=8 * ONE_MEGABYTE + 1) | block(4444, spend=out[16], block_size=8 * ONE_MEGABYTE + 1) | ||||
yield rejected(RejectResult(16, b'bad-blk-length')) | yield rejected(RejectResult(16, b'bad-blk-length')) | ||||
# Rewind bad block. | # Rewind bad block. | ||||
tip(5103) | tip(5104) | ||||
# Actiavte the May 15, 2018 HF | # Actiavte the May 15, 2018 HF | ||||
block(5104) | block(5556) | ||||
yield accepted() | yield accepted() | ||||
# Now MTP is exactly the fork time. Bigger blocks are now accepted. | |||||
assert_equal(node.getblockheader(node.getbestblockhash())['mediantime'], | |||||
MONOLITH_START_TIME) | |||||
# block of maximal size | # block of maximal size | ||||
block(17, spend=out[16], block_size=self.excessive_block_size) | block(17, spend=out[16], block_size=self.excessive_block_size) | ||||
yield accepted() | yield accepted() | ||||
# Reject oversized blocks with bad-blk-length error | # Reject oversized blocks with bad-blk-length error | ||||
block(18, spend=out[17], block_size=self.excessive_block_size + 1) | block(18, spend=out[17], block_size=self.excessive_block_size + 1) | ||||
yield rejected(RejectResult(16, b'bad-blk-length')) | yield rejected(RejectResult(16, b'bad-blk-length')) | ||||
▲ Show 20 Lines • Show All 136 Lines • Show Last 20 Lines |