def test_query_utxo_set(setup_wallets): load_test_config() jm_single().bc_interface.tick_forward_chain_interval = 1 wallet_service = create_wallet_for_sync( [2, 3, 0, 0, 0], ["wallet4utxo.json", "4utxo", [2, 3]]) wallet_service.sync_wallet(fast=True) txid = do_tx(wallet_service, 90000000) txid2 = do_tx(wallet_service, 20000000) print("Got txs: ", txid, txid2) res1 = jm_single().bc_interface.query_utxo_set((txid, 0), includeunconf=True) res2 = jm_single().bc_interface.query_utxo_set([(txid, 0), (txid2, 1)], includeconf=True, includeunconf=True) assert len(res1) == 1 assert len(res2) == 2 assert all([x in res1[0] for x in ['script', 'address', 'value']]) assert not 'confirms' in res1[0] assert 'confirms' in res2[0] assert 'confirms' in res2[1] res3 = jm_single().bc_interface.query_utxo_set((b"\xee" * 32, 25)) assert res3 == [None]
def test_sync(setup_sync, internal): load_test_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)
def test_tumble_tweak(destaddrs, txcparams, mixdepthcount, lastcompleted, makercountrange): load_test_config() options = get_options() options['mixdepthcount'] = mixdepthcount options['txcountparams'] = txcparams options['makercountrange'] = makercountrange schedule = get_tumble_schedule(options, destaddrs, {0:1}) dests = [x[3] for x in schedule] assert set(destaddrs).issubset(set(dests)) new_schedule = tweak_tumble_schedule(options, schedule, lastcompleted) #sanity check: each amount fraction list should add up to near 1.0, #so some is left over for sweep for i in range(mixdepthcount): entries = [x for x in new_schedule if x[0] == i] total_frac_for_mixdepth = sum([x[1] for x in entries]) #TODO spurious failure is possible here, not an ideal check print('got total frac for mixdepth: ', str(total_frac_for_mixdepth)) assert total_frac_for_mixdepth < 0.999 from pprint import pformat print("here is the new schedule: ") print(pformat(new_schedule)) print("and old:") print(pformat(schedule))
# (which may be the most likely): # (1) TLS clearnet server # (0) onion non-SSL server # so the third argument is 0 or 1 as per that. # the 4th argument, serverport, is required for (0), # since it's an ephemeral HS address and must include the port # Note on setting up the Hidden Service: # this happens automatically when running test/payjoinserver.py # under pytest, and it prints out the hidden service url after # some seconds (just as it prints out the wallet hex). usessl = int(sys.argv[3]) serverport = None if len(sys.argv) > 4: serverport = sys.argv[4] load_test_config() jm_single().datadir = "." check_regtest() if not usessl: if not serverport: print("test configuration error: usessl = 0 assumes onion " "address which must be specified as the fourth argument") else: pjurl = "http://" + serverport else: # hardcoded port for tests: pjurl = "https://127.0.0.1:8080" bip21uri = "bitcoin:2N7CAdEUjJW9tUHiPhDkmL9ukPtcukJMoxK?amount=0.3&pj=" + pjurl wallet_path = get_wallet_path(wallet_name, None) if jm_single().config.get("POLICY", "native") == "true":
def setup_wallet(): load_test_config() btc.select_chain_params("bitcoin/regtest") #see note in cryptoengine.py: cryptoengine.BTC_P2WPKH.VBYTE = 100 jm_single().bc_interface.tick_forward_chain_interval = 2
def setup_tx_creation(): load_test_config()
def setup_snicker(request): load_test_config() def teardown(): if os.path.exists(TEST_PROPOSALS_FILE): os.remove(TEST_PROPOSALS_FILE) request.addfinalizer(teardown)
def setup_env_nodeps(monkeypatch): monkeypatch.setattr(jmclient.configure, 'get_blockchain_interface_instance', lambda x: DummyBlockchainInterface()) btc.select_chain_params("bitcoin/regtest") load_test_config()
def test_net_byte(): load_test_config() assert struct.unpack(b'B', get_p2pk_vbyte())[0] == 0x6f assert struct.unpack(b'B', get_p2sh_vbyte())[0] == 196
def setup_env_nodeps(monkeypatch): monkeypatch.setattr(jmclient.configure, 'get_blockchain_interface_instance', lambda x: DummyBlockchainInterface()) load_test_config()
def setup_snicker(request): load_test_config()
def setup_wallet(): load_test_config() #see note in cryptoengine.py: cryptoengine.BTC_P2WPKH.VBYTE = 100 jm_single().bc_interface.tick_forward_chain_interval = 2
def test_fast_sync_unavailable(setup_sync): load_test_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)
def setup_psbt_wallet(): load_test_config()
def setUp(self): load_test_config() jm_single().bc_interface.tick_forward_chain_interval = 5 jm_single().bc_interface.simulate_blocks()
def setup_payjoin_server(): load_test_config() jm_single().bc_interface.tick_forward_chain_interval = 10 jm_single().bc_interface.simulate_blocks() # handles the custom regtest hrp for bech32 cryptoengine.BTC_P2WPKH.VBYTE = 100
def setUp(self): load_test_config() factory = JMClientProtocolFactory(DummyMaker(), proto_type='MAKER') self.client = factory.buildProtocol(None) self.tr = proto_helpers.StringTransport() self.client.makeConnection(self.tr)
def test_absurd_fee(setup_wallets): jm_single().config.set("POLICY", "absurd_fee_per_kb", "1000") with pytest.raises(ValueError) as e_info: estimate_tx_fee(10, 2) load_test_config()
def setup_full_coinjoin(): load_test_config() jm_single().bc_interface.tick_forward_chain_interval = 10 jm_single().bc_interface.simulate_blocks()
def setup_wallets(): load_test_config() jm_single().bc_interface.tick_forward_chain_interval = 1
def setup_keys(): load_test_config()