diff --git a/bscript/script.go b/bscript/script.go index ac01150a..3ca7ea6d 100644 --- a/bscript/script.go +++ b/bscript/script.go @@ -218,10 +218,12 @@ func (s *Script) ToASM() (string, error) { } } else { if data && len(p) <= 4 { + b := make([]byte, 0) + b = append(b, p...) for i := 0; i < 4-len(p); i++ { - p = append(p, 0) + b = append(b, 0) } - asmScript.WriteString(fmt.Sprintf("%d", binary.LittleEndian.Uint32(p))) + asmScript.WriteString(fmt.Sprintf("%d", binary.LittleEndian.Uint32(b))) } else { asmScript.WriteString(hex.EncodeToString(p)) } diff --git a/bscript/script_test.go b/bscript/script_test.go index 1b41bcca..7e5e65e4 100644 --- a/bscript/script_test.go +++ b/bscript/script_test.go @@ -214,3 +214,19 @@ func TestRunScriptExample2(t *testing.T) { t.Errorf("\nExpected %q\ngot %q", expected, asm) } } + +func TestRunScriptExample3(t *testing.T) { + script, _ := hex.DecodeString("006a223139694733575459537362796f7333754a373333794b347a45696f69314665734e55010042666166383166326364346433663239383061623162363564616166656231656631333561626339643534386461633466366134656361623230653033656365362d300274780134") + s := bscript.Script(script) + + asm, err := s.ToASM() + if err != nil { + t.Error(err) + t.FailNow() + } + + expected := "0 OP_RETURN 3139694733575459537362796f7333754a373333794b347a45696f69314665734e55 0 666166383166326364346433663239383061623162363564616166656231656631333561626339643534386461633466366134656361623230653033656365362d30 30836 52" + if asm != expected { + t.Errorf("\nExpected %q\ngot %q", expected, asm) + } +}