Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc-segwit-recovery.py
Show All 38 Lines | |||||
from test_framework.util import ( | from test_framework.util import ( | ||||
assert_raises_rpc_error, | assert_raises_rpc_error, | ||||
sync_blocks, | sync_blocks, | ||||
) | ) | ||||
TEST_TIME = int(time.time()) | TEST_TIME = int(time.time()) | ||||
# Error due to non clean stack | # Error due to non clean stack | ||||
CLEANSTACK_ERROR = b'non-mandatory-script-verify-flag (Script did not clean its stack)' | CLEANSTACK_ERROR = 'non-mandatory-script-verify-flag (Script did not clean its stack)' | ||||
RPC_CLEANSTACK_ERROR = CLEANSTACK_ERROR.decode('utf-8') + " (code 64)" | RPC_CLEANSTACK_ERROR = CLEANSTACK_ERROR + " (code 64)" | ||||
EVAL_FALSE_ERROR = b'non-mandatory-script-verify-flag (Script evaluated without error but finished with a false/empty top stack elem' | EVAL_FALSE_ERROR = 'non-mandatory-script-verify-flag (Script evaluated without error but finished with a false/empty top stack elem' | ||||
RPC_EVAL_FALSE_ERROR = EVAL_FALSE_ERROR.decode('utf-8') + "ent) (code 64)" | RPC_EVAL_FALSE_ERROR = EVAL_FALSE_ERROR + "ent) (code 64)" | ||||
class PreviousSpendableOutput(object): | class PreviousSpendableOutput(object): | ||||
def __init__(self, tx=CTransaction(), n=-1): | def __init__(self, tx=CTransaction(), n=-1): | ||||
self.tx = tx | self.tx = tx | ||||
self.n = n | self.n = n | ||||
▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
# get an output that we previously marked as spendable | # get an output that we previously marked as spendable | ||||
def get_spendable_output(): | def get_spendable_output(): | ||||
return PreviousSpendableOutput(spendable_outputs.pop(0).vtx[0], 0) | return PreviousSpendableOutput(spendable_outputs.pop(0).vtx[0], 0) | ||||
# submit current tip and check it was accepted | # submit current tip and check it was accepted | ||||
def accepted(node): | def accepted(node): | ||||
node.p2p.send_blocks_and_test([self.tip], node) | node.p2p.send_blocks_and_test([self.tip], node) | ||||
# submit current tip and check it was rejected (and we are banned) | |||||
def rejected(node, reject_code, reject_reason): | |||||
node.p2p.send_blocks_and_test( | |||||
[self.tip], node, success=False, reject_code=reject_code, reject_reason=reject_reason, expect_disconnect=True) | |||||
self.reconnect_p2p() | |||||
# 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): | ||||
block = self.blocks[block_number] | block = self.blocks[block_number] | ||||
block.vtx.extend(new_transactions) | block.vtx.extend(new_transactions) | ||||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
CTxIn(COutPoint(txfund.sha256, i), CScript([redeem_scripts[i]]))) | CTxIn(COutPoint(txfund.sha256, i), CScript([redeem_scripts[i]]))) | ||||
txspend.vout = [CTxOut(50 * COIN - 2000, | txspend.vout = [CTxOut(50 * COIN - 2000, | ||||
CScript([OP_HASH160, hash160(CScript([OP_TRUE])), OP_EQUAL]))] | CScript([OP_HASH160, hash160(CScript([OP_TRUE])), OP_EQUAL]))] | ||||
txspend.rehash() | txspend.rehash() | ||||
return txfund, txspend | return txfund, txspend | ||||
# Check we are not banned when sending a txn that is rejected. | # Check we are not banned when sending a txn that is rejected. | ||||
def check_for_no_ban_on_rejected_tx(node, tx, reject_code, reject_reason): | def check_for_no_ban_on_rejected_tx(node, tx, reject_reason): | ||||
node.p2p.send_txs_and_test( | node.p2p.send_txs_and_test( | ||||
[tx], node, success=False, reject_code=reject_code, reject_reason=reject_reason) | [tx], node, success=False, reject_reason=reject_reason) | ||||
# Create a new block | # Create a new block | ||||
block(0) | block(0) | ||||
save_spendable_output() | save_spendable_output() | ||||
accepted(node_nonstd) | accepted(node_nonstd) | ||||
# Now we need that block to mature so we can spend the coinbase. | # Now we need that block to mature so we can spend the coinbase. | ||||
matureblocks = [] | matureblocks = [] | ||||
Show All 20 Lines | def run_test(self): | ||||
accepted(node_nonstd) | accepted(node_nonstd) | ||||
# Check both nodes are synchronized before continuing. | # Check both nodes are synchronized before continuing. | ||||
sync_blocks(self.nodes) | sync_blocks(self.nodes) | ||||
# Check that upgraded nodes checking for standardness are not banning | # Check that upgraded nodes checking for standardness are not banning | ||||
# nodes sending segwit spending txns. | # nodes sending segwit spending txns. | ||||
check_for_no_ban_on_rejected_tx( | check_for_no_ban_on_rejected_tx( | ||||
node_nonstd, txspend, 64, CLEANSTACK_ERROR) | node_nonstd, txspend, CLEANSTACK_ERROR) | ||||
check_for_no_ban_on_rejected_tx( | check_for_no_ban_on_rejected_tx( | ||||
node_nonstd, txspend_case0, 64, EVAL_FALSE_ERROR) | node_nonstd, txspend_case0, EVAL_FALSE_ERROR) | ||||
check_for_no_ban_on_rejected_tx( | check_for_no_ban_on_rejected_tx( | ||||
node_std, txspend, 64, CLEANSTACK_ERROR) | node_std, txspend, CLEANSTACK_ERROR) | ||||
check_for_no_ban_on_rejected_tx( | check_for_no_ban_on_rejected_tx( | ||||
node_std, txspend_case0, 64, EVAL_FALSE_ERROR) | node_std, txspend_case0, EVAL_FALSE_ERROR) | ||||
# Segwit recovery txns are never accepted into the mempool, | # Segwit recovery txns are never accepted into the mempool, | ||||
# as they are included in standard flags. | # as they are included in standard flags. | ||||
assert_raises_rpc_error(-26, RPC_CLEANSTACK_ERROR, | assert_raises_rpc_error(-26, RPC_CLEANSTACK_ERROR, | ||||
node_nonstd.sendrawtransaction, ToHex(txspend)) | node_nonstd.sendrawtransaction, ToHex(txspend)) | ||||
assert_raises_rpc_error(-26, RPC_EVAL_FALSE_ERROR, | assert_raises_rpc_error(-26, RPC_EVAL_FALSE_ERROR, | ||||
node_nonstd.sendrawtransaction, ToHex(txspend_case0)) | node_nonstd.sendrawtransaction, ToHex(txspend_case0)) | ||||
assert_raises_rpc_error(-26, RPC_CLEANSTACK_ERROR, | assert_raises_rpc_error(-26, RPC_CLEANSTACK_ERROR, | ||||
Show All 13 Lines |