mirror of
https://github.com/basicswap/basicswap.git
synced 2025-11-14 22:38:10 +01:00
coins: Add LTC MWEB wallet
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (c) 2021-2022 tecnovert
|
||||
# Copyright (c) 2021-2023 tecnovert
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
@@ -24,9 +24,10 @@ from tests.basicswap.common import (
|
||||
wait_for_bid,
|
||||
wait_for_offer,
|
||||
wait_for_in_progress,
|
||||
TEST_HTTP_PORT,
|
||||
LTC_BASE_RPC_PORT,
|
||||
)
|
||||
from .test_btc_xmr import BasicSwapTest, test_delay_event
|
||||
from .test_btc_xmr import BasicSwapTest, test_delay_event, callnoderpc
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
@@ -37,9 +38,20 @@ class TestLTC(BasicSwapTest):
|
||||
start_ltc_nodes = True
|
||||
base_rpc_port = LTC_BASE_RPC_PORT
|
||||
|
||||
@classmethod
|
||||
def prepareExtraCoins(cls):
|
||||
logging.info('Mining {} chain to height 1352 to activate CVS (BIP66)'.format(cls.test_coin_from.name))
|
||||
chain_height = callnoderpc(0, 'getblockcount', base_rpc_port=LTC_BASE_RPC_PORT)
|
||||
num_blocks: int = 1352 - chain_height
|
||||
callnoderpc(0, 'generatetoaddress', [num_blocks, cls.ltc_addr], base_rpc_port=LTC_BASE_RPC_PORT)
|
||||
|
||||
def mineBlock(self, num_blocks=1):
|
||||
self.callnoderpc('generatetoaddress', [num_blocks, self.ltc_addr])
|
||||
|
||||
def check_softfork_active(self, feature_name):
|
||||
deploymentinfo = self.callnoderpc('getblockchaininfo')
|
||||
assert (deploymentinfo['softforks'][feature_name]['active'] is True)
|
||||
|
||||
def test_001_nested_segwit(self):
|
||||
logging.info('---------- Test {} p2sh nested segwit'.format(self.test_coin_from.name))
|
||||
logging.info('Skipped')
|
||||
@@ -47,17 +59,18 @@ class TestLTC(BasicSwapTest):
|
||||
def test_002_native_segwit(self):
|
||||
logging.info('---------- Test {} p2sh native segwit'.format(self.test_coin_from.name))
|
||||
|
||||
addr_segwit = self.callnoderpc('getnewaddress', ['segwit test', 'bech32'])
|
||||
addr_info = self.callnoderpc('getaddressinfo', [addr_segwit, ])
|
||||
ci = self.swap_clients[0].ci(self.test_coin_from)
|
||||
addr_segwit = ci.rpc_wallet('getnewaddress', ['segwit test', 'bech32'])
|
||||
addr_info = ci.rpc_wallet('getaddressinfo', [addr_segwit, ])
|
||||
assert addr_info['iswitness'] is True
|
||||
|
||||
txid = self.callnoderpc('sendtoaddress', [addr_segwit, 1.0])
|
||||
txid = ci.rpc_wallet('sendtoaddress', [addr_segwit, 1.0])
|
||||
assert len(txid) == 64
|
||||
tx_wallet = self.callnoderpc('gettransaction', [txid, ])['hex']
|
||||
tx = self.callnoderpc('decoderawtransaction', [tx_wallet, ])
|
||||
tx_wallet = ci.rpc_wallet('gettransaction', [txid, ])['hex']
|
||||
tx = ci.rpc('decoderawtransaction', [tx_wallet, ])
|
||||
|
||||
self.mineBlock()
|
||||
ro = self.callnoderpc('scantxoutset', ['start', ['addr({})'.format(addr_segwit)]])
|
||||
ro = ci.rpc('scantxoutset', ['start', ['addr({})'.format(addr_segwit)]])
|
||||
assert (len(ro['unspents']) == 1)
|
||||
assert (ro['unspents'][0]['txid'] == txid)
|
||||
|
||||
@@ -68,10 +81,10 @@ class TestLTC(BasicSwapTest):
|
||||
break
|
||||
assert prevout_n > -1
|
||||
|
||||
tx_funded = self.callnoderpc('createrawtransaction', [[{'txid': txid, 'vout': prevout_n}], {addr_segwit: 0.99}])
|
||||
tx_signed = self.callnoderpc('signrawtransactionwithwallet', [tx_funded, ])['hex']
|
||||
tx_funded_decoded = self.callnoderpc('decoderawtransaction', [tx_funded, ])
|
||||
tx_signed_decoded = self.callnoderpc('decoderawtransaction', [tx_signed, ])
|
||||
tx_funded = ci.rpc('createrawtransaction', [[{'txid': txid, 'vout': prevout_n}], {addr_segwit: 0.99}])
|
||||
tx_signed = ci.rpc_wallet('signrawtransactionwithwallet', [tx_funded, ])['hex']
|
||||
tx_funded_decoded = ci.rpc('decoderawtransaction', [tx_funded, ])
|
||||
tx_signed_decoded = ci.rpc('decoderawtransaction', [tx_signed, ])
|
||||
assert tx_funded_decoded['txid'] == tx_signed_decoded['txid']
|
||||
|
||||
def test_007_hdwallet(self):
|
||||
@@ -108,6 +121,115 @@ class TestLTC(BasicSwapTest):
|
||||
assert (js_0['num_swapping'] == 0 and js_0['num_watched_outputs'] == 0)
|
||||
assert (js_1['num_swapping'] == 0 and js_1['num_watched_outputs'] == 0)
|
||||
|
||||
def test_21_mweb(self):
|
||||
logging.info('---------- Test MWEB {}'.format(self.test_coin_from.name))
|
||||
swap_clients = self.swap_clients
|
||||
|
||||
ci0 = swap_clients[0].ci(self.test_coin_from)
|
||||
ci1 = swap_clients[1].ci(self.test_coin_from)
|
||||
|
||||
mweb_addr_0 = ci0.rpc_wallet('getnewaddress', ['mweb addr test 0', 'mweb'])
|
||||
mweb_addr_1 = ci1.rpc_wallet('getnewaddress', ['mweb addr test 1', 'mweb'])
|
||||
|
||||
addr_info0 = ci0.rpc_wallet('getaddressinfo', [mweb_addr_0,])
|
||||
assert (addr_info0['ismweb'] is True)
|
||||
|
||||
addr_info1 = ci1.rpc_wallet('getaddressinfo', [mweb_addr_1,])
|
||||
assert (addr_info1['ismweb'] is True)
|
||||
|
||||
txid = ci0.rpc_wallet('sendtoaddress', [mweb_addr_0, 10.0])
|
||||
|
||||
self.mineBlock()
|
||||
|
||||
txns = ci0.rpc_wallet('listtransactions')
|
||||
|
||||
utxos = ci0.rpc_wallet('listunspent')
|
||||
balances = ci0.rpc_wallet('getbalances')
|
||||
wi = ci0.rpc_wallet('getwalletinfo')
|
||||
|
||||
txid = ci0.rpc_wallet('sendtoaddress', [mweb_addr_1, 10.0])
|
||||
|
||||
self.mineBlock()
|
||||
|
||||
txns = ci1.rpc_wallet('listtransactions')
|
||||
|
||||
utxos = ci1.rpc_wallet('listunspent')
|
||||
balances = ci1.rpc_wallet('getbalances')
|
||||
wi = ci1.rpc_wallet('getwalletinfo')
|
||||
|
||||
mweb_tx = None
|
||||
for utxo in utxos:
|
||||
if utxo.get('address', '') == mweb_addr_1:
|
||||
mweb_tx = utxo
|
||||
assert (mweb_tx is not None)
|
||||
|
||||
tx = ci1.rpc_wallet('gettransaction', [mweb_tx['txid'],])
|
||||
|
||||
blockhash = tx['blockhash']
|
||||
block = ci1.rpc('getblock', [blockhash, 3])
|
||||
block = ci1.rpc('getblock', [blockhash, 0])
|
||||
|
||||
# TODO
|
||||
|
||||
def test_22_mweb_balance(self):
|
||||
logging.info('---------- Test MWEB balance {}'.format(self.test_coin_from.name))
|
||||
swap_clients = self.swap_clients
|
||||
|
||||
ci_mweb = swap_clients[0].ci(Coins.LTC_MWEB)
|
||||
mweb_addr_0 = ci_mweb.getNewAddress()
|
||||
addr_info0 = ci_mweb.rpc_wallet('getaddressinfo', [mweb_addr_0,])
|
||||
assert (addr_info0['ismweb'] is True)
|
||||
|
||||
ltc_addr = read_json_api(TEST_HTTP_PORT + 0, 'wallets/ltc/nextdepositaddr')
|
||||
ltc_mweb_addr = read_json_api(TEST_HTTP_PORT + 0, 'wallets/ltc_mweb/nextdepositaddr')
|
||||
ltc_mweb_addr2 = read_json_api(TEST_HTTP_PORT + 0, 'wallets/ltc/newmwebaddress')
|
||||
|
||||
assert (ci_mweb.rpc_wallet('getaddressinfo', [ltc_addr,])['ismweb'] is False)
|
||||
assert (ci_mweb.rpc_wallet('getaddressinfo', [ltc_mweb_addr,])['ismweb'] is True)
|
||||
assert (ci_mweb.rpc_wallet('getaddressinfo', [ltc_mweb_addr2,])['ismweb'] is True)
|
||||
|
||||
post_json = {
|
||||
'value': 10,
|
||||
'address': ltc_mweb_addr,
|
||||
'subfee': False,
|
||||
}
|
||||
json_rv = read_json_api(TEST_HTTP_PORT + 0, 'wallets/ltc/withdraw', post_json)
|
||||
assert (len(json_rv['txid']) == 64)
|
||||
|
||||
self.mineBlock()
|
||||
|
||||
json_rv = read_json_api(TEST_HTTP_PORT + 0, 'wallets/ltc', post_json)
|
||||
assert (json_rv['mweb_balance'] == 10.0)
|
||||
mweb_address = json_rv['mweb_address']
|
||||
|
||||
post_json = {
|
||||
'value': 11,
|
||||
'address': mweb_address,
|
||||
'subfee': False,
|
||||
}
|
||||
json_rv = read_json_api(TEST_HTTP_PORT + 0, 'wallets/ltc/withdraw', post_json)
|
||||
assert (len(json_rv['txid']) == 64)
|
||||
|
||||
self.mineBlock()
|
||||
|
||||
json_rv = read_json_api(TEST_HTTP_PORT + 0, 'wallets/ltc_mweb', post_json)
|
||||
assert (json_rv['mweb_balance'] == 21.0)
|
||||
assert (json_rv['mweb_address'] == mweb_address)
|
||||
ltc_address = json_rv['deposit_address']
|
||||
|
||||
# Check that spending the mweb balance takes from the correct wallet
|
||||
post_json = {
|
||||
'value': 1,
|
||||
'address': ltc_address,
|
||||
'subfee': False,
|
||||
'type_from': 'mweb',
|
||||
}
|
||||
json_rv = read_json_api(TEST_HTTP_PORT + 0, 'wallets/ltc/withdraw', post_json)
|
||||
assert (len(json_rv['txid']) == 64)
|
||||
|
||||
json_rv = read_json_api(TEST_HTTP_PORT + 0, 'wallets/ltc', post_json)
|
||||
assert (json_rv['mweb_balance'] <= 20.0)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user