-
Notifications
You must be signed in to change notification settings - Fork 26
/
output_test.go
59 lines (46 loc) · 1.46 KB
/
output_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package bt
import (
"encoding/hex"
"testing"
"github.com/stretchr/testify/assert"
)
const outputHexStr = "8a08ac4a000000001976a9148bf10d323ac757268eb715e613cb8e8e1d1793aa88ac00000000"
func TestNewOutputFromBytes(t *testing.T) {
t.Parallel()
t.Run("invalid output, too short", func(t *testing.T) {
o, s, err := newOutputFromBytes([]byte(""))
assert.Error(t, err)
assert.Nil(t, o)
assert.Equal(t, 0, s)
})
t.Run("invalid output, too short + script", func(t *testing.T) {
o, s, err := newOutputFromBytes([]byte("0000000000000"))
assert.Error(t, err)
assert.Nil(t, o)
assert.Equal(t, 0, s)
})
t.Run("valid output", func(t *testing.T) {
bytes, err := hex.DecodeString(outputHexStr)
assert.NoError(t, err)
var o *Output
var s int
o, s, err = newOutputFromBytes(bytes)
assert.NoError(t, err)
assert.NotNil(t, o)
assert.Equal(t, 34, s)
assert.Equal(t, uint64(1252788362), o.Satoshis)
assert.Equal(t, 25, len(*o.LockingScript))
assert.Equal(t, "76a9148bf10d323ac757268eb715e613cb8e8e1d1793aa88ac", o.LockingScriptHexString())
})
}
func TestOutput_String(t *testing.T) {
t.Run("compare string output", func(t *testing.T) {
bytes, err := hex.DecodeString(outputHexStr)
assert.NoError(t, err)
var o *Output
o, _, err = newOutputFromBytes(bytes)
assert.NoError(t, err)
assert.NotNil(t, o)
assert.Equal(t, "value: 1252788362\nscriptLen: 25\nscript: 76a9148bf10d323ac757268eb715e613cb8e8e1d1793aa88ac\n", o.String())
})
}