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

Function TestScriptTemplateOptions

txscript/template_test.go:226–269  ·  view source on GitHub ↗

TestScriptTemplateOptions tests the ScriptTemplate option functions.

(t *testing.T)

Source from the content-addressed store, hash-verified

224
225// TestScriptTemplateOptions tests the ScriptTemplate option functions.
226func TestScriptTemplateOptions(t *testing.T) {
227 t.Run("WithScriptTemplateParams", func(t *testing.T) {
228 template := "{{ .Value }} OP_DROP"
229 params := map[string]interface{}{
230 "Value": 42,
231 }
232
233 script, err := ScriptTemplate(
234 template, WithScriptTemplateParams(params),
235 )
236 require.NoError(t, err, "unexpected error")
237
238 disasm, err := DisasmString(script)
239 require.NoError(t, err, "Failed to disassemble script")
240
241 expected := "2a OP_DROP"
242 require.Equal(
243 t, expected, disasm,
244 "ScriptTemplate(%q):\ngot: %s\nwant: %s",
245 template, disasm, expected,
246 )
247 })
248
249 t.Run("WithCustomTemplateFunc", func(t *testing.T) {
250 template := "{{ multiply 6 7 }} OP_DROP"
251 script, err := ScriptTemplate(
252 template,
253 WithCustomTemplateFunc("multiply", func(a, b int) int {
254 return a * b
255 }),
256 )
257 require.NoError(t, err, "Unexpected error")
258
259 disasm, err := DisasmString(script)
260 require.NoError(t, err, "Failed to disassemble script")
261
262 expected := "2a OP_DROP"
263 require.Equal(
264 t, expected, disasm,
265 "ScriptTemplate(%q):\ngot: %s\nwant: %s",
266 template, disasm, expected,
267 )
268 })
269}
270
271// TestScriptTemplateHelperFunctions tests the helper functions used in
272// templates.

Callers

nothing calls this directly

Calls 4

ScriptTemplateFunction · 0.85
WithScriptTemplateParamsFunction · 0.85
DisasmStringFunction · 0.85
WithCustomTemplateFuncFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…