tests: Fix intermittent failure

This commit is contained in:
tecnovert 2021-09-05 01:18:34 +02:00
parent 2562aec4bd
commit e69409514c
No known key found for this signature in database
GPG Key ID: 8ED6D8750C4E3F93
4 changed files with 237 additions and 215 deletions

View File

@ -4,6 +4,8 @@
# Distributed under the MIT software license, see the accompanying
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
import threading
from enum import IntEnum
from .util import (
COIN,
@ -208,6 +210,7 @@ class CoinInterface:
def __init__(self, network):
self.setDefaults()
self._network = network
self._mx_wallet = threading.Lock()
def setDefaults(self):
self._unknown_wallet_seed = True

View File

@ -245,6 +245,12 @@ class BTCInterface(CoinInterface):
return bytes(segwit_addr.decode(bech32_prefix, address)[1])
return decodeAddress(address)[1:]
def pubkey_to_segwit_address(self, pk):
bech32_prefix = chainparams[self.coin_type()][self._network]['hrp']
version = 0
pkh = hash160(pk)
return encode_segwit_address(bech32_prefix, version, pkh)
def getNewSecretKey(self):
return getSecretInt()
@ -830,6 +836,9 @@ class BTCInterface(CoinInterface):
tx.vout.append(self.txoType()(output_amount, p2wpkh))
return tx.serialize()
def encodeSharedAddress(self, Kbv, Kbs):
return self.pubkey_to_segwit_address(Kbs)
def publishBLockTx(self, Kbv, Kbs, output_amount, feerate):
b_lock_tx = self.createBLockTx(Kbs, output_amount)

View File

@ -78,6 +78,7 @@ class XMRInterface(CoinInterface):
self._wallet_filename = wallet_filename
def initialiseWallet(self, key_view, key_spend, restore_height=None):
with self._mx_wallet:
try:
self.rpc_wallet_cb('open_wallet', {'filename': self._wallet_filename})
# TODO: Check address
@ -101,6 +102,7 @@ class XMRInterface(CoinInterface):
self.rpc_wallet_cb('open_wallet', {'filename': self._wallet_filename})
def ensureWalletExists(self):
with self._mx_wallet:
self.rpc_wallet_cb('open_wallet', {'filename': self._wallet_filename})
def testDaemonRPC(self):
@ -125,6 +127,7 @@ class XMRInterface(CoinInterface):
return self.rpc_cb2('get_height')['height']
def getWalletInfo(self):
with self._mx_wallet:
self.rpc_wallet_cb('open_wallet', {'filename': self._wallet_filename})
rv = {}
self.rpc_wallet_cb('refresh')
@ -137,10 +140,12 @@ class XMRInterface(CoinInterface):
return self._restore_height
def getMainWalletAddress(self):
with self._mx_wallet:
self.rpc_wallet_cb('open_wallet', {'filename': self._wallet_filename})
return self.rpc_wallet_cb('get_address')['address']
def getNewAddress(self, placeholder):
with self._mx_wallet:
self._log.warning('TODO - subaddress?')
self.rpc_wallet_cb('open_wallet', {'filename': self._wallet_filename})
return self.rpc_wallet_cb('get_address')['address']
@ -199,7 +204,11 @@ class XMRInterface(CoinInterface):
def sumPubkeys(self, Ka, Kb):
return ed25519_add(Ka, Kb)
def encodeSharedAddress(self, Kbv, Kbs):
return xmr_util.encode_address(Kbv, Kbs)
def publishBLockTx(self, Kbv, Kbs, output_amount, feerate):
with self._mx_wallet:
self.rpc_wallet_cb('open_wallet', {'filename': self._wallet_filename})
shared_addr = xmr_util.encode_address(Kbv, Kbs)
@ -223,6 +232,7 @@ class XMRInterface(CoinInterface):
return tx_hash
def findTxB(self, kbv, Kbs, cb_swap_value, cb_block_confirmed, restore_height):
with self._mx_wallet:
Kbv = self.getPubkey(kbv)
address_b58 = xmr_util.encode_address(Kbv, Kbs)
@ -246,7 +256,7 @@ class XMRInterface(CoinInterface):
self._log.info('generate_from_keys %s', dumpj(rv))
rv = self.rpc_wallet_cb('open_wallet', {'filename': address_b58})
rv = self.rpc_wallet_cb('refresh', timeout=600)
self.rpc_wallet_cb('refresh', timeout=600)
'''
# Debug
@ -270,7 +280,7 @@ class XMRInterface(CoinInterface):
return None
def waitForLockTxB(self, kbv, Kbs, cb_swap_value, cb_block_confirmed, restore_height):
with self._mx_wallet:
Kbv_enc = self.encodePubkey(self.pubkey(kbv))
address_b58 = xmr_util.encode_address(Kbv_enc, self.encodePubkey(Kbs))
@ -331,6 +341,7 @@ class XMRInterface(CoinInterface):
return False
def findTxnByHash(self, txid):
with self._mx_wallet:
self.rpc_wallet_cb('open_wallet', {'filename': self._wallet_filename})
self.rpc_wallet_cb('refresh')
@ -345,7 +356,6 @@ class XMRInterface(CoinInterface):
rv = self.rpc_wallet_cb('incoming_transfers', params)
if 'transfers' in rv:
for transfer in rv['transfers']:
print('[rm] transfer', transfer)
if transfer['tx_hash'] == txid \
and (current_height is None or current_height - transfer['block_height'] > self.blocks_confirmed):
return {'txid': transfer['tx_hash'], 'amount': transfer['amount'], 'height': transfer['block_height']}
@ -353,7 +363,7 @@ class XMRInterface(CoinInterface):
return None
def spendBLockTx(self, address_to, kbv, kbs, cb_swap_value, b_fee_rate, restore_height):
with self._mx_wallet:
Kbv = self.getPubkey(kbv)
Kbs = self.getPubkey(kbs)
address_b58 = xmr_util.encode_address(Kbv, Kbs)
@ -404,6 +414,7 @@ class XMRInterface(CoinInterface):
return bytes.fromhex(rv['tx_hash_list'][0])
def withdrawCoin(self, value, addr_to, subfee):
with self._mx_wallet:
value_sats = make_int(value, self.exp())
self.rpc_wallet_cb('open_wallet', {'filename': self._wallet_filename})

View File

@ -246,7 +246,6 @@ def run_coins_loop(cls):
try:
if cls.btc_addr is not None:
btcRpc('generatetoaddress 1 {}'.format(cls.btc_addr))
logging.warning('cls.xmr_addr ' + str(cls.xmr_addr))
if cls.xmr_addr is not None:
callrpc_xmr_na(XMR_BASE_RPC_PORT + 1, 'generateblocks', {'wallet_address': cls.xmr_addr, 'amount_of_blocks': 1})
except Exception as e: