it seems that all other functional tests that have such unit tests are all in test/functional/test_framework
instead.
0 test % grep -r 'unittest.TestCase' .
1./functional/feature_framework_unit_tests.py:# the output of `git grep unittest.TestCase ./test/functional/test_framework`
2./functional/test_framework/address.py:class TestFrameworkScript(unittest.TestCase):
3./functional/test_framework/crypto/ellswift.py:class TestFrameworkEllSwift(unittest.TestCase):
4./functional/test_framework/crypto/muhash.py:class TestFrameworkMuhash(unittest.TestCase):
5./functional/test_framework/crypto/poly1305.py:class TestFrameworkPoly1305(unittest.TestCase):
6./functional/test_framework/crypto/chacha20.py:class TestFrameworkChacha(unittest.TestCase):
7./functional/test_framework/crypto/ripemd160.py:class TestFrameworkKey(unittest.TestCase):
8./functional/test_framework/crypto/bip324_cipher.py:class TestFrameworkAEAD(unittest.TestCase):
9./functional/test_framework/crypto/secp256k1.py:class TestFrameworkSecp256k1(unittest.TestCase):
10./functional/test_framework/key.py:class TestFrameworkKey(unittest.TestCase):
11./functional/test_framework/script_util.py:class TestFrameworkScriptUtil(unittest.TestCase):
12./functional/test_framework/wallet_util.py:class TestFrameworkWalletUtil(unittest.TestCase):
13./functional/test_framework/segwit_addr.py:class TestFrameworkScript(unittest.TestCase):
14./functional/test_framework/blocktools.py:class TestFrameworkBlockTools(unittest.TestCase):
15./functional/test_framework/messages.py:class TestFrameworkScript(unittest.TestCase):
16./functional/test_framework/compressor.py:class TestFrameworkCompressor(unittest.TestCase):
17./functional/test_framework/script.py:class TestFrameworkScript(unittest.TestCase):
18./functional/tool_rpcauth.py:class TestRPCAuth(unittest.TestCase):
But instead of moving the new test there - given that all other tool_*
tests are in the same place -, we could change the test structure instead to correspond to the other ones in the same category
0git ls-files test/functional/tool_*.py
1test/functional/tool_bitcoin_chainstate.py
2test/functional/tool_rpcauth.py
3test/functional/tool_signet_miner.py
4test/functional/tool_utils.py
5test/functional/tool_utxo_to_sqlite.py
6test/functional/tool_wallet.py
I was thinking something like this:
0#!/usr/bin/env python3
1# Copyright (c) 2015-present The Bitcoin Core developers
2# Distributed under the MIT software license, see the accompanying
3# file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5"""Test share/rpcauth/rpcauth.py
6"""
7
8import hmac
9import re
10
11from hashlib import sha256
12from importlib.util import spec_from_file_location, module_from_spec
13from test_framework.test_framework import BitcoinTestFramework
14
15
16class ToolRPCAuthTest(BitcoinTestFramework):
17 def set_test_params(self):
18 self.num_nodes = 0 # No node/datadir needed
19
20 def setup_network(self):
21 pass # nothing to start
22
23 def run_test(self):
24 spec = spec_from_file_location('rpcauth', self.config['environment']['RPCAUTH'])
25 spec.loader.exec_module(rpcauth := module_from_spec(spec))
26
27 self.log.info("Verify generate_salt() returns hex of correct length")
28 for i in range(16, 32 + 1):
29 assert len(rpcauth.generate_salt(i)) == i * 2
30
31 self.log.info("Test that generated passwords only consist of urlsafe characters")
32 assert re.fullmatch(r"[-\w]+", rpcauth.generate_password(), flags=re.ASCII)
33
34 self.log.info("Verify password_to_hmac() matches SHA-256 HMAC")
35 salt = rpcauth.generate_salt(16)
36 pwd = rpcauth.generate_password()
37 expected = hmac.new(salt.encode(), pwd.encode(), sha256).hexdigest()
38 assert rpcauth.password_to_hmac(salt, pwd) == expected
39
40
41if __name__ == '__main__':
42 ToolRPCAuthTest(__file__).main()