nmc: Update test.

This commit is contained in:
tecnovert
2025-03-28 22:31:50 +02:00
parent 8967f677c3
commit f263bb53c3
6 changed files with 309 additions and 741 deletions

View File

@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2020-2022 tecnovert
# Copyright (c) 2025 The Basicswap developers
# Distributed under the MIT software license, see the accompanying
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
@@ -14,38 +15,56 @@ class NMCInterface(BTCInterface):
def coin_type():
return Coins.NMC
def getLockTxHeight(
self,
txid,
dest_address,
bid_amount,
rescan_from,
find_index: bool = False,
vout: int = -1,
):
self._log.debug("[rm] scantxoutset start") # scantxoutset is slow
ro = self.rpc(
"scantxoutset", ["start", ["addr({})".format(dest_address)]]
) # TODO: Use combo(address) where possible
self._log.debug("[rm] scantxoutset end")
return_txid = True if txid is None else False
for o in ro["unspents"]:
if txid and o["txid"] != txid.hex():
continue
# Verify amount
if self.make_int(o["amount"]) != int(bid_amount):
self._log.warning(
"Found output to lock tx address of incorrect value: %s, %s",
str(o["amount"]),
o["txid"],
)
continue
def lockNonSegwitPrevouts(self) -> None:
# For tests
# NMC Seems to ignore utxo locks
unspent = self.rpc_wallet("listunspent")
rv = {"depth": 0, "height": o["height"]}
if o["height"] > 0:
rv["depth"] = ro["height"] - o["height"]
if find_index:
rv["index"] = o["vout"]
if return_txid:
rv["txid"] = o["txid"]
return rv
to_lock = []
for u in unspent:
if u.get("spendable", False) is False:
continue
if "desc" in u:
desc = u["desc"]
if self.use_p2shp2wsh():
if not desc.startswith("sh(wpkh"):
to_lock.append(
{
"txid": u["txid"],
"vout": u["vout"],
"amount": u["amount"],
}
)
else:
if not desc.startswith("wpkh"):
to_lock.append(
{
"txid": u["txid"],
"vout": u["vout"],
"amount": u["amount"],
}
)
if len(to_lock) > 0:
self._log.debug(f"Spending {len(to_lock)} non segwit prevouts")
addr_out = self.rpc_wallet(
"getnewaddress", ["convert non segwit", "bech32"]
)
prevouts = []
sum_amount: int = 0
for utxo in to_lock:
prevouts.append(
{
"txid": utxo["txid"],
"vout": utxo["vout"],
}
)
sum_amount += self.make_int(utxo["amount"])
fee = 100000 * len(prevouts)
funded_tx = self.rpc(
"createrawtransaction",
[prevouts, {addr_out: self.format_amount(sum_amount - fee)}],
)
signed_tx = self.rpc_wallet("signrawtransactionwithwallet", [funded_tx])
self.rpc("sendrawtransaction", [signed_tx["hex"]])