@@ -90,26 +90,43 @@ func TestDecodeC32Address(t *testing.T) {
90
90
}
91
91
92
92
func 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
+ },
96
105
}
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
+ }
97
112
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
+ }
102
117
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
+ }
107
122
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
+ }
111
126
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
+ })
114
131
}
115
132
}
0 commit comments