def test_whole(cache, exp_conf_balance, exp_unconf_balance): cm = CacheManager() # Don't prune for testing purposes cm.load_from_dict(cache, prune_provisional=False) addrs = cm.get_addresses_for_chain(0x80000000, 0) + \ cm.get_addresses_for_chain(0x80000000, 1) conf_balances = cm.get_balances(addrs) unconf_balances = cm.get_balances(addrs, True) conf_balance = sum([v for k, v in conf_balances.items()]) unconf_balance = sum([v for k, v in unconf_balances.items()]) assert conf_balance == exp_conf_balance assert unconf_balance == exp_unconf_balance
def test_all(num_used_payout_addresses, num_used_change_addresses, expected_balance): m = mock_provider m.reset_mocks() m.set_num_used_addresses(0, num_used_payout_addresses, 0) m.set_num_used_addresses(0, num_used_change_addresses, 1) m.set_num_used_accounts(1) total_used = num_used_payout_addresses + num_used_change_addresses expected_call_count = m.set_txn_side_effect_for_hd_discovery() cm = CacheManager() acct = HDAccount(acct0_key, "default", 0, m, cm) mk0 = m._acct_keys[0] assert acct._chain_priv_keys[0].to_b58check( ) == mk0['payout_key'].to_b58check() assert m.get_transactions.call_count == expected_call_count assert acct.last_indices[0] == num_used_payout_addresses - 1 assert acct.last_indices[1] == num_used_change_addresses - 1 assert acct.balance == expected_balance if total_used: assert acct.has_txns() else: assert not acct.has_txns() exp_used = mk0['payout_addresses'][:num_used_payout_addresses] + \ mk0['change_addresses'][:num_used_change_addresses] assert acct.all_used_addresses == exp_used change_index = 0 if num_used_change_addresses == 0 else num_used_change_addresses - 1 payout_index = 0 if num_used_payout_addresses == 0 else num_used_payout_addresses - 1 # The mock provider doesn't have a transaction per used address # so we need to check to see what the right index is change_addr = acct.get_address(True, change_index) payout_addr = acct.get_address(False, payout_index) if acct._cache_manager.address_has_txns(change_addr): change_index += 1 if acct._cache_manager.address_has_txns(payout_addr): payout_index += 1 assert acct.get_next_address(True) == mk0['change_addresses'][change_index] assert acct.get_next_address( False) == mk0['payout_addresses'][payout_index]
import inspect import os.path import time from two1.blockchain.twentyone_provider import TwentyOneProvider from two1.bitcoin.hash import Hash from two1.wallet.cache_manager import CacheManager from two1.wallet.wallet_txn import WalletTransaction this_file_path = os.path.dirname( os.path.abspath(inspect.getfile(inspect.currentframe()))) cm = CacheManager() dp = TwentyOneProvider() def test_addresses(): cm.insert_address(0, 0, 0, "15qCydrcqURADXJHrtMW9m6SpPTa3kqkQb") cm.insert_address(0, 0, 1, "15hyvVXH2eJnakwhpqKBf5oTCa3o2bp8m8") cm.insert_address(0, 0, 19, "17TNXJSWjBdMpHAkSfuyfVKSvb3rLuWZqQ") cm.insert_address(0, 1, 0, "1BbPtYsbBPFRCwnU5RuMTttraghXQ5JSZm") cm.insert_address(0, 1, 1, "1JuFprygqrra7vwYzrpBkGUbXjYao3RaR3") cm.insert_address(0, 1, 2, "16iY4btKxq9tz7sSZnva3691RYigcWDaSv") cm.insert_address(0, 1, 3, "1MDXXbB8JBV4bZU4buzxV456RAFqL7Z93f") cm.insert_address(0, 1, 4, "18vZXvhQAg8Fd8Ym7fbDUiBQS8o1iYDnkT") cm.insert_address(0, 1, 5, "1A9Gn3srogH6nNSqyWRf4YSBvvarvJzepc") cm.insert_address(0, 1, 6, "1FHkYaLSQ9A32PAopjLiBdZr1XQ5TueJWr") cm.insert_address(0, 1, 7, "1FAqCWr2EkAz43JzPRsdqLKBQeLJo4Tc7M") cm.insert_address(0, 1, 8, "12gR11fhqeDWpERmTfggVKUpDLfkq1dKbZ") cm.insert_address(0, 1, 9, "1Pr6wKbrfbtqacm4aDhN4zscMTAbc7cztz")
def test_init(): with pytest.raises(TypeError): HDAccount(master_key_passphrase, "default", 0, mock_provider, CacheManager())