-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbob_test.go
120 lines (101 loc) · 3 KB
/
bob_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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package b
import (
"testing"
"github.com/bitcoinschema/go-bob"
)
// TestNewFromTape tests for nil case in NewFromTape()
func TestNewFromTape(t *testing.T) {
expectedTx := "10afc796d06fec11a4b6077012a1522355c82e5de316f4dd5c42ddccd6d61cdb"
expectedEncoding := string(EncodingBinary)
tx, err := bob.NewFromString(exampleBobTx)
if err != nil {
t.Fatalf("error occurred: %s", err.Error())
}
if tx.Tx.Tx.H != expectedTx {
t.Fatalf("expected Tx.h: %s got: %s", expectedTx, tx.Tx.Tx.H)
}
// Invalid tape
var b *B
_, err = NewFromTape(tx.Out[0].Tape[0])
if err == nil {
t.Fatalf("error should have occurred")
}
// Valid tape
b, err = NewFromTape(tx.Out[0].Tape[1])
if err != nil {
t.Fatalf("error occurred: %s", err.Error())
}
if b.Encoding != expectedEncoding {
t.Fatalf("expected Encoding: %s got: %s", expectedEncoding, b.Encoding)
}
// todo: finish tests (error cases) and examples (need BOB txs)
}
// TestNewFromTapes tests for nil case in NewFromTapes()
func TestNewFromTapes(t *testing.T) {
expectedTx := "10afc796d06fec11a4b6077012a1522355c82e5de316f4dd5c42ddccd6d61cdb"
expectedEncoding := string(EncodingBinary)
tx, err := bob.NewFromString(exampleBobTx)
if err != nil {
t.Fatalf("error occurred: %s", err.Error())
}
if tx.Tx.Tx.H != expectedTx {
t.Fatalf("expected Tx.h: %s got: %s", expectedTx, tx.Tx.Tx.H)
}
// Valid
var b *B
b, err = NewFromTapes(tx.Out[0].Tape)
if err != nil {
t.Fatalf("error occurred: %s", err.Error())
}
if b.Encoding != expectedEncoding {
t.Fatalf("expected Encoding: %s got: %s", expectedEncoding, b.Encoding)
}
// Change type
gzip := string(EncodingGzip)
tx.Out[0].Tape[1].Cell[3].S = &gzip
b, err = NewFromTapes(tx.Out[0].Tape)
if err != nil {
t.Fatalf("error occurred: %s", err.Error())
}
if b.Encoding != gzip {
t.Fatalf("expected Encoding: %s got: %s", EncodingGzip, b.Encoding)
}
// Invalid
_, err = NewFromTapes(tx.Out[1].Tape)
if err == nil {
t.Fatalf("error should have occurred")
}
// todo: finish tests and examples (need BOB tx)
}
// TestNewFromTapes tests for nil case in NewFromTapes()
func TestNewFromTape2(t *testing.T) {
expectedTx := "8216e4be2e93dc90c561ce03b25338756efb80cbf6fda46c9df932696a2f5814"
tx, err := bob.NewFromString(exampleBobTx2)
if err != nil {
t.Fatalf("error occurred: %s", err.Error())
}
if tx.Tx.Tx.H != expectedTx {
t.Fatalf("expected Tx.h: %s got: %s", expectedTx, tx.Tx.Tx.H)
}
b := &B{}
err = b.FromTape(tx.Out[0].Tape[1])
if err != nil {
t.Fatalf("error occurred: %s", err.Error())
}
if b.Encoding != "UTF-8" {
t.Fatalf("expected Encoding: UTF-8 got: %s", b.Encoding)
}
if b.MediaType != "text/markdown" {
t.Fatalf("expected MediaType: text/markdown got: %s", b.Encoding)
}
err = b.FromTape(tx.Out[0].Tape[2])
if err != nil {
t.Fatalf("error occurred: %s", err.Error())
}
if b.Encoding != string(EncodingBinary) {
t.Fatalf("expected Encoding: binary got: %s", b.Encoding)
}
if b.MediaType != "image/png" {
t.Fatalf("expected MediaType: image/png got: %s", b.Encoding)
}
}