JoinMarket-Org / joinmarket-clientserver

Bitcoin CoinJoin implementation with incentive structure to convince people to take part
GNU General Public License v3.0
727 stars 178 forks source link

Tests failing with Bitcoin Core v0.19.0.1 #477

Closed takinbo closed 4 years ago

takinbo commented 4 years ago

The tests test_tx_creation.py and test_wallet.py fail when using bitcoin core v0.19.0.1. It is possible that the reason this is happening is due to the recent enforcement of standard transactions for regtest (see release notes for v0.19.0.1).

It affects test_create_p2sh_output_tx()

___ test_create_p2sh_output_tx[1-wallet_structures0-4-1.4-600000000-pubs0-2] ___

setup_tx_creation = None, nw = 1, wallet_structures = [[2, 1, 4, 0, 0]], mean_amt = 4, sdev_amt = 1.4, amount = 600000000, pubs = ['0280125e42c1984923106e281615dfada44d38c4125c005963b322427110d709d6', '02726fa5b19e9406aaa46ee22fd9e81a09dd5eb7c87505b93a11efcf4b945e778c', '03600a739be32a14938680b3b3d61b51f217a60df118160d0decab22c9e1329862'], k = 0

    @pytest.mark.parametrize(
        "nw, wallet_structures, mean_amt, sdev_amt, amount, pubs, k", [
            (1, [[2, 1, 4, 0, 0]], 4, 1.4, 600000000, vpubs[1:4], 2),
            (1, [[3, 3, 0, 0, 3]], 4, 1.4, 100000000, vpubs[:4], 3),
        ])
    def test_create_p2sh_output_tx(setup_tx_creation, nw, wallet_structures,
                                   mean_amt, sdev_amt, amount, pubs, k):
        wallets = make_wallets(nw, wallet_structures, mean_amt, sdev_amt)
        for w in wallets.values():
            w['wallet'].sync_wallet(fast=True)
        for k, w in enumerate(wallets.values()):
            wallet_service = w['wallet']
            ins_full = wallet_service.select_utxos(0, amount)
            script = bitcoin.mk_multisig_script(pubs, k)
            output_addr = bitcoin.script_to_address(script, vbyte=196)
            txid = make_sign_and_push(ins_full,
                                      wallet_service,
                                      amount,
                                      output_addr=output_addr)
>           assert txid
E           assert False

