Skip to content

Commit

Permalink
Add test code for no-history sync
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-belcher committed Nov 11, 2019
1 parent 3fdcdc9 commit 1325e24
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
11 changes: 11 additions & 0 deletions jmclient/jmclient/blockchaininterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
52 changes: 52 additions & 0 deletions jmclient/test/test_core_nohistory_sync.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#! /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."""

import binascii
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

0 comments on commit 1325e24

Please sign in to comment.