Tests: Add test for getdifficulty #10229

pull jimmysong wants to merge 1 commits into bitcoin:master from jimmysong:test_getdifficulty changing 1 files +13 −1
  1. jimmysong commented at 2:58 AM on April 19, 2017: contributor

    Test added to blockchain.py as adding a new test to reduce test run time.

  2. fanquake added the label Tests on Apr 19, 2017
  3. in test/functional/blockchain.py:65 in bfd615c6e2 outdated
      63 | @@ -57,7 +64,8 @@ def _test_gettxoutsetinfo(self):
      64 |      def _test_getblockheader(self):
      65 |          node = self.nodes[0]
      66 |  
      67 | -        assert_raises_jsonrpc(-5, "Block not found", node.getblockheader, "nonsense")
      68 | +        assert_raises_jsonrpc(-5, "Block not found",
    


    paveljanik commented at 2:21 PM on April 19, 2017:

    Why this change?


    jimmysong commented at 2:54 PM on April 19, 2017:

    flake8 warning: E501 line too long (85 > 79 characters)


    jnewbery commented at 9:40 PM on April 19, 2017:

    My personal preference is to ignore the 'line too long' warning. Nothing wrong with going over 79 character lines in my opinion (but we don't have a style guide for functional tests, so entirely up to you)

  4. in test/functional/blockchain.py:47 in bfd615c6e2 outdated
      39 | @@ -40,8 +40,15 @@ def setup_network(self, split=False):
      40 |      def run_test(self):
      41 |          self._test_gettxoutsetinfo()
      42 |          self._test_getblockheader()
      43 | +        self._test_getdifficulty()
      44 |          self.nodes[0].verifychain(4, 0)
      45 |  
      46 | +    def _test_getdifficulty(self):
      47 | +        res = self.nodes[0].getdifficulty()
    


    paveljanik commented at 2:27 PM on April 19, 2017:

    Mention the getdifficulty RPC test in the top level comment or remove the list of tested methods there.


    jimmysong commented at 2:54 PM on April 19, 2017:

    adding to the comment, thanks!

  5. in test/functional/blockchain.py:46 in bfd615c6e2 outdated
      39 | @@ -40,8 +40,15 @@ def setup_network(self, split=False):
      40 |      def run_test(self):
      41 |          self._test_gettxoutsetinfo()
      42 |          self._test_getblockheader()
      43 | +        self._test_getdifficulty()
      44 |          self.nodes[0].verifychain(4, 0)
      45 |  
      46 | +    def _test_getdifficulty(self):
    


    paveljanik commented at 2:42 PM on April 19, 2017:

    Can you move the def after the _test_getblockheader so it is ordered the same as it is called?


    jimmysong commented at 2:53 PM on April 19, 2017:

    Yep, will do.

  6. in test/functional/blockchain.py:50 in bfd615c6e2 outdated
      45 |  
      46 | +    def _test_getdifficulty(self):
      47 | +        res = self.nodes[0].getdifficulty()
      48 | +        # 1 hash in 2 should be valid, so difficulty should be 1/2**31
      49 | +        # binary => decimal => binary math is why we round
      50 | +        assert_equal(round(res * 2**31, 4), 1.0)
    


    paveljanik commented at 2:50 PM on April 19, 2017:

    Ugh.


    jimmysong commented at 2:54 PM on April 19, 2017:

    Is there a cleverer way to do this?

  7. paveljanik changes_requested
  8. jimmysong force-pushed on Apr 19, 2017
  9. jimmysong commented at 3:03 PM on April 19, 2017: contributor

    Fixed issues, rebased to master.

  10. jimmysong force-pushed on Apr 19, 2017
  11. jimmysong force-pushed on Apr 19, 2017
  12. paveljanik approved
  13. paveljanik commented at 4:13 PM on April 19, 2017: contributor

    ACK 821dd5e

  14. in test/functional/blockchain.py:13 in ba2b295093 outdated
       5 | @@ -6,6 +6,7 @@
       6 |  
       7 |  Test the following RPCs:
       8 |      - gettxoutsetinfo
       9 | +    - getdifficulty
      10 |      - verifychain
    


    jnewbery commented at 9:39 PM on April 19, 2017:

    Might as well fix this docstring while you're at it. The following RPCs are also tested:

    • getbestblockhash
    • getblockhash
    • getblockheader

    jimmysong commented at 9:52 PM on April 19, 2017:

    good idea.

  15. in test/functional/blockchain.py:86 in ba2b295093 outdated
      81 | @@ -79,5 +82,11 @@ def _test_getblockheader(self):
      82 |          assert isinstance(int(header['versionHex'], 16), int)
      83 |          assert isinstance(header['difficulty'], Decimal)
      84 |  
      85 | +    def _test_getdifficulty(self):
      86 | +        res = self.nodes[0].getdifficulty()
    


    jnewbery commented at 9:41 PM on April 19, 2017:

    I'd prefer a more descriptive name than res, perhaps difficulty? (or even combine with the line below)


    jimmysong commented at 9:53 PM on April 19, 2017:

    Makes sense.

  16. jnewbery commented at 9:41 PM on April 19, 2017: member

    Looks good. Tested ACK ba2b295093d5f5cad4701f9ca86b2c83e60c3ef9.

    A few nits which you can take or leave.

  17. jnewbery approved
  18. Tests: Add test for getdifficulty
    Test added to blockchain.py as adding a new test to reduce test run time.
    821dd5e3e1
  19. jimmysong force-pushed on Apr 19, 2017
  20. jimmysong commented at 9:54 PM on April 19, 2017: contributor

    Fixed nits and squashed.

  21. laanwj merged this on Apr 21, 2017
  22. laanwj closed this on Apr 21, 2017

  23. laanwj referenced this in commit f3db4c6013 on Apr 21, 2017
  24. PastaPastaPasta referenced this in commit 64373eda0d on May 21, 2019
  25. PastaPastaPasta referenced this in commit 73fcaed8a5 on May 22, 2019
  26. PastaPastaPasta referenced this in commit 7881acd853 on May 22, 2019
  27. PastaPastaPasta referenced this in commit 5a4845ec9d on May 22, 2019
  28. PastaPastaPasta referenced this in commit b889dfdc9e on May 23, 2019
  29. PastaPastaPasta referenced this in commit f221038c5e on May 23, 2019
  30. PastaPastaPasta referenced this in commit 9d2e8fccf5 on May 28, 2019
  31. PastaPastaPasta referenced this in commit dfca65cee4 on May 28, 2019
  32. PastaPastaPasta referenced this in commit b6df927e51 on Jun 7, 2019
  33. PastaPastaPasta referenced this in commit 6fb2866868 on Jun 8, 2019
  34. PastaPastaPasta referenced this in commit 59e7a0a913 on Jun 10, 2019
  35. barrystyle referenced this in commit 97b8756acb on Jan 22, 2020
  36. 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-27 15:16 UTC

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