nmc: Add to test_xmr_persistent.

This commit is contained in:
tecnovert
2025-03-30 22:36:03 +02:00
parent e9ed334a54
commit 6b724ece84
16 changed files with 240 additions and 128 deletions

View File

@@ -34,6 +34,11 @@ from tests.basicswap.common import (
PIVX_BASE_PORT,
BTC_USE_DESCRIPTORS,
)
from tests.basicswap.extended.test_nmc import (
NMC_BASE_PORT,
NMC_BASE_RPC_PORT,
NMC_BASE_TOR_PORT,
)
from tests.basicswap.extended.test_dcr import (
DCR_BASE_PORT,
DCR_BASE_RPC_PORT,
@@ -50,13 +55,6 @@ from tests.basicswap.extended.test_doge import (
import basicswap.config as cfg
import basicswap.bin.run as runSystem
XMR_BASE_P2P_PORT = 17792
XMR_BASE_RPC_PORT = 29798
XMR_BASE_WALLET_RPC_PORT = 29998
FIRO_BASE_PORT = 34832
FIRO_BASE_RPC_PORT = 35832
FIRO_RPC_PORT_BASE = int(os.getenv("FIRO_RPC_PORT_BASE", FIRO_BASE_RPC_PORT))
TEST_PATH = os.path.expanduser(os.getenv("TEST_PATH", "~/test_basicswap1"))
@@ -68,7 +66,21 @@ BITCOIN_RPC_PORT_BASE = int(os.getenv("BITCOIN_RPC_PORT_BASE", BTC_BASE_RPC_PORT
BITCOIN_TOR_PORT_BASE = int(os.getenv("BITCOIN_TOR_PORT_BASE", BTC_BASE_TOR_PORT))
LITECOIN_RPC_PORT_BASE = int(os.getenv("LITECOIN_RPC_PORT_BASE", LTC_BASE_RPC_PORT))
DECRED_RPC_PORT_BASE = int(os.getenv("DECRED_RPC_PORT_BASE", DCR_BASE_RPC_PORT))
NAMECOIN_PORT_BASE = int(os.getenv("NAMECOIN_PORT_BASE", NMC_BASE_PORT))
NAMECOIN_RPC_PORT_BASE = int(os.getenv("NAMECOIN_RPC_PORT_BASE", NMC_BASE_RPC_PORT))
NAMECOIN_TOR_PORT_BASE = int(os.getenv("NAMECOIN_TOR_PORT_BASE", NMC_BASE_TOR_PORT))
XMR_BASE_P2P_PORT = 17792
XMR_BASE_RPC_PORT = 29798
XMR_BASE_WALLET_RPC_PORT = 29998
FIRO_BASE_PORT = 34832
FIRO_BASE_RPC_PORT = 35832
FIRO_RPC_PORT_BASE = int(os.getenv("FIRO_RPC_PORT_BASE", FIRO_BASE_RPC_PORT))
BITCOINCASH_RPC_PORT_BASE = int(
os.getenv("BITCOINCASH_RPC_PORT_BASE", BCH_BASE_RPC_PORT)
)
@@ -130,19 +142,21 @@ def run_prepare(
os.environ["BTC_RPC_PORT"] = str(BITCOIN_RPC_PORT_BASE)
os.environ["BTC_PORT"] = str(BITCOIN_PORT_BASE)
os.environ["BTC_USE_DESCRIPTORS"] = str(BTC_USE_DESCRIPTORS)
os.environ["BTC_ONION_PORT"] = str(BITCOIN_TOR_PORT_BASE)
os.environ["LTC_RPC_PORT"] = str(LITECOIN_RPC_PORT_BASE)
os.environ["DCR_RPC_PORT"] = str(DECRED_RPC_PORT_BASE)
os.environ["DCR_RPC_PWD"] = "dcr_pwd"
os.environ["NMC_RPC_PORT"] = str(NAMECOIN_RPC_PORT_BASE)
os.environ["NMC_PORT"] = str(NMC_BASE_PORT)
os.environ["NMC_ONION_PORT"] = str(NAMECOIN_TOR_PORT_BASE)
os.environ["XMR_RPC_USER"] = "xmr_user"
os.environ["XMR_RPC_PWD"] = "xmr_pwd"
os.environ["FIRO_RPC_PORT"] = str(FIRO_RPC_PORT_BASE)
os.environ["BCH_PORT"] = str(BCH_BASE_PORT)
os.environ["BCH_RPC_PORT"] = str(BITCOINCASH_RPC_PORT_BASE)
os.environ["DOGE_PORT"] = str(DOGE_BASE_PORT)
os.environ["DOGE_RPC_PORT"] = str(DOGECOIN_RPC_PORT_BASE)
os.environ["XMR_RPC_USER"] = "xmr_user"
os.environ["XMR_RPC_PWD"] = "xmr_pwd"
os.environ["DCR_RPC_PWD"] = "dcr_pwd"
import basicswap.bin.prepare as prepareSystem
# Hack: Reload module to set env vars as the basicswap_prepare module is initialised if imported from elsewhere earlier
@@ -320,6 +334,62 @@ def run_prepare(
with open(config_filename, "a") as fp:
fp.write("enablevoting=1\n")
if "namecoin" in coins_array:
# Pruned nodes don't provide blocks
config_filename = os.path.join(datadir_path, "namecoin", "namecoin.conf")
with open(config_filename, "r") as fp:
lines = fp.readlines()
with open(config_filename, "w") as fp:
for line in lines:
if not line.startswith("prune"):
fp.write(line)
# fp.write("bind=127.0.0.1\n") # Causes BTC v28 to try and bind to bind=127.0.0.1:8444, even with a bind...=onion present
# listenonion=0 does not stop the node from trying to bind to the tor port
# https://github.com/bitcoin/bitcoin/issues/22726
fp.write(
"bind=127.0.0.1:{}=onion\n".format(
NAMECOIN_TOR_PORT_BASE + node_id + port_ofs
)
)
fp.write("dnsseed=0\n")
fp.write("discover=0\n")
fp.write("listenonion=0\n")
fp.write("upnp=0\n")
if use_rpcauth:
salt = generate_salt(16)
rpc_user = "test_nmc_" + str(node_id)
rpc_pass = "test_nmc_pwd_" + str(node_id)
fp.write(
"rpcauth={}:{}${}\n".format(
rpc_user, salt, password_to_hmac(salt, rpc_pass)
)
)
settings["chainclients"]["namecoin"]["rpcuser"] = rpc_user
settings["chainclients"]["namecoin"]["rpcpassword"] = rpc_pass
for ip in range(num_nodes):
if ip != node_id:
fp.write(
"connect=127.0.0.1:{}\n".format(
NAMECOIN_PORT_BASE + ip + port_ofs
)
)
for opt in EXTRA_CONFIG_JSON.get("ncm{}".format(node_id), []):
fp.write(opt + "\n")
if "monero" in coins_array:
with open(os.path.join(datadir_path, "monero", "monerod.conf"), "a") as fp:
fp.write("p2p-bind-ip=127.0.0.1\n")
fp.write(
"p2p-bind-port={}\n".format(XMR_BASE_P2P_PORT + node_id + port_ofs)
)
for ip in range(num_nodes):
if ip != node_id:
fp.write(
"add-exclusive-node=127.0.0.1:{}\n".format(
XMR_BASE_P2P_PORT + ip + port_ofs
)
)
if "pivx" in coins_array:
# Pruned nodes don't provide blocks
config_filename = os.path.join(datadir_path, "pivx", "pivx.conf")
@@ -388,20 +458,6 @@ def run_prepare(
for opt in EXTRA_CONFIG_JSON.get("firo{}".format(node_id), []):
fp.write(opt + "\n")
if "monero" in coins_array:
with open(os.path.join(datadir_path, "monero", "monerod.conf"), "a") as fp:
fp.write("p2p-bind-ip=127.0.0.1\n")
fp.write(
"p2p-bind-port={}\n".format(XMR_BASE_P2P_PORT + node_id + port_ofs)
)
for ip in range(num_nodes):
if ip != node_id:
fp.write(
"add-exclusive-node=127.0.0.1:{}\n".format(
XMR_BASE_P2P_PORT + ip + port_ofs
)
)
if "bitcoincash" in coins_array:
config_filename = os.path.join(datadir_path, "bitcoincash", "bitcoin.conf")
with open(config_filename, "r") as fp:

View File

@@ -58,6 +58,7 @@ NMC_USE_DESCRIPTORS = toBool(os.getenv("NMC_USE_DESCRIPTORS", True))
NMC_BASE_PORT = 8136
NMC_BASE_RPC_PORT = 8146
NMC_BASE_TOR_PORT = 8156
def prepareNMCDataDir(datadir, nodeId, conf_file="namecoin.conf"):

View File

@@ -60,6 +60,7 @@ from tests.basicswap.common_xmr import (
prepare_nodes,
XMR_BASE_RPC_PORT,
DOGE_BASE_RPC_PORT,
NMC_BASE_RPC_PORT,
)
from basicswap.interface.dcr.rpc import callrpc as callrpc_dcr
import basicswap.bin.run as runSystem
@@ -73,12 +74,13 @@ UI_PORT = 12700 + PORT_OFS
PARTICL_RPC_PORT_BASE = int(os.getenv("PARTICL_RPC_PORT_BASE", BASE_RPC_PORT))
BITCOIN_RPC_PORT_BASE = int(os.getenv("BITCOIN_RPC_PORT_BASE", BTC_BASE_RPC_PORT))
LITECOIN_RPC_PORT_BASE = int(os.getenv("LITECOIN_RPC_PORT_BASE", LTC_BASE_RPC_PORT))
DOGECOIN_RPC_PORT_BASE = int(os.getenv("DOGECOIN_RPC_PORT_BASE", DOGE_BASE_RPC_PORT))
DECRED_WALLET_RPC_PORT_BASE = int(os.getenv("DECRED_WALLET_RPC_PORT_BASE", 9210))
NAMECOIN_RPC_PORT_BASE = int(os.getenv("NAMECOIN_RPC_PORT_BASE", NMC_BASE_RPC_PORT))
XMR_BASE_RPC_PORT = int(os.getenv("XMR_BASE_RPC_PORT", XMR_BASE_RPC_PORT))
BITCOINCASH_RPC_PORT_BASE = int(
os.getenv("BITCOINCASH_RPC_PORT_BASE", BCH_BASE_RPC_PORT)
)
DECRED_WALLET_RPC_PORT_BASE = int(os.getenv("DECRED_WALLET_RPC_PORT_BASE", 9210))
XMR_BASE_RPC_PORT = int(os.getenv("XMR_BASE_RPC_PORT", XMR_BASE_RPC_PORT))
DOGECOIN_RPC_PORT_BASE = int(os.getenv("DOGECOIN_RPC_PORT_BASE", DOGE_BASE_RPC_PORT))
TEST_COINS_LIST = os.getenv("TEST_COINS_LIST", "bitcoin,monero")
NUM_NODES = int(os.getenv("NUM_NODES", 3))
@@ -130,6 +132,17 @@ def calldcrrpc(
return callrpc_dcr(base_rpc_port + node_id, auth, method, params)
def callnmcrpc(
node_id,
method,
params=[],
wallet="wallet.dat",
base_rpc_port=NAMECOIN_RPC_PORT_BASE + PORT_OFS,
):
auth = "test_nmc_{0}:test_nmc_pwd_{0}".format(node_id)
return callrpc(base_rpc_port + node_id, auth, method, params, wallet)
def callbchrpc(
node_id,
method,
@@ -163,6 +176,8 @@ def updateThread(cls):
callbchrpc(0, "generatetoaddress", [1, cls.bch_addr])
if cls.doge_addr is not None:
calldogerpc(0, "generatetoaddress", [1, cls.doge_addr])
if cls.nmc_addr is not None:
callnmcrpc(0, "generatetoaddress", [1, cls.nmc_addr])
except Exception as e:
print("updateThread error", str(e))
cls.delay_event.wait(random.randrange(cls.update_min, cls.update_max))
@@ -388,6 +403,18 @@ def start_processes(self):
0, "generatetoaddress", [num_blocks - have_blocks, self.doge_addr]
)
if "namecoin" in TEST_COINS_LIST:
self.nmc_addr = callnmcrpc(0, "getnewaddress", ["mining_addr", "bech32"])
num_blocks: int = 500
have_blocks: int = callnmcrpc(0, "getblockcount")
if have_blocks < num_blocks:
logging.info(
f"Mining {num_blocks - have_blocks} Namecoin blocks to {self.nmc_addr}"
)
callnmcrpc(
0, "generatetoaddress", [num_blocks - have_blocks, self.nmc_addr]
)
if RESET_TEST:
# Lower output split threshold for more stakeable outputs
for i in range(NUM_NODES):
@@ -444,6 +471,7 @@ class BaseTestWithPrepare(unittest.TestCase):
dcr_addr = "SsYbXyjkKAEXXcGdFgr4u4bo4L8RkCxwQpH"
dcr_acc = None
doge_addr = None
nmc_addr = None
initialised = False