forked from stellar/go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb_test.go
133 lines (113 loc) · 4.96 KB
/
db_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
121
122
123
124
125
126
127
128
129
130
131
132
133
package xdr_test
import (
"database/sql"
"github.com/stellar/go/xdr"
. "github.com/stellar/go/xdr"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/gomega"
)
var _ = Describe("sql.Scanner implementations", func() {
DescribeTable("AccountFlags",
func(in interface{}, val AccountFlags, shouldSucceed bool) {
var scanned AccountFlags
err := scanned.Scan(in)
if shouldSucceed {
Expect(err).To(BeNil())
} else {
Expect(err).ToNot(BeNil())
}
Expect(scanned).To(Equal(val))
},
Entry("zero", int64(0), AccountFlags(0), true),
Entry("required", int64(1), AccountFlags(1), true),
Entry("revokable", int64(2), AccountFlags(2), true),
Entry("immutable", int64(4), AccountFlags(4), true),
Entry("string", "0", AccountFlags(0), false),
)
DescribeTable("AssetType",
func(in interface{}, val AssetType, shouldSucceed bool) {
var scanned AssetType
err := scanned.Scan(in)
if shouldSucceed {
Expect(err).To(BeNil())
} else {
Expect(err).ToNot(BeNil())
}
Expect(scanned).To(Equal(val))
},
Entry("native", int64(0), AssetTypeAssetTypeNative, true),
Entry("credit alphanum4", int64(1), AssetTypeAssetTypeCreditAlphanum4, true),
Entry("credit alphanum12", int64(2), AssetTypeAssetTypeCreditAlphanum12, true),
Entry("string", "native", AssetTypeAssetTypeNative, false),
)
DescribeTable("Int64",
func(in interface{}, val Int64, shouldSucceed bool) {
var scanned Int64
err := scanned.Scan(in)
if shouldSucceed {
Expect(err).To(BeNil())
} else {
Expect(err).ToNot(BeNil())
}
Expect(scanned).To(Equal(val))
},
Entry("pos", int64(1), Int64(1), true),
Entry("neg", int64(-1), Int64(-1), true),
Entry("zero", int64(0), Int64(0), true),
Entry("string", "0", Int64(0), false),
)
DescribeTable("Thresholds",
func(in interface{}, val Thresholds, shouldSucceed bool) {
var scanned Thresholds
err := scanned.Scan(in)
if shouldSucceed {
Expect(err).To(BeNil())
} else {
Expect(err).ToNot(BeNil())
}
Expect(scanned).To(Equal(val))
},
Entry("default", "AQAAAA==", Thresholds{0x01, 0x00, 0x00, 0x00}, true),
Entry("non-default", "AgACAg==", Thresholds{0x02, 0x00, 0x02, 0x02}, true),
Entry("bytes", []byte("AQAAAA=="), Thresholds{0x01, 0x00, 0x00, 0x00}, true),
Entry("number", 0, Thresholds{}, false),
)
DescribeTable("ClaimPredicate",
func(in interface{}, val ClaimPredicate, shouldSucceed bool) {
var scanned ClaimPredicate
err := scanned.Scan(in)
if shouldSucceed {
Expect(err).To(BeNil())
} else {
Expect(err).ToNot(BeNil())
}
Expect(scanned).To(Equal(val))
},
Entry("default", "AAAAAA==", xdr.ClaimPredicate{
Type: xdr.ClaimPredicateTypeClaimPredicateUnconditional,
}, true),
)
DescribeTable("Scanning base64 strings (happy paths only)",
func(dest interface{}, in string) {
err := dest.(sql.Scanner).Scan(in)
Expect(err).To(BeNil())
},
Entry("ClaimablePredicate", &ClaimPredicate{},
"AAAAAA=="),
Entry("LedgerEntryChanges", &LedgerEntryChanges{},
"AAAAAgAAAAMAAAABAAAAAAAAAABi/B0L0JGythwN1lY0aypo19NHxvLCyO5tBEcCVvwF9w3gtrOnZAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAEAAAACAAAAAAAAAABi/B0L0JGythwN1lY0aypo19NHxvLCyO5tBEcCVvwF9w3gtrOnY/+cAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAA=="),
Entry("LedgerHeader", &LedgerHeader{},
"AAAAAWPZj1Nu5o0bJ7W4nyOvUxG3Vpok+vFAOtC1K2M7B76ZlmEdOpVCM5HLr9FNj55qa6w2HKMtqTPFLvG8yPU/aAoAAAAAVmX5PQAAAAIAAAAIAAAAAQAAAAEAAAAIAAAAAwAAADIAAAAARUAVxJm1lDMwwqujKcyQzs97F/AETiCgQPrw63wqaPGOtj0VqejCRGn8A4KwJni7nqeau/0Ehh/Gk8yEDm7nHgAAAAIN4Lazp2QAAAAAAAAAAAEsAAAAAAAAAAAAAAAAAAAAZAX14QAAAAAyAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"),
Entry("ScpEnvelope", &ScpEnvelope{},
"AAAAAHrhN3GHEnrzTWJhFpClc59zx+BDb5xg65XqG+z5jnC7AAAAAAAAAAMAAAACAAAAAQAAADC/LifyiYybRvcg7+v7J44d4hsQc5Zc16IYRoo1xslnCAAAAABWZfk+AAAAAAAAAAAAAAABebIw2H2gD0qa+oOpLf5MdO3oYdixAJ2WXGefyG5JefMAAABAvTupFluE8rWgS3FR8nUi34+ya58L+Lv4KwYBeCxaibmjuqjlYL7EnIYORmAWVQPYHoviKOIidnB6JHfWXkZ+BQ=="),
Entry("ScpQuorumSet", &ScpQuorumSet{},
"AAAAAQAAAAEAAAAAeuE3cYcSevNNYmEWkKVzn3PH4ENvnGDrleob7PmOcLsAAAAA"),
Entry("TransactionEnvelope", &TransactionEnvelope{},
"AAAAAGL8HQvQkbK2HA3WVjRrKmjX00fG8sLI7m0ERwJW/AX3AAAAZAAAAAAAAAABAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAA5BFB2+Hs81DQk/cAlJes5R0+3PUQaZ62NZJoKPsBWnsAAAACVAvkAAAAAAAAAAABVvwF9wAAAEC96/+BcbMflvMQfFAQTbAKGu+6BR1M6SG/KVzTJSlIY8ovSVywuthk9dOW9jm23siTiIZE0IAl84wK83gnAcEK"),
Entry("TransactionMeta", &TransactionMeta{},
"AAAAAAAAAAEAAAACAAAAAAAAAAIAAAAAAAAAAOQRQdvh7PNQ0JP3AJSXrOUdPtz1EGmetjWSaCj7AVp7AAAAAlQL5AAAAAACAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAIAAAAAAAAAAGL8HQvQkbK2HA3WVjRrKmjX00fG8sLI7m0ERwJW/AX3DeC2sVNYGtQAAAAAAAAAAwAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAA"),
Entry("TransactionResult", &TransactionResult{},
"AAAAAAAAAGQAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAA="),
)
})