-
Notifications
You must be signed in to change notification settings - Fork 10
/
tx_input_test.go
49 lines (45 loc) · 1.38 KB
/
tx_input_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
package libada
import (
"encoding/hex"
"testing"
"github.com/fxamacker/cbor/v2"
)
func TestInput_Bytes(t *testing.T) {
testdata := []struct {
txid string
index uint32
want string
}{
{
txid: "9c37cb5294abce709bfa57bdcab039d75e212a503bc48d5b45e6ff4eb6272759",
index: 1,
want: "8258209c37cb5294abce709bfa57bdcab039d75e212a503bc48d5b45e6ff4eb627275901",
},
{
txid: "77df5bd720b6fb8699762fea21bdbc8193a61b770a59443266383ba01a6b8900",
index: 1,
want: "82582077df5bd720b6fb8699762fea21bdbc8193a61b770a59443266383ba01a6b890001",
},
}
for index, item := range testdata {
data, err := cbor.Marshal(MustInput(item.txid, item.index))
if err != nil {
t.Fatal(err)
}
if got := hex.EncodeToString(data); got != item.want {
t.Errorf("[%d] got %s want %s", index, got, item.want)
}
}
}
func TestInput_Bytes_slice(t *testing.T) {
input_0 := MustInput("9c37cb5294abce709bfa57bdcab039d75e212a503bc48d5b45e6ff4eb6272759", 1)
input_1 := MustInput("77df5bd720b6fb8699762fea21bdbc8193a61b770a59443266383ba01a6b8900", 1)
data, err := cbor.Marshal([]*Input{input_0, input_1})
if err != nil {
t.Fatal(err)
}
want := "828258209c37cb5294abce709bfa57bdcab039d75e212a503bc48d5b45e6ff4eb62727590182582077df5bd720b6fb8699762fea21bdbc8193a61b770a59443266383ba01a6b890001"
if got := hex.EncodeToString(data); got != want {
t.Errorf("got: %s want: %s", got, want)
}
}