mirror of
https://github.com/basicswap/basicswap.git
synced 2026-06-08 12:11:41 +02:00
test: fix Dash tests
This commit is contained in:
@@ -5552,8 +5552,8 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
|
|||||||
use_cursor = self.openDB(cursor)
|
use_cursor = self.openDB(cursor)
|
||||||
|
|
||||||
bid, offer = self.getBidAndOffer(bid_id, use_cursor)
|
bid, offer = self.getBidAndOffer(bid_id, use_cursor)
|
||||||
ensure(bid, "Bid not found")
|
ensure(bid, f"Bid not found: {self.log.id(bid_id)}.")
|
||||||
ensure(offer, "Offer not found")
|
ensure(offer, f"Offer not found: {self.log.id(bid.offer_id)}.")
|
||||||
|
|
||||||
# Ensure bid is still valid
|
# Ensure bid is still valid
|
||||||
now: int = self.getTime()
|
now: int = self.getTime()
|
||||||
@@ -6828,8 +6828,8 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
|
|||||||
try:
|
try:
|
||||||
use_cursor = self.openDB(cursor)
|
use_cursor = self.openDB(cursor)
|
||||||
bid, offer = self.getBidAndOffer(bid_id, use_cursor, with_txns=False)
|
bid, offer = self.getBidAndOffer(bid_id, use_cursor, with_txns=False)
|
||||||
ensure(bid, "Bid not found")
|
ensure(bid, f"Bid not found: {self.log.id(bid_id)}.")
|
||||||
ensure(offer, "Offer not found")
|
ensure(offer, f"Offer not found: {self.log.id(bid.offer_id)}.")
|
||||||
|
|
||||||
bid.setState(new_state)
|
bid.setState(new_state)
|
||||||
self.deactivateBid(use_cursor, offer, bid)
|
self.deactivateBid(use_cursor, offer, bid)
|
||||||
@@ -13018,8 +13018,8 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
|
|||||||
self.log.info(f"Route established for bid {self.log.id(bid_id)}")
|
self.log.info(f"Route established for bid {self.log.id(bid_id)}")
|
||||||
|
|
||||||
bid, offer = self.getBidAndOffer(bid_id, cursor)
|
bid, offer = self.getBidAndOffer(bid_id, cursor)
|
||||||
ensure(bid, "Bid not found")
|
ensure(bid, f"Bid not found: {self.log.id(bid_id)}.")
|
||||||
ensure(offer, "Offer not found")
|
ensure(offer, f"Offer not found: {self.log.id(bid.offer_id)}.")
|
||||||
|
|
||||||
coin_from = Coins(offer.coin_from)
|
coin_from = Coins(offer.coin_from)
|
||||||
coin_to = Coins(offer.coin_to)
|
coin_to = Coins(offer.coin_to)
|
||||||
@@ -15133,8 +15133,7 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
|
|||||||
return
|
return
|
||||||
|
|
||||||
bid = self.getBid(bid_id)
|
bid = self.getBid(bid_id)
|
||||||
if bid is None:
|
ensure(bid, f"Bid not found: {self.log.id(bid_id)}.")
|
||||||
raise ValueError("Bid not found.")
|
|
||||||
|
|
||||||
bid.debug_ind = debug_ind
|
bid.debug_ind = debug_ind
|
||||||
|
|
||||||
|
|||||||
@@ -3667,7 +3667,7 @@ class BTCInterface(FeeValidator, Secp256k1Interface):
|
|||||||
continue
|
continue
|
||||||
if "desc" in u:
|
if "desc" in u:
|
||||||
desc = u["desc"]
|
desc = u["desc"]
|
||||||
if self.using_segwit:
|
if self.using_segwit():
|
||||||
if self.use_p2shp2wsh():
|
if self.use_p2shp2wsh():
|
||||||
if not desc.startswith("sh(wpkh"):
|
if not desc.startswith("sh(wpkh"):
|
||||||
continue
|
continue
|
||||||
@@ -3828,7 +3828,7 @@ class BTCInterface(FeeValidator, Secp256k1Interface):
|
|||||||
|
|
||||||
ensure(
|
ensure(
|
||||||
sign_for_addr is not None,
|
sign_for_addr is not None,
|
||||||
"Could not find address with enough funds for proof",
|
f"Could not find {self.ticker()} address with enough funds for proof",
|
||||||
)
|
)
|
||||||
|
|
||||||
self._log.debug(f"sign_for_addr {sign_for_addr}")
|
self._log.debug(f"sign_for_addr {sign_for_addr}")
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ class LTCInterface(BTCInterface):
|
|||||||
continue
|
continue
|
||||||
if "desc" in u:
|
if "desc" in u:
|
||||||
desc = u["desc"]
|
desc = u["desc"]
|
||||||
if self.using_segwit:
|
if self.using_segwit():
|
||||||
if self.use_p2shp2wsh():
|
if self.use_p2shp2wsh():
|
||||||
if not desc.startswith("sh(wpkh"):
|
if not desc.startswith("sh(wpkh"):
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -170,3 +170,13 @@ class PIVXInterface(BTCInterface):
|
|||||||
block_height = self.getBlockHeader(rv["blockhash"])["height"]
|
block_height = self.getBlockHeader(rv["blockhash"])["height"]
|
||||||
return {"txid": txid_hex, "amount": 0, "height": block_height}
|
return {"txid": txid_hex, "amount": 0, "height": block_height}
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def getChainMedianTime(self) -> int:
|
||||||
|
bestblockhash = self.rpc("getbestblockhash")
|
||||||
|
bestblockheader = self.rpc(
|
||||||
|
"getblockheader",
|
||||||
|
[
|
||||||
|
bestblockhash,
|
||||||
|
],
|
||||||
|
)
|
||||||
|
return bestblockheader["mediantime"]
|
||||||
|
|||||||
@@ -50,11 +50,11 @@ def recoverNoScriptTxnWithKey(self, bid_id: bytes, encoded_key, cursor=None):
|
|||||||
try:
|
try:
|
||||||
use_cursor = self.openDB(cursor)
|
use_cursor = self.openDB(cursor)
|
||||||
bid, xmr_swap = self.getXmrBidFromSession(use_cursor, bid_id)
|
bid, xmr_swap = self.getXmrBidFromSession(use_cursor, bid_id)
|
||||||
ensure(bid, "Bid not found: {}.".format(bid_id.hex()))
|
ensure(bid, f"Bid not found: {self.log.id(bid_id)}.")
|
||||||
ensure(xmr_swap, "Adaptor-sig swap not found: {}.".format(bid_id.hex()))
|
ensure(xmr_swap, f"Adaptor-sig swap not found: {self.log.id(bid_id)}.")
|
||||||
offer, xmr_offer = self.getXmrOfferFromSession(use_cursor, bid.offer_id)
|
offer, xmr_offer = self.getXmrOfferFromSession(use_cursor, bid.offer_id)
|
||||||
ensure(offer, "Offer not found: {}.".format(bid.offer_id.hex()))
|
ensure(offer, f"Offer not found: {self.log.id(bid.offer_id)}.")
|
||||||
ensure(xmr_offer, "Adaptor-sig offer not found: {}.".format(bid.offer_id.hex()))
|
ensure(xmr_offer, f"Adaptor-sig offer not found: {self.log.id(bid.offer_id)}.")
|
||||||
|
|
||||||
# The no-script coin is always the follower
|
# The no-script coin is always the follower
|
||||||
reverse_bid: bool = self.is_reverse_ads_bid(offer.coin_from, offer.coin_to)
|
reverse_bid: bool = self.is_reverse_ads_bid(offer.coin_from, offer.coin_to)
|
||||||
@@ -106,7 +106,10 @@ def recoverNoScriptTxnWithKey(self, bid_id: bytes, encoded_key, cursor=None):
|
|||||||
address_to = self.getReceiveAddressFromPool(
|
address_to = self.getReceiveAddressFromPool(
|
||||||
base_coin_to, bid_id, TxTypes.XMR_SWAP_B_LOCK_SPEND, use_cursor
|
base_coin_to, bid_id, TxTypes.XMR_SWAP_B_LOCK_SPEND, use_cursor
|
||||||
)
|
)
|
||||||
amount = bid.amount_to
|
amount: int = bid.amount_to
|
||||||
|
chain_b_fee_rate: int = (
|
||||||
|
xmr_offer.a_fee_rate if reverse_bid else xmr_offer.b_fee_rate
|
||||||
|
)
|
||||||
lock_tx_vout = bid.getLockTXBVout()
|
lock_tx_vout = bid.getLockTXBVout()
|
||||||
txid = ci_follower.spendBLockTx(
|
txid = ci_follower.spendBLockTx(
|
||||||
xmr_swap.b_lock_tx_id,
|
xmr_swap.b_lock_tx_id,
|
||||||
@@ -114,7 +117,7 @@ def recoverNoScriptTxnWithKey(self, bid_id: bytes, encoded_key, cursor=None):
|
|||||||
xmr_swap.vkbv,
|
xmr_swap.vkbv,
|
||||||
vkbs,
|
vkbs,
|
||||||
amount,
|
amount,
|
||||||
xmr_offer.b_fee_rate,
|
chain_b_fee_rate,
|
||||||
bid.chain_b_height_start,
|
bid.chain_b_height_start,
|
||||||
spend_actual_balance=True,
|
spend_actual_balance=True,
|
||||||
lock_tx_vout=lock_tx_vout,
|
lock_tx_vout=lock_tx_vout,
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Copyright (c) 2020-2024 tecnovert
|
# Copyright (c) 2020-2024 tecnovert
|
||||||
@@ -163,7 +162,7 @@ def prepare_balance(
|
|||||||
post_json["type_to"] = type_to
|
post_json["type_to"] = type_to
|
||||||
json_rv = read_json_api(
|
json_rv = read_json_api(
|
||||||
port_take_from_node,
|
port_take_from_node,
|
||||||
"wallets/{}/withdraw".format(coin_ticker.lower()),
|
f"wallets/{coin_ticker.lower()}/withdraw",
|
||||||
post_json,
|
post_json,
|
||||||
)
|
)
|
||||||
assert len(json_rv["txid"]) == 64
|
assert len(json_rv["txid"]) == 64
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Copyright (c) 2020-2024 tecnovert
|
# Copyright (c) 2020-2024 tecnovert
|
||||||
|
|||||||
@@ -175,6 +175,7 @@ def prepareDir(datadir, nodeId, network_key, network_pubkey):
|
|||||||
"datadir": node_dir,
|
"datadir": node_dir,
|
||||||
"bindir": cfg.PARTICL_BINDIR,
|
"bindir": cfg.PARTICL_BINDIR,
|
||||||
"blocks_confirmed": 2, # Faster testing
|
"blocks_confirmed": 2, # Faster testing
|
||||||
|
"wallet_name": "bsx_wallet",
|
||||||
},
|
},
|
||||||
"dash": {
|
"dash": {
|
||||||
"connection_type": "rpc",
|
"connection_type": "rpc",
|
||||||
@@ -184,6 +185,7 @@ def prepareDir(datadir, nodeId, network_key, network_pubkey):
|
|||||||
"bindir": DASH_BINDIR,
|
"bindir": DASH_BINDIR,
|
||||||
"use_csv": True,
|
"use_csv": True,
|
||||||
"use_segwit": False,
|
"use_segwit": False,
|
||||||
|
"wallet_name": "bsx_wallet",
|
||||||
},
|
},
|
||||||
"bitcoin": {
|
"bitcoin": {
|
||||||
"connection_type": "rpc",
|
"connection_type": "rpc",
|
||||||
@@ -192,6 +194,7 @@ def prepareDir(datadir, nodeId, network_key, network_pubkey):
|
|||||||
"datadir": btcdatadir,
|
"datadir": btcdatadir,
|
||||||
"bindir": cfg.BITCOIN_BINDIR,
|
"bindir": cfg.BITCOIN_BINDIR,
|
||||||
"use_segwit": True,
|
"use_segwit": True,
|
||||||
|
"wallet_name": "bsx_wallet",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"check_progress_seconds": 2,
|
"check_progress_seconds": 2,
|
||||||
@@ -285,7 +288,7 @@ class Test(unittest.TestCase):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
super(Test, cls).setUpClass()
|
super().setUpClass()
|
||||||
|
|
||||||
k = PrivateKey()
|
k = PrivateKey()
|
||||||
cls.network_key = toWIF(PREFIX_SECRET_KEY_REGTEST, k.secret)
|
cls.network_key = toWIF(PREFIX_SECRET_KEY_REGTEST, k.secret)
|
||||||
@@ -409,15 +412,15 @@ class Test(unittest.TestCase):
|
|||||||
|
|
||||||
waitForRPC(dashRpc, delay_event, rpc_command="getblockchaininfo")
|
waitForRPC(dashRpc, delay_event, rpc_command="getblockchaininfo")
|
||||||
if len(dashRpc("listwallets")) < 1:
|
if len(dashRpc("listwallets")) < 1:
|
||||||
dashRpc("createwallet wbsx_wallet")
|
dashRpc("createwallet bsx_wallet")
|
||||||
|
|
||||||
sc.start()
|
sc.start()
|
||||||
|
|
||||||
waitForRPC(dashRpc, delay_event)
|
waitForRPC(dashRpc, delay_event)
|
||||||
num_blocks = 500
|
num_blocks = 500
|
||||||
logging.info("Mining %d dash blocks", num_blocks)
|
logging.info(f"Mining {num_blocks} dash blocks")
|
||||||
cls.dash_addr = dashRpc("getnewaddress mining_addr")
|
cls.dash_addr = dashRpc("getnewaddress mining_addr")
|
||||||
dashRpc("generatetoaddress {} {}".format(num_blocks, cls.dash_addr))
|
dashRpc(f"generatetoaddress {num_blocks} {cls.dash_addr}")
|
||||||
|
|
||||||
ro = dashRpc("getblockchaininfo")
|
ro = dashRpc("getblockchaininfo")
|
||||||
try:
|
try:
|
||||||
@@ -431,8 +434,8 @@ class Test(unittest.TestCase):
|
|||||||
|
|
||||||
waitForRPC(btcRpc, delay_event)
|
waitForRPC(btcRpc, delay_event)
|
||||||
cls.btc_addr = btcRpc("getnewaddress mining_addr bech32")
|
cls.btc_addr = btcRpc("getnewaddress mining_addr bech32")
|
||||||
logging.info("Mining %d Bitcoin blocks to %s", num_blocks, cls.btc_addr)
|
logging.info(f"Mining {num_blocks} Bitcoin blocks to {cls.btc_addr}")
|
||||||
btcRpc("generatetoaddress {} {}".format(num_blocks, cls.btc_addr))
|
btcRpc(f"generatetoaddress {num_blocks} {cls.btc_addr}")
|
||||||
|
|
||||||
ro = btcRpc("getblockchaininfo")
|
ro = btcRpc("getblockchaininfo")
|
||||||
checkForks(ro)
|
checkForks(ro)
|
||||||
@@ -449,7 +452,7 @@ class Test(unittest.TestCase):
|
|||||||
|
|
||||||
# Wait for height, or sequencelock is thrown off by genesis blocktime
|
# Wait for height, or sequencelock is thrown off by genesis blocktime
|
||||||
num_blocks = 3
|
num_blocks = 3
|
||||||
logging.info("Waiting for Particl chain height %d", num_blocks)
|
logging.info(f"Waiting for Particl chain height {num_blocks}")
|
||||||
for i in range(60):
|
for i in range(60):
|
||||||
particl_blocks = cls.swap_clients[0].callrpc("getblockcount")
|
particl_blocks = cls.swap_clients[0].callrpc("getblockcount")
|
||||||
print("particl_blocks", particl_blocks)
|
print("particl_blocks", particl_blocks)
|
||||||
@@ -473,7 +476,7 @@ class Test(unittest.TestCase):
|
|||||||
cls.swap_clients.clear()
|
cls.swap_clients.clear()
|
||||||
cls.daemons.clear()
|
cls.daemons.clear()
|
||||||
|
|
||||||
super(Test, cls).tearDownClass()
|
super().tearDownClass()
|
||||||
|
|
||||||
def test_02_part_dash(self):
|
def test_02_part_dash(self):
|
||||||
logging.info("---------- Test PART to DASH")
|
logging.info("---------- Test PART to DASH")
|
||||||
@@ -683,9 +686,9 @@ class Test(unittest.TestCase):
|
|||||||
offer_id = swap_clients[0].postOffer(
|
offer_id = swap_clients[0].postOffer(
|
||||||
Coins.DASH,
|
Coins.DASH,
|
||||||
Coins.BTC,
|
Coins.BTC,
|
||||||
0.001 * COIN,
|
0.01 * COIN,
|
||||||
1.0 * COIN,
|
1.0 * COIN,
|
||||||
0.001 * COIN,
|
0.01 * COIN,
|
||||||
SwapTypes.SELLER_FIRST,
|
SwapTypes.SELLER_FIRST,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -709,7 +712,7 @@ class Test(unittest.TestCase):
|
|||||||
del swap_clients[0].getChainClientSettings(Coins.DASH)["override_feerate"]
|
del swap_clients[0].getChainClientSettings(Coins.DASH)["override_feerate"]
|
||||||
|
|
||||||
def test_08_wallet(self):
|
def test_08_wallet(self):
|
||||||
logging.info("---------- Test {} wallet".format(self.test_coin_from.name))
|
logging.info(f"---------- Test {self.test_coin_from.name} wallet")
|
||||||
|
|
||||||
logging.info("Test withdrawal")
|
logging.info("Test withdrawal")
|
||||||
addr = dashRpc('getnewaddress "Withdrawal test"')
|
addr = dashRpc('getnewaddress "Withdrawal test"')
|
||||||
|
|||||||
@@ -747,14 +747,14 @@ class Test(BaseTest):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def tearDownClass(cls):
|
def tearDownClass(cls):
|
||||||
logging.info("Finalising Decred Test")
|
logging.info("Finalising Decred Test")
|
||||||
super(Test, cls).tearDownClass()
|
super().tearDownClass()
|
||||||
|
|
||||||
stopDaemons(cls.dcr_daemons)
|
stopDaemons(cls.dcr_daemons)
|
||||||
cls.dcr_daemons.clear()
|
cls.dcr_daemons.clear()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def coins_loop(cls):
|
def coins_loop(cls):
|
||||||
super(Test, cls).coins_loop()
|
super().coins_loop()
|
||||||
ci0 = cls.swap_clients[0].ci(cls.test_coin)
|
ci0 = cls.swap_clients[0].ci(cls.test_coin)
|
||||||
|
|
||||||
num_passed: int = 0
|
num_passed: int = 0
|
||||||
|
|||||||
@@ -179,6 +179,7 @@ class Test(TestFunctions):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def prepareExtraCoins(cls):
|
def prepareExtraCoins(cls):
|
||||||
|
super().prepareExtraCoins()
|
||||||
if cls.restore_instance:
|
if cls.restore_instance:
|
||||||
void_block_rewards_pubkey = cls.getRandomPubkey()
|
void_block_rewards_pubkey = cls.getRandomPubkey()
|
||||||
cls.doge_addr = (
|
cls.doge_addr = (
|
||||||
@@ -232,7 +233,7 @@ class Test(TestFunctions):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def tearDownClass(cls):
|
def tearDownClass(cls):
|
||||||
logging.info("Finalising DOGE Test")
|
logging.info("Finalising DOGE Test")
|
||||||
super(Test, cls).tearDownClass()
|
super().tearDownClass()
|
||||||
|
|
||||||
stopDaemons(cls.doge_daemons)
|
stopDaemons(cls.doge_daemons)
|
||||||
cls.doge_daemons.clear()
|
cls.doge_daemons.clear()
|
||||||
@@ -251,11 +252,12 @@ class Test(TestFunctions):
|
|||||||
"use_segwit": False,
|
"use_segwit": False,
|
||||||
"blocks_confirmed": 1,
|
"blocks_confirmed": 1,
|
||||||
"min_relay_fee": 0.01, # RECOMMENDED_MIN_TX_FEE
|
"min_relay_fee": 0.01, # RECOMMENDED_MIN_TX_FEE
|
||||||
|
"wallet_name": "bsx_wallet",
|
||||||
}
|
}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def coins_loop(cls):
|
def coins_loop(cls):
|
||||||
super(Test, cls).coins_loop()
|
super().coins_loop()
|
||||||
if cls.pause_chain:
|
if cls.pause_chain:
|
||||||
return
|
return
|
||||||
ci0 = cls.swap_clients[0].ci(cls.test_coin)
|
ci0 = cls.swap_clients[0].ci(cls.test_coin)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Copyright (c) 2024 The Basicswap developers
|
# Copyright (c) 2024-2026 The Basicswap developers
|
||||||
# Distributed under the MIT software license, see the accompanying
|
# Distributed under the MIT software license, see the accompanying
|
||||||
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
@@ -12,7 +12,7 @@ mkdir -p ${TEST_PATH}/bin
|
|||||||
cp -r ~/tmp/basicswap_bin/* ${TEST_PATH}/bin
|
cp -r ~/tmp/basicswap_bin/* ${TEST_PATH}/bin
|
||||||
export PYTHONPATH=$(pwd)
|
export PYTHONPATH=$(pwd)
|
||||||
export TEST_COINS_LIST='bitcoin,dogecoin'
|
export TEST_COINS_LIST='bitcoin,dogecoin'
|
||||||
python tests/basicswap/extended/test_doge.py
|
python tests/basicswap/extended/test_doge_with_prepare.py
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@@ -27,11 +27,9 @@ from tests.basicswap.extended.test_xmr_persistent import (
|
|||||||
BaseTestWithPrepare,
|
BaseTestWithPrepare,
|
||||||
UI_PORT,
|
UI_PORT,
|
||||||
)
|
)
|
||||||
from tests.basicswap.extended.test_scripts import (
|
|
||||||
wait_for_offers,
|
|
||||||
)
|
|
||||||
from tests.basicswap.util import (
|
from tests.basicswap.util import (
|
||||||
read_json_api,
|
read_json_api,
|
||||||
|
wait_for_offers,
|
||||||
)
|
)
|
||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
@@ -50,11 +48,11 @@ def wait_for_bid(
|
|||||||
|
|
||||||
bid = read_json_api(UI_PORT + node_id, f"bids/{bid_id}")
|
bid = read_json_api(UI_PORT + node_id, f"bids/{bid_id}")
|
||||||
|
|
||||||
if "state" not in bid:
|
if "bid_state" not in bid:
|
||||||
continue
|
continue
|
||||||
if state is None:
|
if state is None:
|
||||||
return
|
return
|
||||||
if bid["state"].lower() == state.lower():
|
if bid["bid_state"].lower() == state.lower():
|
||||||
return
|
return
|
||||||
raise ValueError("wait_for_bid failed")
|
raise ValueError("wait_for_bid failed")
|
||||||
|
|
||||||
@@ -101,8 +99,8 @@ def prepare_balance(
|
|||||||
|
|
||||||
|
|
||||||
class DOGETest(BaseTestWithPrepare):
|
class DOGETest(BaseTestWithPrepare):
|
||||||
|
__test__ = True
|
||||||
def test_a(self):
|
def test_a(self):
|
||||||
|
|
||||||
amount_from = 10.0
|
amount_from = 10.0
|
||||||
offer_json = {
|
offer_json = {
|
||||||
"coin_from": "btc",
|
"coin_from": "btc",
|
||||||
@@ -114,10 +112,8 @@ class DOGETest(BaseTestWithPrepare):
|
|||||||
"automation_strat_id": 1,
|
"automation_strat_id": 1,
|
||||||
}
|
}
|
||||||
offer_id = read_json_api(UI_PORT + 0, "offers/new", offer_json)["offer_id"]
|
offer_id = read_json_api(UI_PORT + 0, "offers/new", offer_json)["offer_id"]
|
||||||
logging.debug(f"offer_id {offer_id}")
|
|
||||||
|
|
||||||
prepare_balance(self.delay_event, 1, 0, "DOGE", 1000.0)
|
prepare_balance(self.delay_event, 1, 0, "DOGE", 1000.0)
|
||||||
|
|
||||||
wait_for_offers(self.delay_event, 1, 1, offer_id)
|
wait_for_offers(self.delay_event, 1, 1, offer_id)
|
||||||
|
|
||||||
post_json = {"offer_id": offer_id, "amount_from": amount_from}
|
post_json = {"offer_id": offer_id, "amount_from": amount_from}
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ def prepareDataDir(
|
|||||||
fp.write("debug=1\n")
|
fp.write("debug=1\n")
|
||||||
fp.write("debugexclude=libevent\n")
|
fp.write("debugexclude=libevent\n")
|
||||||
|
|
||||||
fp.write("fallbackfee=0.01\n")
|
fp.write("fallbackfee=0.0002\n")
|
||||||
fp.write("acceptnonstdtxn=0\n")
|
fp.write("acceptnonstdtxn=0\n")
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import unittest
|
|||||||
from tests.basicswap.util import (
|
from tests.basicswap.util import (
|
||||||
read_json_api,
|
read_json_api,
|
||||||
waitForServer,
|
waitForServer,
|
||||||
|
UI_PORT,
|
||||||
)
|
)
|
||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
@@ -37,9 +38,6 @@ if not len(logger.handlers):
|
|||||||
logger.addHandler(logging.StreamHandler(sys.stdout))
|
logger.addHandler(logging.StreamHandler(sys.stdout))
|
||||||
|
|
||||||
|
|
||||||
PORT_OFS = int(os.getenv("PORT_OFS", 1))
|
|
||||||
UI_PORT = 12700 + PORT_OFS
|
|
||||||
|
|
||||||
ELECTRUM_PATH = os.getenv("ELECTRUM_PATH")
|
ELECTRUM_PATH = os.getenv("ELECTRUM_PATH")
|
||||||
ELECTRUM_DATADIR = os.getenv("ELECTRUM_DATADIR")
|
ELECTRUM_DATADIR = os.getenv("ELECTRUM_DATADIR")
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Copyright (c) 2022-2023 tecnovert
|
# Copyright (c) 2022-2023 tecnovert
|
||||||
# Copyright (c) 2024-2025 The Basicswap developers
|
# Copyright (c) 2024-2026 The Basicswap developers
|
||||||
# Distributed under the MIT software license, see the accompanying
|
# Distributed under the MIT software license, see the accompanying
|
||||||
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
@@ -147,6 +147,7 @@ def prepareDir(datadir, nodeId, network_key, network_pubkey):
|
|||||||
|
|
||||||
fp.write("acceptnonstdtxn=0\n")
|
fp.write("acceptnonstdtxn=0\n")
|
||||||
fp.write("minstakeinterval=5\n")
|
fp.write("minstakeinterval=5\n")
|
||||||
|
fp.write("stakethreadconddelayms=1000\n")
|
||||||
fp.write("smsgsregtestadjust=0\n")
|
fp.write("smsgsregtestadjust=0\n")
|
||||||
|
|
||||||
for i in range(0, NUM_NODES):
|
for i in range(0, NUM_NODES):
|
||||||
@@ -293,7 +294,7 @@ class Test(unittest.TestCase):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
super(Test, cls).setUpClass()
|
super().setUpClass()
|
||||||
|
|
||||||
k = PrivateKey()
|
k = PrivateKey()
|
||||||
cls.network_key = toWIF(PREFIX_SECRET_KEY_REGTEST, k.secret)
|
cls.network_key = toWIF(PREFIX_SECRET_KEY_REGTEST, k.secret)
|
||||||
@@ -473,7 +474,7 @@ class Test(unittest.TestCase):
|
|||||||
cls.swap_clients.clear()
|
cls.swap_clients.clear()
|
||||||
cls.daemons.clear()
|
cls.daemons.clear()
|
||||||
|
|
||||||
super(Test, cls).tearDownClass()
|
super().tearDownClass()
|
||||||
|
|
||||||
def test_02_part_pivx(self):
|
def test_02_part_pivx(self):
|
||||||
logging.info("---------- Test PART to PIVX")
|
logging.info("---------- Test PART to PIVX")
|
||||||
@@ -500,7 +501,7 @@ class Test(unittest.TestCase):
|
|||||||
wait_for_in_progress(delay_event, swap_clients[1], bid_id, sent=True)
|
wait_for_in_progress(delay_event, swap_clients[1], bid_id, sent=True)
|
||||||
|
|
||||||
wait_for_bid(
|
wait_for_bid(
|
||||||
delay_event, swap_clients[0], bid_id, BidStates.SWAP_COMPLETED, wait_for=60
|
delay_event, swap_clients[0], bid_id, BidStates.SWAP_COMPLETED, wait_for=80
|
||||||
)
|
)
|
||||||
wait_for_bid(
|
wait_for_bid(
|
||||||
delay_event,
|
delay_event,
|
||||||
@@ -508,7 +509,7 @@ class Test(unittest.TestCase):
|
|||||||
bid_id,
|
bid_id,
|
||||||
BidStates.SWAP_COMPLETED,
|
BidStates.SWAP_COMPLETED,
|
||||||
sent=True,
|
sent=True,
|
||||||
wait_for=60,
|
wait_for=80,
|
||||||
)
|
)
|
||||||
|
|
||||||
js_0 = read_json_api(1800)
|
js_0 = read_json_api(1800)
|
||||||
@@ -548,7 +549,7 @@ class Test(unittest.TestCase):
|
|||||||
wait_for=60,
|
wait_for=60,
|
||||||
)
|
)
|
||||||
wait_for_bid(
|
wait_for_bid(
|
||||||
delay_event, swap_clients[1], bid_id, BidStates.SWAP_COMPLETED, wait_for=60
|
delay_event, swap_clients[1], bid_id, BidStates.SWAP_COMPLETED, wait_for=80
|
||||||
)
|
)
|
||||||
|
|
||||||
js_0 = read_json_api(1800)
|
js_0 = read_json_api(1800)
|
||||||
@@ -580,7 +581,7 @@ class Test(unittest.TestCase):
|
|||||||
wait_for_in_progress(delay_event, swap_clients[1], bid_id, sent=True)
|
wait_for_in_progress(delay_event, swap_clients[1], bid_id, sent=True)
|
||||||
|
|
||||||
wait_for_bid(
|
wait_for_bid(
|
||||||
delay_event, swap_clients[0], bid_id, BidStates.SWAP_COMPLETED, wait_for=60
|
delay_event, swap_clients[0], bid_id, BidStates.SWAP_COMPLETED, wait_for=80
|
||||||
)
|
)
|
||||||
wait_for_bid(
|
wait_for_bid(
|
||||||
delay_event,
|
delay_event,
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Copyright (c) 2023-2024 tecnovert
|
# Copyright (c) 2023-2024 tecnovert
|
||||||
# Copyright (c) 2024-2025 The Basicswap developers
|
# Copyright (c) 2024-2026 The Basicswap developers
|
||||||
# Distributed under the MIT software license, see the accompanying
|
# Distributed under the MIT software license, see the accompanying
|
||||||
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
@@ -36,6 +36,8 @@ from tests.basicswap.common import (
|
|||||||
from tests.basicswap.util import (
|
from tests.basicswap.util import (
|
||||||
read_json_api,
|
read_json_api,
|
||||||
waitForServer,
|
waitForServer,
|
||||||
|
wait_for_offers,
|
||||||
|
UI_PORT,
|
||||||
)
|
)
|
||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
@@ -44,10 +46,6 @@ if not len(logger.handlers):
|
|||||||
logger.addHandler(logging.StreamHandler(sys.stdout))
|
logger.addHandler(logging.StreamHandler(sys.stdout))
|
||||||
|
|
||||||
|
|
||||||
PORT_OFS = int(os.getenv("PORT_OFS", 1))
|
|
||||||
UI_PORT = 12700 + PORT_OFS
|
|
||||||
|
|
||||||
|
|
||||||
class HttpHandler(BaseHTTPRequestHandler):
|
class HttpHandler(BaseHTTPRequestHandler):
|
||||||
|
|
||||||
def js_response(self, url_split, post_string, is_json):
|
def js_response(self, url_split, post_string, is_json):
|
||||||
@@ -131,18 +129,6 @@ def clear_offers(delay_event, node_id) -> None:
|
|||||||
raise ValueError("clear_offers failed")
|
raise ValueError("clear_offers failed")
|
||||||
|
|
||||||
|
|
||||||
def wait_for_offers(delay_event, node_id, num_offers, offer_id=None) -> None:
|
|
||||||
logging.info(f"Waiting for {num_offers} offers on node {node_id}")
|
|
||||||
for i in range(20):
|
|
||||||
delay_event.wait(1)
|
|
||||||
offers = read_json_api(
|
|
||||||
UI_PORT + node_id, "offers" if offer_id is None else f"offers/{offer_id}"
|
|
||||||
)
|
|
||||||
if len(offers) >= num_offers:
|
|
||||||
return
|
|
||||||
raise ValueError("wait_for_offers failed")
|
|
||||||
|
|
||||||
|
|
||||||
def wait_for_bids(delay_event, node_id, num_bids, offer_id=None) -> None:
|
def wait_for_bids(delay_event, node_id, num_bids, offer_id=None) -> None:
|
||||||
logging.info(f"Waiting for {num_bids} bids on node {node_id}")
|
logging.info(f"Waiting for {num_bids} bids on node {node_id}")
|
||||||
for i in range(20):
|
for i in range(20):
|
||||||
|
|||||||
@@ -59,6 +59,8 @@ from tests.basicswap.util import (
|
|||||||
make_boolean,
|
make_boolean,
|
||||||
read_json_api,
|
read_json_api,
|
||||||
waitForServer,
|
waitForServer,
|
||||||
|
PORT_OFS,
|
||||||
|
UI_PORT,
|
||||||
)
|
)
|
||||||
from tests.basicswap.common_xmr import (
|
from tests.basicswap.common_xmr import (
|
||||||
prepare_nodes,
|
prepare_nodes,
|
||||||
@@ -73,9 +75,6 @@ import basicswap.bin.run as runSystem
|
|||||||
test_path = os.path.expanduser(os.getenv("TEST_PATH", "/tmp/test_persistent"))
|
test_path = os.path.expanduser(os.getenv("TEST_PATH", "/tmp/test_persistent"))
|
||||||
RESET_TEST = make_boolean(os.getenv("RESET_TEST", "true"))
|
RESET_TEST = make_boolean(os.getenv("RESET_TEST", "true"))
|
||||||
|
|
||||||
PORT_OFS = int(os.getenv("PORT_OFS", 1))
|
|
||||||
UI_PORT = 12700 + PORT_OFS
|
|
||||||
|
|
||||||
PARTICL_RPC_PORT_BASE = int(os.getenv("PARTICL_RPC_PORT_BASE", BASE_RPC_PORT))
|
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))
|
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))
|
LITECOIN_RPC_PORT_BASE = int(os.getenv("LITECOIN_RPC_PORT_BASE", LTC_BASE_RPC_PORT))
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Copyright (c) 2020 tecnovert
|
# Copyright (c) 2020 tecnovert
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Copyright (c) 2023 tecnovert
|
# Copyright (c) 2023 tecnovert
|
||||||
|
|||||||
@@ -306,11 +306,7 @@ class TestFunctions(BaseTest):
|
|||||||
def do_test_02_leader_recover_a_lock_tx(
|
def do_test_02_leader_recover_a_lock_tx(
|
||||||
self, coin_from: Coins, coin_to: Coins, lock_value: int = 32
|
self, coin_from: Coins, coin_to: Coins, lock_value: int = 32
|
||||||
) -> None:
|
) -> None:
|
||||||
logging.info(
|
logging.info(f"---------- Test {coin_from.name} to {coin_to.name} leader recovers coin a lock tx")
|
||||||
"---------- Test {} to {} leader recovers coin a lock tx".format(
|
|
||||||
coin_from.name, coin_to.name
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
id_offerer: int = self.node_a_id
|
id_offerer: int = self.node_a_id
|
||||||
id_bidder: int = self.node_b_id
|
id_bidder: int = self.node_b_id
|
||||||
@@ -499,23 +495,19 @@ class TestFunctions(BaseTest):
|
|||||||
# Test manually redeeming the no-script lock tx
|
# Test manually redeeming the no-script lock tx
|
||||||
offerer_key = read_json_api(
|
offerer_key = read_json_api(
|
||||||
1800 + id_offerer,
|
1800 + id_offerer,
|
||||||
"bids/{}".format(bid_id.hex()),
|
f"bids/{bid_id.hex()}",
|
||||||
{"chainbkeysplit": True},
|
{"chainbkeysplit": True},
|
||||||
)["splitkey"]
|
)["splitkey"]
|
||||||
data = {"spendchainblocktx": True, "remote_key": offerer_key}
|
data = {"spendchainblocktx": True, "remote_key": offerer_key}
|
||||||
redeemed_txid = read_json_api(
|
redeemed_txid = read_json_api(
|
||||||
1800 + id_bidder, "bids/{}".format(bid_id.hex()), data
|
1800 + id_bidder, f"bids/{bid_id.hex()}", data
|
||||||
)["txid"]
|
)["txid"]
|
||||||
assert len(redeemed_txid) == 64
|
assert len(redeemed_txid) == 64
|
||||||
|
|
||||||
def do_test_04_follower_recover_b_lock_tx(
|
def do_test_04_follower_recover_b_lock_tx(
|
||||||
self, coin_from, coin_to, lock_value: int = 32
|
self, coin_from, coin_to, lock_value: int = 32
|
||||||
):
|
):
|
||||||
logging.info(
|
logging.info(f"---------- Test {coin_from.name} to {coin_to.name} follower recovers coin b lock tx")
|
||||||
"---------- Test {} to {} follower recovers coin b lock tx".format(
|
|
||||||
coin_from.name, coin_to.name
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
id_offerer: int = self.node_a_id
|
id_offerer: int = self.node_a_id
|
||||||
id_bidder: int = self.node_b_id
|
id_bidder: int = self.node_b_id
|
||||||
|
|||||||
@@ -815,7 +815,7 @@ class BaseTest(unittest.TestCase):
|
|||||||
.pubkey_to_address(void_block_rewards_pubkey)
|
.pubkey_to_address(void_block_rewards_pubkey)
|
||||||
)
|
)
|
||||||
logging.info(
|
logging.info(
|
||||||
"Mining %d Litecoin blocks to %s", num_blocks, cls.ltc_addr
|
f"Mining {num_blocks} Litecoin blocks to {cls.ltc_addr}"
|
||||||
)
|
)
|
||||||
callnoderpc(
|
callnoderpc(
|
||||||
0,
|
0,
|
||||||
|
|||||||
+19
-2
@@ -1,4 +1,3 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Copyright (c) 2022-2024 tecnovert
|
# Copyright (c) 2022-2024 tecnovert
|
||||||
@@ -7,9 +6,15 @@
|
|||||||
# file LICENSE.txt or http://www.opensource.org/licenses/mit-license.php.
|
# file LICENSE.txt or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
import urllib
|
import urllib
|
||||||
from urllib.request import urlopen
|
from urllib.request import urlopen
|
||||||
|
|
||||||
|
|
||||||
|
PORT_OFS = int(os.getenv("PORT_OFS", 1))
|
||||||
|
UI_PORT = 12700 + PORT_OFS
|
||||||
|
|
||||||
REQUIRED_SETTINGS = {
|
REQUIRED_SETTINGS = {
|
||||||
"blocks_confirmed": 1,
|
"blocks_confirmed": 1,
|
||||||
"conf_target": 1,
|
"conf_target": 1,
|
||||||
@@ -67,5 +72,17 @@ def waitForServer(delay_event, port, wait_for=40):
|
|||||||
_ = read_json_api(port)
|
_ = read_json_api(port)
|
||||||
return
|
return
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("waitForServer, error:", str(e))
|
logging.error(f"waitForServer: {e}")
|
||||||
raise ValueError("waitForServer failed")
|
raise ValueError("waitForServer failed")
|
||||||
|
|
||||||
|
|
||||||
|
def wait_for_offers(delay_event, node_id, num_offers, offer_id=None) -> None:
|
||||||
|
logging.info(f"Waiting for {num_offers} offers on node {node_id}")
|
||||||
|
for i in range(20):
|
||||||
|
delay_event.wait(1)
|
||||||
|
offers = read_json_api(
|
||||||
|
UI_PORT + node_id, "offers" if offer_id is None else f"offers/{offer_id}"
|
||||||
|
)
|
||||||
|
if len(offers) >= num_offers:
|
||||||
|
return
|
||||||
|
raise ValueError("wait_for_offers failed")
|
||||||
|
|||||||
Reference in New Issue
Block a user