Skip to content

Commit cf7f153

Browse files
committed
Bump test_framework to v30.0
Can be reproduced or verified as follows: ```bash git clone [email protected]:bitcoin/bitcoin.git --depth 1 --branch 30.x tmp rm -rf resources/scenarios/test_framework/ mv tmp/test/functional/test_framework/ resources/scenarios/ rm -rf tmp ```
1 parent b3ad63b commit cf7f153

35 files changed

+2690
-1109
lines changed

resources/scenarios/test_framework/address.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,20 @@ class AddressType(enum.Enum):
4747
b58chars = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
4848

4949

50-
def create_deterministic_address_bcrt1_p2tr_op_true():
50+
def create_deterministic_address_bcrt1_p2tr_op_true(explicit_internal_key=None):
5151
"""
5252
Generates a deterministic bech32m address (segwit v1 output) that
5353
can be spent with a witness stack of OP_TRUE and the control block
5454
with internal public key (script-path spending).
5555
56-
Returns a tuple with the generated address and the internal key.
56+
Returns a tuple with the generated address and the TaprootInfo object.
5757
"""
58-
internal_key = (1).to_bytes(32, 'big')
59-
address = output_key_to_p2tr(taproot_construct(internal_key, [(None, CScript([OP_TRUE]))]).output_pubkey)
60-
assert_equal(address, 'bcrt1p9yfmy5h72durp7zrhlw9lf7jpwjgvwdg0jr0lqmmjtgg83266lqsekaqka')
61-
return (address, internal_key)
58+
internal_key = explicit_internal_key or (1).to_bytes(32, 'big')
59+
taproot_info = taproot_construct(internal_key, [("only-path", CScript([OP_TRUE]))])
60+
address = output_key_to_p2tr(taproot_info.output_pubkey)
61+
if explicit_internal_key is None:
62+
assert_equal(address, 'bcrt1p9yfmy5h72durp7zrhlw9lf7jpwjgvwdg0jr0lqmmjtgg83266lqsekaqka')
63+
return (address, taproot_info)
6264

6365

6466
def byte_to_base58(b, version):
@@ -153,6 +155,9 @@ def output_key_to_p2tr(key, main=False):
153155
assert len(key) == 32
154156
return program_to_witness(1, key, main)
155157

158+
def p2a(main=False):
159+
return program_to_witness(1, "4e73", main)
160+
156161
def check_key(key):
157162
if (type(key) is str):
158163
key = bytes.fromhex(key) # Assuming this is hex string

resources/scenarios/test_framework/authproxy.py

Lines changed: 54 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
2727
- HTTP connections persist for the life of the AuthServiceProxy object
2828
(if server supports HTTP/1.1)
29-
- sends protocol 'version', per JSON-RPC 1.1
29+
- sends "jsonrpc":"2.0", per JSON-RPC 2.0
3030
- sends proper, incrementing 'id'
3131
- sends Basic HTTP authentication headers
3232
- parses all JSON numbers that look like floats as Decimal
@@ -75,6 +75,7 @@ def __init__(self, service_url, service_name=None, timeout=HTTP_TIMEOUT, connect
7575
self.__service_url = service_url
7676
self._service_name = service_name
7777
self.ensure_ascii = ensure_ascii # can be toggled on the fly by tests
78+
self.reuse_http_connections = True
7879
self.__url = urllib.parse.urlparse(service_url)
7980
user = None if self.__url.username is None else self.__url.username.encode('utf8')
8081
passwd = None if self.__url.password is None else self.__url.password.encode('utf8')
@@ -92,6 +93,8 @@ def __getattr__(self, name):
9293
raise AttributeError
9394
if self._service_name is not None:
9495
name = "%s.%s" % (self._service_name, name)
96+
if not self.reuse_http_connections:
97+
self._set_conn()
9598
return AuthServiceProxy(self.__service_url, name, connection=self.__conn)
9699

97100
def _request(self, method, path, postdata):
@@ -102,47 +105,67 @@ def _request(self, method, path, postdata):
102105
'User-Agent': USER_AGENT,
103106
'Authorization': self.__auth_header,
104107
'Content-type': 'application/json'}
108+
if not self.reuse_http_connections:
109+
self._set_conn()
105110
self.__conn.request(method, path, postdata, headers)
106111
return self._get_response()
107112

113+
def _json_dumps(self, obj):
114+
return json.dumps(obj, default=serialization_fallback, ensure_ascii=self.ensure_ascii)
115+
108116
def get_request(self, *args, **argsn):
109117
AuthServiceProxy.__id_count += 1
110118

