Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc-minimaldata-activation.py
Show First 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | |||||
# the upgrade activation time, which we artificially set far into the future | # the upgrade activation time, which we artificially set far into the future | ||||
GRAVITON_START_TIME = 2000000000 | GRAVITON_START_TIME = 2000000000 | ||||
# If we don't do this, autoreplay protection will activate before graviton and | # If we don't do this, autoreplay protection will activate before graviton and | ||||
# all our sigs will mysteriously fail. | # all our sigs will mysteriously fail. | ||||
REPLAY_PROTECTION_START_TIME = GRAVITON_START_TIME * 2 | REPLAY_PROTECTION_START_TIME = GRAVITON_START_TIME * 2 | ||||
# Both before and after the upgrade, minimal push violations are rejected as nonstandard. | # Both before and after the upgrade, minimal push violations are rejected as | ||||
# After the upgrade they are actually invalid, but we get the same error since MINIMALDATA is internally marked as a "standardness" flag. | # nonstandard. After the upgrade they are actually invalid, but we get the | ||||
MINIMALPUSH_ERROR = dict(reject_code=64, | # same error since MINIMALDATA is internally marked as a "standardness" flag. | ||||
reject_reason=b'non-mandatory-script-verify-flag (Data push larger than necessary)') | MINIMALPUSH_ERROR = 'non-mandatory-script-verify-flag (Data push larger than necessary)' | ||||
# Blocks with invalid scripts give this error: | # Blocks with invalid scripts give this error: | ||||
BADINPUTS_ERROR = dict(reject_code=16, | BADINPUTS_ERROR = 'blk-bad-inputs' | ||||
reject_reason=b'blk-bad-inputs') | |||||
def rpc_error(*, reject_code, reject_reason): | |||||
# RPC indicates rejected items in a slightly different way than p2p. | |||||
return '{:s} (code {:d})'.format(reject_reason.decode(), reject_code) | |||||
class SchnorrTest(BitcoinTestFramework): | class SchnorrTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.num_nodes = 1 | self.num_nodes = 1 | ||||
self.block_heights = {} | self.block_heights = {} | ||||
self.extra_args = [["-gravitonactivationtime={}".format( | self.extra_args = [["-gravitonactivationtime={}".format( | ||||
Show All 40 Lines | def build_block(self, parent, transactions=(), nTime=None): | ||||
parent.sha256, create_coinbase(block_height), block_time) | parent.sha256, create_coinbase(block_height), block_time) | ||||
block.vtx.extend(transactions) | block.vtx.extend(transactions) | ||||
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() | ||||
self.block_heights[block.sha256] = block_height | self.block_heights[block.sha256] = block_height | ||||
return block | return block | ||||
def check_for_ban_on_rejected_tx(self, tx, reject_code=None, reject_reason=None): | def check_for_ban_on_rejected_tx(self, tx, reject_reason=None): | ||||
"""Check we are disconnected when sending a txn that the node rejects. | """Check we are disconnected when sending a txn that the node rejects. | ||||
(Can't actually get banned, since bitcoind won't ban local peers.)""" | (Can't actually get banned, since bitcoind won't ban local peers.)""" | ||||
self.nodes[0].p2p.send_txs_and_test( | self.nodes[0].p2p.send_txs_and_test( | ||||
[tx], self.nodes[0], success=False, expect_disconnect=True, reject_code=reject_code, reject_reason=reject_reason) | [tx], self.nodes[0], success=False, expect_disconnect=True, reject_reason=reject_reason) | ||||
self.reconnect_p2p() | self.reconnect_p2p() | ||||
def check_for_no_ban_on_rejected_tx(self, tx, reject_code, reject_reason): | def check_for_no_ban_on_rejected_tx(self, tx, reject_reason): | ||||
"""Check we are not disconnected when sending a txn that the node rejects.""" | """Check we are not disconnected when sending a txn that the node rejects.""" | ||||
self.nodes[0].p2p.send_txs_and_test( | self.nodes[0].p2p.send_txs_and_test( | ||||
[tx], self.nodes[0], success=False, reject_code=reject_code, reject_reason=reject_reason) | [tx], self.nodes[0], success=False, reject_reason=reject_reason) | ||||
def check_for_ban_on_rejected_block(self, block, reject_code=None, reject_reason=None): | def check_for_ban_on_rejected_block(self, block, reject_reason=None): | ||||
"""Check we are disconnected when sending a block that the node rejects. | """Check we are disconnected when sending a block that the node rejects. | ||||
(Can't actually get banned, since bitcoind won't ban local peers.)""" | (Can't actually get banned, since bitcoind won't ban local peers.)""" | ||||
self.nodes[0].p2p.send_blocks_and_test( | self.nodes[0].p2p.send_blocks_and_test( | ||||
[block], self.nodes[0], success=False, reject_code=reject_code, reject_reason=reject_reason, expect_disconnect=True) | [block], self.nodes[0], success=False, reject_reason=reject_reason, expect_disconnect=True) | ||||
self.reconnect_p2p() | self.reconnect_p2p() | ||||
def run_test(self): | def run_test(self): | ||||
node, = self.nodes | node, = self.nodes | ||||
self.bootstrap_p2p() | self.bootstrap_p2p() | ||||
tip = self.getbestblock(node) | tip = self.getbestblock(node) | ||||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
nonminimaltx_3 = create_fund_and_spend_tx() | nonminimaltx_3 = create_fund_and_spend_tx() | ||||
tip = self.build_block(tip, fundings) | tip = self.build_block(tip, fundings) | ||||
node.p2p.send_blocks_and_test([tip], node) | node.p2p.send_blocks_and_test([tip], node) | ||||
self.log.info("Start preupgrade tests") | self.log.info("Start preupgrade tests") | ||||
self.log.info("Sending rejected transactions via RPC") | self.log.info("Sending rejected transactions via RPC") | ||||
assert_raises_rpc_error(-26, rpc_error(**MINIMALPUSH_ERROR), | assert_raises_rpc_error(-26, MINIMALPUSH_ERROR, | ||||
node.sendrawtransaction, ToHex(nonminimaltx)) | node.sendrawtransaction, ToHex(nonminimaltx)) | ||||
assert_raises_rpc_error(-26, rpc_error(**MINIMALPUSH_ERROR), | assert_raises_rpc_error(-26, MINIMALPUSH_ERROR, | ||||
node.sendrawtransaction, ToHex(nonminimaltx_2)) | node.sendrawtransaction, ToHex(nonminimaltx_2)) | ||||
assert_raises_rpc_error(-26, rpc_error(**MINIMALPUSH_ERROR), | assert_raises_rpc_error(-26, MINIMALPUSH_ERROR, | ||||
node.sendrawtransaction, ToHex(nonminimaltx_3)) | node.sendrawtransaction, ToHex(nonminimaltx_3)) | ||||
self.log.info( | self.log.info( | ||||
"Sending rejected transactions via net (no banning)") | "Sending rejected transactions via net (no banning)") | ||||
self.check_for_no_ban_on_rejected_tx( | self.check_for_no_ban_on_rejected_tx( | ||||
nonminimaltx, **MINIMALPUSH_ERROR) | nonminimaltx, MINIMALPUSH_ERROR) | ||||
self.check_for_no_ban_on_rejected_tx( | self.check_for_no_ban_on_rejected_tx( | ||||
nonminimaltx_2, **MINIMALPUSH_ERROR) | nonminimaltx_2, MINIMALPUSH_ERROR) | ||||
self.check_for_no_ban_on_rejected_tx( | self.check_for_no_ban_on_rejected_tx( | ||||
nonminimaltx_3, **MINIMALPUSH_ERROR) | nonminimaltx_3, MINIMALPUSH_ERROR) | ||||
assert_equal(node.getrawmempool(), []) | assert_equal(node.getrawmempool(), []) | ||||
self.log.info("Successfully mine nonstandard transaction") | self.log.info("Successfully mine nonstandard transaction") | ||||
tip = self.build_block(tip, [nonminimaltx]) | tip = self.build_block(tip, [nonminimaltx]) | ||||
node.p2p.send_blocks_and_test([tip], node) | node.p2p.send_blocks_and_test([tip], node) | ||||
# Activation tests | # Activation tests | ||||
Show All 17 Lines | def run_test(self): | ||||
self.log.info("We have activated!") | self.log.info("We have activated!") | ||||
assert_equal(node.getblockchaininfo()[ | assert_equal(node.getblockchaininfo()[ | ||||
'mediantime'], GRAVITON_START_TIME) | 'mediantime'], GRAVITON_START_TIME) | ||||
self.log.info( | self.log.info( | ||||
"Trying to mine a minimaldata violation, but we are just barely too late") | "Trying to mine a minimaldata violation, but we are just barely too late") | ||||
self.check_for_ban_on_rejected_block( | self.check_for_ban_on_rejected_block( | ||||
self.build_block(tip, [nonminimaltx_3]), **BADINPUTS_ERROR) | self.build_block(tip, [nonminimaltx_3]), BADINPUTS_ERROR) | ||||
self.log.info( | self.log.info( | ||||
"If we try to submit it by mempool or RPC we still aren't banned") | "If we try to submit it by mempool or RPC we still aren't banned") | ||||
assert_raises_rpc_error(-26, rpc_error(**MINIMALPUSH_ERROR), | assert_raises_rpc_error(-26, MINIMALPUSH_ERROR, | ||||
node.sendrawtransaction, ToHex(nonminimaltx_3)) | node.sendrawtransaction, ToHex(nonminimaltx_3)) | ||||
self.check_for_no_ban_on_rejected_tx( | self.check_for_no_ban_on_rejected_tx( | ||||
nonminimaltx_3, **MINIMALPUSH_ERROR) | nonminimaltx_3, MINIMALPUSH_ERROR) | ||||
self.log.info("Mine a normal block") | self.log.info("Mine a normal block") | ||||
tip = self.build_block(tip) | tip = self.build_block(tip) | ||||
node.p2p.send_blocks_and_test([tip], node) | node.p2p.send_blocks_and_test([tip], node) | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
SchnorrTest().main() | SchnorrTest().main() |