@@ -113,3 +113,71 @@ func TestBase58EncodeMissingChecksum(t *testing.T) {
113113 script .Base58EncodeMissingChecksum (input ),
114114 )
115115}
116+
117+ func TestNewAddressFromPublicKeyHash (t * testing.T ) {
118+ t .Parallel ()
119+
120+ t .Run ("mainnet" , func (t * testing.T ) {
121+ hash , err := hex .DecodeString (testPublicKeyHash )
122+ require .NoError (t , err )
123+
124+ addr , err := script .NewAddressFromPublicKeyHash (hash , true )
125+ require .NoError (t , err )
126+ require .NotNil (t , addr )
127+
128+ require .Equal (t , testPublicKeyHash , addr .PublicKeyHash .String ())
129+ require .Equal (t , "114ZWApV4EEU8frr7zygqQcB1V2BodGZuS" , addr .AddressString )
130+ })
131+
132+ t .Run ("testnet" , func (t * testing.T ) {
133+ hash , err := hex .DecodeString (testPublicKeyHash )
134+ require .NoError (t , err )
135+
136+ addr , err := script .NewAddressFromPublicKeyHash (hash , false )
137+ require .NoError (t , err )
138+ require .NotNil (t , addr )
139+
140+ require .Equal (t , testPublicKeyHash , addr .PublicKeyHash .String ())
141+ require .Equal (t , "mfaWoDuTsFfiunLTqZx4fKpVsUctiDV9jk" , addr .AddressString )
142+ })
143+ }
144+
145+ func TestNewAddressFromPublicKeyStringInvalid (t * testing.T ) {
146+ t .Parallel ()
147+
148+ addr , err := script .NewAddressFromPublicKeyString ("invalid_pubkey" , true )
149+ require .Error (t , err )
150+ require .Nil (t , addr )
151+ }
152+
153+ func TestNewAddressFromPublicKeyInvalid (t * testing.T ) {
154+ t .Parallel ()
155+
156+ invalidPubKeyBytes := []byte {0x00 , 0x01 , 0x02 } // Invalid public key
157+ invalidPubKey , err := ec .ParsePubKey (invalidPubKeyBytes )
158+ require .Error (t , err )
159+ require .Nil (t , invalidPubKey )
160+ }
161+
162+ func TestBase58EncodeMissingChecksumEdgeCases (t * testing.T ) {
163+ t .Parallel ()
164+
165+ t .Run ("empty input" , func (t * testing.T ) {
166+ result := script .Base58EncodeMissingChecksum ([]byte {})
167+ require .NotEmpty (t , result )
168+ })
169+
170+ t .Run ("single byte input" , func (t * testing.T ) {
171+ result := script .Base58EncodeMissingChecksum ([]byte {0x00 })
172+ require .NotEmpty (t , result )
173+ })
174+
175+ t .Run ("large input" , func (t * testing.T ) {
176+ largeInput := make ([]byte , 1000 )
177+ for i := range largeInput {
178+ largeInput [i ] = byte (i % 256 )
179+ }
180+ result := script .Base58EncodeMissingChecksum (largeInput )
181+ require .NotEmpty (t , result )
182+ })
183+ }
0 commit comments