@@ -68,6 +68,12 @@ def T(hex_scriptpubkey, expected_str_address, expected_class):
6868 P2SHBitcoinAddress )
6969 T ('76a914000000000000000000000000000000000000000088ac' , '1111111111111111111114oLvT2' ,
7070 P2PKHBitcoinAddress )
71+ T ('0014751e76e8199196d454941c45d1b3a323f1433bd6' ,
72+ 'bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4' ,
73+ P2WPKHBitcoinAddress )
74+ T ('0020c7a1f1a4d6b4c1802a59631966a18359de779e8a6a65973735a3ccdfdabc407d' ,
75+ 'bc1qc7slrfxkknqcq2jevvvkdgvrt8080852dfjewde450xdlk4ugp7szw5tk9' ,
76+ P2WSHBitcoinAddress )
7177
7278 def test_from_nonstd_scriptPubKey (self ):
7379 """CBitcoinAddress.from_scriptPubKey() with non-standard scriptPubKeys"""
@@ -111,6 +117,23 @@ def test_from_invalid_scriptPubKey(self):
111117 with self .assertRaises (CBitcoinAddressError ):
112118 CBitcoinAddress .from_scriptPubKey (scriptPubKey )
113119
120+ def test_to_redeemScript (self ):
121+ def T (str_addr , expected_scriptPubKey_hexbytes ):
122+ addr = CBitcoinAddress (str_addr )
123+
124+ actual_scriptPubKey = addr .to_redeemScript ()
125+ self .assertEqual (b2x (actual_scriptPubKey ),
126+ expected_scriptPubKey_hexbytes )
127+
128+ T ('31h1vYVSYuKP6AhS86fbRdMw9XHieotbST' ,
129+ 'a914000000000000000000000000000000000000000087' )
130+
131+ T ('1111111111111111111114oLvT2' ,
132+ '76a914000000000000000000000000000000000000000088ac' )
133+
134+ T ('bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4' ,
135+ '76a914751e76e8199196d454941c45d1b3a323f1433bd688ac' )
136+
114137 def test_to_scriptPubKey (self ):
115138 """CBitcoinAddress.to_scriptPubKey() works"""
116139 def T (str_addr , expected_scriptPubKey_hexbytes ):
@@ -125,10 +148,17 @@ def T(str_addr, expected_scriptPubKey_hexbytes):
125148 T ('1111111111111111111114oLvT2' ,
126149 '76a914000000000000000000000000000000000000000088ac' )
127150
151+
128152class Test_P2SHBitcoinAddress (unittest .TestCase ):
129153 def test_from_redeemScript (self ):
130- addr = P2SHBitcoinAddress .from_redeemScript (CScript ())
131- self .assertEqual (str (addr ), '3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy' )
154+ def T (script , expected_str_address ):
155+ addr = P2SHBitcoinAddress .from_redeemScript (script )
156+ self .assertEqual (str (addr ), expected_str_address )
157+
158+ T (CScript (), '3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy' )
159+ T (CScript (x ('76a914751e76e8199196d454941c45d1b3a323f1433bd688ac' )),
160+ '3LRW7jeCvQCRdPF8S3yUCfRAx4eqXFmdcr' )
161+
132162
133163class Test_P2PKHBitcoinAddress (unittest .TestCase ):
134164 def test_from_non_canonical_scriptPubKey (self ):
0 commit comments