Host-customized fork of https://github.com/tecnovert/basicswap/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
2.9 KiB
83 lines
2.9 KiB
6 years ago
|
#!/usr/bin/env python3
|
||
|
# -*- coding: utf-8 -*-
|
||
|
|
||
|
# Copyright (c) 2019 tecnovert
|
||
|
# Distributed under the MIT software license, see the accompanying
|
||
4 years ago
|
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
||
6 years ago
|
|
||
|
import os
|
||
|
import sys
|
||
4 years ago
|
import json
|
||
|
import shutil
|
||
|
import logging
|
||
6 years ago
|
import unittest
|
||
4 years ago
|
|
||
6 years ago
|
from io import StringIO
|
||
4 years ago
|
from unittest.mock import patch
|
||
6 years ago
|
|
||
5 years ago
|
import basicswap.config as cfg
|
||
6 years ago
|
import bin.basicswap_prepare as prepareSystem
|
||
5 years ago
|
test_path = os.path.expanduser(os.getenv('TEST_PREPARE_PATH', '~/test_basicswap'))
|
||
6 years ago
|
|
||
|
logger = logging.getLogger()
|
||
|
logger.level = logging.DEBUG
|
||
6 years ago
|
if not len(logger.handlers):
|
||
|
logger.addHandler(logging.StreamHandler(sys.stdout))
|
||
6 years ago
|
|
||
|
|
||
|
class Test(unittest.TestCase):
|
||
|
@classmethod
|
||
|
def tearDownClass(self):
|
||
|
try:
|
||
|
shutil.rmtree(test_path)
|
||
5 years ago
|
except Exception as ex:
|
||
|
logger.warning('tearDownClass %s', str(ex))
|
||
5 years ago
|
super(Test, self).tearDownClass()
|
||
6 years ago
|
|
||
6 years ago
|
def test(self):
|
||
4 years ago
|
testargs = ['basicswap-prepare', '-datadir=' + test_path, '-withcoin=litecoin']
|
||
6 years ago
|
with patch.object(sys, 'argv', testargs):
|
||
|
prepareSystem.main()
|
||
|
|
||
5 years ago
|
config_path = os.path.join(test_path, cfg.CONFIG_FILENAME)
|
||
6 years ago
|
self.assertTrue(os.path.exists(config_path))
|
||
6 years ago
|
|
||
6 years ago
|
logger.info('Test no overwrite')
|
||
4 years ago
|
testargs = ['basicswap-prepare', '-datadir=' + test_path, '-withcoin=litecoin']
|
||
6 years ago
|
with patch('sys.stderr', new=StringIO()) as fake_stderr:
|
||
|
with patch.object(sys, 'argv', testargs):
|
||
|
with self.assertRaises(SystemExit) as cm:
|
||
|
prepareSystem.main()
|
||
|
|
||
|
self.assertEqual(cm.exception.code, 1)
|
||
|
logger.info('fake_stderr.getvalue() %s', fake_stderr.getvalue())
|
||
|
self.assertTrue('exists, exiting' in fake_stderr.getvalue())
|
||
|
|
||
6 years ago
|
logger.info('Test addcoin new')
|
||
|
testargs = ['basicswap-prepare', '-datadir=' + test_path, '-addcoin=namecoin']
|
||
|
with patch.object(sys, 'argv', testargs):
|
||
|
prepareSystem.main()
|
||
|
with open(config_path) as fs:
|
||
|
settings = json.load(fs)
|
||
|
self.assertTrue(settings['chainclients']['namecoin']['connection_type'] == 'rpc')
|
||
|
|
||
|
logger.info('Test disablecoin')
|
||
|
testargs = ['basicswap-prepare', '-datadir=' + test_path, '-disablecoin=namecoin']
|
||
|
with patch.object(sys, 'argv', testargs):
|
||
|
prepareSystem.main()
|
||
|
with open(config_path) as fs:
|
||
|
settings = json.load(fs)
|
||
|
self.assertTrue(settings['chainclients']['namecoin']['connection_type'] == 'none')
|
||
|
|
||
|
logger.info('Test addcoin existing')
|
||
5 years ago
|
testargs = ['basicswap-prepare', '-datadir=' + test_path, '-addcoin=namecoin']
|
||
6 years ago
|
with patch.object(sys, 'argv', testargs):
|
||
|
prepareSystem.main()
|
||
|
with open(config_path) as fs:
|
||
|
settings = json.load(fs)
|
||
|
self.assertTrue(settings['chainclients']['namecoin']['connection_type'] == 'rpc')
|
||
|
|
||
6 years ago
|
|
||
|
if __name__ == '__main__':
|
||
|
unittest.main()
|