Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc-replay-protection.py
- This file was copied to test/functional/abc-mempool-coherence-on-activations.py.
Show First 20 Lines • Show All 204 Lines • ▼ Show 20 Lines | def get_tests(self): | ||||
yield accepted() | yield accepted() | ||||
for i in range(5): | 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 we are just before the activation time | # Check we are just before the activation time | ||||
assert_equal(node.getblockheader(node.getbestblockhash())['mediantime'], | assert_equal( | ||||
node.getblockheader(node.getbestblockhash())['mediantime'], | |||||
REPLAY_PROTECTION_START_TIME - 1) | REPLAY_PROTECTION_START_TIME - 1) | ||||
# We are just before the fork, replay protected txns still are rejected | # We are just before the fork, replay protected txns still are rejected | ||||
assert_raises_rpc_error(-26, RPC_INVALID_SIGNATURE_ERROR, | assert_raises_rpc_error(-26, RPC_INVALID_SIGNATURE_ERROR, | ||||
node.sendrawtransaction, ToHex(replay_txns[1])) | node.sendrawtransaction, ToHex(replay_txns[1])) | ||||
block(3) | block(3) | ||||
update_block(3, replay_txns) | update_block(3, replay_txns) | ||||
yield rejected(RejectResult(16, b'blk-bad-inputs')) | yield rejected(RejectResult(16, b'blk-bad-inputs')) | ||||
# Rewind bad block | # Rewind bad block | ||||
tip(5104) | tip(5104) | ||||
# Send some non replay protected txns in the mempool to check | # Send some non replay protected txns in the mempool to check | ||||
# they get cleaned at activation. | # they get cleaned at activation. | ||||
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 | # Check we just activated the replay protection | ||||
assert_equal(node.getblockheader(node.getbestblockhash())['mediantime'], | assert_equal( | ||||
node.getblockheader(node.getbestblockhash())['mediantime'], | |||||
REPLAY_PROTECTION_START_TIME) | 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]) | ||||
Show All 40 Lines | def get_tests(self): | ||||
postforkblockid = node.getbestblockhash() | postforkblockid = node.getbestblockhash() | ||||
node.invalidateblock(postforkblockid) | node.invalidateblock(postforkblockid) | ||||
assert(replay_tx0_id in set(node.getrawmempool())) | assert(replay_tx0_id in set(node.getrawmempool())) | ||||
assert(replay_tx1_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_tx0_id not in set(node.getrawmempool())) | # The funding tx is not evicted from the mempool, since it's valid in | ||||
# both sides of the fork | |||||
assert(replay_tx0_id in set(node.getrawmempool())) | |||||
assert(replay_tx1_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_tx0_id not in set(node.getrawmempool())) | assert(replay_tx0_id in set(node.getrawmempool())) | ||||
assert(replay_tx1_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() |