jmclient/test/test_tx_creation.py:49: AssertionError
--- Captured log setup ---
DEBUG    joinmarket:blockchaininterface.py:194 rpc: getnewaddress []
--- Captured stderr call ---
2019-12-22 14:51:42,831 [INFO]  Detected new wallet, performing initial import
--- Captured log call ---
DEBUG    joinmarket:blockchaininterface.py:194 rpc: sendtoaddress ['2MwE3tEhFv3Xw8MyVMx2eV2UCwSa2YpW3Bn', 4.09850527]
DEBUG    joinmarket:blockchaininterface.py:194 rpc: generatetoaddress [1, '2N6udmVmkSv1zDRpB2myBt9wiNPuy6AUPf8']
DEBUG    joinmarket:blockchaininterface.py:194 rpc: sendtoaddress ['2N73zp7HN4C6kMWLGW4ythKueUmS5mjrKhy', 3.51787977]
DEBUG    joinmarket:blockchaininterface.py:194 rpc: generatetoaddress [1, '2N6udmVmkSv1zDRpB2myBt9wiNPuy6AUPf8']
DEBUG    joinmarket:blockchaininterface.py:194 rpc: sendtoaddress ['2N6q26QjHWCk13zxxaPeEo1QabNdt5LVRte', 3.59084519]
DEBUG    joinmarket:blockchaininterface.py:194 rpc: generatetoaddress [1, '2N6udmVmkSv1zDRpB2myBt9wiNPuy6AUPf8']
DEBUG    joinmarket:blockchaininterface.py:194 rpc: sendtoaddress ['2N2Jx5Mvi8TsHREGJepAnyHHYDFePQtG2ai', 4.49323168]
DEBUG    joinmarket:blockchaininterface.py:194 rpc: generatetoaddress [1, '2N6udmVmkSv1zDRpB2myBt9wiNPuy6AUPf8']
DEBUG    joinmarket:blockchaininterface.py:194 rpc: sendtoaddress ['2N2k9GU3Cj32WjzWXMqcZoUHj5DenmPex6c', 3.96154473]
DEBUG    joinmarket:blockchaininterface.py:194 rpc: generatetoaddress [1, '2N6udmVmkSv1zDRpB2myBt9wiNPuy6AUPf8']
DEBUG    joinmarket:blockchaininterface.py:194 rpc: sendtoaddress ['2N1ADDgSiWWdbqXphFTUgyHhYnwLEcY18Vh', 3.98289858]
DEBUG    joinmarket:blockchaininterface.py:194 rpc: generatetoaddress [1, '2N6udmVmkSv1zDRpB2myBt9wiNPuy6AUPf8']
DEBUG    joinmarket:blockchaininterface.py:194 rpc: sendtoaddress ['2N3md9u35uEZESShGqKFaiwsafXTMUCFMiw', 4.01547218]
DEBUG    joinmarket:blockchaininterface.py:194 rpc: generatetoaddress [1, '2N6udmVmkSv1zDRpB2myBt9wiNPuy6AUPf8']
DEBUG    joinmarket:blockchaininterface.py:194 rpc: listaddressgroupings []
INFO     joinmarket:wallet_service.py:381 Detected new wallet, performing initial import
DEBUG    joinmarket:wallet_service.py:478 requesting detailed wallet history
DEBUG    joinmarket:blockchaininterface.py:194 rpc: getaddressesbyaccount ['joinmarket-wallet-0bfe61']
DEBUG    joinmarket:blockchaininterface.py:194 rpc: listlabels []
DEBUG    joinmarket:blockchaininterface.py:194 rpc: listunspent [0]
DEBUG    joinmarket:wallet_service.py:550 bitcoind sync_unspent took 0.13032197952270508sec
DEBUG    joinmarket:blockchaininterface.py:194 rpc: sendrawtransaction ['0100000000010219f49ee3342a051a6fa37568d66b7e6d21ec01b22c74bd7dbfc9ccbf82625c2001000000171600146c2b8b093ade634e48044d164d45d2bba4298bb2ffffffffeb50355822a504b793ca32c414ec66674b7f07abbeb0a43964fdbc41b8f1b0d300000000171600149ddf96f29c3fdd32b47e90f8720c6e98eccb2454ffffffff020046c3230000000069a9140
280125e42c1984923106e281615dfada44d38c4125c005963b322427110d709d62102726fa5b19e9406aaa46ee22fd9e81a09dd5eb7c87505b93a11efcf4b945e778c2103600a739be32a14938680b3b3d61b51f217a60df118160d0decab22c9e132986253875841a2090000000017a91419b3244165403c5c88eb7c240abd708875ef16168702483045022100d55896886146b003f95d11bd5d546af36d54bbbe8d54e9f37cec42ed292c1ff502207f8e4aaf9b6794fca
45dc2980b959abbf79bb907c28d48452d14145e022d4f3d012102161afad55dee0dd991cbd68aac60156db1adac50e4833b2547641129762eb536024730440220772baf00a9474c295189c600cf323fffdaacf2110c5988ea6829973c4d35e02302200b196178932fc7401c63972aaaa83a372ba6ed064de88a30cb11ea9e7663955801210225d38a3aceaefe341914a3d728f4b957062182b26976f7a62466a885b74a7b6500000000']
DEBUG    joinmarket:blockchaininterface.py:318 error pushing = -26 scriptpubkey (code 64)

Also affects test_signing_imported()

___ test_signing_imported[cVqtSSoVxFyPqTRGfeESi31uCYfgTF4tGWRtGeVs84fzybiX5TPk-0-assert_not_segwit] ___

setup_wallet = None, wif = 'cVqtSSoVxFyPqTRGfeESi31uCYfgTF4tGWRtGeVs84fzybiX5TPk', keytype = 0, type_check = <function assert_not_segwit at 0x7fbb7a9a7ae8>

    @pytest.mark.parametrize('wif,keytype,type_check', [
        ['cVqtSSoVxFyPqTRGfeESi31uCYfgTF4tGWRtGeVs84fzybiX5TPk',
         cryptoengine.TYPE_P2PKH, assert_not_segwit],
        ['cRAGLvPmhpzJNgdMT4W2gVwEW3fusfaDqdQWM2vnWLgXKzCWKtcM',
         cryptoengine.TYPE_P2SH_P2WPKH, assert_segwit]
    ])
    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)]))
        script = wallet.get_script_path(path)
        tx = wallet.sign_tx(tx, {0: (script, 10**8)})
        type_check(tx)
        txout = jm_single().bc_interface.pushtx(btc.serialize(tx))
