test: Use MiniWallet in rpc_rawtransaction.py #25044

pull danielabrozzoni wants to merge 2 commits into bitcoin:master from danielabrozzoni:test_rawtransaction_miniwallet changing 3 files +93 −119
  1. danielabrozzoni commented at 5:29 PM on April 30, 2022: contributor

    This PR allows rpc_rawtransaction.py to be run even without the Core wallet by using the MiniWallet instead, as proposed in #20078. This test was previously run twice, once with --legacy-wallet and once with --descriptors. Since this would have meant running the same test twice if the wallet wasn't compiled, now we run it just once with the legacy wallet.

  2. fanquake added the label Tests on Apr 30, 2022
  3. fanquake commented at 7:37 PM on April 30, 2022: member

    https://github.com/bitcoin/bitcoin/pull/25044/checks?check_run_id=6241399894:

    
    85/242 - rpc_rawtransaction.py --legacy-wallet failed, Duration: 2 s
    
    2022-04-30T17:43:46.674000Z TestFramework (INFO): Initializing test directory /tmp/cirrus-ci-build/ci/scratch/test_runner/test_runner_₿_🏃_20220430_174259/rpc_rawtransaction_151
    2022-04-30T17:43:47.170000Z TestFramework (INFO): Prepare some coins for multiple *rawtransaction commands
    2022-04-30T17:43:48.329000Z TestFramework (INFO): Test getrawtransaction with -txindex
    2022-04-30T17:43:48.333000Z TestFramework (INFO): Test getrawtransaction without -txindex
    2022-04-30T17:43:48.337000Z TestFramework (ERROR): Assertion failed
    Traceback (most recent call last):
      File "/tmp/cirrus-ci-build/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/test/functional/test_framework/test_framework.py", line 133, in main
        self.run_test()
      File "/tmp/cirrus-ci-build/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/test/functional/rpc_rawtransaction.py", line 86, in run_test
        self.getrawtransaction_tests()
      File "/tmp/cirrus-ci-build/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/test/functional/rpc_rawtransaction.py", line 143, in getrawtransaction_tests
        tx = self.wallet.send_self_transfer(from_node=self.nodes[2])['txid']
      File "/tmp/cirrus-ci-build/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/test/functional/test_framework/wallet.py", line 171, in send_self_transfer
        tx = self.create_self_transfer(**kwargs)
      File "/tmp/cirrus-ci-build/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/test/functional/test_framework/wallet.py", line 264, in create_self_transfer
        assert_equal(mempool_valid, tx_info['allowed'])
      File "/tmp/cirrus-ci-build/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/test/functional/test_framework/util.py", line 51, in assert_equal
        raise AssertionError("not(%s)" % " == ".join(str(arg) for arg in (thing1, thing2) + args))
    AssertionError: not(True == False)
    2022-04-30T17:43:48.389000Z TestFramework (INFO): Stopping nodes
    
  4. danielabrozzoni marked this as a draft on Apr 30, 2022
  5. danielabrozzoni force-pushed on Apr 30, 2022
  6. DrahtBot commented at 8:47 PM on April 30, 2022: member

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #23319 (rpc: Return fee and prevout (utxos) to getrawtransaction by dougEfresh)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  7. danielabrozzoni force-pushed on Apr 30, 2022
  8. danielabrozzoni marked this as ready for review on May 1, 2022
  9. danielabrozzoni commented at 9:21 AM on May 1, 2022: contributor

    Ops :( Should be ok now, thanks!

  10. jonatack commented at 3:06 PM on May 3, 2022: member

    Concept ACK, will review after our seminar tomorrow :)

  11. in test/functional/rpc_rawtransaction.py:66 in f9d5b49772 outdated
      61 | @@ -62,44 +62,51 @@ def set_test_params(self):
      62 |          # whitelist all peers to speed up tx relay / mempool sync
      63 |          for args in self.extra_args:
      64 |              args.append("-whitelist=noban@127.0.0.1")
      65 | +        if self.is_wallet_compiled():
      66 | +            self.requires_wallet = True
    


    vincenzopalazzo commented at 8:27 PM on May 3, 2022:
            self.requires_wallet = self.is_wallet_compiled()
    
  12. vincenzopalazzo approved
  13. ayush933 approved
  14. ayush933 commented at 8:36 AM on May 4, 2022: contributor

    tACK f9d5b49.

  15. in test/functional/rpc_rawtransaction.py:76 in f9d5b49772 outdated
      71 | -        self.skip_if_no_wallet()
      72 | +        if self.is_wallet_compiled():
      73 | +            if self.options.descriptors:
      74 | +                self.skip_if_no_sqlite()
      75 | +            else:
      76 | +                self.skip_if_no_bdb()
    


    MarcoFalke commented at 8:52 AM on May 4, 2022:

    Interesting. I think the goal of this change it to not run the test at all to avoid wasting resources if a specific wallet type is requested, but not available?

    However, the test will still run twice when the wallet isn't compiled: https://cirrus-ci.com/task/5291414786408448?logs=ci#L3574

    I think it might be better to fix this by removing this whole method and also consolidate the two tasks into one:

    $ git grep 'rpc_rawtransaction.py'
    test/functional/test_runner.py:    'rpc_rawtransaction.py --legacy-wallet',
    test/functional/test_runner.py:    'rpc_rawtransaction.py --descriptors',
    

    danielabrozzoni commented at 9:50 PM on May 7, 2022:

    I think the goal of this change it to not run the test at all to avoid wasting resources if a specific wallet type is requested, but not available?

    It's more that without this function if you try to run the test with --descriptors but without having sqlite compiled (or, viceversa, legacy but no bdb) the whole test fails...

    ❯ ./configure --without-bdb
    ❯ make -j 9
    ❯ ./test/functional/rpc_rawtransaction.py --legacy-wallet
    2022-05-07T21:43:41.365000Z TestFramework (INFO): Initializing test directory /tmp/bitcoin_func_test_7w6fc454
    2022-05-07T21:43:41.641000Z TestFramework (ERROR): JSONRPC error
    Traceback (most recent call last):
      File "/home/daniela/Developer/bitcoin/test/functional/test_framework/test_framework.py", line 132, in main
        self.setup()
      File "/home/daniela/Developer/bitcoin/test/functional/test_framework/test_framework.py", line 295, in setup
        self.setup_network()
      File "/home/daniela/Developer/bitcoin/./test/functional/rpc_rawtransaction.py", line 72, in setup_network
        super().setup_network()
      File "/home/daniela/Developer/bitcoin/test/functional/test_framework/test_framework.py", line 389, in setup_network
        self.setup_nodes()
      File "/home/daniela/Developer/bitcoin/test/functional/test_framework/test_framework.py", line 416, in setup_nodes
        self.import_deterministic_coinbase_privkeys()
      File "/home/daniela/Developer/bitcoin/test/functional/test_framework/test_framework.py", line 433, in import_deterministic_coinbase_privkeys
        self.init_wallet(node=i)
      File "/home/daniela/Developer/bitcoin/test/functional/test_framework/test_framework.py", line 440, in init_wallet
        n.createwallet(wallet_name=wallet_name, descriptors=self.options.descriptors, load_on_startup=True)
      File "/home/daniela/Developer/bitcoin/test/functional/test_framework/test_node.py", line 753, in createwallet
        return self.__getattr__('createwallet')(wallet_name, disable_private_keys, blank, passphrase, avoid_reuse, descriptors, load_on_startup, external_signer)
      File "/home/daniela/Developer/bitcoin/test/functional/test_framework/coverage.py", line 49, in __call__
        return_val = self.auth_service_proxy_instance.__call__(*args, **kwargs)
      File "/home/daniela/Developer/bitcoin/test/functional/test_framework/authproxy.py", line 144, in __call__
        raise JSONRPCException(response['error'], status)
    test_framework.authproxy.JSONRPCException: Compiled without bdb support (required for legacy wallets) (-4)
    2022-05-07T21:43:41.694000Z TestFramework (INFO): Stopping nodes
    2022-05-07T21:43:41.800000Z TestFramework (WARNING): Not cleaning up dir /tmp/bitcoin_func_test_7w6fc454
    2022-05-07T21:43:41.800000Z TestFramework (ERROR): Test failed. Test logging available at /tmp/bitcoin_func_test_7w6fc454/test_framework.log
    2022-05-07T21:43:41.801000Z TestFramework (ERROR): 
    2022-05-07T21:43:41.801000Z TestFramework (ERROR): Hint: Call /home/daniela/Developer/bitcoin/test/functional/combine_logs.py '/tmp/bitcoin_func_test_7w6fc454' to consolidate all logs
    2022-05-07T21:43:41.801000Z TestFramework (ERROR): 
    2022-05-07T21:43:41.801000Z TestFramework (ERROR): If this failure happened unexpectedly or intermittently, please file a bug and provide a link or upload of the combined log.
    2022-05-07T21:43:41.801000Z TestFramework (ERROR): https://github.com/bitcoin/bitcoin/issues
    2022-05-07T21:43:41.801000Z TestFramework (ERROR):
    

    I think it might be better to fix this by removing this whole method and also consolidate the two tasks into one:

    I've given a bit of thought to this, but I really don't know how I would do that... self.signrawtransactionwithwallet_tests still has to use the Core wallet, shouldn't we test it with both the legacy and the descriptor wallet?


    MarcoFalke commented at 5:47 AM on May 8, 2022:

    You can execute the subtests conditionally

    if sqlite:
      do_sqlite_test()
    test()
    

    danielabrozzoni commented at 10:52 AM on May 15, 2022:

    I'm sorry, I really can't figure out how to do this without massively changing the test_framework.py code. To me it seems that you can't in a single run test both with the descriptors and the legacy wallet...


    MarcoFalke commented at 5:04 PM on May 15, 2022:

    Right. This should only be possible when both the descriptor wallet and legacy wallet are compiled (and this test is slightly rewritten).

    However, I think it is fine to simply run just one (either sqlite or bdb).

    This means that any sqlite test case line of code will need to be guarded by a check that checks for sqlite (and the same for bdb). This should not need any framework changes.


    MarcoFalke commented at 5:08 PM on May 15, 2022:

    Unless of course the test is largely monolithic (most lines depend on previous lines), so conditional execution is not straightforward.


    MarcoFalke commented at 1:32 PM on May 17, 2022:

    Let me know if you are stuck on this and I can take a closer look myself.


    danielabrozzoni commented at 1:34 PM on May 17, 2022:

    I'm working on it, I'll let you know, thanks 😄


    danielabrozzoni commented at 9:50 AM on May 18, 2022:

    Should be ok now :)

  16. in test/functional/rpc_rawtransaction.py:88 in f9d5b49772 outdated
      89 | -            self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), amount)
      90 | -        self.sync_all()
      91 | -        self.generate(self.nodes[0], 5)
      92 | +        if self.is_wallet_compiled():
      93 | +            self.generate(self.nodes[2], 1)
      94 | +            self.generate(self.nodes[0], COINBASE_MATURITY + 1)
    


    MarcoFalke commented at 8:52 AM on May 4, 2022:

    Why are those two calls needed?


    danielabrozzoni commented at 3:27 PM on May 5, 2022:

    Those two were already in the test:

    https://github.com/bitcoin/bitcoin/blob/fcf6c8f4eb217763545ede1766831a6b93f583bd/test/functional/rpc_rawtransaction.py#L75-L80

    But yeah, you're right, I can just drop them:

    • It seems to me that generating from nodes[2] was never really needed
    • Generating from nodes[0] is not needed anymore (I'm already doing it a couple of lines above, to make sure that all the self.wallet utxos are mature)

    MarcoFalke commented at 3:32 PM on May 5, 2022:

    No, you are adding them twice? Whereas before they were only there once?


    danielabrozzoni commented at 4:02 PM on May 5, 2022:

    Yeah, I was doing self.generate(self.nodes[0], COINBASE_MATURITY + 1) twice without a real reason :)

    It should be better now, thanks!

  17. in test/functional/rpc_rawtransaction.py:28 in f9d5b49772 outdated
      23 | @@ -24,8 +24,8 @@
      24 |  from test_framework.util import (
      25 |      assert_equal,
      26 |      assert_raises_rpc_error,
      27 | -    find_vout_for_address,
      28 |  )
      29 | +from test_framework.wallet import MiniWallet, getnewdestination
    


    theStack commented at 12:22 PM on May 4, 2022:

    nit:

    from test_framework.wallet import (
        MiniWallet,
        getnewdestination,
    )
    

    (that way, potential merge conflicts can be resolved easier)


    danielabrozzoni commented at 3:28 PM on May 5, 2022:

    Updated, thanks :)

  18. theStack commented at 12:26 PM on May 4, 2022: member

    Concept ACK,

    and warm welcome as a new contributor!

  19. in test/functional/rpc_rawtransaction.py:86 in f9d5b49772 outdated
      87 |          self.generate(self.nodes[0], COINBASE_MATURITY + 1)
      88 | -        for amount in [1.5, 1.0, 5.0]:
      89 | -            self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), amount)
      90 | -        self.sync_all()
      91 | -        self.generate(self.nodes[0], 5)
      92 | +        if self.is_wallet_compiled():
    


    brunoerg commented at 12:35 PM on May 4, 2022:
            if self.requires_wallet:
    

    maybe you can avoid calls to is_wallet_compiled() since you defined a var for it in set_test_params:

    if self.is_wallet_compiled():
        self.requires_wallet = True
    

    danielabrozzoni commented at 3:29 PM on May 5, 2022:

    Oh, right! I just updated it, thank you :)

  20. danielabrozzoni force-pushed on May 5, 2022
  21. danielabrozzoni force-pushed on May 5, 2022
  22. in test/functional/rpc_rawtransaction.py:323 in 6672cebfb1 outdated
     334 | -        outputs = {self.nodes[0].getnewaddress(): Decimal("0.99990000")}
     335 | -        rawTx = self.nodes[2].createrawtransaction(inputs, outputs)
     336 | -        rawTxSigned = self.nodes[2].signrawtransactionwithwallet(rawTx)
     337 | -        assert_equal(rawTxSigned['complete'], True)
     338 | -        # Fee 10,000 satoshis, ~100 b transaction, fee rate should land around 100 sat/byte = 0.00100000 BTC/kB
     339 | +        # Fee rate is 0.00100000 BTC/kB
    


    jonatack commented at 11:25 AM on May 17, 2022:

    nit here and line 337 below

            # Fee rate is 0.00100000 BTC/kvB
    
  23. in test/functional/rpc_rawtransaction.py:103 in 6672cebfb1 outdated
     113 | -        vout = find_vout_for_address(self.nodes[1], txid, addr)
     114 | -        rawTx = self.nodes[1].createrawtransaction([{'txid': txid, 'vout': vout}], {self.nodes[1].getnewaddress(): 9.999})
     115 | -        rawTxSigned = self.nodes[1].signrawtransactionwithwallet(rawTx)
     116 | -        txId = self.nodes[1].sendrawtransaction(rawTxSigned['hex'])
     117 | -        self.generateblock(self.nodes[0], output=self.nodes[0].getnewaddress(), transactions=[rawTxSigned['hex']])
     118 | +        txId = tx["txid"]
    


    jonatack commented at 11:35 AM on May 17, 2022:

    nit, consistency with your changes

            txId = tx['txid']
    
  24. in test/functional/rpc_rawtransaction.py:210 in 6672cebfb1 outdated
     207 |                                      self.nodes[0].createrawtransaction, inputs, outputs)
     208 |          # with valid sequence number
     209 |          for valid_seq in [1000, 4294967294]:
     210 |              inputs = [{'txid': TXID, 'vout': 1, 'sequence': valid_seq}]
     211 | -            outputs = {self.nodes[0].getnewaddress(): 1}
     212 | +            outputs = {getnewdestination()[2]: 1}
    


    jonatack commented at 11:42 AM on May 17, 2022:

    nit, not sure how obvious it is to readers that getnewdestination()[2] is an address without looking up the function, so (here and just above) this might be clearer

    -            outputs = {getnewdestination()[2]: 1}
    -            rawtx = self.nodes[0].createrawtransaction(inputs, outputs)
    +            address = getnewdestination()[2]
    +            rawtx = self.nodes[0].createrawtransaction(inputs=inputs, outputs={address: 1})
    

    MarcoFalke commented at 1:32 PM on May 17, 2022:

    If this is unclear, it might be clearer to change this everywhere wheregetnewdestination is used (in a separate pull)?


    jonatack commented at 1:44 PM on May 17, 2022:

    Right, and/or maybe have it return a dict: getnewdestination()['address']


    danielabrozzoni commented at 9:51 AM on May 18, 2022:

    Fixed, thanks! From a quick git grep it seems to me the usage of getnewdestination is clear in the other tests:

    test/functional/feature_coinstatsindex.py:    getnewdestination,
    test/functional/feature_coinstatsindex.py:        reorg_blocks = self.generatetoaddress(index_node, 2, getnewdestination()[2])
    test/functional/interface_rest.py:    getnewdestination,
    test/functional/interface_rest.py:        txid, _ = self.wallet.send_to(from_node=self.nodes[0], scriptPubKey=getnewdestination()[1], amount=int(0.1 * COIN))
    test/functional/interface_rest.py:        txid, _ = self.wallet.send_to(from_node=self.nodes[0], scriptPubKey=getnewdestination()[1], amount=int(0.1 * COIN))
    test/functional/p2p_filter.py:    getnewdestination,
    test/functional/p2p_filter.py:        block_hash = self.generatetoscriptpubkey(getnewdestination()[1])
    test/functional/p2p_filter.py:        self.wallet.send_to(from_node=self.nodes[0], scriptPubKey=getnewdestination()[1], amount=7 * COIN)
    test/functional/p2p_filter.py:            txid, _ = self.wallet.send_to(from_node=self.nodes[0], scriptPubKey=getnewdestination()[1], amount=7 * COIN)
    test/functional/p2p_filter.py:            block_hash = self.generatetoscriptpubkey(getnewdestination()[1])
    test/functional/rpc_createmultisig.py:    getnewdestination,
    test/functional/rpc_createmultisig.py:            self.final = getnewdestination()[2]
    test/functional/rpc_createmultisig.py:        pk0 = getnewdestination()[0].hex()
    test/functional/rpc_createmultisig.py:        pk1 = getnewdestination()[0].hex()
    test/functional/rpc_createmultisig.py:        pk2 = getnewdestination()[0].hex()
    test/functional/rpc_rawtransaction.py:    getnewdestination,
    test/functional/rpc_rawtransaction.py:            address = getnewdestination()[2]
    test/functional/rpc_rawtransaction.py:            address = getnewdestination()[2]
    test/functional/rpc_rawtransaction.py:        address = getnewdestination()[2]
    test/functional/rpc_rawtransaction.py:        address2 = getnewdestination()[2]
    test/functional/rpc_scantxoutset.py:    getnewdestination,
    test/functional/rpc_scantxoutset.py:        pubk1, spk_P2SH_SEGWIT, addr_P2SH_SEGWIT = getnewdestination("p2sh-segwit")
    test/functional/rpc_scantxoutset.py:        pubk2, spk_LEGACY, addr_LEGACY = getnewdestination("legacy")
    test/functional/rpc_scantxoutset.py:        pubk3, spk_BECH32, addr_BECH32 = getnewdestination("bech32")
    test/functional/test_framework/wallet.py:def getnewdestination(address_type='bech32'):
    
  25. in test/functional/rpc_rawtransaction.py:217 in 6672cebfb1 outdated
     216 |  
     217 |          # Test `createrawtransaction` invalid `outputs`
     218 | -        address = self.nodes[0].getnewaddress()
     219 | -        address2 = self.nodes[0].getnewaddress()
     220 | +        address = getnewdestination()[2]
     221 | +        address2 = getnewdestination()[2]
    


    jonatack commented at 11:44 AM on May 17, 2022:

    nit, since you are touching this maybe move address2 to where it is first used

             address = getnewdestination()[2]
    -        address2 = getnewdestination()[2]
             assert_raises_rpc_error(-1, "JSON value is not an array as expected", self.nodes[0].createrawtransaction, [], 'foo')
             self.nodes[0].createrawtransaction(inputs=[], outputs={})  # Should not throw for backwards compatibility
             self.nodes[0].createrawtransaction(inputs=[], outputs=[])
    @@ -246,6 +242,7 @@ class RawTransactionsTest(BitcoinTestFramework):
                 self.nodes[2].createrawtransaction(inputs=[{'txid': TXID, 'vout': 9}], outputs=[{address: 99}]),
             )
             # Two outputs
    +        address2 = getnewdestination()[2]
             tx = tx_from_hex(self.nodes[2].createrawtransaction(inputs=[{'txid': TXID, 'vout': 9}], outputs=OrderedDict([(address, 99), (address2, 99)])))
    
  26. jonatack commented at 11:57 AM on May 17, 2022: member

    I'm not familiar with reviewing the "convert tests to use MiniWallet" pulls, but poked around a bit and this LGTM.

    ACK 6672cebfb10da112eaca29b4ff0a0a4438749624 this pull also speeds up the test from 17-20 to 12-13 seconds for me

    A few minor comments follow, feel free to pick/choose/ignore, happy to re-ACK if you take any.

  27. danielabrozzoni force-pushed on May 17, 2022
  28. in test/functional/rpc_rawtransaction.py:88 in 66dfa27fe8 outdated
      95 |          self.sendrawtransaction_tests()
      96 |          self.sendrawtransaction_testmempoolaccept_tests()
      97 |          self.decoderawtransaction_tests()
      98 |          self.transaction_version_number_tests()
      99 | -        if not self.options.descriptors:
     100 | +        if self.requires_wallet:
    


    MarcoFalke commented at 11:59 AM on May 18, 2022:

    hmm. Does this mean this test won't be run even if the bdb is compiled, unless the user specifies --legacy-wallet?

    I think it would be better to just run this test if bdb is compiled, no?


    MarcoFalke commented at 11:47 AM on May 27, 2022:

    was this addressed?


    danielabrozzoni commented at 12:51 PM on May 27, 2022:

    I didn't see this comment, sorry!

    If you don't specify any flag, the test_framework will pick self.options.descriptors for you, preferring BDB if it's compiled:

    https://github.com/bitcoin/bitcoin/blob/66bb4df4105945b907a81da0886a1206070554e1/test/functional/test_framework/test_framework.py#L215-L224

    If you specify --descriptors instead, the test won't be run.

    So, the test will be run if the user doesn't specify any flag and bdb is compiled, or if the user specifies --legacy-wallet

  29. in test/functional/rpc_rawtransaction.py:84 in 66dfa27fe8 outdated
      88 | -        self.generate(self.nodes[0], 5)
      89 |  
      90 |          self.getrawtransaction_tests()
      91 |          self.createrawtransaction_tests()
      92 | -        self.signrawtransactionwithwallet_tests()
      93 | +        if self.requires_wallet:
    


    MarcoFalke commented at 12:04 PM on May 18, 2022:

    Hmm. I guess it is not possible to just run the test with the wallet that was compiled, since this will break if both bdb and sqlite are compiled.

    An alternative would be to duplicate the test here once for sqlite and once with bdb? Otherwise, a user will need to run the whole test twice just to test both wallet implementations.

    Another alternative would be to move this to one of the wallet tests?


    danielabrozzoni commented at 4:34 PM on May 18, 2022:

    I just realized I can create the wallets manually inside the tests:

        def signrawtransactionwithwallet_tests(self):
            for descriptors in [True, False]:
                if not descriptors and not self.is_bdb_compiled():
                    pass
                if descriptors and not self.is_sqlite_compiled():
                    pass
                wallet_name = "descriptors" if descriptors else "legacy"
                self.nodes[0].createwallet(wallet_name=wallet_name, descriptors=descriptors)
                wallet = self.nodes[0].get_wallet_rpc(wallet_name)
                for type in ["bech32", "p2sh-segwit", "legacy"]:
                    # etc...
    

    This tests all the wallets that's compiled for, but I'm not sure if it's clean - maybe moving those in the wallet tests, as you suggested, is cleaner?


    MarcoFalke commented at 7:34 AM on May 21, 2022:

    Yeah, it might be cleaner, but a bit more work.


    kouloumos commented at 1:08 PM on May 25, 2022:

    Not exactly an immediate solution, but is there a reason that signrawtransactionwithwallet_tests are not part of rpc_signrawtransaction.py? From my understanding, this issue will also come up for anyone tackling that non-wallet tests convertion, so maybe an other alternative would be to move this to rpc_signrawtransaction.py?


    danielabrozzoni commented at 1:21 PM on May 25, 2022:

    Yeah, since rpc_signrawtransaction.py can't be converted to the MiniWallet (as all the tests in the file require the Core wallet), we could go with moving both signrawtransactionwithwallet_tests and raw_multisig_transaction_legacy_tests, I like it :)


    kouloumos commented at 2:06 PM on May 25, 2022:

    I think that part of rpc_signrawtransaction.py can be converted, similar to how rpc_signmessage.py was converted in #22641. So by moving signrawtransactionwithwallet_tests we'll need to deal with this issue only once (while imo moving the test to a more suitable location).

    I don't think that is neccesary to move raw_multisig_transaction_legacy_tests as it doesn't need more work, it just needs the previous not self.options.descriptors conditional clause instead of self.requires_wallet.


    danielabrozzoni commented at 12:51 PM on May 27, 2022:

    Done in 76f0542a2ae4fd9af7f29d84d89eac1817d47871

  30. MarcoFalke approved
  31. MarcoFalke commented at 12:04 PM on May 18, 2022: member

    LGTM.

    Left some ideas/questions.

  32. jonatack commented at 7:37 PM on May 20, 2022: member

    ACK 66dfa27fe8d68a423ce7e64da05090f1b410fcdc

    modulo addressing the feedback here or in a follow-up

  33. danielabrozzoni force-pushed on May 27, 2022
  34. danielabrozzoni force-pushed on May 27, 2022
  35. in test/functional/rpc_rawtransaction.py:316 in ddf22ff911 outdated
     255 | @@ -260,71 +256,49 @@ def createrawtransaction_tests(self):
     256 |  
     257 |      def sendrawtransaction_tests(self):
     258 |          self.log.info("Test sendrawtransaction with missing input")
     259 | -        inputs = [{'txid': TXID, 'vout': 1}]  # won't exist
     260 | -        outputs = {self.nodes[0].getnewaddress(): 4.998}
     261 | -        rawtx = self.nodes[2].createrawtransaction(inputs, outputs)
     262 | -        rawtx = self.nodes[2].signrawtransactionwithwallet(rawtx)
    


    MarcoFalke commented at 11:47 AM on May 27, 2022:

    I think you can keep this test as-is and just remove this line and replace the call to getnewaddress


    danielabrozzoni commented at 12:51 PM on May 27, 2022:

    Right, thanks!

  36. danielabrozzoni force-pushed on May 27, 2022
  37. in test/functional/rpc_rawtransaction.py:93 in 5a6cd726cc outdated
     100 |  
     101 |      def getrawtransaction_tests(self):
     102 | -        addr = self.nodes[1].getnewaddress()
     103 | -        txid = self.nodes[0].sendtoaddress(addr, 10)
     104 | +        tx = self.wallet.send_self_transfer(from_node=self.nodes[1])
     105 | +        self.sync_all()
    


    kouloumos commented at 2:56 PM on May 28, 2022:

    Is there a reason that this is not from_node=self.nodes[0]? As that would remove the need for self.sync_all(). Or alternatively generate the block from node[1].


    danielabrozzoni commented at 6:36 PM on May 28, 2022:

    As that would remove the need for self.sync_all()

    I think it would still be needed, as we're calling getrawtransaction below, and we want every node to be aware of the tx (sync_all syncs both the mempools and the blocks)

    EDIT: Oh, no, you're right. generate calls sync_all anyways, so sending from node[0] would need a sync_all less. Updating the code :)

  38. kouloumos commented at 2:59 PM on May 28, 2022: member

    ACK 5a6cd726cc56ca26b7af01322d1a344df86cebf6 Tested on macOS 10.15.7 with --disable-wallet, --without-bdb and --enable-wallet and tests run/skip as expected.

    I am not yet familiar with test nodes overhead, but based on my test runs, there is no apparent reason for 4 nodes and this can run a bit faster with 3 nodes (minor changes needed on L58,L62,L101,L139).

  39. danielabrozzoni force-pushed on May 30, 2022
  40. danielabrozzoni commented at 12:50 PM on May 30, 2022: contributor

    Thanks for your review @kouloumos! You're right, the 4th node is useless - I updated the code to use only 3 nodes, (and also removed the useless sync_all), and it runs slightly faster.

    Before: test/functional/rpc_rawtransaction.py 2.12s user 0.64s system 27% cpu 10.121 total After: test/functional/rpc_rawtransaction.py 1.58s user 0.46s system 26% cpu 7.798 total

  41. in test/functional/rpc_signrawtransaction.py:337 in 813b643e36 outdated
     333 | @@ -334,6 +334,56 @@ def test_signing_with_cltv(self):
     334 |          assert_equal(signed["complete"], True)
     335 |          self.nodes[0].sendrawtransaction(signed["hex"])
     336 |  
     337 | +    def signrawtransactionwithwallet_tests(self):
    


    jonatack commented at 1:42 PM on May 30, 2022:

    Looks like the test could use renaming and the logging updated In the first commit? maybe something like this

    diff --git a/test/functional/rpc_signrawtransaction.py b/test/functional/rpc_signrawtransaction.py
    index 29cb116793..8da2cfa72b 100755
    --- a/test/functional/rpc_signrawtransaction.py
    +++ b/test/functional/rpc_signrawtransaction.py
    @@ -334,10 +334,10 @@ class SignRawTransactionsTest(BitcoinTestFramework):
             assert_equal(signed["complete"], True)
             self.nodes[0].sendrawtransaction(signed["hex"])
     
    -    def signrawtransactionwithwallet_tests(self):
    +    def test_signing_with_missing_prevtx_info(self):
             txid = "1d1d4e24ed99057e84c3f80fd8fbec79ed9e1acee37da269356ecea000000000"
             for type in ["bech32", "p2sh-segwit", "legacy"]:
    -            self.log.info(f"Test signrawtransactionwithwallet with missing prevtx info ({type})")
    +            self.log.info(f"Test signing with missing prevtx info ({type})")
                 addr = self.nodes[0].getnewaddress("", type)
                 addrinfo = self.nodes[0].getaddressinfo(addr)
                 pubkey = addrinfo["scriptPubKey"]
    @@ -393,7 +393,7 @@ class SignRawTransactionsTest(BitcoinTestFramework):
             self.test_fully_signed_tx()
             self.test_signing_with_csv()
             self.test_signing_with_cltv()
    -        self.signrawtransactionwithwallet_tests()
    +        self.test_signing_with_missing_prevtx_info()
    
    $ test/functional/rpc_signrawtransaction.py 
    2022-05-30T13:39:10.050000Z TestFramework (INFO): Initializing test directory /tmp/bitcoin_func_test_ukdy99c_
    2022-05-30T13:39:10.954000Z TestFramework (INFO): Test valid raw transaction with one input
    2022-05-30T13:39:10.958000Z TestFramework (INFO): Test script verification errors
    2022-05-30T13:39:10.969000Z TestFramework (INFO): Test signing transaction to P2SH-P2WSH addresses without wallet
    2022-05-30T13:39:12.667000Z TestFramework (INFO): Test with a P2PKH script as the witnessScript
    2022-05-30T13:39:12.822000Z TestFramework (INFO): Test with a P2PK script as the witnessScript
    2022-05-30T13:39:12.970000Z TestFramework (INFO): Test OP_1NEGATE (0x4f) satisfies BIP62 minimal push standardness rule
    2022-05-30T13:39:12.972000Z TestFramework (INFO): Test correct error reporting when trying to sign a locked output
    2022-05-30T13:39:13.519000Z TestFramework (INFO): Test signing a fully signed transaction does nothing
    2022-05-30T13:39:14.504000Z TestFramework (INFO): Test signing a transaction containing a fully signed CSV input
    2022-05-30T13:39:15.920000Z TestFramework (INFO): Test signing a transaction containing a fully signed CLTV input
    2022-05-30T13:39:16.368000Z TestFramework (INFO): Test signing with missing prevtx info (bech32)
    2022-05-30T13:39:16.458000Z TestFramework (INFO): Test signing with missing prevtx info (p2sh-segwit)
    2022-05-30T13:39:16.558000Z TestFramework (INFO): Test signing with missing prevtx info (legacy)
    2022-05-30T13:39:16.699000Z TestFramework (INFO): Stopping nodes
    2022-05-30T13:39:16.904000Z TestFramework (INFO): Cleaning up /tmp/bitcoin_func_test_ukdy99c_ on exit
    2022-05-30T13:39:16.904000Z TestFramework (INFO): Tests successful
    

    jonatack commented at 1:47 PM on May 30, 2022:

    Also in the first commit

    diff --git a/test/functional/rpc_rawtransaction.py b/test/functional/rpc_rawtransaction.py
    index fecb8310b9..54357ccd31 100755
    --- a/test/functional/rpc_rawtransaction.py
    +++ b/test/functional/rpc_rawtransaction.py
    @@ -7,7 +7,6 @@
     Test the following RPCs:
        - getrawtransaction
        - createrawtransaction
    -   - signrawtransactionwithwallet
        - sendrawtransaction
        - decoderawtransaction
     """
    

    Edit: hm, there are still a few in raw_multisig_transaction_legacy_tests() so perhaps never mind


    danielabrozzoni commented at 2:27 PM on May 30, 2022:

    Edit: hm, there are still a few in raw_multisig_transaction_legacy_tests() so perhaps never mind

    Yeah, I'd say it's better to leave it :)

  42. jonatack commented at 1:52 PM on May 30, 2022: member

    ACK 813b643e36bd3bf2a21156ed83a30b33d7703167 per git diff 66dfa27 813b643 modulo a comment or two

  43. MOVEONLY: Move signrawtransactionwithwallet test
    Put signrawtransactionwithwallet_tests in rpc_signrawtransaction.py,
    as the test is mainly testing the signrawtransaction RPC.
    Review with `git show --color-moved=dimmed-zebra`
    e93046c10b
  44. test: Use MiniWallet in rpc_rawtransaction.py
    This test was previously run twice, once with `--legacy-wallet` and once with
    `--descriptors`.
    Now we run it only with `--legacy-wallet`, as all the tests has been
    ported to the MiniWallet but `raw_multisig_transaction_legacy_tests`,
    which can be run only with the legacy wallet.
    We also decrease the number of nodes used from 4 to 3, making the test
    run slightly faster.
    e8959000b6
  45. danielabrozzoni force-pushed on May 30, 2022
  46. jonatack commented at 2:31 PM on May 30, 2022: member

    ACK e8959000b63db4f2a21579fd4be27618c5fbd5b9

  47. MarcoFalke merged this on May 30, 2022
  48. MarcoFalke closed this on May 30, 2022

  49. MarcoFalke commented at 3:27 PM on May 30, 2022: member

    Some further ideas on this test: It looks like it can be speed up by removing sync_all calls, as it is not needed to sync txs when a block is mined on the node that already has the tx. Also, some unused symbols can be removed. Maybe the test should be split up to avoid the re-use of symbols?

    diff --git a/test/functional/rpc_rawtransaction.py b/test/functional/rpc_rawtransaction.py
    index fecb8310b9..31a5002528 100755
    --- a/test/functional/rpc_rawtransaction.py
    +++ b/test/functional/rpc_rawtransaction.py
    @@ -366,5 +366,4 @@ class RawTransactionsTest(BitcoinTestFramework):
             # send 1.2 BTC to msig adr
             txId = self.nodes[0].sendtoaddress(mSigObj, 1.2)
    -        self.sync_all()
             self.generate(self.nodes[0], 1)
             # node2 has both keys of the 2of2 ms addr, tx should affect the balance
    @@ -387,5 +386,4 @@ class RawTransactionsTest(BitcoinTestFramework):
             decTx = self.nodes[0].gettransaction(txId)
             rawTx = self.nodes[0].decoderawtransaction(decTx['hex'])
    -        self.sync_all()
             self.generate(self.nodes[0], 1)
     
    @@ -407,7 +405,5 @@ class RawTransactionsTest(BitcoinTestFramework):
             rawTxSigned = self.nodes[2].signrawtransactionwithwallet(rawTx, inputs)
             assert_equal(rawTxSigned['complete'], True)  # node2 can sign the tx compl., own two of three keys
    -        self.nodes[2].sendrawtransaction(rawTxSigned['hex'])
    -        rawTx = self.nodes[0].decoderawtransaction(rawTxSigned['hex'])
    -        self.sync_all()
    +        self.nodes[0].sendrawtransaction(rawTxSigned['hex'])
             self.generate(self.nodes[0], 1)
             assert_equal(self.nodes[0].getbalance(), bal + Decimal('50.00000000') + Decimal('2.19000000'))  # block reward + tx
    @@ -426,7 +422,4 @@ class RawTransactionsTest(BitcoinTestFramework):
     
             txId = self.nodes[0].sendtoaddress(mSigObj, 2.2)
    -        decTx = self.nodes[0].gettransaction(txId)
    -        rawTx2 = self.nodes[0].decoderawtransaction(decTx['hex'])
    -        self.sync_all()
             self.generate(self.nodes[0], 1)
     
    @@ -450,7 +443,5 @@ class RawTransactionsTest(BitcoinTestFramework):
             rawTxComb = self.nodes[2].combinerawtransaction([rawTxPartialSigned1['hex'], rawTxPartialSigned2['hex']])
             self.log.debug(rawTxComb)
    -        self.nodes[2].sendrawtransaction(rawTxComb)
    -        rawTx2 = self.nodes[0].decoderawtransaction(rawTxComb)
    -        self.sync_all()
    +        self.nodes[0].sendrawtransaction(rawTxComb)
             self.generate(self.nodes[0], 1)
             assert_equal(self.nodes[0].getbalance(), bal + Decimal('50.00000000') + Decimal('2.19000000'))  # block reward + tx
    

    EDIT: Leave a comment here in this thread, if you started working on the previous comment, to avoid duplicate work.

  50. danielabrozzoni deleted the branch on May 30, 2022
  51. jonatack commented at 4:54 PM on May 30, 2022: member

    There is the Part 2 of #22437 (initially #24113 before it was chopped to bugfix only) that I was planning to repropose after updating for the changes here. Won't do it right away so it can be used if anyone wants to: https://github.com/jonatack/bitcoin/commits/improve-getrawtransaction-tests-part-2

  52. MarcoFalke locked this on Jan 24, 2023
  53. MarcoFalke deleted a comment on Jan 24, 2023
  54. MarcoFalke deleted a comment on Jan 24, 2023

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-27 21:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me