Skip to content

Commit

Permalink
Merge pull request #10 from ordishs/master
Browse files Browse the repository at this point in the history
  • Loading branch information
jadwahab authored Jan 11, 2021
2 parents 589e2dd + 69f4b49 commit f584c99
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
8 changes: 5 additions & 3 deletions bscript/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,7 @@ func (s *Script) ToString() string { // TODO: change to HexString?
// ToASM returns the string ASM opcodes of the script.
func (s *Script) ToASM() (string, error) {
parts, err := DecodeParts(*s)
if err != nil {
return "", err
}
// if err != nil, we will append [error] to the ASM script below (as done in the node).

var asmScript string
for _, p := range parts {
Expand All @@ -211,6 +209,10 @@ func (s *Script) ToASM() (string, error) {
}
}

if err != nil {
asmScript += " [error]"
}

return strings.TrimSpace(asmScript), nil
}

Expand Down
10 changes: 10 additions & 0 deletions bscript/script_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package bscript_test

import (
"encoding/hex"
"strings"
"testing"

"github.com/bitcoinsv/bsvd/bsvec"
Expand Down Expand Up @@ -170,3 +171,12 @@ func TestScript_GetPublicKeyHash(t *testing.T) {
assert.EqualError(t, err, "script is empty")
})
}

func TestErrorIsAppended(t *testing.T) {
script, _ := hex.DecodeString("6a0548656c6c6f0548656c6c")
s := bscript.Script(script)

asm, err := s.ToASM()
assert.NoError(t, err)
assert.True(t, strings.HasSuffix(asm, "[error]"), "toASM() should end with [error]")
}

0 comments on commit f584c99

Please sign in to comment.