Skip to content

Commit 011e784

Browse files
committed
[tests] Rename segwit encode and decode functions
These functions can be exported to other modules, so be explicit that they're encoding and decoding segwit addresses
1 parent e455713 commit 011e784

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

test/functional/test_framework/address.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
import unittest
99

1010
from .script import hash256, hash160, sha256, CScript, OP_0
11+
from .segwit_addr import encode_segwit_address
1112
from .util import hex_str_to_bytes
1213

13-
from . import segwit_addr
1414

1515
from test_framework.util import assert_equal
1616

@@ -100,7 +100,7 @@ def program_to_witness(version, program, main = False):
100100
assert 0 <= version <= 16
101101
assert 2 <= len(program) <= 40
102102
assert version > 0 or len(program) in [20, 32]
103-
return segwit_addr.encode("bc" if main else "bcrt", version, program)
103+
return encode_segwit_address("bc" if main else "bcrt", version, program)
104104

105105
def script_to_p2wsh(script, main = False):
106106
script = check_script(script)

test/functional/test_framework/segwit_addr.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def convertbits(data, frombits, tobits, pad=True):
8484
return ret
8585

8686

87-
def decode(hrp, addr):
87+
def decode_segwit_address(hrp, addr):
8888
"""Decode a segwit address."""
8989
hrpgot, data = bech32_decode(addr)
9090
if hrpgot != hrp:
@@ -99,10 +99,10 @@ def decode(hrp, addr):
9999
return (data[0], decoded)
100100

101101

102-
def encode(hrp, witver, witprog):
102+
def encode_segwit_address(hrp, witver, witprog):
103103
"""Encode a segwit address."""
104104
ret = bech32_encode(hrp, [witver] + convertbits(witprog, 8, 5))
105-
if decode(hrp, ret) == (None, None):
105+
if decode_segwit_address(hrp, ret) == (None, None):
106106
return None
107107
return ret
108108

@@ -111,8 +111,8 @@ def test_segwit_encode_decode(self):
111111
def test_python_bech32(addr):
112112
hrp = addr[:4]
113113
self.assertEqual(hrp, "bcrt")
114-
(witver, witprog) = decode(hrp, addr)
115-
self.assertEqual(encode(hrp, witver, witprog), addr)
114+
(witver, witprog) = decode_segwit_address(hrp, addr)
115+
self.assertEqual(encode_segwit_address(hrp, witver, witprog), addr)
116116

117117
# P2WPKH
118118
test_python_bech32('bcrt1qthmht0k2qnh3wy7336z05lu2km7emzfpm3wg46')

0 commit comments

Comments
 (0)