Rewrite functional tests to not use the wallet #14216

issue MarcoFalke opened this issue on September 13, 2018
  1. MarcoFalke commented at 10:02 PM on September 13, 2018: member

    This is a fun good first issue. Basically you checkout master, compile without wallet support and run the functional test suite. Then replace generate with generatetoaddress in all non-wallet tests that are skipped (greyed out in the summary).

    Example:

    diff --git a/test/functional/p2p_unrequested_blocks.py b/test/functional/p2p_unrequested_blocks.py
    index 232274f59e..c681ffce90 100755
    --- a/test/functional/p2p_unrequested_blocks.py
    +++ b/test/functional/p2p_unrequested_blocks.py
    @@ -85,8 +85,8 @@ class AcceptBlockTest(BitcoinTestFramework):
             min_work_node = self.nodes[1].add_p2p_connection(P2PInterface())
     
             # 1. Have nodes mine a block (leave IBD)
    -        [ n.generate(1) for n in self.nodes ]
    -        tips = [ int("0x" + n.getbestblockhash(), 0) for n in self.nodes ]
    +        [n.generatetoaddress(1, n.get_deterministic_priv_key()[0]) for n in self.nodes]
    +        tips = [int("0x" + n.getbestblockhash(), 0) for n in self.nodes]
     
             # 2. Send one block that builds on each tip.
             # This should be accepted by node0
    diff --git a/test/functional/rpc_bind.py b/test/functional/rpc_bind.py
    index 53916d5290..c2792401a6 100755
    --- a/test/functional/rpc_bind.py
    +++ b/test/functional/rpc_bind.py
    @@ -17,7 +17,7 @@ class RPCBindTest(BitcoinTestFramework):
             self.num_nodes = 1
     
         def setup_network(self):
    -        self.add_nodes(self.num_nodes, None)
    +        self.add_nodes(self.num_nodes)
     
         def add_options(self, parser):
             parser.add_argument("--ipv4", action='store_true', dest="run_ipv4", help="Run ipv4 tests only", default=False)
    diff --git a/test/functional/rpc_preciousblock.py b/test/functional/rpc_preciousblock.py
    index f383b82bb5..5fe5a553f3 100755
    --- a/test/functional/rpc_preciousblock.py
    +++ b/test/functional/rpc_preciousblock.py
    @@ -38,28 +38,26 @@ class PreciousTest(BitcoinTestFramework):
             self.setup_clean_chain = True
             self.num_nodes = 3
     
    -    def skip_test_if_missing_module(self):
    -        self.skip_if_no_wallet()
    -
         def setup_network(self):
             self.setup_nodes()
     
         def run_test(self):
    +        gen_address = lambda i: self.nodes[i].get_deterministic_priv_key()[0]  # A non-wallet address to mine to
             self.log.info("Ensure submitblock can in principle reorg to a competing chain")
    -        self.nodes[0].generate(1)
    +        self.nodes[0].generatetoaddress(1, gen_address(0))
             assert_equal(self.nodes[0].getblockcount(), 1)
    -        hashZ = self.nodes[1].generate(2)[-1]
    +        hashZ = self.nodes[1].generatetoaddress(2, gen_address(1))[-1]
             assert_equal(self.nodes[1].getblockcount(), 2)
             node_sync_via_rpc(self.nodes[0:3])
             assert_equal(self.nodes[0].getbestblockhash(), hashZ)
     
             self.log.info("Mine blocks A-B-C on Node 0")
    -        hashC = self.nodes[0].generate(3)[-1]
    +        hashC = self.nodes[0].generatetoaddress(3, gen_address(0))[-1]
             assert_equal(self.nodes[0].getblockcount(), 5)
             self.log.info("Mine competing blocks E-F-G on Node 1")
    -        hashG = self.nodes[1].generate(3)[-1]
    +        hashG = self.nodes[1].generatetoaddress(3, gen_address(1))[-1]
             assert_equal(self.nodes[1].getblockcount(), 5)
    -        assert(hashC != hashG)
    +        assert (hashC != hashG)
             self.log.info("Connect nodes and check no reorg occurs")
             # Submit competing blocks via RPC so any reorg should occur before we proceed (no way to wait on inaction for p2p sync)
             node_sync_via_rpc(self.nodes[0:2])
    @@ -86,7 +84,7 @@ class PreciousTest(BitcoinTestFramework):
             self.nodes[1].preciousblock(hashC)
             assert_equal(self.nodes[1].getbestblockhash(), hashC)
             self.log.info("Mine another block (E-F-G-)H on Node 0 and reorg Node 1")
    -        self.nodes[0].generate(1)
    +        self.nodes[0].generatetoaddress(1, gen_address(0))
             assert_equal(self.nodes[0].getblockcount(), 6)
             sync_blocks(self.nodes[0:2])
             hashH = self.nodes[0].getbestblockhash()
    @@ -95,7 +93,7 @@ class PreciousTest(BitcoinTestFramework):
             self.nodes[1].preciousblock(hashC)
             assert_equal(self.nodes[1].getbestblockhash(), hashH)
             self.log.info("Mine competing blocks I-J-K-L on Node 2")
    -        self.nodes[2].generate(4)
    +        self.nodes[2].generatetoaddress(4, gen_address(2))
             assert_equal(self.nodes[2].getblockcount(), 6)
             hashL = self.nodes[2].getbestblockhash()
             self.log.info("Connect nodes and check no reorg occurs")
    
  2. MarcoFalke added the label Tests on Sep 13, 2018
  3. MarcoFalke added the label good first issue on Sep 13, 2018
  4. MarcoFalke added this to the milestone 0.18.0 on Sep 13, 2018
  5. MarcoFalke commented at 10:05 PM on September 13, 2018: member

    There are extra points when you change get_deterministic_priv_key to return a named tuple (address, key) instead of the currently unnamed tuple. :tada:

  6. sanket1729 commented at 5:32 AM on September 15, 2018: contributor

    I would like to give this a try. Seems pretty fun for a first issue. If I understand correctly, instead of skipping the tests for non-wallet mode we simply mine to non-wallet address to make the tests run.

  7. laanwj commented at 9:20 AM on September 15, 2018: member

    I think this is good to have, but be careful that you don't accidentally reduce wallet test coverage: at the least, don't do this for tests which intentionally test wallet functionality, especially those that have "wallet" in the name :-)

    If I understand correctly, instead of skipping the tests for non-wallet mode we simply mine to non-wallet address to make the tests run.

    yes—if nothing is done with the coins, that's all it takes

  8. MarcoFalke commented at 1:19 PM on September 15, 2018: member

    Jup, you can filter out all tests that do something like getbalance or sendtoaddress and leave them as is.

    The only replacement should be generate --> generatetoaddress with a dummy address.

  9. sanket1729 commented at 3:58 PM on September 15, 2018: contributor

    Related to this issue, I was wondering if some of tests could be changed to spend the deterministic address instead of using rpcs to spend them. That way we only have to we sendrawtransaction which should not require wallet.

  10. MarcoFalke commented at 4:05 PM on September 15, 2018: member

    Yeah makes sense to do this as well. Maybe as separate commit on top of the trivial generate --> generatetoaddress changes? But feel free to do it the way you like more. I bet other reviewers will chime in later.

  11. sanket1729 referenced this in commit 28b7101509 on Sep 17, 2018
  12. sanket1729 referenced this in commit b3b8f04c49 on Sep 17, 2018
  13. sanket1729 referenced this in commit 0ca4c8b3c6 on Sep 17, 2018
  14. MarcoFalke referenced this in commit 4901c00792 on Sep 17, 2018
  15. MarcoFalke commented at 10:01 PM on September 25, 2018: member

    The remaining non-wallet tests could be rewritten to use a primitive python wallet implementation as fallback for transaction creation if the Bitcoin Core wallet is not available.

  16. MarcoFalke closed this on Sep 25, 2018

  17. practicalswift referenced this in commit 84d80e54b2 on Oct 3, 2018
  18. jfhk referenced this in commit 95d7f6539f on Nov 14, 2018
  19. DrahtBot locked this on Sep 8, 2021

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-14 18:15 UTC

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