2020-12-11 23:17:10 +01:00
|
|
|
#!/usr/bin/env python3
|
2023-12-31 01:00:00 +01:00
|
|
|
# Copyright (c) 2015-2023 The Dash Core developers
|
2020-12-11 23:17:10 +01:00
|
|
|
# Distributed under the MIT software license, see the accompanying
|
|
|
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
2021-06-24 12:47:04 +02:00
|
|
|
from test_framework.messages import COIN, COutPoint, CTransaction, CTxIn, CTxOut
|
2018-05-12 16:33:07 +02:00
|
|
|
from test_framework.script import CScript, OP_CAT, OP_DROP, OP_TRUE
|
2020-12-11 23:17:10 +01:00
|
|
|
from test_framework.test_framework import BitcoinTestFramework
|
2023-05-18 19:15:08 +02:00
|
|
|
from test_framework.util import assert_raises_rpc_error, softfork_active, satoshi_round
|
2020-12-11 23:17:10 +01:00
|
|
|
|
|
|
|
'''
|
|
|
|
feature_dip0020_activation.py
|
|
|
|
|
|
|
|
This test checks activation of DIP0020 opcodes
|
|
|
|
'''
|
|
|
|
|
|
|
|
DISABLED_OPCODE_ERROR = "non-mandatory-script-verify-flag (Attempted to use a disabled opcode)"
|
|
|
|
|
|
|
|
|
|
|
|
class DIP0020ActivationTest(BitcoinTestFramework):
|
|
|
|
def set_test_params(self):
|
|
|
|
self.num_nodes = 1
|
2019-07-16 22:07:14 +02:00
|
|
|
self.extra_args = [["-acceptnonstdtxn=1"]]
|
2020-12-11 23:17:10 +01:00
|
|
|
|
2018-09-13 12:33:15 +02:00
|
|
|
def skip_test_if_missing_module(self):
|
|
|
|
self.skip_if_no_wallet()
|
|
|
|
|
2020-12-11 23:17:10 +01:00
|
|
|
def run_test(self):
|
|
|
|
self.node = self.nodes[0]
|
|
|
|
self.relayfee = satoshi_round(self.nodes[0].getnetworkinfo()["relayfee"])
|
|
|
|
|
|
|
|
# We should have some coins already
|
|
|
|
utxos = self.node.listunspent()
|
2021-08-27 21:03:02 +02:00
|
|
|
assert len(utxos) > 0
|
2020-12-11 23:17:10 +01:00
|
|
|
|
2019-07-16 22:07:14 +02:00
|
|
|
# Lock some coins using disabled opcodes
|
2020-12-11 23:17:10 +01:00
|
|
|
utxo = utxos[len(utxos) - 1]
|
|
|
|
value = int(satoshi_round(utxo["amount"] - self.relayfee) * COIN)
|
|
|
|
tx = CTransaction()
|
|
|
|
tx.vin.append(CTxIn(COutPoint(int(utxo["txid"], 16), utxo["vout"])))
|
|
|
|
tx.vout.append(CTxOut(value, CScript([b'1', b'2', OP_CAT])))
|
2021-06-24 12:47:04 +02:00
|
|
|
tx_signed_hex = self.node.signrawtransactionwithwallet(tx.serialize().hex())["hex"]
|
2020-12-11 23:17:10 +01:00
|
|
|
txid = self.node.sendrawtransaction(tx_signed_hex)
|
|
|
|
|
|
|
|
# This tx should be completely valid, should be included in mempool and mined in the next block
|
2021-08-27 21:03:02 +02:00
|
|
|
assert txid in set(self.node.getrawmempool())
|
2020-12-11 23:17:10 +01:00
|
|
|
self.node.generate(1)
|
2021-08-27 21:03:02 +02:00
|
|
|
assert txid not in set(self.node.getrawmempool())
|
2020-12-11 23:17:10 +01:00
|
|
|
|
|
|
|
# Create spending tx
|
|
|
|
value = int(value - self.relayfee * COIN)
|
|
|
|
tx0 = CTransaction()
|
|
|
|
tx0.vin.append(CTxIn(COutPoint(int(txid, 16), 0)))
|
2018-05-12 16:33:07 +02:00
|
|
|
tx0.vout.append(CTxOut(value, CScript([OP_TRUE, OP_DROP] * 15 + [OP_TRUE])))
|
2020-12-11 23:17:10 +01:00
|
|
|
tx0.rehash()
|
2021-06-24 12:47:04 +02:00
|
|
|
tx0_hex = tx0.serialize().hex()
|
2020-12-11 23:17:10 +01:00
|
|
|
|
|
|
|
# This tx isn't valid yet
|
2023-05-18 19:15:08 +02:00
|
|
|
assert not softfork_active(self.nodes[0], 'dip0020')
|
2020-12-11 23:17:10 +01:00
|
|
|
assert_raises_rpc_error(-26, DISABLED_OPCODE_ERROR, self.node.sendrawtransaction, tx0_hex)
|
|
|
|
|
|
|
|
# Generate enough blocks to activate DIP0020 opcodes
|
|
|
|
self.node.generate(98)
|
2019-08-15 22:02:02 +02:00
|
|
|
assert softfork_active(self.nodes[0], 'dip0020')
|
2020-12-11 23:17:10 +01:00
|
|
|
|
|
|
|
# Still need 1 more block for mempool to accept new opcodes
|
|
|
|
assert_raises_rpc_error(-26, DISABLED_OPCODE_ERROR, self.node.sendrawtransaction, tx0_hex)
|
|
|
|
self.node.generate(1)
|
|
|
|
|
|
|
|
# Should be spendable now
|
|
|
|
tx0id = self.node.sendrawtransaction(tx0_hex)
|
2021-08-27 21:03:02 +02:00
|
|
|
assert tx0id in set(self.node.getrawmempool())
|
2020-12-11 23:17:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
DIP0020ActivationTest().main()
|