MCPcopy Create free account
hub / github.com/btcsuite/btcd / TestScriptTemplateHelperFunctions

Function TestScriptTemplateHelperFunctions

txscript/template_test.go:273–344  ·  view source on GitHub ↗

TestScriptTemplateHelperFunctions tests the helper functions used in templates.

(t *testing.T)

Source from the content-addressed store, hash-verified

271// TestScriptTemplateHelperFunctions tests the helper functions used in
272// templates.
273func TestScriptTemplateHelperFunctions(t *testing.T) {
274 t.Run("rangeIter", func(t *testing.T) {
275 result := rangeIter(2, 5)
276 expected := []int{2, 3, 4}
277
278 require.Equal(
279 t, expected, result,
280 "rangeIter(2, 5) returned unexpected result",
281 )
282 })
283
284 t.Run("hexEncode", func(t *testing.T) {
285 input := []byte{0x12, 0x34, 0x56}
286 result := hexEncode(input)
287 expected := "0x123456"
288
289 require.Equal(
290 t, expected, result,
291 "hexEncode(%v) = %q, want %q",
292 input, result, expected,
293 )
294 })
295
296 t.Run("hexStr", func(t *testing.T) {
297 input := []byte{0x12, 0x34, 0x56}
298 result := hexStr(input)
299 expected := "123456"
300
301 require.Equal(
302 t, expected, result,
303 "hexStr(%v) = %q, want %q",
304 input, result, expected,
305 )
306 })
307
308 t.Run("hexDecode", func(t *testing.T) {
309 tests := []struct {
310 input string
311 expected []byte
312 wantErr bool
313 }{
314 {"123456", []byte{0x12, 0x34, 0x56}, false},
315 {"0x123456", []byte{0x12, 0x34, 0x56}, false},
316 {"zz", nil, true},
317 }
318
319 for _, test := range tests {
320 result, err := hexDecode(test.input)
321
322 if test.wantErr {
323 require.Error(
324 t, err,
325 "hexDecode(%q) expected error, got nil",
326 test.input,
327 )
328 continue
329 }
330

Callers

nothing calls this directly

Calls 5

rangeIterFunction · 0.85
hexEncodeFunction · 0.85
hexStrFunction · 0.85
hexDecodeFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…