Skip to content

Conversation

jimmysong
Copy link
Contributor

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

@fanquake fanquake added the Tests label Apr 19, 2017
@@ -57,7 +64,8 @@ def _test_gettxoutsetinfo(self):
def _test_getblockheader(self):
node = self.nodes[0]

assert_raises_jsonrpc(-5, "Block not found", node.getblockheader, "nonsense")
assert_raises_jsonrpc(-5, "Block not found",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change?

Copy link
Contributor Author

@jimmysong jimmysong Apr 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

self.nodes[0].verifychain(4, 0)

def _test_getdifficulty(self):
res = self.nodes[0].getdifficulty()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding to the comment, thanks!

self.nodes[0].verifychain(4, 0)

def _test_getdifficulty(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, will do.

res = self.nodes[0].getdifficulty()
# 1 hash in 2 should be valid, so difficulty should be 1/2**31
# binary => decimal => binary math is why we round
assert_equal(round(res * 2**31, 4), 1.0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a cleverer way to do this?

@jimmysong jimmysong force-pushed the test_getdifficulty branch from bfd615c to a75c80e Compare April 19, 2017 15:02
@jimmysong
Copy link
Contributor Author

Fixed issues, rebased to master.

@jimmysong jimmysong force-pushed the test_getdifficulty branch 2 times, most recently from 8fd75de to ba2b295 Compare April 19, 2017 15:19
Copy link
Contributor

@paveljanik paveljanik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 821dd5e

Copy link
Contributor

@jnewbery jnewbery left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Tested ACK ba2b295093d5f5cad4701f9ca86b2c83e60c3ef9.

A few nits which you can take or leave.

@@ -6,6 +6,7 @@

Test the following RPCs:
- gettxoutsetinfo
- getdifficulty
- verifychain
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  • getbestblockhash
  • getblockhash
  • getblockheader

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea.

@@ -57,7 +64,8 @@ def _test_gettxoutsetinfo(self):
def _test_getblockheader(self):
node = self.nodes[0]

assert_raises_jsonrpc(-5, "Block not found", node.getblockheader, "nonsense")
assert_raises_jsonrpc(-5, "Block not found",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

@@ -79,5 +82,11 @@ def _test_getblockheader(self):
assert isinstance(int(header['versionHex'], 16), int)
assert isinstance(header['difficulty'], Decimal)

def _test_getdifficulty(self):
res = self.nodes[0].getdifficulty()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense.

Test added to blockchain.py as adding a new test to reduce test run time.
@jimmysong jimmysong force-pushed the test_getdifficulty branch from ba2b295 to 821dd5e Compare April 19, 2017 21:53
@jimmysong
Copy link
Contributor Author

Fixed nits and squashed.

@laanwj laanwj merged commit 821dd5e into bitcoin:master Apr 21, 2017
laanwj added a commit that referenced this pull request Apr 21, 2017
821dd5e Tests: Add test for getdifficulty (Jimmy Song)

Tree-SHA512: 3da78c4f88efdaab8374582cda606620beb2f1e9a93119a72b67572702c17c36b68c3abf9d466e8c7fb8ba9e8afa9a172e454c553df10d3054f19b3282d3097b
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request May 21, 2019
821dd5e Tests: Add test for getdifficulty (Jimmy Song)

Tree-SHA512: 3da78c4f88efdaab8374582cda606620beb2f1e9a93119a72b67572702c17c36b68c3abf9d466e8c7fb8ba9e8afa9a172e454c553df10d3054f19b3282d3097b
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request May 22, 2019
821dd5e Tests: Add test for getdifficulty (Jimmy Song)

Tree-SHA512: 3da78c4f88efdaab8374582cda606620beb2f1e9a93119a72b67572702c17c36b68c3abf9d466e8c7fb8ba9e8afa9a172e454c553df10d3054f19b3282d3097b
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request May 22, 2019
821dd5e Tests: Add test for getdifficulty (Jimmy Song)

Tree-SHA512: 3da78c4f88efdaab8374582cda606620beb2f1e9a93119a72b67572702c17c36b68c3abf9d466e8c7fb8ba9e8afa9a172e454c553df10d3054f19b3282d3097b
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request May 22, 2019
821dd5e Tests: Add test for getdifficulty (Jimmy Song)

Tree-SHA512: 3da78c4f88efdaab8374582cda606620beb2f1e9a93119a72b67572702c17c36b68c3abf9d466e8c7fb8ba9e8afa9a172e454c553df10d3054f19b3282d3097b
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request May 23, 2019
821dd5e Tests: Add test for getdifficulty (Jimmy Song)

Tree-SHA512: 3da78c4f88efdaab8374582cda606620beb2f1e9a93119a72b67572702c17c36b68c3abf9d466e8c7fb8ba9e8afa9a172e454c553df10d3054f19b3282d3097b
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request May 23, 2019
821dd5e Tests: Add test for getdifficulty (Jimmy Song)

Tree-SHA512: 3da78c4f88efdaab8374582cda606620beb2f1e9a93119a72b67572702c17c36b68c3abf9d466e8c7fb8ba9e8afa9a172e454c553df10d3054f19b3282d3097b
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request May 28, 2019
821dd5e Tests: Add test for getdifficulty (Jimmy Song)

Tree-SHA512: 3da78c4f88efdaab8374582cda606620beb2f1e9a93119a72b67572702c17c36b68c3abf9d466e8c7fb8ba9e8afa9a172e454c553df10d3054f19b3282d3097b
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request May 28, 2019
821dd5e Tests: Add test for getdifficulty (Jimmy Song)

Tree-SHA512: 3da78c4f88efdaab8374582cda606620beb2f1e9a93119a72b67572702c17c36b68c3abf9d466e8c7fb8ba9e8afa9a172e454c553df10d3054f19b3282d3097b
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 7, 2019
821dd5e Tests: Add test for getdifficulty (Jimmy Song)

Tree-SHA512: 3da78c4f88efdaab8374582cda606620beb2f1e9a93119a72b67572702c17c36b68c3abf9d466e8c7fb8ba9e8afa9a172e454c553df10d3054f19b3282d3097b
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 8, 2019
821dd5e Tests: Add test for getdifficulty (Jimmy Song)

Tree-SHA512: 3da78c4f88efdaab8374582cda606620beb2f1e9a93119a72b67572702c17c36b68c3abf9d466e8c7fb8ba9e8afa9a172e454c553df10d3054f19b3282d3097b
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 10, 2019
821dd5e Tests: Add test for getdifficulty (Jimmy Song)

Tree-SHA512: 3da78c4f88efdaab8374582cda606620beb2f1e9a93119a72b67572702c17c36b68c3abf9d466e8c7fb8ba9e8afa9a172e454c553df10d3054f19b3282d3097b
barrystyle pushed a commit to PACGlobalOfficial/PAC that referenced this pull request Jan 22, 2020
821dd5e Tests: Add test for getdifficulty (Jimmy Song)

Tree-SHA512: 3da78c4f88efdaab8374582cda606620beb2f1e9a93119a72b67572702c17c36b68c3abf9d466e8c7fb8ba9e8afa9a172e454c553df10d3054f19b3282d3097b
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants