MCPcopy Index your code
hub / github.com/btcsuite/btcd / TestCheckPubKeyEncoding

Function TestCheckPubKeyEncoding

txscript/engine_test.go:202–258  ·  view source on GitHub ↗

TestCheckPubKeyEncoding ensures the internal checkPubKeyEncoding function works as expected.

(t *testing.T)

Source from the content-addressed store, hash-verified

200// TestCheckPubKeyEncoding ensures the internal checkPubKeyEncoding function
201// works as expected.
202func TestCheckPubKeyEncoding(t *testing.T) {
203 t.Parallel()
204
205 tests := []struct {
206 name string
207 key []byte
208 isValid bool
209 }{
210 {
211 name: "uncompressed ok",
212 key: hexToBytes("0411db93e1dcdb8a016b49840f8c53bc1eb68" +
213 "a382e97b1482ecad7b148a6909a5cb2e0eaddfb84ccf" +
214 "9744464f82e160bfa9b8b64f9d4c03f999b8643f656b" +
215 "412a3"),
216 isValid: true,
217 },
218 {
219 name: "compressed ok",
220 key: hexToBytes("02ce0b14fb842b1ba549fdd675c98075f12e9" +
221 "c510f8ef52bd021a9a1f4809d3b4d"),
222 isValid: true,
223 },
224 {
225 name: "compressed ok",
226 key: hexToBytes("032689c7c2dab13309fb143e0e8fe39634252" +
227 "1887e976690b6b47f5b2a4b7d448e"),
228 isValid: true,
229 },
230 {
231 name: "hybrid",
232 key: hexToBytes("0679be667ef9dcbbac55a06295ce870b07029" +
233 "bfcdb2dce28d959f2815b16f81798483ada7726a3c46" +
234 "55da4fbfc0e1108a8fd17b448a68554199c47d08ffb1" +
235 "0d4b8"),
236 isValid: false,
237 },
238 {
239 name: "empty",
240 key: nil,
241 isValid: false,
242 },
243 }
244
245 vm := Engine{flags: ScriptVerifyStrictEncoding}
246 for _, test := range tests {
247 err := vm.checkPubKeyEncoding(test.key)
248 if err != nil && test.isValid {
249 t.Errorf("checkSignatureEncoding test '%s' failed "+
250 "when it should have succeeded: %v", test.name,
251 err)
252 } else if err == nil && !test.isValid {
253 t.Errorf("checkSignatureEncooding test '%s' succeeded "+
254 "when it should have failed", test.name)
255 }
256 }
257
258}
259

Callers

nothing calls this directly

Calls 2

checkPubKeyEncodingMethod · 0.95
hexToBytesFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…