Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc-replay-protection.py
Show First 20 Lines • Show All 228 Lines • ▼ Show 20 Lines | def get_tests(self): | ||||
txns = create_fund_and_spend_tx(out[2]) | txns = create_fund_and_spend_tx(out[2]) | ||||
send_transaction_to_mempool(txns[0]) | send_transaction_to_mempool(txns[0]) | ||||
tx_id = send_transaction_to_mempool(txns[1]) | tx_id = send_transaction_to_mempool(txns[1]) | ||||
# Activate the replay protection | # Activate the replay protection | ||||
block(5556) | block(5556) | ||||
yield accepted() | yield accepted() | ||||
# Check we just activated the replay protection | |||||
assert_equal(node.getblockheader(node.getbestblockhash())['mediantime'], | |||||
REPLAY_PROTECTION_START_TIME) | |||||
# Non replay protected transactions are not valid anymore, | # Non replay protected transactions are not valid anymore, | ||||
# so they should be removed from the mempool. | # so they should be removed from the mempool. | ||||
assert(tx_id not in set(node.getrawmempool())) | assert(tx_id not in set(node.getrawmempool())) | ||||
# Good old transactions are now invalid. | # Good old transactions are now invalid. | ||||
send_transaction_to_mempool(txns[0]) | send_transaction_to_mempool(txns[0]) | ||||
assert_raises_rpc_error(-26, RPC_INVALID_SIGNATURE_ERROR, | assert_raises_rpc_error(-26, RPC_INVALID_SIGNATURE_ERROR, | ||||
node.sendrawtransaction, ToHex(txns[1])) | node.sendrawtransaction, ToHex(txns[1])) | ||||
# They also cannot be mined | # They also cannot be mined | ||||
block(4) | block(4) | ||||
update_block(4, txns) | update_block(4, txns) | ||||
yield rejected(RejectResult(16, b'blk-bad-inputs')) | yield rejected(RejectResult(16, b'blk-bad-inputs')) | ||||
# Rewind bad block | # Rewind bad block | ||||
tip(5556) | tip(5556) | ||||
# The replay protected transaction is now valid | # The replay protected transaction is now valid | ||||
send_transaction_to_mempool(replay_txns[0]) | replay_tx0_id = send_transaction_to_mempool(replay_txns[0]) | ||||
replay_tx_id = send_transaction_to_mempool(replay_txns[1]) | replay_tx1_id = send_transaction_to_mempool(replay_txns[1]) | ||||
# Make sure the transaction are ready to be mined. | |||||
tmpl = node.getblocktemplate() | |||||
found_id0 = False | |||||
found_id1 = False | |||||
for txn in tmpl['transactions']: | |||||
txid = txn['txid'] | |||||
if txid == replay_tx0_id: | |||||
found_id0 = True | |||||
elif txid == replay_tx1_id: | |||||
found_id1 = True | |||||
assert(found_id0 and found_id1) | |||||
# And the mempool is still in good shape. | |||||
assert(replay_tx0_id in set(node.getrawmempool())) | |||||
assert(replay_tx1_id in set(node.getrawmempool())) | |||||
# They also can also be mined | # They also can also be mined | ||||
b5 = block(5) | b5 = block(5) | ||||
update_block(5, replay_txns) | update_block(5, replay_txns) | ||||
yield accepted() | yield accepted() | ||||
# Ok, now we check if a reorg work properly accross the activation. | # Ok, now we check if a reorg work properly accross the activation. | ||||
postforkblockid = node.getbestblockhash() | postforkblockid = node.getbestblockhash() | ||||
node.invalidateblock(postforkblockid) | node.invalidateblock(postforkblockid) | ||||
assert(replay_tx_id in set(node.getrawmempool())) | assert(replay_tx0_id in set(node.getrawmempool())) | ||||
assert(replay_tx1_id in set(node.getrawmempool())) | |||||
# Deactivating replay protection. | # Deactivating replay protection. | ||||
forkblockid = node.getbestblockhash() | forkblockid = node.getbestblockhash() | ||||
node.invalidateblock(forkblockid) | node.invalidateblock(forkblockid) | ||||
assert(replay_tx_id not in set(node.getrawmempool())) | assert(replay_tx0_id not in set(node.getrawmempool())) | ||||
assert(replay_tx1_id not in set(node.getrawmempool())) | |||||
# Check that we also do it properly on deeper reorg. | # Check that we also do it properly on deeper reorg. | ||||
node.reconsiderblock(forkblockid) | node.reconsiderblock(forkblockid) | ||||
node.reconsiderblock(postforkblockid) | node.reconsiderblock(postforkblockid) | ||||
node.invalidateblock(forkblockid) | node.invalidateblock(forkblockid) | ||||
assert(replay_tx_id not in set(node.getrawmempool())) | assert(replay_tx0_id not in set(node.getrawmempool())) | ||||
assert(replay_tx1_id not in set(node.getrawmempool())) | |||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
ReplayProtectionTest().main() | ReplayProtectionTest().main() |