diff --git a/basicswap/basicswap.py b/basicswap/basicswap.py index ac11c27..22106b5 100644 --- a/basicswap/basicswap.py +++ b/basicswap/basicswap.py @@ -727,7 +727,7 @@ class BasicSwap(BaseApp): return root_key = self.getWalletKey(coin_type, 1) - root_hash = ci.getAddressHashFromKey(root_key)[::-1] + root_hash = ci.getSeedHash(root_key) try: ci.initialiseWallet(root_key) diff --git a/basicswap/interface/btc.py b/basicswap/interface/btc.py index aeff269..1115f42 100644 --- a/basicswap/interface/btc.py +++ b/basicswap/interface/btc.py @@ -371,6 +371,9 @@ class BTCInterface(CoinInterface): pk = self.getPubkey(key) return hash160(pk) + def getSeedHash(self, seed): + return self.getAddressHashFromKey(seed)[::-1] + def verifyKey(self, k): i = b2i(k) return (i < ep.o and i > 0) diff --git a/basicswap/interface/firo.py b/basicswap/interface/firo.py index a6e46d8..4ec421e 100644 --- a/basicswap/interface/firo.py +++ b/basicswap/interface/firo.py @@ -156,6 +156,9 @@ class FIROInterface(BTCInterface): return CScript([OP_HASH160, script_hash_hash, OP_EQUAL]) + def getSeedHash(self, seed): + return hash160(seed)[::-1] + def encodeScriptDest(self, script): # Extract hash from script script_hash = script[2:-1] diff --git a/tests/basicswap/extended/test_firo.py b/tests/basicswap/extended/test_firo.py index 638beb8..1e00ee7 100644 --- a/tests/basicswap/extended/test_firo.py +++ b/tests/basicswap/extended/test_firo.py @@ -112,6 +112,13 @@ class Test(BaseTest): test_atomic = True test_xmr = False + # Particl node mnemonics are set in test/basicswap/mnemonics.py + firo_seeds = [ + 'd90b7ed1be614e1c172653aee1f3b6230f43b7fa99cf07fa984a17966ad81de7', + '6c81d6d74ba33a0db9e41518c2b6789fbe938e98018a4597dac661cfc5f2dfc1', + 'c5de2be44834e7e47ad7dc8e35c6b77c79f17c6bb40d5509a00fc3dff384a865', + ] + @classmethod def setUpClass(cls): cls.start_ltc_nodes = False @@ -121,11 +128,13 @@ class Test(BaseTest): @classmethod def prepareExtraDataDir(cls, i): if not cls.restore_instance: + seed_hex = cls.firo_seeds[i] + extra_opts = [f'-hdseed={seed_hex}', ] data_dir = prepareDataDir(cfg.TEST_DATADIRS, i, 'firo.conf', 'firo_', base_p2p_port=FIRO_BASE_PORT, base_rpc_port=FIRO_BASE_RPC_PORT) if os.path.exists(os.path.join(cfg.FIRO_BINDIR, 'firo-wallet')): callrpc_cli(cfg.FIRO_BINDIR, data_dir, 'regtest', '-wallet=wallet.dat create', 'firo-wallet') - cls.firo_daemons.append(startDaemon(os.path.join(cfg.TEST_DATADIRS, 'firo_' + str(i)), cfg.FIRO_BINDIR, cfg.FIROD)) + cls.firo_daemons.append(startDaemon(os.path.join(cfg.TEST_DATADIRS, 'firo_' + str(i)), cfg.FIRO_BINDIR, cfg.FIROD, opts=extra_opts)) logging.info('Started %s %d', cfg.FIROD, cls.part_daemons[-1].pid) waitForRPC(make_rpc_func(i, base_rpc_port=FIRO_BASE_RPC_PORT)) @@ -193,7 +202,7 @@ class Test(BaseTest): def callnoderpc(self, method, params=[], wallet=None, node_id=0): return callnoderpc(node_id, method, params, wallet, base_rpc_port=FIRO_BASE_RPC_PORT) - def test_01_firo(self): + def test_001_firo(self): logging.info('---------- Test {} segwit'.format(self.test_coin_from.name)) ''' @@ -244,6 +253,16 @@ class Test(BaseTest): assert tx_funded_decoded['txid'] != tx_signed_decoded['txid'] assert txid_with_scriptsig == tx_signed_decoded['txid'] + def test_007_hdwallet(self): + logging.info('---------- Test {} hdwallet'.format(self.test_coin_from.name)) + + swap_client = self.swap_clients[0] + # Run initialiseWallet to set 'main_wallet_seedid_' + swap_client.initialiseWallet(self.test_coin_from) + ci = swap_client.ci(self.test_coin_from) + assert ('490ba1e2c3894d5534c467141ee3cdf77292c362' == ci.getWalletSeedID()) + assert swap_client.checkWalletSeed(self.test_coin_from) is True + def test_02_part_coin(self): logging.info('---------- Test PART to {}'.format(self.test_coin_from.name)) if not self.test_atomic: diff --git a/tests/basicswap/test_btc_xmr.py b/tests/basicswap/test_btc_xmr.py index 9a48cb7..7e7d964 100644 --- a/tests/basicswap/test_btc_xmr.py +++ b/tests/basicswap/test_btc_xmr.py @@ -236,6 +236,18 @@ class Test(BaseTest): block = self.callnoderpc('getblock', [best_hash, 2]) assert ('vin' in block['tx'][0]) + def test_007_hdwallet(self): + logging.info('---------- Test {} hdwallet'.format(self.test_coin_from.name)) + + test_seed = '8e54a313e6df8918df6d758fafdbf127a115175fdd2238d0e908dd8093c9ac3b' + test_wif = self.swap_clients[0].ci(self.test_coin_from).encodeKey(bytes.fromhex(test_seed)) + new_wallet_name = random.randbytes(10).hex() + self.callnoderpc('createwallet', [new_wallet_name]) + self.callnoderpc('sethdseed', [True, test_wif], wallet=new_wallet_name) + addr = self.callnoderpc('getnewaddress', wallet=new_wallet_name) + self.callnoderpc('unloadwallet', [new_wallet_name]) + assert (addr == 'bcrt1qps7hnjd866e9ynxadgseprkc2l56m00dvwargr') + def test_01_full_swap(self): logging.info('---------- Test {} to XMR'.format(self.test_coin_from.name)) swap_clients = self.swap_clients