@@ -90,26 +90,43 @@ func TestDecodeC32Address(t *testing.T) {
9090}
9191
9292func TestC32CheckEncodeDecode (t * testing.T ) {
93- hash160 , err := hex .DecodeString ("1a2b3c4d5e6f7081920a1b2c3d4e5f60718293a4" )
94- if err != nil {
95- t .Fatalf ("Failed to decode hash160: %v" , err )
93+ tests := []struct {
94+ name string
95+ hash160 string
96+ }{
97+ {
98+ name : "Sanity" ,
99+ hash160 : "1a2b3c4d5e6f7081920a1b2c3d4e5f60718293a4" ,
100+ },
101+ {
102+ name : "With leading zeros" ,
103+ hash160 : "00aa83fa8c13e363bcd190e22a8be3344c9fa416" ,
104+ },
96105 }
106+ for _ , tt := range tests {
107+ t .Run (tt .name , func (t * testing.T ) {
108+ hash160 , err := hex .DecodeString (tt .hash160 )
109+ if err != nil {
110+ t .Fatalf ("Failed to decode hash160: %v" , err )
111+ }
97112
98- address , err := SerializeAddress (stacks .AddressVersionMainnetSingleSig , hash160 )
99- if err != nil {
100- t .Fatalf ("Failed to serialize address: %v" , err )
101- }
113+ address , err := SerializeAddress (stacks .AddressVersionMainnetSingleSig , hash160 )
114+ if err != nil {
115+ t .Fatalf ("Failed to serialize address: %v" , err )
116+ }
102117
103- version , decodedHash , err := DeserializeAddress (address )
104- if err != nil {
105- t .Fatalf ("Failed to deserialize address: %v" , err )
106- }
118+ version , decodedHash , err := DeserializeAddress (address )
119+ if err != nil {
120+ t .Fatalf ("Failed to deserialize address: %v" , err )
121+ }
107122
108- if version != stacks .AddressVersionMainnetSingleSig {
109- t .Errorf ("Expected version %d, got %d" , stacks .AddressVersionMainnetSingleSig , version )
110- }
123+ if version != stacks .AddressVersionMainnetSingleSig {
124+ t .Errorf ("Expected version %d, got %d" , stacks .AddressVersionMainnetSingleSig , version )
125+ }
111126
112- if string (decodedHash ) != string (hash160 ) {
113- t .Errorf ("Decoded hash160 does not match original" )
127+ if string (decodedHash ) != string (hash160 ) {
128+ t .Errorf ("Decoded hash160 does not match original" )
129+ }
130+ })
114131 }
115132}
0 commit comments