mirror of
https://github.com/basicswap/basicswap.git
synced 2025-11-05 10:28:10 +01:00
Add simplex chat test.
This commit is contained in:
@@ -30,7 +30,6 @@ from basicswap.contrib.test_framework.messages import (
|
||||
CTransaction,
|
||||
CTxIn,
|
||||
COutPoint,
|
||||
ToHex,
|
||||
)
|
||||
from basicswap.contrib.test_framework.script import (
|
||||
CScript,
|
||||
@@ -318,7 +317,7 @@ class Test(TestFunctions):
|
||||
tx = CTransaction()
|
||||
tx.nVersion = ci.txVersion()
|
||||
tx.vout.append(ci.txoType()(ci.make_int(1.1), script_dest))
|
||||
tx_hex = ToHex(tx)
|
||||
tx_hex = tx.serialize().hex()
|
||||
tx_funded = ci.rpc_wallet("fundrawtransaction", [tx_hex])
|
||||
utxo_pos = 0 if tx_funded["changepos"] == 1 else 1
|
||||
tx_signed = ci.rpc_wallet(
|
||||
@@ -357,10 +356,10 @@ class Test(TestFunctions):
|
||||
)
|
||||
)
|
||||
tx_spend.vout.append(ci.txoType()(ci.make_int(1.099), script_out))
|
||||
tx_spend_hex = ToHex(tx_spend)
|
||||
tx_spend_hex = tx_spend.serialize().hex()
|
||||
|
||||
tx_spend.nLockTime = chain_height + 2
|
||||
tx_spend_invalid_hex = ToHex(tx_spend)
|
||||
tx_spend_invalid_hex = tx_spend.serialize().hex()
|
||||
|
||||
for tx_hex in [tx_spend_invalid_hex, tx_spend_hex]:
|
||||
try:
|
||||
|
||||
342
tests/basicswap/extended/test_simplex.py
Normal file
342
tests/basicswap/extended/test_simplex.py
Normal file
@@ -0,0 +1,342 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# 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.
|
||||
|
||||
"""
|
||||
docker run \
|
||||
-e "ADDR=127.0.0.1" \
|
||||
-e "PASS=password" \
|
||||
-p 5223:5223 \
|
||||
-v /tmp/simplex/smp/config:/etc/opt/simplex:z \
|
||||
-v /tmp/simplex/smp/logs:/var/opt/simplex:z \
|
||||
-v /tmp/simplex/certs:/certificates \
|
||||
simplexchat/smp-server:latest
|
||||
|
||||
Fingerprint: Q8SNxc2SRcKyXlhJM8KFUgPNW4KXPGRm4eSLtT_oh-I=
|
||||
|
||||
export SIMPLEX_SERVER_ADDRESS=smp://Q8SNxc2SRcKyXlhJM8KFUgPNW4KXPGRm4eSLtT_oh-I=:password@127.0.0.1:5223,443
|
||||
|
||||
|
||||
https://github.com/simplex-chat/simplex-chat/issues/4127
|
||||
json: {"corrId":"3","cmd":"/_send #1 text test123"}
|
||||
direct message: {"corrId":"1","cmd":"/_send @2 text the message"}
|
||||
|
||||
"""
|
||||
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import random
|
||||
import shutil
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
import basicswap.config as cfg
|
||||
|
||||
from basicswap.basicswap import (
|
||||
BidStates,
|
||||
SwapTypes,
|
||||
)
|
||||
from basicswap.chainparams import Coins
|
||||
|
||||
from basicswap.network.simplex import (
|
||||
WebSocketThread,
|
||||
waitForConnected,
|
||||
waitForResponse,
|
||||
)
|
||||
from basicswap.network.simplex_chat import startSimplexClient
|
||||
from tests.basicswap.common import (
|
||||
stopDaemons,
|
||||
wait_for_bid,
|
||||
wait_for_offer,
|
||||
)
|
||||
from tests.basicswap.test_xmr import BaseTest, test_delay_event, RESET_TEST
|
||||
|
||||
|
||||
SIMPLEX_SERVER_ADDRESS = os.getenv("SIMPLEX_SERVER_ADDRESS")
|
||||
SIMPLEX_CLIENT_PATH = os.path.expanduser(os.getenv("SIMPLEX_CLIENT_PATH"))
|
||||
TEST_DIR = cfg.TEST_DATADIRS
|
||||
|
||||
|
||||
logger = logging.getLogger()
|
||||
logger.level = logging.DEBUG
|
||||
if not len(logger.handlers):
|
||||
logger.addHandler(logging.StreamHandler(sys.stdout))
|
||||
|
||||
|
||||
class TestSimplex(unittest.TestCase):
|
||||
daemons = []
|
||||
remove_testdir: bool = False
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
stopDaemons(cls.daemons)
|
||||
|
||||
def test_basic(self):
|
||||
|
||||
if os.path.isdir(TEST_DIR):
|
||||
if RESET_TEST:
|
||||
logging.info("Removing " + TEST_DIR)
|
||||
shutil.rmtree(TEST_DIR)
|
||||
else:
|
||||
logging.info("Restoring instance from " + TEST_DIR)
|
||||
if not os.path.exists(TEST_DIR):
|
||||
os.makedirs(TEST_DIR)
|
||||
|
||||
client1_dir = os.path.join(TEST_DIR, "client1")
|
||||
if os.path.exists(client1_dir):
|
||||
shutil.rmtree(client1_dir)
|
||||
|
||||
client1_daemon = startSimplexClient(
|
||||
SIMPLEX_CLIENT_PATH,
|
||||
client1_dir,
|
||||
SIMPLEX_SERVER_ADDRESS,
|
||||
5225,
|
||||
logger,
|
||||
test_delay_event,
|
||||
)
|
||||
self.daemons.append(client1_daemon)
|
||||
|
||||
client2_dir = os.path.join(TEST_DIR, "client2")
|
||||
if os.path.exists(client2_dir):
|
||||
shutil.rmtree(client2_dir)
|
||||
client2_daemon = startSimplexClient(
|
||||
SIMPLEX_CLIENT_PATH,
|
||||
client2_dir,
|
||||
SIMPLEX_SERVER_ADDRESS,
|
||||
5226,
|
||||
logger,
|
||||
test_delay_event,
|
||||
)
|
||||
self.daemons.append(client2_daemon)
|
||||
|
||||
threads = []
|
||||
try:
|
||||
ws_thread = WebSocketThread("ws://127.0.0.1:5225", tag="C1")
|
||||
ws_thread.start()
|
||||
threads.append(ws_thread)
|
||||
|
||||
ws_thread2 = WebSocketThread("ws://127.0.0.1:5226", tag="C2")
|
||||
ws_thread2.start()
|
||||
threads.append(ws_thread2)
|
||||
|
||||
waitForConnected(ws_thread, test_delay_event)
|
||||
sent_id = ws_thread.send_command("/group bsx")
|
||||
response = waitForResponse(ws_thread, sent_id, test_delay_event)
|
||||
assert response["resp"]["type"] == "groupCreated"
|
||||
|
||||
ws_thread.send_command("/set voice #bsx off")
|
||||
ws_thread.send_command("/set files #bsx off")
|
||||
ws_thread.send_command("/set direct #bsx off")
|
||||
ws_thread.send_command("/set reactions #bsx off")
|
||||
ws_thread.send_command("/set reports #bsx off")
|
||||
ws_thread.send_command("/set disappear #bsx on week")
|
||||
sent_id = ws_thread.send_command("/create link #bsx")
|
||||
|
||||
connReqContact = None
|
||||
connReqMsgData = waitForResponse(ws_thread, sent_id, test_delay_event)
|
||||
connReqContact = connReqMsgData["resp"]["connReqContact"]
|
||||
|
||||
group_link = "https://simplex.chat" + connReqContact[8:]
|
||||
logger.info(f"group_link: {group_link}")
|
||||
|
||||
sent_id = ws_thread2.send_command("/c " + group_link)
|
||||
response = waitForResponse(ws_thread2, sent_id, test_delay_event)
|
||||
assert "groupLinkId" in response["resp"]["connection"]
|
||||
|
||||
sent_id = ws_thread2.send_command("/groups")
|
||||
response = waitForResponse(ws_thread2, sent_id, test_delay_event)
|
||||
assert len(response["resp"]["groups"]) == 1
|
||||
|
||||
ws_thread.send_command("#bsx test msg 1")
|
||||
|
||||
found_1 = False
|
||||
found_2 = False
|
||||
for i in range(100):
|
||||
message = ws_thread.queue_get()
|
||||
if message is not None:
|
||||
data = json.loads(message)
|
||||
# print(f"message 1: {json.dumps(data, indent=4)}")
|
||||
try:
|
||||
if data["resp"]["type"] in (
|
||||
"chatItemsStatusesUpdated",
|
||||
"newChatItems",
|
||||
):
|
||||
for chat_item in data["resp"]["chatItems"]:
|
||||
# print(f"chat_item 1: {json.dumps(chat_item, indent=4)}")
|
||||
if chat_item["chatItem"]["meta"]["itemStatus"][
|
||||
"type"
|
||||
] in ("sndRcvd", "rcvNew"):
|
||||
if (
|
||||
chat_item["chatItem"]["content"]["msgContent"][
|
||||
"text"
|
||||
]
|
||||
== "test msg 1"
|
||||
):
|
||||
found_1 = True
|
||||
except Exception as e:
|
||||
print(f"error 1: {e}")
|
||||
|
||||
message = ws_thread2.queue_get()
|
||||
if message is not None:
|
||||
data = json.loads(message)
|
||||
# print(f"message 2: {json.dumps(data, indent=4)}")
|
||||
try:
|
||||
if data["resp"]["type"] in (
|
||||
"chatItemsStatusesUpdated",
|
||||
"newChatItems",
|
||||
):
|
||||
for chat_item in data["resp"]["chatItems"]:
|
||||
# print(f"chat_item 1: {json.dumps(chat_item, indent=4)}")
|
||||
if chat_item["chatItem"]["meta"]["itemStatus"][
|
||||
"type"
|
||||
] in ("sndRcvd", "rcvNew"):
|
||||
if (
|
||||
chat_item["chatItem"]["content"]["msgContent"][
|
||||
"text"
|
||||
]
|
||||
== "test msg 1"
|
||||
):
|
||||
found_2 = True
|
||||
except Exception as e:
|
||||
print(f"error 2: {e}")
|
||||
|
||||
if found_1 and found_2:
|
||||
break
|
||||
test_delay_event.wait(0.5)
|
||||
|
||||
assert found_1 is True
|
||||
assert found_2 is True
|
||||
|
||||
finally:
|
||||
for t in threads:
|
||||
t.stop()
|
||||
t.join()
|
||||
|
||||
|
||||
class Test(BaseTest):
|
||||
__test__ = True
|
||||
start_ltc_nodes = False
|
||||
start_xmr_nodes = True
|
||||
group_link = None
|
||||
daemons = []
|
||||
coin_to = Coins.XMR
|
||||
# coin_to = Coins.PART
|
||||
|
||||
@classmethod
|
||||
def prepareTestDir(cls):
|
||||
base_ws_port: int = 5225
|
||||
for i in range(cls.num_nodes):
|
||||
|
||||
client_dir = os.path.join(TEST_DIR, f"simplex_client{i}")
|
||||
if os.path.exists(client_dir):
|
||||
shutil.rmtree(client_dir)
|
||||
|
||||
client_daemon = startSimplexClient(
|
||||
SIMPLEX_CLIENT_PATH,
|
||||
client_dir,
|
||||
SIMPLEX_SERVER_ADDRESS,
|
||||
base_ws_port + i,
|
||||
logger,
|
||||
test_delay_event,
|
||||
)
|
||||
cls.daemons.append(client_daemon)
|
||||
|
||||
# Create the group for bsx
|
||||
logger.info("Creating BSX group")
|
||||
ws_thread = None
|
||||
try:
|
||||
ws_thread = WebSocketThread(f"ws://127.0.0.1:{base_ws_port}", tag="C0")
|
||||
ws_thread.start()
|
||||
waitForConnected(ws_thread, test_delay_event)
|
||||
sent_id = ws_thread.send_command("/group bsx")
|
||||
response = waitForResponse(ws_thread, sent_id, test_delay_event)
|
||||
assert response["resp"]["type"] == "groupCreated"
|
||||
|
||||
ws_thread.send_command("/set voice #bsx off")
|
||||
ws_thread.send_command("/set files #bsx off")
|
||||
ws_thread.send_command("/set direct #bsx off")
|
||||
ws_thread.send_command("/set reactions #bsx off")
|
||||
ws_thread.send_command("/set reports #bsx off")
|
||||
ws_thread.send_command("/set disappear #bsx on week")
|
||||
sent_id = ws_thread.send_command("/create link #bsx")
|
||||
|
||||
connReqContact = None
|
||||
connReqMsgData = waitForResponse(ws_thread, sent_id, test_delay_event)
|
||||
connReqContact = connReqMsgData["resp"]["connReqContact"]
|
||||
cls.group_link = "https://simplex.chat" + connReqContact[8:]
|
||||
logger.info(f"BSX group_link: {cls.group_link}")
|
||||
|
||||
finally:
|
||||
if ws_thread:
|
||||
ws_thread.stop()
|
||||
ws_thread.join()
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
logging.info("Finalising Test")
|
||||
super(Test, cls).tearDownClass()
|
||||
stopDaemons(cls.daemons)
|
||||
|
||||
@classmethod
|
||||
def addCoinSettings(cls, settings, datadir, node_id):
|
||||
|
||||
settings["networks"] = [
|
||||
{
|
||||
"type": "simplex",
|
||||
"server_address": SIMPLEX_SERVER_ADDRESS,
|
||||
"client_path": SIMPLEX_CLIENT_PATH,
|
||||
"ws_port": 5225 + node_id,
|
||||
"group_link": cls.group_link,
|
||||
},
|
||||
]
|
||||
|
||||
def test_01_swap(self):
|
||||
logging.info("---------- Test xmr swap")
|
||||
|
||||
swap_clients = self.swap_clients
|
||||
|
||||
for sc in swap_clients:
|
||||
sc.dleag_split_size_init = 9000
|
||||
sc.dleag_split_size = 11000
|
||||
|
||||
assert len(swap_clients[0].active_networks) == 1
|
||||
assert swap_clients[0].active_networks[0]["type"] == "simplex"
|
||||
|
||||
coin_from = Coins.BTC
|
||||
coin_to = self.coin_to
|
||||
|
||||
ci_from = swap_clients[0].ci(coin_from)
|
||||
ci_to = swap_clients[1].ci(coin_to)
|
||||
|
||||
swap_value = ci_from.make_int(random.uniform(0.2, 20.0), r=1)
|
||||
rate_swap = ci_to.make_int(random.uniform(0.2, 20.0), r=1)
|
||||
offer_id = swap_clients[0].postOffer(
|
||||
coin_from, coin_to, swap_value, rate_swap, swap_value, SwapTypes.XMR_SWAP
|
||||
)
|
||||
|
||||
wait_for_offer(test_delay_event, swap_clients[1], offer_id)
|
||||
offer = swap_clients[1].getOffer(offer_id)
|
||||
bid_id = swap_clients[1].postBid(offer_id, offer.amount_from)
|
||||
|
||||
wait_for_bid(test_delay_event, swap_clients[0], bid_id, BidStates.BID_RECEIVED)
|
||||
swap_clients[0].acceptBid(bid_id)
|
||||
|
||||
wait_for_bid(
|
||||
test_delay_event,
|
||||
swap_clients[0],
|
||||
bid_id,
|
||||
BidStates.SWAP_COMPLETED,
|
||||
wait_for=320,
|
||||
)
|
||||
wait_for_bid(
|
||||
test_delay_event,
|
||||
swap_clients[1],
|
||||
bid_id,
|
||||
BidStates.SWAP_COMPLETED,
|
||||
sent=True,
|
||||
wait_for=320,
|
||||
)
|
||||
147
tests/basicswap/extended/test_smsg.py
Normal file
147
tests/basicswap/extended/test_smsg.py
Normal file
@@ -0,0 +1,147 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# 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.
|
||||
|
||||
import logging
|
||||
|
||||
from basicswap.chainparams import Coins
|
||||
from basicswap.util.smsg import (
|
||||
smsgEncrypt,
|
||||
smsgDecrypt,
|
||||
smsgGetID,
|
||||
smsgGetTimestamp,
|
||||
SMSG_BUCKET_LEN,
|
||||
)
|
||||
from basicswap.contrib.test_framework.messages import (
|
||||
NODE_SMSG,
|
||||
msg_smsgPong,
|
||||
msg_smsgMsg,
|
||||
)
|
||||
from basicswap.contrib.test_framework.p2p import (
|
||||
P2PInterface,
|
||||
P2P_SERVICES,
|
||||
NetworkThread,
|
||||
)
|
||||
from basicswap.contrib.test_framework.util import (
|
||||
PortSeed,
|
||||
)
|
||||
|
||||
from tests.basicswap.common import BASE_PORT
|
||||
from tests.basicswap.test_xmr import BaseTest, test_delay_event
|
||||
|
||||
|
||||
class P2PInterfaceSMSG(P2PInterface):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.is_part = True
|
||||
|
||||
def on_smsgPing(self, msg):
|
||||
logging.info("on_smsgPing")
|
||||
self.send_message(msg_smsgPong(1))
|
||||
|
||||
def on_smsgPong(self, msg):
|
||||
logging.info("on_smsgPong", msg)
|
||||
|
||||
def on_smsgInv(self, msg):
|
||||
logging.info("on_smsgInv")
|
||||
|
||||
|
||||
def wait_for_smsg(ci, msg_id: str, wait_for=20) -> None:
|
||||
for i in range(wait_for):
|
||||
if test_delay_event.is_set():
|
||||
raise ValueError("Test stopped.")
|
||||
try:
|
||||
ci.rpc_wallet("smsg", [msg_id])
|
||||
return
|
||||
except Exception as e:
|
||||
logging.info(e)
|
||||
test_delay_event.wait(1)
|
||||
|
||||
raise ValueError("wait_for_smsg timed out.")
|
||||
|
||||
|
||||
class Test(BaseTest):
|
||||
__test__ = True
|
||||
start_ltc_nodes = False
|
||||
start_xmr_nodes = False
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(Test, cls).setUpClass()
|
||||
PortSeed.n = 1
|
||||
|
||||
logging.info("Setting up network thread")
|
||||
cls.network_thread = NetworkThread()
|
||||
cls.network_thread.network_event_loop.set_debug(True)
|
||||
cls.network_thread.start()
|
||||
cls.network_thread.network_event_loop.set_debug(True)
|
||||
|
||||
@classmethod
|
||||
def run_loop_ended(cls):
|
||||
logging.info("run_loop_ended")
|
||||
logging.info("Closing down network thread")
|
||||
cls.network_thread.close()
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
logging.info("Finalising Test")
|
||||
|
||||
# logging.info('Closing down network thread')
|
||||
# cls.network_thread.close()
|
||||
|
||||
super(Test, cls).tearDownClass()
|
||||
|
||||
@classmethod
|
||||
def coins_loop(cls):
|
||||
super(Test, cls).coins_loop()
|
||||
|
||||
def test_01_p2p(self):
|
||||
swap_clients = self.swap_clients
|
||||
|
||||
kwargs = {}
|
||||
kwargs["dstport"] = BASE_PORT
|
||||
kwargs["dstaddr"] = "127.0.0.1"
|
||||
services = P2P_SERVICES | NODE_SMSG
|
||||
p2p_conn = P2PInterfaceSMSG()
|
||||
p2p_conn.p2p_connected_to_node = True
|
||||
p2p_conn.peer_connect(
|
||||
**kwargs,
|
||||
services=services,
|
||||
send_version=True,
|
||||
net="regtest",
|
||||
timeout_factor=99999,
|
||||
supports_v2_p2p=False,
|
||||
)()
|
||||
|
||||
p2p_conn.wait_for_connect()
|
||||
p2p_conn.wait_for_verack()
|
||||
p2p_conn.sync_with_ping()
|
||||
|
||||
ci0_part = swap_clients[0].ci(Coins.PART)
|
||||
test_key_recv: bytes = ci0_part.getNewRandomKey()
|
||||
test_key_recv_wif: str = ci0_part.encodeKey(test_key_recv)
|
||||
test_key_recv_pk: bytes = ci0_part.getPubkey(test_key_recv)
|
||||
ci0_part.rpc("smsgimportprivkey", [test_key_recv_wif, "test key"])
|
||||
|
||||
message_test: str = "Test message"
|
||||
test_key_send: bytes = ci0_part.getNewRandomKey()
|
||||
encrypted_message: bytes = smsgEncrypt(
|
||||
test_key_send, test_key_recv_pk, message_test.encode("utf-8")
|
||||
)
|
||||
|
||||
decrypted_message: bytes = smsgDecrypt(test_key_recv, encrypted_message)
|
||||
assert decrypted_message.decode("utf-8") == message_test
|
||||
|
||||
msg_id: bytes = smsgGetID(encrypted_message)
|
||||
smsg_timestamp: int = smsgGetTimestamp(encrypted_message)
|
||||
smsg_bucket: int = smsg_timestamp - (smsg_timestamp % SMSG_BUCKET_LEN)
|
||||
|
||||
smsgMsg = msg_smsgMsg(1, smsg_bucket, encrypted_message)
|
||||
p2p_conn.send_message(smsgMsg)
|
||||
|
||||
wait_for_smsg(ci0_part, msg_id.hex())
|
||||
rv = ci0_part.rpc_wallet("smsg", [msg_id.hex()])
|
||||
assert rv["text"] == message_test
|
||||
@@ -26,7 +26,6 @@ from tests.basicswap.common import (
|
||||
waitForRPC,
|
||||
)
|
||||
from basicswap.contrib.test_framework.messages import (
|
||||
ToHex,
|
||||
CTxIn,
|
||||
COutPoint,
|
||||
CTransaction,
|
||||
@@ -251,7 +250,7 @@ class TestBCH(BasicSwapTest):
|
||||
tx = CTransaction()
|
||||
tx.nVersion = ci.txVersion()
|
||||
tx.vout.append(ci.txoType()(ci.make_int(1.1), script_dest))
|
||||
tx_hex = ToHex(tx)
|
||||
tx_hex = tx.serialize().hex()
|
||||
tx_funded = ci.rpc_wallet("fundrawtransaction", [tx_hex])
|
||||
utxo_pos = 0 if tx_funded["changepos"] == 1 else 1
|
||||
tx_signed = ci.rpc_wallet(
|
||||
@@ -285,10 +284,10 @@ class TestBCH(BasicSwapTest):
|
||||
)
|
||||
)
|
||||
tx_spend.vout.append(ci.txoType()(ci.make_int(1.0999), script_out))
|
||||
tx_spend_hex = ToHex(tx_spend)
|
||||
tx_spend_hex = tx_spend.serialize().hex()
|
||||
|
||||
tx_spend.nLockTime = chain_height + 2
|
||||
tx_spend_invalid_hex = ToHex(tx_spend)
|
||||
tx_spend_invalid_hex = tx_spend.serialize().hex()
|
||||
|
||||
for tx_hex in [tx_spend_invalid_hex, tx_spend_hex]:
|
||||
try:
|
||||
@@ -362,7 +361,7 @@ class TestBCH(BasicSwapTest):
|
||||
tx = CTransaction()
|
||||
tx.nVersion = ci.txVersion()
|
||||
tx.vout.append(ci.txoType()(ci.make_int(1.1), script_dest))
|
||||
tx_hex = ToHex(tx)
|
||||
tx_hex = tx.serialize().hex()
|
||||
tx_funded = ci.rpc_wallet("fundrawtransaction", [tx_hex])
|
||||
utxo_pos = 0 if tx_funded["changepos"] == 1 else 1
|
||||
tx_signed = ci.rpc_wallet(
|
||||
@@ -405,7 +404,7 @@ class TestBCH(BasicSwapTest):
|
||||
)
|
||||
)
|
||||
tx_spend.vout.append(ci.txoType()(ci.make_int(1.0999), script_out))
|
||||
tx_spend_hex = ToHex(tx_spend)
|
||||
tx_spend_hex = tx_spend.serialize().hex()
|
||||
try:
|
||||
txid = ci.rpc(
|
||||
"sendrawtransaction",
|
||||
@@ -640,7 +639,7 @@ class TestBCH(BasicSwapTest):
|
||||
tx = CTransaction()
|
||||
tx.nVersion = ci.txVersion()
|
||||
tx.vout.append(ci.txoType()(ci.make_int(1.1), script_dest))
|
||||
tx_hex = ToHex(tx)
|
||||
tx_hex = tx.serialize().hex()
|
||||
tx_funded = ci.rpc_wallet("fundrawtransaction", [tx_hex])
|
||||
utxo_pos = 0 if tx_funded["changepos"] == 1 else 1
|
||||
tx_signed = ci.rpc_wallet(
|
||||
@@ -682,7 +681,7 @@ class TestBCH(BasicSwapTest):
|
||||
)
|
||||
)
|
||||
tx_spend.vout.append(ci.txoType()(ci.make_int(1.0999), script_out))
|
||||
tx_spend_hex = ToHex(tx_spend)
|
||||
tx_spend_hex = tx_spend.serialize().hex()
|
||||
|
||||
txid = ci.rpc(
|
||||
"sendrawtransaction",
|
||||
@@ -730,7 +729,7 @@ class TestBCH(BasicSwapTest):
|
||||
tx = CTransaction()
|
||||
tx.nVersion = ci.txVersion()
|
||||
tx.vout.append(ci.txoType()(ci.make_int(1.1), script_dest))
|
||||
tx_hex = ToHex(tx)
|
||||
tx_hex = tx.serialize().hex()
|
||||
tx_funded = ci.rpc_wallet("fundrawtransaction", [tx_hex])
|
||||
utxo_pos = 0 if tx_funded["changepos"] == 1 else 1
|
||||
tx_signed = ci.rpc_wallet(
|
||||
@@ -772,7 +771,7 @@ class TestBCH(BasicSwapTest):
|
||||
)
|
||||
)
|
||||
tx_spend.vout.append(ci.txoType()(ci.make_int(1.0999), script_out))
|
||||
tx_spend_hex = ToHex(tx_spend)
|
||||
tx_spend_hex = tx_spend.serialize().hex()
|
||||
|
||||
txid = ci.rpc(
|
||||
"sendrawtransaction",
|
||||
|
||||
@@ -46,8 +46,7 @@ from tests.basicswap.common import (
|
||||
)
|
||||
from basicswap.contrib.test_framework.descriptors import descsum_create
|
||||
from basicswap.contrib.test_framework.messages import (
|
||||
ToHex,
|
||||
FromHex,
|
||||
from_hex,
|
||||
CTxIn,
|
||||
COutPoint,
|
||||
CTransaction,
|
||||
@@ -860,7 +859,7 @@ class BasicSwapTest(TestFunctions):
|
||||
addr_p2sh_segwit,
|
||||
],
|
||||
)
|
||||
decoded_tx = FromHex(CTransaction(), tx_funded)
|
||||
decoded_tx = from_hex(CTransaction(), tx_funded)
|
||||
decoded_tx.vin[0].scriptSig = bytes.fromhex("16" + addr_p2sh_segwit_info["hex"])
|
||||
txid_with_scriptsig = decoded_tx.rehash()
|
||||
assert txid_with_scriptsig == tx_signed_decoded["txid"]
|
||||
@@ -950,7 +949,7 @@ class BasicSwapTest(TestFunctions):
|
||||
tx = CTransaction()
|
||||
tx.nVersion = ci.txVersion()
|
||||
tx.vout.append(ci.txoType()(ci.make_int(1.1), script_dest))
|
||||
tx_hex = ToHex(tx)
|
||||
tx_hex = tx.serialize().hex()
|
||||
tx_funded = ci.rpc_wallet("fundrawtransaction", [tx_hex])
|
||||
utxo_pos = 0 if tx_funded["changepos"] == 1 else 1
|
||||
tx_signed = ci.rpc_wallet(
|
||||
@@ -979,10 +978,10 @@ class BasicSwapTest(TestFunctions):
|
||||
tx_spend.wit.vtxinwit[0].scriptWitness.stack = [
|
||||
script,
|
||||
]
|
||||
tx_spend_hex = ToHex(tx_spend)
|
||||
tx_spend_hex = tx_spend.serialize().hex()
|
||||
|
||||
tx_spend.nLockTime = chain_height + 2
|
||||
tx_spend_invalid_hex = ToHex(tx_spend)
|
||||
tx_spend_invalid_hex = tx_spend.serialize().hex()
|
||||
|
||||
for tx_hex in [tx_spend_invalid_hex, tx_spend_hex]:
|
||||
try:
|
||||
@@ -1055,7 +1054,7 @@ class BasicSwapTest(TestFunctions):
|
||||
tx = CTransaction()
|
||||
tx.nVersion = ci.txVersion()
|
||||
tx.vout.append(ci.txoType()(ci.make_int(1.1), script_dest))
|
||||
tx_hex = ToHex(tx)
|
||||
tx_hex = tx.serialize().hex()
|
||||
tx_funded = ci.rpc_wallet("fundrawtransaction", [tx_hex])
|
||||
utxo_pos = 0 if tx_funded["changepos"] == 1 else 1
|
||||
tx_signed = ci.rpc_wallet(
|
||||
@@ -1094,7 +1093,7 @@ class BasicSwapTest(TestFunctions):
|
||||
tx_spend.wit.vtxinwit[0].scriptWitness.stack = [
|
||||
script,
|
||||
]
|
||||
tx_spend_hex = ToHex(tx_spend)
|
||||
tx_spend_hex = tx_spend.serialize().hex()
|
||||
try:
|
||||
txid = ci.rpc(
|
||||
"sendrawtransaction",
|
||||
@@ -1435,7 +1434,7 @@ class BasicSwapTest(TestFunctions):
|
||||
tx = CTransaction()
|
||||
tx.nVersion = ci.txVersion()
|
||||
tx.vout.append(ci.txoType()(ci.make_int(1.1), script_dest))
|
||||
tx_hex = ToHex(tx)
|
||||
tx_hex = tx.serialize().hex()
|
||||
tx_funded = ci.rpc_wallet("fundrawtransaction", [tx_hex])
|
||||
utxo_pos = 0 if tx_funded["changepos"] == 1 else 1
|
||||
tx_signed = ci.rpc_wallet(
|
||||
@@ -1477,7 +1476,7 @@ class BasicSwapTest(TestFunctions):
|
||||
)
|
||||
)
|
||||
tx_spend.vout.append(ci.txoType()(ci.make_int(1.0999), script_out))
|
||||
tx_spend_hex = ToHex(tx_spend)
|
||||
tx_spend_hex = tx_spend.serialize().hex()
|
||||
|
||||
txid = ci.rpc(
|
||||
"sendrawtransaction",
|
||||
@@ -1525,7 +1524,7 @@ class BasicSwapTest(TestFunctions):
|
||||
tx = CTransaction()
|
||||
tx.nVersion = ci.txVersion()
|
||||
tx.vout.append(ci.txoType()(ci.make_int(1.1), script_dest))
|
||||
tx_hex = ToHex(tx)
|
||||
tx_hex = tx.serialize().hex()
|
||||
tx_funded = ci.rpc_wallet("fundrawtransaction", [tx_hex])
|
||||
utxo_pos = 0 if tx_funded["changepos"] == 1 else 1
|
||||
tx_signed = ci.rpc_wallet(
|
||||
@@ -1567,7 +1566,7 @@ class BasicSwapTest(TestFunctions):
|
||||
tx_spend.wit.vtxinwit[0].scriptWitness.stack = [
|
||||
script,
|
||||
]
|
||||
tx_spend_hex = ToHex(tx_spend)
|
||||
tx_spend_hex = tx_spend.serialize().hex()
|
||||
|
||||
txid = ci.rpc(
|
||||
"sendrawtransaction",
|
||||
|
||||
@@ -56,7 +56,6 @@ from basicswap.contrib.test_framework.messages import (
|
||||
CTransaction,
|
||||
CTxIn,
|
||||
CTxInWitness,
|
||||
ToHex,
|
||||
)
|
||||
from basicswap.contrib.test_framework.script import (
|
||||
CScript,
|
||||
@@ -211,7 +210,7 @@ class Test(BaseTest):
|
||||
tx = CTransaction()
|
||||
tx.nVersion = ci.txVersion()
|
||||
tx.vout.append(ci.txoType()(ci.make_int(1.1), script_dest))
|
||||
tx_hex = ToHex(tx)
|
||||
tx_hex = tx.serialize().hex()
|
||||
tx_funded = callnoderpc(0, "fundrawtransaction", [tx_hex])
|
||||
utxo_pos = 0 if tx_funded["changepos"] == 1 else 1
|
||||
tx_signed = callnoderpc(
|
||||
@@ -248,10 +247,10 @@ class Test(BaseTest):
|
||||
tx_spend.wit.vtxinwit[0].scriptWitness.stack = [
|
||||
script,
|
||||
]
|
||||
tx_spend_hex = ToHex(tx_spend)
|
||||
tx_spend_hex = tx_spend.serialize().hex()
|
||||
|
||||
tx_spend.nLockTime = chain_height + 2
|
||||
tx_spend_invalid_hex = ToHex(tx_spend)
|
||||
tx_spend_invalid_hex = tx_spend.serialize().hex()
|
||||
|
||||
for tx_hex in [tx_spend_invalid_hex, tx_spend_hex]:
|
||||
try:
|
||||
|
||||
@@ -247,7 +247,7 @@ def ltcCli(cmd, node_id=0):
|
||||
|
||||
|
||||
def signal_handler(sig, frame):
|
||||
logging.info("signal {} detected.".format(sig))
|
||||
logging.info(f"signal {sig} detected.")
|
||||
signal_event.set()
|
||||
test_delay_event.set()
|
||||
|
||||
@@ -309,6 +309,7 @@ def run_loop(cls):
|
||||
for c in cls.swap_clients:
|
||||
c.update()
|
||||
test_delay_event.wait(1.0)
|
||||
cls.run_loop_ended()
|
||||
|
||||
|
||||
class BaseTest(unittest.TestCase):
|
||||
@@ -322,12 +323,13 @@ class BaseTest(unittest.TestCase):
|
||||
ltc_daemons = []
|
||||
xmr_daemons = []
|
||||
xmr_wallet_auth = []
|
||||
restore_instance = False
|
||||
extra_wait_time = 0
|
||||
restore_instance: bool = False
|
||||
extra_wait_time: int = 0
|
||||
num_nodes: int = NUM_NODES
|
||||
|
||||
start_ltc_nodes = False
|
||||
start_xmr_nodes = True
|
||||
has_segwit = True
|
||||
start_ltc_nodes: bool = False
|
||||
start_xmr_nodes: bool = True
|
||||
has_segwit: bool = True
|
||||
|
||||
xmr_addr = None
|
||||
btc_addr = None
|
||||
@@ -392,6 +394,8 @@ class BaseTest(unittest.TestCase):
|
||||
cls.stream_fp.setFormatter(formatter)
|
||||
logger.addHandler(cls.stream_fp)
|
||||
|
||||
cls.prepareTestDir()
|
||||
|
||||
try:
|
||||
logging.info("Preparing coin nodes.")
|
||||
for i in range(NUM_NODES):
|
||||
@@ -645,6 +649,7 @@ class BaseTest(unittest.TestCase):
|
||||
start_nodes,
|
||||
cls,
|
||||
)
|
||||
|
||||
basicswap_dir = os.path.join(
|
||||
os.path.join(TEST_DIR, "basicswap_" + str(i))
|
||||
)
|
||||
@@ -966,6 +971,10 @@ class BaseTest(unittest.TestCase):
|
||||
|
||||
super(BaseTest, cls).tearDownClass()
|
||||
|
||||
@classmethod
|
||||
def prepareTestDir(cls):
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def addCoinSettings(cls, settings, datadir, node_id):
|
||||
pass
|
||||
@@ -995,6 +1004,10 @@ class BaseTest(unittest.TestCase):
|
||||
{"wallet_address": cls.xmr_addr, "amount_of_blocks": 1},
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def run_loop_ended(cls):
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def waitForParticlHeight(cls, num_blocks, node_id=0):
|
||||
logging.info(
|
||||
|
||||
Reference in New Issue
Block a user