Changeset View
Changeset View
Standalone View
Standalone View
test/functional/p2p-fullblocktest.py
Show First 20 Lines • Show All 391 Lines • ▼ Show 20 Lines | def get_tests(self): | ||||
b26.vtx[0].vin[0].scriptSig = b'\x00' | b26.vtx[0].vin[0].scriptSig = b'\x00' | ||||
b26.vtx[0].rehash() | b26.vtx[0].rehash() | ||||
# update_block causes the merkle root to get updated, even with no new | # update_block causes the merkle root to get updated, even with no new | ||||
# transactions, and updates the required state. | # transactions, and updates the required state. | ||||
b26 = update_block(26, []) | b26 = update_block(26, []) | ||||
yield rejected(RejectResult(16, b'bad-cb-length')) | yield rejected(RejectResult(16, b'bad-cb-length')) | ||||
# Extend the b26 chain to make sure bitcoind isn't accepting b26 | # Extend the b26 chain to make sure bitcoind isn't accepting b26 | ||||
b27 = block(27, spend=out[7]) | block(27, spend=out[7]) | ||||
yield rejected(False) | yield rejected(False) | ||||
# Now try a too-large-coinbase script | # Now try a too-large-coinbase script | ||||
tip(15) | tip(15) | ||||
b28 = block(28, spend=out[6]) | b28 = block(28, spend=out[6]) | ||||
b28.vtx[0].vin[0].scriptSig = b'\x00' * 101 | b28.vtx[0].vin[0].scriptSig = b'\x00' * 101 | ||||
b28.vtx[0].rehash() | b28.vtx[0].rehash() | ||||
b28 = update_block(28, []) | b28 = update_block(28, []) | ||||
yield rejected(RejectResult(16, b'bad-cb-length')) | yield rejected(RejectResult(16, b'bad-cb-length')) | ||||
# Extend the b28 chain to make sure bitcoind isn't accepting b28 | # Extend the b28 chain to make sure bitcoind isn't accepting b28 | ||||
b29 = block(29, spend=out[7]) | block(29, spend=out[7]) | ||||
yield rejected(False) | yield rejected(False) | ||||
# b30 has a max-sized coinbase scriptSig. | # b30 has a max-sized coinbase scriptSig. | ||||
tip(23) | tip(23) | ||||
b30 = block(30) | b30 = block(30) | ||||
b30.vtx[0].vin[0].scriptSig = b'\x00' * 100 | b30.vtx[0].vin[0].scriptSig = b'\x00' * 100 | ||||
b30.vtx[0].rehash() | b30.vtx[0].rehash() | ||||
b30 = update_block(30, []) | b30 = update_block(30, []) | ||||
▲ Show 20 Lines • Show All 176 Lines • ▼ Show 20 Lines | def get_tests(self): | ||||
pad_tx(tx) | pad_tx(tx) | ||||
tx.rehash() | tx.rehash() | ||||
new_txs.append(tx) | new_txs.append(tx) | ||||
update_block(40, new_txs) | update_block(40, new_txs) | ||||
yield rejected(RejectResult(16, b'bad-blk-sigops')) | yield rejected(RejectResult(16, b'bad-blk-sigops')) | ||||
# same as b40, but one less sigop | # same as b40, but one less sigop | ||||
tip(39) | tip(39) | ||||
b41 = block(41, spend=None) | block(41, spend=None) | ||||
update_block(41, [b40tx for b40tx in b40.vtx[1:] if b40tx != tx]) | update_block(41, [b40tx for b40tx in b40.vtx[1:] if b40tx != tx]) | ||||
b41_sigops_to_fill = b40_sigops_to_fill - 1 | b41_sigops_to_fill = b40_sigops_to_fill - 1 | ||||
tx = CTransaction() | tx = CTransaction() | ||||
tx.vin.append(CTxIn(lastOutpoint, b'')) | tx.vin.append(CTxIn(lastOutpoint, b'')) | ||||
tx.vout.append(CTxOut(1, CScript([OP_CHECKSIG] * b41_sigops_to_fill))) | tx.vout.append(CTxOut(1, CScript([OP_CHECKSIG] * b41_sigops_to_fill))) | ||||
pad_tx(tx) | pad_tx(tx) | ||||
update_block(41, [tx]) | update_block(41, [tx]) | ||||
yield accepted() | yield accepted() | ||||
▲ Show 20 Lines • Show All 331 Lines • ▼ Show 20 Lines | def get_tests(self): | ||||
yield accepted() | yield accepted() | ||||
save_spendable_output() | save_spendable_output() | ||||
# Spend an output created in the block itself | # Spend an output created in the block itself | ||||
# | # | ||||
# -> b42 (12) -> b43 (13) -> b53 (14) -> b55 (15) -> b57 (16) -> b60 (17) -> b64 (18) -> b65 (19) | # -> b42 (12) -> b43 (13) -> b53 (14) -> b55 (15) -> b57 (16) -> b60 (17) -> b64 (18) -> b65 (19) | ||||
# | # | ||||
tip(64) | tip(64) | ||||
b65 = block(65) | block(65) | ||||
tx1 = create_and_sign_tx( | tx1 = create_and_sign_tx( | ||||
out[19].tx, out[19].n, out[19].tx.vout[0].nValue) | out[19].tx, out[19].n, out[19].tx.vout[0].nValue) | ||||
tx2 = create_and_sign_tx(tx1, 0, 0) | tx2 = create_and_sign_tx(tx1, 0, 0) | ||||
update_block(65, [tx1, tx2]) | update_block(65, [tx1, tx2]) | ||||
yield accepted() | yield accepted() | ||||
save_spendable_output() | save_spendable_output() | ||||
# Attempt to double-spend a transaction created in a block | # Attempt to double-spend a transaction created in a block | ||||
# | # | ||||
# -> b43 (13) -> b53 (14) -> b55 (15) -> b57 (16) -> b60 (17) -> b64 (18) -> b65 (19) | # -> b43 (13) -> b53 (14) -> b55 (15) -> b57 (16) -> b60 (17) -> b64 (18) -> b65 (19) | ||||
# \-> b67 (20) | # \-> b67 (20) | ||||
# | # | ||||
# | # | ||||
tip(65) | tip(65) | ||||
b67 = block(67) | block(67) | ||||
tx1 = create_and_sign_tx( | tx1 = create_and_sign_tx( | ||||
out[20].tx, out[20].n, out[20].tx.vout[0].nValue) | out[20].tx, out[20].n, out[20].tx.vout[0].nValue) | ||||
tx2 = create_and_sign_tx(tx1, 0, 1) | tx2 = create_and_sign_tx(tx1, 0, 1) | ||||
tx3 = create_and_sign_tx(tx1, 0, 2) | tx3 = create_and_sign_tx(tx1, 0, 2) | ||||
update_block(67, [tx1, tx2, tx3]) | update_block(67, [tx1, tx2, tx3]) | ||||
yield rejected(RejectResult(16, b'bad-txns-inputs-missingorspent')) | yield rejected(RejectResult(16, b'bad-txns-inputs-missingorspent')) | ||||
# More tests of block subsidy | # More tests of block subsidy | ||||
# | # | ||||
# -> b43 (13) -> b53 (14) -> b55 (15) -> b57 (16) -> b60 (17) -> b64 (18) -> b65 (19) -> b69 (20) | # -> b43 (13) -> b53 (14) -> b55 (15) -> b57 (16) -> b60 (17) -> b64 (18) -> b65 (19) -> b69 (20) | ||||
# \-> b68 (20) | # \-> b68 (20) | ||||
# | # | ||||
# b68 - coinbase with an extra 10 satoshis, | # b68 - coinbase with an extra 10 satoshis, | ||||
# creates a tx that has 9 satoshis from out[20] go to fees | # creates a tx that has 9 satoshis from out[20] go to fees | ||||
# this fails because the coinbase is trying to claim 1 satoshi too much in fees | # this fails because the coinbase is trying to claim 1 satoshi too much in fees | ||||
# | # | ||||
# b69 - coinbase with extra 10 satoshis, and a tx that gives a 10 satoshi fee | # b69 - coinbase with extra 10 satoshis, and a tx that gives a 10 satoshi fee | ||||
# this succeeds | # this succeeds | ||||
# | # | ||||
tip(65) | tip(65) | ||||
b68 = block(68, additional_coinbase_value=10) | block(68, additional_coinbase_value=10) | ||||
tx = create_and_sign_tx( | tx = create_and_sign_tx( | ||||
out[20].tx, out[20].n, out[20].tx.vout[0].nValue - 9) | out[20].tx, out[20].n, out[20].tx.vout[0].nValue - 9) | ||||
update_block(68, [tx]) | update_block(68, [tx]) | ||||
yield rejected(RejectResult(16, b'bad-cb-amount')) | yield rejected(RejectResult(16, b'bad-cb-amount')) | ||||
tip(65) | tip(65) | ||||
b69 = block(69, additional_coinbase_value=10) | b69 = block(69, additional_coinbase_value=10) | ||||
tx = create_and_sign_tx( | tx = create_and_sign_tx( | ||||
▲ Show 20 Lines • Show All 196 Lines • ▼ Show 20 Lines | |||||
assert_equal(len(mempool), 2) | assert_equal(len(mempool), 2) | ||||
assert(tx78.hash in mempool) | assert(tx78.hash in mempool) | ||||
assert(tx79.hash in mempool) | assert(tx79.hash in mempool) | ||||
# Test invalid opcodes in dead execution paths. | # Test invalid opcodes in dead execution paths. | ||||
# | # | ||||
# -> b81 (26) -> b82 (27) -> b83 (28) | # -> b81 (26) -> b82 (27) -> b83 (28) | ||||
# | # | ||||
b83 = block(83) | block(83) | ||||
op_codes = [OP_IF, OP_INVALIDOPCODE, OP_ELSE, OP_TRUE, OP_ENDIF] | op_codes = [OP_IF, OP_INVALIDOPCODE, OP_ELSE, OP_TRUE, OP_ENDIF] | ||||
script = CScript(op_codes) | script = CScript(op_codes) | ||||
tx1 = create_and_sign_tx( | tx1 = create_and_sign_tx( | ||||
out[28].tx, out[28].n, out[28].tx.vout[0].nValue, script) | out[28].tx, out[28].n, out[28].tx.vout[0].nValue, script) | ||||
tx2 = create_and_sign_tx(tx1, 0, 0, CScript([OP_TRUE])) | tx2 = create_and_sign_tx(tx1, 0, 0, CScript([OP_TRUE])) | ||||
tx2.vin[0].scriptSig = CScript([OP_FALSE]) | tx2.vin[0].scriptSig = CScript([OP_FALSE]) | ||||
tx2.rehash() | tx2.rehash() | ||||
update_block(83, [tx1, tx2]) | update_block(83, [tx1, tx2]) | ||||
yield accepted() | yield accepted() | ||||
save_spendable_output() | save_spendable_output() | ||||
# Reorg on/off blocks that have OP_RETURN in them (and try to spend them) | # Reorg on/off blocks that have OP_RETURN in them (and try to spend them) | ||||
# | # | ||||
# -> b81 (26) -> b82 (27) -> b83 (28) -> b84 (29) -> b87 (30) -> b88 (31) | # -> b81 (26) -> b82 (27) -> b83 (28) -> b84 (29) -> b87 (30) -> b88 (31) | ||||
# \-> b85 (29) -> b86 (30) \-> b89a (32) | # \-> b85 (29) -> b86 (30) \-> b89a (32) | ||||
# | # | ||||
# | # | ||||
b84 = block(84) | block(84) | ||||
tx1 = create_tx(out[29].tx, out[29].n, 0, CScript([OP_RETURN])) | tx1 = create_tx(out[29].tx, out[29].n, 0, CScript([OP_RETURN])) | ||||
vout_offset = len(tx1.vout) | vout_offset = len(tx1.vout) | ||||
tx1.vout.append(CTxOut(0, CScript([OP_TRUE]))) | tx1.vout.append(CTxOut(0, CScript([OP_TRUE]))) | ||||
tx1.vout.append(CTxOut(0, CScript([OP_TRUE]))) | tx1.vout.append(CTxOut(0, CScript([OP_TRUE]))) | ||||
tx1.vout.append(CTxOut(0, CScript([OP_TRUE]))) | tx1.vout.append(CTxOut(0, CScript([OP_TRUE]))) | ||||
tx1.vout.append(CTxOut(0, CScript([OP_TRUE]))) | tx1.vout.append(CTxOut(0, CScript([OP_TRUE]))) | ||||
tx1.calc_sha256() | tx1.calc_sha256() | ||||
self.sign_tx(tx1, out[29].tx, out[29].n) | self.sign_tx(tx1, out[29].tx, out[29].n) | ||||
▲ Show 20 Lines • Show All 83 Lines • Show Last 20 Lines |