Example #1
0
    def setUpClass(cls):
        super(Test, cls).setUpClass()

        for i in range(2):
            client_path = os.path.join(test_path, 'client{}'.format(i))
            config_path = os.path.join(client_path, cfg.CONFIG_FILENAME)
            try:
                shutil.rmtree(client_path)
            except Exception as ex:
                logger.warning('setUpClass %s', str(ex))
            testargs = [
                'basicswap-prepare',
                '-datadir="{}"'.format(client_path),
                '-bindir="{}"'.format(os.path.join(test_path, 'bin')),
                '-portoffset={}'.format(i),
                '-particl_mnemonic="{}"'.format(mnemonics[0]),
                '-regtest', '-withoutcoin=litecoin', '-withcoin=monero,bitcoin']
            with patch.object(sys, 'argv', testargs):
                prepareSystem.main()

            with open(os.path.join(client_path, 'particl', 'particl.conf'), 'r') as fp:
                lines = fp.readlines()
            with open(os.path.join(client_path, 'particl', 'particl.conf'), 'w') as fp:
                for line in lines:
                    if not line.startswith('staking'):
                        fp.write(line)
                fp.write('port={}\n'.format(PARTICL_PORT_BASE + i))
                fp.write('bind=127.0.0.1\n')
                fp.write('dnsseed=0\n')
                fp.write('minstakeinterval=5\n')
                for ip in range(3):
                    if ip != i:
                        fp.write('connect=localhost:{}\n'.format(PARTICL_PORT_BASE + ip))

            # Pruned nodes don't provide blocks
            with open(os.path.join(client_path, 'bitcoin', 'bitcoin.conf'), 'r') as fp:
                lines = fp.readlines()
            with open(os.path.join(client_path, 'bitcoin', 'bitcoin.conf'), 'w') as fp:
                for line in lines:
                    if not line.startswith('prune'):
                        fp.write(line)
                fp.write('port={}\n'.format(BITCOIN_PORT_BASE + i))
                fp.write('discover=0\n')
                fp.write('dnsseed=0\n')
                fp.write('listenonion=0\n')
                fp.write('upnp=0\n')
                fp.write('bind=127.0.0.1\n')
                for ip in range(3):
                    if ip != i:
                        fp.write('connect=localhost:{}\n'.format(BITCOIN_PORT_BASE + ip))

            with open(os.path.join(client_path, 'monero', 'monerod.conf'), 'a') as fp:
                fp.write('p2p-bind-ip=127.0.0.1\n')
                fp.write('p2p-bind-port={}\n'.format(XMR_BASE_P2P_PORT + i))
                for ip in range(3):
                    if ip != i:
                        fp.write('add-exclusive-node=127.0.0.1:{}\n'.format(XMR_BASE_P2P_PORT + ip))

            assert(os.path.exists(config_path))
Example #2
0
    def test(self):
        testargs = [
            'basicswap-prepare', '-datadir=' + test_path, '-withcoin=litecoin'
        ]
        with patch.object(sys, 'argv', testargs):
            prepareSystem.main()

        config_path = os.path.join(test_path, cfg.CONFIG_FILENAME)
        self.assertTrue(os.path.exists(config_path))

        logger.info('Test no overwrite')
        testargs = [
            'basicswap-prepare', '-datadir=' + test_path, '-withcoin=litecoin'
        ]
        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())

        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')
        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')
Example #3
0
    def setUpClass(cls):
        super(Test, cls).setUpClass()

        config_path = os.path.join(test_path, 'basicswap.json')
        try:
            os.remove(config_path)
            shutil.rmtree(os.path.join(test_path, 'particl'))
            shutil.rmtree(os.path.join(test_path, 'bitcoin'))
        except Exception as ex:
            logger.warning('setUpClass %s', str(ex))

        testargs = ['basicswap-prepare', '-datadir=' + test_path, '-regtest', '-withoutcoin=litecoin', '-withcoin=bitcoin']
        with patch.object(sys, 'argv', testargs):
            prepareSystem.main()

        assert(os.path.exists(config_path))
