Changeset View
Changeset View
Standalone View
Standalone View
test/functional/p2p-fullblocktest.py
Show First 20 Lines • Show All 167 Lines • ▼ Show 20 Lines | def get_tests(self): | ||||
else: | else: | ||||
return TestInstance([[self.tip, reject]]) | return TestInstance([[self.tip, reject]]) | ||||
# move the tip back to a previous block | # move the tip back to a previous block | ||||
def tip(number): | def tip(number): | ||||
self.tip = self.blocks[number] | self.tip = self.blocks[number] | ||||
# adds transactions to the block and updates state | # adds transactions to the block and updates state | ||||
def update_block(block_number, new_transactions): | def update_block(block_number, new_transactions, reorder=True): | ||||
block = self.blocks[block_number] | block = self.blocks[block_number] | ||||
self.add_transactions_to_block(block, new_transactions) | self.add_transactions_to_block(block, new_transactions) | ||||
old_sha256 = block.sha256 | old_sha256 = block.sha256 | ||||
if reorder: | |||||
make_conform_to_ctor(block) | make_conform_to_ctor(block) | ||||
block.hashMerkleRoot = block.calc_merkle_root() | block.hashMerkleRoot = block.calc_merkle_root() | ||||
block.solve() | block.solve() | ||||
# Update the internal state just like in next_block | # Update the internal state just like in next_block | ||||
self.tip = block | self.tip = block | ||||
if block.sha256 != old_sha256: | if block.sha256 != old_sha256: | ||||
self.block_heights[ | self.block_heights[block.sha256] = self.block_heights[old_sha256] | ||||
block.sha256] = self.block_heights[old_sha256] | |||||
del self.block_heights[old_sha256] | del self.block_heights[old_sha256] | ||||
self.blocks[block_number] = block | self.blocks[block_number] = block | ||||
return block | return block | ||||
# shorthand for functions | # shorthand for functions | ||||
block = self.next_block | block = self.next_block | ||||
create_tx = self.create_tx | create_tx = self.create_tx | ||||
create_and_sign_tx = self.create_and_sign_transaction | create_and_sign_tx = self.create_and_sign_transaction | ||||
▲ Show 20 Lines • Show All 516 Lines • ▼ Show 20 Lines | def get_tests(self): | ||||
# A block with two coinbase txns | # A block with two coinbase txns | ||||
tip(44) | tip(44) | ||||
b51 = block(51) | b51 = block(51) | ||||
cb2 = create_coinbase(51, self.coinbase_pubkey) | cb2 = create_coinbase(51, self.coinbase_pubkey) | ||||
b51 = update_block(51, [cb2]) | b51 = update_block(51, [cb2]) | ||||
yield rejected(RejectResult(16, b'bad-tx-coinbase')) | yield rejected(RejectResult(16, b'bad-tx-coinbase')) | ||||
# A block w/ duplicate txns | # A block w/ duplicate txns | ||||
# Note: txns have to be in the right position in the merkle tree to | |||||
# trigger this error | |||||
tip(44) | tip(44) | ||||
b52 = block(52, spend=out[15]) | b52 = block(52, spend=out[15]) | ||||
tx = create_tx(b52.vtx[1], 0, 1) | b52 = update_block(52, [b52.vtx[1]]) | ||||
b52 = update_block(52, [tx, tx]) | yield rejected(RejectResult(16, b'tx-duplicate')) | ||||
yield rejected(RejectResult(16, b'bad-txns-duplicate')) | |||||
# Test block timestamps | # Test block timestamps | ||||
# -> b31 (8) -> b33 (9) -> b35 (10) -> b39 (11) -> b42 (12) -> b43 (13) -> b53 (14) -> b55 (15) | # -> b31 (8) -> b33 (9) -> b35 (10) -> b39 (11) -> b42 (12) -> b43 (13) -> b53 (14) -> b55 (15) | ||||
# \-> b54 (15) | # \-> b54 (15) | ||||
# | # | ||||
tip(43) | tip(43) | ||||
block(53, spend=out[14]) | block(53, spend=out[14]) | ||||
yield rejected() # rejected since b44 is at same height | yield rejected() # rejected since b44 is at same height | ||||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | def get_tests(self): | ||||
tx3 = create_tx(tx2, 0, 1) | tx3 = create_tx(tx2, 0, 1) | ||||
tx4 = create_tx(tx3, 0, 1) | tx4 = create_tx(tx3, 0, 1) | ||||
b57p2 = update_block("57p2", [tx, tx1, tx2, tx3, tx4]) | b57p2 = update_block("57p2", [tx, tx1, tx2, tx3, tx4]) | ||||
# b56p2 - copy b57p2, duplicate two non-consecutive tx's | # b56p2 - copy b57p2, duplicate two non-consecutive tx's | ||||
tip(55) | tip(55) | ||||
b56p2 = copy.deepcopy(b57p2) | b56p2 = copy.deepcopy(b57p2) | ||||
self.blocks["b56p2"] = b56p2 | self.blocks["b56p2"] = b56p2 | ||||
assert_equal(b56p2.hash, b57p2.hash) | |||||
assert_equal(len(b56p2.vtx), 6) | assert_equal(len(b56p2.vtx), 6) | ||||
b56p2 = update_block("b56p2", [tx3, tx4]) | b56p2 = update_block("b56p2", b56p2.vtx[4:6], reorder=False) | ||||
assert_equal(b56p2.hash, b57p2.hash) | |||||
yield rejected(RejectResult(16, b'bad-txns-duplicate')) | yield rejected(RejectResult(16, b'bad-txns-duplicate')) | ||||
tip("57p2") | tip("57p2") | ||||
yield accepted() | yield accepted() | ||||
tip(57) | tip(57) | ||||
yield rejected() # rejected because 57p2 seen first | yield rejected() # rejected because 57p2 seen first | ||||
save_spendable_output() | save_spendable_output() | ||||
▲ Show 20 Lines • Show All 496 Lines • Show Last 20 Lines |