MCPcopy
hub / github.com/btcsuite/btcd / TestRemoveOpcodeByData

Function TestRemoveOpcodeByData

txscript/script_test.go:344–501  ·  view source on GitHub ↗

TestRemoveOpcodeByData ensures that removing data carrying opcodes based on the data they contain works as expected.

(t *testing.T)

Source from the content-addressed store, hash-verified

342// TestRemoveOpcodeByData ensures that removing data carrying opcodes based on
343// the data they contain works as expected.
344func TestRemoveOpcodeByData(t *testing.T) {
345 t.Parallel()
346
347 tests := []struct {
348 name string
349 before []byte
350 remove []byte
351 err error
352 after []byte
353 }{
354 {
355 name: "nothing to do",
356 before: []byte{OP_NOP},
357 remove: []byte{1, 2, 3, 4},
358 after: []byte{OP_NOP},
359 },
360 {
361 name: "",
362 before: []byte{OP_NOP, OP_DATA_8, 1, 2, 3, 4, 5, 6, 7, 8, OP_DATA_4, 1, 2, 3, 4},
363 remove: []byte{1, 2, 3, 4},
364 after: []byte{OP_NOP, OP_DATA_8, 1, 2, 3, 4, 5, 6, 7, 8},
365 },
366 {
367 name: "simple case",
368 before: []byte{OP_DATA_4, 1, 2, 3, 4},
369 remove: []byte{1, 2, 3, 4},
370 after: nil,
371 },
372 {
373 name: "simple case (miss)",
374 before: []byte{OP_DATA_4, 1, 2, 3, 4},
375 remove: []byte{1, 2, 3, 5},
376 after: []byte{OP_DATA_4, 1, 2, 3, 4},
377 },
378 {
379 // padded to keep it canonical.
380 name: "simple case (pushdata1)",
381 before: append(append([]byte{OP_PUSHDATA1, 76},
382 bytes.Repeat([]byte{0}, 72)...),
383 []byte{1, 2, 3, 4}...),
384 remove: []byte{1, 2, 3, 4},
385 after: append(append([]byte{OP_PUSHDATA1, 76},
386 bytes.Repeat([]byte{0}, 72)...),
387 []byte{1, 2, 3, 4}...),
388 },
389 {
390 name: "simple case (pushdata1 miss)",
391 before: append(append([]byte{OP_PUSHDATA1, 76},
392 bytes.Repeat([]byte{0}, 72)...),
393 []byte{1, 2, 3, 4}...),
394 remove: []byte{1, 2, 3, 5},
395 after: append(append([]byte{OP_PUSHDATA1, 76},
396 bytes.Repeat([]byte{0}, 72)...),
397 []byte{1, 2, 3, 4}...),
398 },
399 {
400 name: "simple case (pushdata1 miss noncanonical)",
401 before: []byte{OP_PUSHDATA1, 4, 1, 2, 3, 4},

Callers

nothing calls this directly

Calls 4

scriptErrorFunction · 0.85
checkScriptParsesFunction · 0.85
removeOpcodeByDataFunction · 0.85
tstCheckScriptErrorFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…