Skip to content

Conversation

cvengler
Copy link
Contributor

A test for rpcwhitelistdefault.

@fanquake fanquake added the Tests label Dec 27, 2019
@cvengler cvengler force-pushed the 2019-12-rpc-whitelistdefault-test branch 3 times, most recently from d522a1a to 5450f6f Compare December 27, 2019 21:02
Copy link
Contributor

@promag promag left a comment

Choose a reason for hiding this comment

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

Concept ACK.

@cvengler cvengler force-pushed the 2019-12-rpc-whitelistdefault-test branch from 5450f6f to 669d046 Compare December 28, 2019 00:46
@practicalswift
Copy link
Contributor

Concept ACK

@cvengler cvengler force-pushed the 2019-12-rpc-whitelistdefault-test branch from 669d046 to d76a516 Compare December 28, 2019 02:29
Copy link
Member

@jonatack jonatack left a comment

Choose a reason for hiding this comment

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

I think this test should be added to the existing rpc_whitelist.py test with which this test shares the same imports and rpccall code.

from test_framework.util import (
assert_equal,
get_datadir_path,
str_to_b64str
Copy link
Member

Choose a reason for hiding this comment

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

nit: comma at EOL so it doesn't need to be touched if adding a method below it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The comma is at the end of every line or am I getting it wrong?

Copy link
Member

Choose a reason for hiding this comment

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

Have a look at example_test.py

f.write("rpcwhitelist=__cookie__:getblockcount,getwalletinfo,importprivkey,getblockchaininfo,submitblock,addnode,getpeerinfo,getbestblockhash,getrawmempool,syncwithvalidationinterfacequeue,stop\n")

def run_test(self):
self.log.info("Testing rpcwhitelistdefault=0 with no specififed permissions")
Copy link
Member

Choose a reason for hiding this comment

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

"specified" -- typo here and lines 91 and 94 below


def run_test(self):
self.log.info("Testing rpcwhitelistdefault=0 with no specififed permissions")
assert_equal(200, rpccall(self.nodes[0], "user1", "12345", "getbestblockhash"))
Copy link
Member

Choose a reason for hiding this comment

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

perhaps hoist 200 and 403 to constants like HTTP_OK and HTTP_FORBIDDEN

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a featrue for another PR. Other tests use the plain codes as well


class RPCWhitelistDefaultTest(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 4
Copy link
Member

@jonatack jonatack Dec 28, 2019

Choose a reason for hiding this comment

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

perhaps add self.setup_clean_chain = False for explicitness

Copy link
Contributor Author

@cvengler cvengler Dec 28, 2019

Choose a reason for hiding this comment

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

It doesn't matter anyway as this isn't a chain related test

Copy link
Member

Choose a reason for hiding this comment

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

It is false by default (see test_framework.py::L96), but most tests set it explicitly even when false. It matters a bit for test speed as it controls whether or not to use the cached data directories for the test setup.

@cvengler
Copy link
Contributor Author

I think this test should be added to the existing rpc_whitelist.py test with which this test shares the same imports and rpccall code.

They are two different options. The test would be to big to test both.

@cvengler cvengler force-pushed the 2019-12-rpc-whitelistdefault-test branch from d76a516 to a478f6d Compare December 28, 2019 19:25
@jonatack
Copy link
Member

I think this test should be added to the existing rpc_whitelist.py test with which this test shares the same imports and rpccall code.

They are two different options. The test would be to big to test both.

The tests can be organised into different methods within the same test class and file. Many functional test files are much larger than this one would become. Have a look at the size at p2p_segwit.py, feature_block.py, etc. It may be a bit faster in test run time to group similar tests into the same testfile setup where possible. And otherwise, rpccall could be extracted to a common helper method (if one does not already exist). I could be wrong but this is what I'd try to do. It's up to you.

@cvengler
Copy link
Contributor Author

Even if the featrue is very similar, they test both two different things. rpc_whitelist.py tests permissions, invalid syntaxes, etc.
This test tests if users can even do something but is not limited to specific permissions

Copy link
Contributor

@promag promag left a comment

Choose a reason for hiding this comment

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

I think the new file is fine.

However have you considered to use just one node? Like

  1. change config
  2. restart
  3. test calls/access
  4. repeat

I prefer this way because:

  • new test cases don't imply messing with more nodes;
  • testing the calls/access is immediately after the config.

@cvengler
Copy link
Contributor Author

However have you considered to use just one node? Like

Yes but after all I believe this would make the code much messier because I would need to re-implement some functions. This is probably the most cleanest way on how to do it

@DrahtBot
Copy link
Contributor

DrahtBot commented Jan 4, 2020

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

Conflicts

No conflicts as of last run.

@fanquake
Copy link
Member

Closing as "Up for grabs". If these tests are going to be added, I think adding them to the existing rpc_whitelist.py is the better approach, as well as using a single node as suggested.

@fanquake fanquake closed this Aug 18, 2021
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 18, 2022
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.

7 participants