111-
log.debug("-{}-> {} {}".format(
119+
log.debug("-{}-> {} {} {}".format(
112120
AuthServiceProxy.__id_count,
113121
self._service_name,
114-
json.dumps(args or argsn, default=serialization_fallback, ensure_ascii=self.ensure_ascii),
122+
self._json_dumps(args),
123+
self._json_dumps(argsn),
115124
))
125+
116126
if args and argsn:
117127
params = dict(args=args, **argsn)
118128
else:
119129
params = args or argsn
120-
return {'version': '1.1',
130+
return {'jsonrpc': '2.0',
121131
'method': self._service_name,
122132
'params': params,
123133
'id': AuthServiceProxy.__id_count}
124134

125135
def __call__(self, *args, **argsn):
126-
postdata = json.dumps(self.get_request(*args, **argsn), default=serialization_fallback, ensure_ascii=self.ensure_ascii)
136+
postdata = self._json_dumps(self.get_request(*args, **argsn))
127137
response, status = self._request('POST', self.__url.path, postdata.encode('utf-8'))
128-
if response['error'] is not None:
129-
raise JSONRPCException(response['error'], status)
130-
elif 'result' not in response:
131-
raise JSONRPCException({
132-
'code': -343, 'message': 'missing JSON-RPC result'}, status)
133-
elif status != HTTPStatus.OK:
134-
raise JSONRPCException({
135-
'code': -342, 'message': 'non-200 HTTP status code but no JSON-RPC error'}, status)
138+
# For backwards compatibility tests, accept JSON RPC 1.1 responses
139+
if 'jsonrpc' not in response:
140+
if response['error'] is not None:
141+
raise JSONRPCException(response['error'], status)
142+
elif 'result' not in response:
143+
raise JSONRPCException({
144+
'code': -343, 'message': 'missing JSON-RPC result'}, status)
145+
elif status != HTTPStatus.OK:
146+
raise JSONRPCException({
147+
'code': -342, 'message': 'non-200 HTTP status code but no JSON-RPC error'}, status)
148+
else:
149+
return response['result']
136150
else:
151+
assert response['jsonrpc'] == '2.0'
152+
if status != HTTPStatus.OK:
153+
raise JSONRPCException({
154+
'code': -342, 'message': 'non-200 HTTP status code'}, status)
155+
if 'error' in response:
156+
raise JSONRPCException(response['error'], status)
157+
elif 'result' not in response:
158+
raise JSONRPCException({
159+
'code': -343, 'message': 'missing JSON-RPC 2.0 result and error'}, status)
137160
return response['result']
138161

139162
def batch(self, rpc_call_list):
140-
postdata = json.dumps(list(rpc_call_list), default=serialization_fallback, ensure_ascii=self.ensure_ascii)
163+
postdata = self._json_dumps(list(rpc_call_list))
141164
log.debug("--> " + postdata)
142165
response, status = self._request('POST', self.__url.path, postdata.encode('utf-8'))
143166
if status != HTTPStatus.OK:
144167
raise JSONRPCException({
145-
'code': -342, 'message': 'non-200 HTTP status code but no JSON-RPC error'}, status)
168+
'code': -342, 'message': 'non-200 HTTP status code'}, status)
146169
return response
147170

148171
def _get_response(self):
@@ -160,17 +183,31 @@ def _get_response(self):
160183
raise JSONRPCException({
161184
'code': -342, 'message': 'missing HTTP response from server'})
162185

186+
# Check for no-content HTTP status code, which can be returned when an
187+
# RPC client requests a JSON-RPC 2.0 "notification" with no response.
188+
# Currently this is only possible if clients call the _request() method
189+
# directly to send a raw request.
190+
if http_response.status == HTTPStatus.NO_CONTENT:
191+
if len(http_response.read()) != 0:
192+
raise JSONRPCException({'code': -342, 'message': 'Content received with NO CONTENT status code'})
193+
return None, http_response.status
194+
163195
content_type = http_response.getheader('Content-Type')
164196
if content_type != 'application/json':
165197
raise JSONRPCException(
166198
{'code': -342, 'message': 'non-JSON HTTP response with \'%i %s\' from server' % (http_response.status, http_response.reason)},
167199
http_response.status)
168200

169-
responsedata = http_response.read().decode('utf8')
201+
data = http_response.read()
202+
try:
203+
responsedata = data.decode('utf8')
204+
except UnicodeDecodeError as e:
205+
raise JSONRPCException({
206+
'code': -342, 'message': f'Cannot decode response in utf8 format, content: {data}, exception: {e}'})
170207
response = json.loads(responsedata, parse_float=decimal.Decimal)
171208
elapsed = time.time() - req_start_time
172209
if "error" in response and response["error"] is None:
173-
log.debug("<-%s- [%.6f] %s" % (response["id"], elapsed, json.dumps(response["result"], default=serialization_fallback, ensure_ascii=self.ensure_ascii)))
210+
log.debug("<-%s- [%.6f] %s" % (response["id"], elapsed, self._json_dumps(response["result"])))
174211
else:
175212
log.debug("<-- [%.6f] %s" % (elapsed, responsedata))
176213
return response, http_response.status

resources/scenarios/test_framework/bdb.py

Lines changed: 0 additions & 151 deletions
This file was deleted.

resources/scenarios/test_framework/bip340_test_vectors.csv

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@ index,secret key,public key,aux_rand,message,signature,verification result,comme
1414
12,,DFF1D77F2A671C5F36183726DB2341BE58FEAE1DA2DECED843240F7B502BA659,,243F6A8885A308D313198A2E03707344A4093822299F31D0082EFA98EC4E6C89,FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F69E89B4C5564D00349106B8497785DD7D1D713A8AE82B32FA79D5F7FC407D39B,FALSE,sig[0:32] is equal to field size
1515
13,,DFF1D77F2A671C5F36183726DB2341BE58FEAE1DA2DECED843240F7B502BA659,,243F6A8885A308D313198A2E03707344A4093822299F31D0082EFA98EC4E6C89,6CFF5C3BA86C69EA4B7376F31A9BCB4F74C1976089B2D9963DA2E5543E177769FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141,FALSE,sig[32:64] is equal to curve order
1616
14,,FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC30,,243F6A8885A308D313198A2E03707344A4093822299F31D0082EFA98EC4E6C89,6CFF5C3BA86C69EA4B7376F31A9BCB4F74C1976089B2D9963DA2E5543E17776969E89B4C5564D00349106B8497785DD7D1D713A8AE82B32FA79D5F7FC407D39B,FALSE,public key is not a valid X coordinate because it exceeds the field size
17+
15,0340034003400340034003400340034003400340034003400340034003400340,778CAA53B4393AC467774D09497A87224BF9FAB6F6E68B23086497324D6FD117,0000000000000000000000000000000000000000000000000000000000000000,,71535DB165ECD9FBBC046E5FFAEA61186BB6AD436732FCCC25291A55895464CF6069CE26BF03466228F19A3A62DB8A649F2D560FAC652827D1AF0574E427AB63,TRUE,message of size 0 (added 2022-12)
18+
16,0340034003400340034003400340034003400340034003400340034003400340,778CAA53B4393AC467774D09497A87224BF9FAB6F6E68B23086497324D6FD117,0000000000000000000000000000000000000000000000000000000000000000,11,08A20A0AFEF64124649232E0693C583AB1B9934AE63B4C3511F3AE1134C6A303EA3173BFEA6683BD101FA5AA5DBC1996FE7CACFC5A577D33EC14564CEC2BACBF,TRUE,message of size 1 (added 2022-12)
19+
17,0340034003400340034003400340034003400340034003400340034003400340,778CAA53B4393AC467774D09497A87224BF9FAB6F6E68B23086497324D6FD117,0000000000000000000000000000000000000000000000000000000000000000,0102030405060708090A0B0C0D0E0F1011,5130F39A4059B43BC7CAC09A19ECE52B5D8699D1A71E3C52DA9AFDB6B50AC370C4A482B77BF960F8681540E25B6771ECE1E5A37FD80E5A51897C5566A97EA5A5,TRUE,message of size 17 (added 2022-12)
20+
18,0340034003400340034003400340034003400340034003400340034003400340,778CAA53B4393AC467774D09497A87224BF9FAB6F6E68B23086497324D6FD117,0000000000000000000000000000000000000000000000000000000000000000,99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999,403B12B0D8555A344175EA7EC746566303321E5DBFA8BE6F091635163ECA79A8585ED3E3170807E7C03B720FC54C7B23897FCBA0E9D0B4A06894CFD249F22367,TRUE,message of size 100 (added 2022-12)

resources/scenarios/test_framework/blockfilter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Helper routines relevant for compact block filters (BIP158).
66
"""
7-
from .siphash import siphash
7+
from .crypto.siphash import siphash
88

99

1010
def bip158_basic_element_hash(script_pub_key, N, block_hash):
@@ -29,7 +29,7 @@ def bip158_basic_element_hash(script_pub_key, N, block_hash):
2929

3030

3131
def bip158_relevant_scriptpubkeys(node, block_hash):
32-
""" Determines the basic filter relvant scriptPubKeys as defined in BIP158:
32+
""" Determines the basic filter relevant scriptPubKeys as defined in BIP158:
3333
3434
'A basic filter MUST contain exactly the following items for each transaction in a block:
3535
- The previous output script (the script being spent) for each input, except for

0 commit comments

Comments
 (0)