>       assert txout
E       assert False

jmclient/test/test_wallet.py:311: AssertionError
--- Captured log call ---
DEBUG    joinmarket:blockchaininterface.py:194 rpc: sendtoaddress ['mpCX9EbdXpcrKMtjEe1fqFhvzctkfzMYTX', 1]
DEBUG    joinmarket:blockchaininterface.py:194 rpc: generatetoaddress [1, '2MtLLEsUz9h1ZbbCynHddgfhBKjEc5gsg2x']
DEBUG    joinmarket:blockchaininterface.py:194 rpc: sendrawtransaction ['01000000011dc44599eeccd08c3ed7fa2ae8955e313045f50f5daf426d7f06edbff602ff62000000006b483045022100ee8cbe2c165e49bdcd3cf78d2148d6e4b4276df61f43cb9e74707c8ac0683077022003c9a483b72b72a840d69fbbbe72fcf3fe6638b36d5f845a8d2b32dafd12e82c0121028a7037734c05b2ca71be46aebb517d9905b0f4fa0fc0b65bbff790b563a18
7a0ffffffff01d8bdf5050000000011000000000000000000000000000000000000000000']
DEBUG    joinmarket:blockchaininterface.py:318 error pushing = -26 scriptpubkey (code 64)
DEBUG    joinmarket:blockchaininterface.py:524 will call tfc after 2 seconds.

and finally, test_signing_simple()

___ test_signing_simple[LegacyWallet-assert_not_segwit] ___

setup_wallet = None, wallet_cls = <class 'jmclient.wallet.LegacyWallet'>, type_check = <function assert_not_segwit at 0x7fbb7a9a7ae8>

    @pytest.mark.parametrize('wallet_cls,type_check', [
        [LegacyWallet, assert_not_segwit],
        [SegwitLegacyWallet, assert_segwit],
        [SegwitWallet, assert_segwit],
    ])
    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))
        # The dummy output is of length 25 bytes, because, for SegwitWallet, we else
        # trigger the tx-size-small DOS limit in Bitcoin Core (82 bytes is the
        # smallest "normal" transaction size (non-segwit size, ie no witness)
        tx = btc.deserialize(btc.mktx(['{}:{}'.format(hexlify(utxo[0]).decode('ascii'),
                                    utxo[1])], ['00'*25 + ':' + str(10**8 - 9000)]))
        script = wallet.get_script(0, 1, 0)
        tx = wallet.sign_tx(tx, {0: (script, 10**8)})
        type_check(tx)
        txout = jm_single().bc_interface.pushtx(btc.serialize(tx))
>       assert txout
E       assert False

jmclient/test/test_wallet.py:334: AssertionError
--- Captured log call ---
DEBUG    joinmarket:blockchaininterface.py:194 rpc: sendtoaddress ['n2BEFhrUTaikQJ6Pa87Zhsmj6HXwrNyqeY', 1]
DEBUG    joinmarket:blockchaininterface.py:194 rpc: generatetoaddress [1, '2MtLLEsUz9h1ZbbCynHddgfhBKjEc5gsg2x']
DEBUG    joinmarket:blockchaininterface.py:194 rpc: sendrawtransaction ['01000000012c6a6e19d104bf50b79557603b050b41737af5acc1558151508eb954bc1636b4000000006b483045022100cebece123a0ca50e113c1827a3b66c3f944f03d351176e7699e4c07dd289e3dc022002ee6a82ac3d2f848faf59faad86a7332955b6cd3d7289188b41ec940f18ecbe012102607f79e1b9239f321eb3ebe406a973f3b382b4c5d79dcc7bfd80be880d37c
c6effffffff01d8bdf50500000000190000000000000000000000000000000000000000000000000000000000']
DEBUG    joinmarket:blockchaininterface.py:318 error pushing = -26 scriptpubkey (code 64)
DEBUG    joinmarket:blockchaininterface.py:524 will call tfc after 2 seconds.
kristapsk commented 4 years ago

Isn't this fixed with #391?

takinbo commented 4 years ago

@kristapsk in a kind of way. The tests use non-standard scripts which, although supported on testnet and regtest for bitcoin-core 0.18 and below, stopped being the default on regtest in 0.19. The solution in #391 was to use a flag explicitly enabling it.

I guess we could close this issue for now, however I think, longterm, we need to update the tests to use standard scripts - possibly use proper p2sh scripts instead.

AdamISZ commented 4 years ago

Oh yes, I see. It should be trivial to replace the dummy output script with a normal one.