2021-01-11 18:13:50 +01:00
|
|
|
#!/usr/bin/env python3
|
2024-10-04 22:06:43 +02:00
|
|
|
# Copyright (c) 2020-2024 The Dash Core developers
|
2021-01-11 18:13:50 +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 CTransaction, from_hex, hash256, ser_compact_size, ser_string
|
2021-01-11 18:13:50 +01:00
|
|
|
from test_framework.test_framework import DashTestFramework
|
2020-08-27 08:21:53 +02:00
|
|
|
from test_framework.util import assert_raises_rpc_error, satoshi_round
|
2021-01-11 18:13:50 +01:00
|
|
|
|
|
|
|
'''
|
|
|
|
rpc_verifyislock.py
|
|
|
|
|
|
|
|
Test verifyislock rpc
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
class RPCVerifyISLockTest(DashTestFramework):
|
|
|
|
def set_test_params(self):
|
|
|
|
# -whitelist is needed to avoid the trickling logic on node0
|
2024-08-27 12:30:39 +02:00
|
|
|
self.set_dash_test_params(6, 5, [["-whitelist=127.0.0.1"], [], [], [], [], []])
|
2021-01-11 18:13:50 +01:00
|
|
|
|
2021-03-25 17:30:00 +01:00
|
|
|
def get_request_id(self, tx_hex):
|
2021-06-24 12:47:04 +02:00
|
|
|
tx = from_hex(CTransaction(), tx_hex)
|
2021-03-25 17:30:00 +01:00
|
|
|
|
|
|
|
request_id_buf = ser_string(b"islock") + ser_compact_size(len(tx.vin))
|
|
|
|
for txin in tx.vin:
|
|
|
|
request_id_buf += txin.prevout.serialize()
|
|
|
|
return hash256(request_id_buf)[::-1].hex()
|
|
|
|
|
2021-01-11 18:13:50 +01:00
|
|
|
def run_test(self):
|
|
|
|
|
|
|
|
node = self.nodes[0]
|
2022-06-18 18:52:45 +02:00
|
|
|
node.sporkupdate("SPORK_17_QUORUM_DKG_ENABLED", 0)
|
2021-01-11 18:13:50 +01:00
|
|
|
self.wait_for_sporks_same()
|
|
|
|
|
2023-11-20 17:17:04 +01:00
|
|
|
self.activate_v19(expected_activation_height=900)
|
|
|
|
self.log.info("Activated v19 at height:" + str(self.nodes[0].getblockcount()))
|
2024-11-23 09:10:07 +01:00
|
|
|
self.mine_cycle_quorum()
|
2023-11-20 17:17:04 +01:00
|
|
|
self.bump_mocktime(1)
|
2024-10-01 18:08:19 +02:00
|
|
|
self.generate(self.nodes[0], 8, sync_fun=self.sync_blocks())
|
2021-01-11 18:13:50 +01:00
|
|
|
|
|
|
|
txid = node.sendtoaddress(node.getnewaddress(), 1)
|
|
|
|
self.wait_for_instantlock(txid, node)
|
|
|
|
|
2021-03-25 17:30:00 +01:00
|
|
|
request_id = self.get_request_id(self.nodes[0].getrawtransaction(txid))
|
2020-08-27 08:21:53 +02:00
|
|
|
self.wait_until(lambda: node.quorum("hasrecsig", 103, request_id, txid))
|
2021-01-11 18:13:50 +01:00
|
|
|
|
2023-11-20 17:17:04 +01:00
|
|
|
rec_sig = node.quorum("getrecsig", 103, request_id, txid)['sig']
|
2021-08-27 21:03:02 +02:00
|
|
|
assert node.verifyislock(request_id, txid, rec_sig)
|
2021-01-11 18:13:50 +01:00
|
|
|
# Not mined, should use maxHeight
|
2021-03-25 17:30:00 +01:00
|
|
|
assert not node.verifyislock(request_id, txid, rec_sig, 1)
|
2024-10-01 21:22:56 +02:00
|
|
|
self.generate(node, 1, sync_fun=self.no_op)
|
2021-08-27 21:03:02 +02:00
|
|
|
assert txid not in node.getrawmempool()
|
2021-01-11 18:13:50 +01:00
|
|
|
# Mined but at higher height, should use maxHeight
|
2021-03-25 17:30:00 +01:00
|
|
|
assert not node.verifyislock(request_id, txid, rec_sig, 1)
|
2021-01-11 18:13:50 +01:00
|
|
|
# Mined, should ignore higher maxHeight
|
2021-08-27 21:03:02 +02:00
|
|
|
assert node.verifyislock(request_id, txid, rec_sig, node.getblockcount() + 100)
|
2021-01-11 18:13:50 +01:00
|
|
|
|
2023-11-20 17:17:04 +01:00
|
|
|
# Mine one more cycle of rotated quorums
|
2024-11-23 09:10:07 +01:00
|
|
|
self.mine_cycle_quorum(is_first=False)
|
2023-11-20 17:17:04 +01:00
|
|
|
# Create an ISLOCK using an active quorum which will be replaced when a new cycle happens
|
2021-03-25 17:30:00 +01:00
|
|
|
request_id = None
|
|
|
|
utxos = node.listunspent()
|
|
|
|
fee = 0.001
|
|
|
|
amount = 1
|
2023-11-20 17:17:04 +01:00
|
|
|
# Try all available utxo's until we have one valid in_amount
|
2021-03-25 17:30:00 +01:00
|
|
|
for utxo in utxos:
|
|
|
|
in_amount = float(utxo['amount'])
|
|
|
|
if in_amount < amount + fee:
|
|
|
|
continue
|
|
|
|
outputs = dict()
|
|
|
|
outputs[node.getnewaddress()] = satoshi_round(amount)
|
|
|
|
change = in_amount - amount - fee
|
|
|
|
if change > 0:
|
|
|
|
outputs[node.getnewaddress()] = satoshi_round(change)
|
|
|
|
rawtx = node.createrawtransaction([utxo], outputs)
|
|
|
|
rawtx = node.signrawtransactionwithwallet(rawtx)["hex"]
|
|
|
|
request_id = self.get_request_id(rawtx)
|
2023-11-20 17:17:04 +01:00
|
|
|
break
|
|
|
|
# Create the ISDLOCK, then mine a cycle quorum to move renew active set
|
|
|
|
isdlock = self.create_isdlock(rawtx)
|
|
|
|
# Mine one block to trigger the "signHeight + dkgInterval" verification for the ISDLOCK
|
2024-11-23 09:10:07 +01:00
|
|
|
self.mine_cycle_quorum(is_first=False)
|
2021-04-16 17:03:41 +02:00
|
|
|
# Verify the ISLOCK for a transaction that is not yet known by the node
|
|
|
|
rawtx_txid = node.decoderawtransaction(rawtx)["txid"]
|
|
|
|
assert_raises_rpc_error(-5, "No such mempool or blockchain transaction", node.getrawtransaction, rawtx_txid)
|
2023-11-20 17:17:04 +01:00
|
|
|
assert node.verifyislock(request_id, rawtx_txid, isdlock.sig.hex(), node.getblockcount())
|
|
|
|
# Send the tx and verify the ISDLOCK for a now known transaction
|
2021-04-16 17:03:41 +02:00
|
|
|
assert rawtx_txid == node.sendrawtransaction(rawtx)
|
2023-11-20 17:17:04 +01:00
|
|
|
assert node.verifyislock(request_id, rawtx_txid, isdlock.sig.hex(), node.getblockcount())
|
2021-03-25 17:30:00 +01:00
|
|
|
|
2021-01-11 18:13:50 +01:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
RPCVerifyISLockTest().main()
|