Browse Source

Add test code for no-history sync

master
chris-belcher 6 years ago
parent
commit
f5e27c39dc
No known key found for this signature in database
GPG Key ID: EF734EA677F31129
  1. 11
      jmclient/jmclient/blockchaininterface.py
  2. 51
      jmclient/test/test_core_nohistory_sync.py

11
jmclient/jmclient/blockchaininterface.py

@ -463,6 +463,17 @@ class BitcoinCoreNoHistoryInterface(BitcoinCoreInterface):
# 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

51
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
Loading…
Cancel
Save