diff --git a/jmclient/jmclient/blockchaininterface.py b/jmclient/jmclient/blockchaininterface.py index 311bdd492..3e77c0161 100644 --- a/jmclient/jmclient/blockchaininterface.py +++ b/jmclient/jmclient/blockchaininterface.py @@ -456,6 +456,17 @@ def post_sync_wallet_callback(self, wallet): # avoidance of address reuse wallet.disable_new_scripts = True + ##these two functions are hacks to make the test code be able to use the + ##same helper functions, perhaps it would be nicer to create mixin classes + ##and use multiple inheritance to make the code more OOP, but its not + ##worth it now + def grab_coins(self, receiving_addr, amt=50): + RegtestBitcoinCoreInterface.grab_coins(self, receiving_addr, amt) + + def tick_forward_chain(self, n): + self.destn_addr = self.rpc("getnewaddress", []) + RegtestBitcoinCoreInterface.tick_forward_chain(self, n) + # class for regtest chain access # running on local daemon. Only # to be instantiated after network is up diff --git a/jmclient/test/test_core_nohistory_sync.py b/jmclient/test/test_core_nohistory_sync.py new file mode 100644 index 000000000..8498b9dc5 --- /dev/null +++ b/jmclient/test/test_core_nohistory_sync.py @@ -0,0 +1,51 @@ +#! /usr/bin/env python +from __future__ import (absolute_import, division, + print_function, unicode_literals) +from builtins import * # noqa: F401 +'''Wallet functionality tests.''' + +"""BitcoinCoreNoHistoryInterface functionality tests.""" + +from commontest import create_wallet_for_sync + +import pytest +from jmbase import get_log +from jmclient import load_program_config + +log = get_log() + +def test_fast_sync_unavailable(setup_sync): + load_program_config(bs="bitcoin-rpc-no-history") + wallet_service = create_wallet_for_sync([0, 0, 0, 0, 0], + ['test_fast_sync_unavailable']) + with pytest.raises(RuntimeError) as e_info: + wallet_service.sync_wallet(fast=True) + +@pytest.mark.parametrize('internal', (False, True)) +def test_sync(setup_sync, internal): + load_program_config(bs="bitcoin-rpc-no-history") + used_count = [1, 3, 6, 2, 23] + wallet_service = create_wallet_for_sync(used_count, ['test_sync'], + populate_internal=internal) + ##the gap limit should be not zero before sync + assert wallet_service.gap_limit > 0 + for md in range(len(used_count)): + ##obtaining an address should be possible without error before sync + wallet_service.get_new_script(md, internal) + + wallet_service.sync_wallet(fast=False) + + for md in range(len(used_count)): + ##plus one to take into account the one new script obtained above + assert used_count[md] + 1 == wallet_service.get_next_unused_index(md, + internal) + #gap limit is zero after sync + assert wallet_service.gap_limit == 0 + #obtaining an address leads to an error after sync + with pytest.raises(RuntimeError) as e_info: + wallet_service.get_new_script(0, internal) + + +@pytest.fixture(scope='module') +def setup_sync(): + pass