def test_remove_old_utxos(setup_wallet): jm_single().config.set('BLOCKCHAIN', 'network', 'testnet') wallet = get_populated_wallet() # add some more utxos to mixdepth 1 for i in range(3): txin = jm_single().bc_interface.grab_coins(wallet.get_internal_addr(1), 1) wallet.add_utxo(unhexlify(txin), 0, wallet.get_script(1, 1, i), 10**8) inputs = wallet.select_utxos_(0, 10**8) inputs.update(wallet.select_utxos_(1, 2 * 10**8)) assert len(inputs) == 3 tx_inputs = list(inputs.keys()) tx_inputs.append((b'\x12' * 32, 6)) tx = btc.deserialize( btc.mktx([ '{}:{}'.format(hexlify(txid).decode('ascii'), i) for txid, i in tx_inputs ], ['0' * 36 + ':' + str(3 * 10**8 - 1000)])) binarize_tx(tx) removed = wallet.remove_old_utxos_(tx) assert len(removed) == len(inputs) for txid in removed: assert txid in inputs balances = wallet.get_balance_by_mixdepth() assert balances[0] == 2 * 10**8 assert balances[1] == 10**8 assert balances[2] == 0 assert len(balances) == wallet.max_mixdepth + 1
def test_add_new_utxos(setup_wallet): jm_single().config.set('BLOCKCHAIN', 'network', 'testnet') wallet = get_populated_wallet(num=1) scripts = [wallet.get_new_script(x, True) for x in range(3)] tx_scripts = list(scripts) tx_scripts.append(b'\x22' * 17) tx = btc.deserialize( btc.mktx(['0' * 64 + ':2'], [{ 'script': hexlify(s).decode('ascii'), 'value': 10**8 } for s in tx_scripts])) binarize_tx(tx) txid = b'\x01' * 32 added = wallet.add_new_utxos_(tx, txid) assert len(added) == len(scripts) added_scripts = {x['script'] for x in added.values()} for s in scripts: assert s in added_scripts balances = wallet.get_balance_by_mixdepth() assert balances[0] == 2 * 10**8 assert balances[1] == 10**8 assert balances[2] == 10**8 assert len(balances) == wallet.max_mixdepth + 1
def test_coinjoin_mixdepth_wrap_maker(monkeypatch, tmpdir, setup_cj): def raise_exit(i): raise Exception("sys.exit called") monkeypatch.setattr(sys, 'exit', raise_exit) set_commitment_file(str(tmpdir.join('commitments.json'))) MAKER_NUM = 2 wallet_services = make_wallets_to_list( make_wallets(MAKER_NUM + 1, wallet_structures=[[0, 0, 0, 0, 4]] * MAKER_NUM + [[3, 0, 0, 0, 0]], mean_amt=1)) for wallet_service in wallet_services: assert wallet_service.max_mixdepth == 4 jm_single().bc_interface.tickchain() jm_single().bc_interface.tickchain() sync_wallets(wallet_services) cj_fee = 2000 makers = [ YieldGeneratorBasic(wallet_services[i], [0, cj_fee, 0, 'swabsoffer', 10**7]) for i in range(MAKER_NUM) ] orderbook = create_orderbook(makers) assert len(orderbook) == MAKER_NUM cj_amount = int(1.1 * 10**8) # mixdepth, amount, counterparties, dest_addr, waittime, rounding schedule = [(0, cj_amount, MAKER_NUM, 'INTERNAL', 0, NO_ROUNDING)] taker = create_taker(wallet_services[-1], schedule, monkeypatch) active_orders, maker_data = init_coinjoin(taker, makers, orderbook, cj_amount) txdata = taker.receive_utxos(maker_data) assert txdata[0], "taker.receive_utxos error" taker_final_result = do_tx_signing(taker, makers, active_orders, txdata) assert taker_final_result is not False tx = btc.deserialize(txdata[2]) binarize_tx(tx) for i in range(MAKER_NUM): wallet_service = wallet_services[i] # TODO as above re: monitoring wallet_service.remove_old_utxos_(tx) wallet_service.add_new_utxos_(tx, b'\x00' * 32) # fake txid balances = wallet_service.get_balance_by_mixdepth() assert balances[0] == cj_amount assert balances[4] == 4 * 10**8 - cj_amount + cj_fee
def test_signing_simple(setup_wallet, wallet_cls, type_check): jm_single().config.set('BLOCKCHAIN', 'network', 'testnet') storage = VolatileStorage() wallet_cls.initialize(storage, get_network()) wallet = wallet_cls(storage) utxo = fund_wallet_addr(wallet, wallet.get_internal_addr(0)) tx = btc.deserialize(btc.mktx(['{}:{}'.format(hexlify(utxo[0]).decode('ascii'), utxo[1])], ['00'*17 + ':' + str(10**8 - 9000)])) binarize_tx(tx) script = wallet.get_script(0, 1, 0) wallet.sign_tx(tx, {0: (script, 10**8)}) type_check(tx) txout = jm_single().bc_interface.pushtx(hexlify(btc.serialize(tx)).decode('ascii')) assert txout
def test_signing_imported(setup_wallet, wif, keytype, type_check): jm_single().config.set('BLOCKCHAIN', 'network', 'testnet') storage = VolatileStorage() SegwitLegacyWallet.initialize(storage, get_network()) wallet = SegwitLegacyWallet(storage) MIXDEPTH = 0 path = wallet.import_private_key(MIXDEPTH, wif, keytype) utxo = fund_wallet_addr(wallet, wallet.get_addr_path(path)) tx = btc.deserialize(btc.mktx(['{}:{}'.format(hexlify(utxo[0]).decode('ascii'), utxo[1])], ['00'*17 + ':' + str(10**8 - 9000)])) binarize_tx(tx) script = wallet.get_script_path(path) wallet.sign_tx(tx, {0: (script, 10**8)}) type_check(tx) txout = jm_single().bc_interface.pushtx(hexlify(btc.serialize(tx)).decode('ascii')) assert txout