mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-05-31 08:13:52 +02:00
scripted-diff: replace remaining Python test equality asserts
Some Python functional tests still use plain `assert x == y`. The earlier commits convert the ambiguous assert patterns by hand, so this commit can rewrite the remaining safe cases mechanically. The verify script excludes `wallet_bumpfee.py`, `test_framework/netutil.py`, and `test_framework/authproxy.py`, which still contain assert forms that the plain line-based substitution would misidentify. -BEGIN VERIFY SCRIPT- perl -pi -e 's/^(\s*)assert (.+?) == ([^,#]+?)$/\1assert_equal(\2, \3)/' $(git ls-files -- 'test/functional' \ ':(exclude)test/functional/wallet_bumpfee.py' ':(exclude)test/functional/test_framework/netutil.py' ':(exclude)test/functional/test_framework/authproxy.py') -END VERIFY SCRIPT-
This commit is contained in:
@@ -132,7 +132,7 @@ class ECKey:
|
||||
|
||||
def set(self, secret, compressed):
|
||||
"""Construct a private key object with given 32-byte secret and compressed flag."""
|
||||
assert len(secret) == 32
|
||||
assert_equal(len(secret), 32)
|
||||
secret = int.from_bytes(secret, 'big')
|
||||
self.valid = (secret > 0 and secret < ORDER)
|
||||
if self.valid:
|
||||
@@ -194,7 +194,7 @@ def compute_xonly_pubkey(key):
|
||||
This also returns whether the resulting public key was negated.
|
||||
"""
|
||||
|
||||
assert len(key) == 32
|
||||
assert_equal(len(key), 32)
|
||||
x = int.from_bytes(key, 'big')
|
||||
if x == 0 or x >= ORDER:
|
||||
return (None, None)
|
||||
@@ -204,8 +204,8 @@ def compute_xonly_pubkey(key):
|
||||
def tweak_add_privkey(key, tweak):
|
||||
"""Tweak a private key (after negating it if needed)."""
|
||||
|
||||
assert len(key) == 32
|
||||
assert len(tweak) == 32
|
||||
assert_equal(len(key), 32)
|
||||
assert_equal(len(tweak), 32)
|
||||
|
||||
x = int.from_bytes(key, 'big')
|
||||
if x == 0 or x >= ORDER:
|
||||
@@ -223,8 +223,8 @@ def tweak_add_privkey(key, tweak):
|
||||
def tweak_add_pubkey(key, tweak):
|
||||
"""Tweak a public key and return whether the result had to be negated."""
|
||||
|
||||
assert len(key) == 32
|
||||
assert len(tweak) == 32
|
||||
assert_equal(len(key), 32)
|
||||
assert_equal(len(tweak), 32)
|
||||
|
||||
P = secp256k1.GE.from_bytes_xonly(key)
|
||||
if P is None:
|
||||
@@ -244,8 +244,8 @@ def verify_schnorr(key, sig, msg):
|
||||
- sig is a 64-byte Schnorr signature
|
||||
- msg is a variable-length message
|
||||
"""
|
||||
assert len(key) == 32
|
||||
assert len(sig) == 64
|
||||
assert_equal(len(key), 32)
|
||||
assert_equal(len(sig), 64)
|
||||
|
||||
P = secp256k1.GE.from_bytes_xonly(key)
|
||||
if P is None:
|
||||
@@ -270,8 +270,8 @@ def sign_schnorr(key, msg, aux=None, flip_p=False, flip_r=False):
|
||||
if aux is None:
|
||||
aux = bytes(32)
|
||||
|
||||
assert len(key) == 32
|
||||
assert len(aux) == 32
|
||||
assert_equal(len(key), 32)
|
||||
assert_equal(len(aux), 32)
|
||||
|
||||
sec = int.from_bytes(key, 'big')
|
||||
if sec == 0 or sec >= ORDER:
|
||||
|
||||
Reference in New Issue
Block a user