Example #4
0
    def setUpClass(cls):
        super(XmrTestBase, cls).setUpClass()

        cls.delay_event = threading.Event()
        cls.update_thread = None
        cls.processes = []

        for i in range(3):
            client_path = os.path.join(test_path, 'client{}'.format(i))
            config_path = os.path.join(client_path, cfg.CONFIG_FILENAME)
            try:
                shutil.rmtree(client_path)
            except Exception as ex:
                logging.warning('setUpClass %s', str(ex))
            testargs = [
                'basicswap-prepare', '-datadir="{}"'.format(client_path),
                '-bindir="{}"'.format(os.path.join(test_path, 'bin')),
                '-portoffset={}'.format(i),
                '-particl_mnemonic="{}"'.format(mnemonics[i]), '-regtest',
                '-withcoin=monero', '-noextractover', '-xmrrestoreheight=0'
            ]
            with patch.object(sys, 'argv', testargs):
                prepareSystem.main()

            with open(os.path.join(client_path, 'particl', 'particl.conf'),
                      'r') as fp:
                lines = fp.readlines()
            with open(os.path.join(client_path, 'particl', 'particl.conf'),
                      'w') as fp:
                for line in lines:
                    if not line.startswith('staking'):
                        fp.write(line)
                fp.write('port={}\n'.format(PARTICL_PORT_BASE + i))
                fp.write('bind=127.0.0.1\n')
                fp.write('dnsseed=0\n')
                fp.write('discover=0\n')
                fp.write('listenonion=0\n')
                fp.write('upnp=0\n')
                fp.write('minstakeinterval=5\n')
                fp.write('smsgsregtestadjust=0\n')
                for ip in range(3):
                    if ip != i:
                        fp.write(
                            'connect=127.0.0.1:{}\n'.format(PARTICL_PORT_BASE +
                                                            ip))

            with open(os.path.join(client_path, 'monero', 'monerod.conf'),
                      'a') as fp:
                fp.write('p2p-bind-ip=127.0.0.1\n')
                fp.write('p2p-bind-port={}\n'.format(XMR_BASE_P2P_PORT + i))
                for ip in range(3):
                    if ip != i:
                        fp.write('add-exclusive-node=127.0.0.1:{}\n'.format(
                            XMR_BASE_P2P_PORT + ip))

            with open(config_path) as fs:
                settings = json.load(fs)

            settings['min_delay_event'] = 1
            settings['max_delay_event'] = 4
            settings['min_delay_retry'] = 10
            settings['max_delay_retry'] = 20

            settings['check_progress_seconds'] = 5
            settings['check_watched_seconds'] = 5
            settings['check_expired_seconds'] = 60
            settings['check_events_seconds'] = 5
            settings['check_xmr_swaps_seconds'] = 5

            with open(config_path, 'w') as fp:
                json.dump(settings, fp, indent=4)

        signal.signal(
            signal.SIGINT,
            lambda signal, frame: cls.signal_handler(cls, signal, frame))
Example #5
0
    def setUpClass(cls):
        super(Test, cls).setUpClass()

        cls.update_min = int(os.getenv('UPDATE_THREAD_MIN_WAIT', '1'))
        cls.update_max = cls.update_min * 4

        cls.xmr_update_min = int(os.getenv('XMR_UPDATE_THREAD_MIN_WAIT', '1'))
        cls.xmr_update_max = cls.xmr_update_min * 4

        cls.delay_event = threading.Event()
        cls.update_thread = None
        cls.update_thread_xmr = None
        cls.processes = []
        cls.btc_addr = None
        cls.xmr_addr = None

        random.seed(time.time())

        logging.info('Preparing %d nodes.', NUM_NODES)
        for i in range(NUM_NODES):
            logging.info('Preparing node: %d.', i)
            client_path = os.path.join(test_path, 'client{}'.format(i))
            config_path = os.path.join(client_path, cfg.CONFIG_FILENAME)
            if RESET_TEST:
                try:
                    logging.info('Removing dir %s', client_path)
                    shutil.rmtree(client_path)
                except Exception as ex:
                    logging.warning('setUpClass %s', str(ex))

            if not os.path.exists(config_path):

                os.environ['PART_RPC_PORT'] = str(BASE_PART_RPC_PORT)
                os.environ['BTC_RPC_PORT'] = str(BASE_BTC_RPC_PORT)

                testargs = [
                    'basicswap-prepare', '-datadir="{}"'.format(client_path),
                    '-bindir="{}"'.format(os.path.join(test_path, 'bin')),
                    '-portoffset={}'.format(i + PORT_OFS), '-regtest',
                    '-withcoins=monero,bitcoin', '-noextractover',
                    '-xmrrestoreheight=0'
                ]
                if i < len(test_mnemonics):
                    testargs.append('-particl_mnemonic="{}"'.format(
                        test_mnemonics[i]))
                with patch.object(sys, 'argv', testargs):
                    prepareSystem.main()

                with open(os.path.join(client_path, 'particl', 'particl.conf'),
                          'r') as fp:
                    lines = fp.readlines()
                with open(os.path.join(client_path, 'particl', 'particl.conf'),
                          'w') as fp:
                    for line in lines:
                        if not line.startswith('staking'):
                            fp.write(line)
                    fp.write('port={}\n'.format(PARTICL_PORT_BASE + i +
                                                PORT_OFS))
                    fp.write('bind=127.0.0.1\n')
                    fp.write('dnsseed=0\n')
                    fp.write('discover=0\n')
                    fp.write('listenonion=0\n')
                    fp.write('upnp=0\n')
                    fp.write('minstakeinterval=5\n')
                    fp.write('smsgsregtestadjust=0\n')
                    salt = generate_salt(16)
                    fp.write('rpcauth={}:{}${}\n'.format(
                        'test_part_' + str(i), salt,
                        password_to_hmac(salt, 'test_part_pwd_' + str(i))))
                    for ip in range(NUM_NODES):
                        if ip != i:
                            fp.write('connect=127.0.0.1:{}\n'.format(
                                PARTICL_PORT_BASE + ip + PORT_OFS))

                # Pruned nodes don't provide blocks
                with open(os.path.join(client_path, 'bitcoin', 'bitcoin.conf'),
                          'r') as fp:
                    lines = fp.readlines()
                with open(os.path.join(client_path, 'bitcoin', 'bitcoin.conf'),
                          'w') as fp:
                    for line in lines:
                        if not line.startswith('prune'):
                            fp.write(line)
                    fp.write('port={}\n'.format(BITCOIN_PORT_BASE + i +
                                                PORT_OFS))
                    fp.write('bind=127.0.0.1\n')
                    fp.write('dnsseed=0\n')
                    fp.write('discover=0\n')
                    fp.write('listenonion=0\n')
                    fp.write('upnp=0\n')
                    salt = generate_salt(16)
                    fp.write('rpcauth={}:{}${}\n'.format(
                        'test_btc_' + str(i), salt,
                        password_to_hmac(salt, 'test_btc_pwd_' + str(i))))
                    for ip in range(NUM_NODES):
                        if ip != i:
                            fp.write('connect=127.0.0.1:{}\n'.format(
                                BITCOIN_PORT_BASE + ip + PORT_OFS))
                    for opt in EXTRA_CONFIG_JSON.get('btc{}'.format(i), []):
                        fp.write(opt + '\n')

                with open(os.path.join(client_path, 'monero', 'monerod.conf'),
                          'a') as fp:
                    fp.write('p2p-bind-ip=127.0.0.1\n')
                    fp.write('p2p-bind-port={}\n'.format(XMR_BASE_P2P_PORT +
                                                         i + PORT_OFS))
                    for ip in range(NUM_NODES):
                        if ip != i:
                            fp.write(
                                'add-exclusive-node=127.0.0.1:{}\n'.format(
                                    XMR_BASE_P2P_PORT + ip + PORT_OFS))

                with open(config_path) as fs:
                    settings = json.load(fs)

                settings['min_delay_event'] = 1
                settings['max_delay_event'] = 4
                settings['min_delay_retry'] = 15
                settings['max_delay_retry'] = 30
                settings['min_sequence_lock_seconds'] = 60

                settings['check_progress_seconds'] = 5
                settings['check_watched_seconds'] = 5
                settings['check_expired_seconds'] = 60
                settings['check_events_seconds'] = 5
                settings['check_xmr_swaps_seconds'] = 5

                settings['chainclients']['particl'][
                    'rpcuser'] = '******' + str(i)
                settings['chainclients']['particl'][
                    'rpcpassword'] = '******' + str(i)

                settings['chainclients']['bitcoin'][
                    'rpcuser'] = '******' + str(i)
                settings['chainclients']['bitcoin'][
                    'rpcpassword'] = '******' + str(i)

                extra_config = EXTRA_CONFIG_JSON.get('sc{}'.format(i), {})
                recursive_update_dict(settings, extra_config)

                with open(config_path, 'w') as fp:
                    json.dump(settings, fp, indent=4)

        signal.signal(
            signal.SIGINT,
            lambda signal, frame: cls.signal_handler(cls, signal, frame))