forked from stellar/go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccount_id_test.go
77 lines (64 loc) · 2.46 KB
/
account_id_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
package xdr_test
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/stellar/go/xdr"
)
var _ = Describe("xdr.AccountId#Address()", func() {
It("returns a strkey string when account id is valid", func() {
var aid AccountId
err := aid.SetAddress("GCR22L3WS7TP72S4Z27YTO6JIQYDJK2KLS2TQNHK6Y7XYPA3AGT3X4FH")
Expect(err).ShouldNot(HaveOccurred())
addy := aid.Address()
Expect(addy).To(Equal("GCR22L3WS7TP72S4Z27YTO6JIQYDJK2KLS2TQNHK6Y7XYPA3AGT3X4FH"))
})
})
var _ = Describe("xdr.AccountId#Equals()", func() {
It("returns true when the account ids have equivalent values", func() {
var l, r AccountId
err := l.SetAddress("GCR22L3WS7TP72S4Z27YTO6JIQYDJK2KLS2TQNHK6Y7XYPA3AGT3X4FH")
Expect(err).ShouldNot(HaveOccurred())
err = r.SetAddress("GCR22L3WS7TP72S4Z27YTO6JIQYDJK2KLS2TQNHK6Y7XYPA3AGT3X4FH")
Expect(err).ShouldNot(HaveOccurred())
Expect(l.Equals(r)).To(BeTrue())
})
It("returns false when the account ids have different values", func() {
var l, r AccountId
err := l.SetAddress("GCR22L3WS7TP72S4Z27YTO6JIQYDJK2KLS2TQNHK6Y7XYPA3AGT3X4FH")
Expect(err).ShouldNot(HaveOccurred())
err = r.SetAddress("GBTBXQEVDNVUEESCTPUT3CHJDVNG44EMPMBELH5F7H3YPHXPZXOTEWB4")
Expect(err).ShouldNot(HaveOccurred())
Expect(l.Equals(r)).To(BeFalse())
})
})
var _ = Describe("xdr.AccountId#LedgerKey()", func() {
It("works", func() {
var aid AccountId
err := aid.SetAddress("GCR22L3WS7TP72S4Z27YTO6JIQYDJK2KLS2TQNHK6Y7XYPA3AGT3X4FH")
Expect(err).ShouldNot(HaveOccurred())
key, err := aid.LedgerKey()
Expect(err).ShouldNot(HaveOccurred())
packed := key.MustAccount().AccountId
Expect(packed.Equals(aid)).To(BeTrue())
})
})
var _ = Describe("xdr.AddressToAccountID()", func() {
It("works", func() {
address := "GCR22L3WS7TP72S4Z27YTO6JIQYDJK2KLS2TQNHK6Y7XYPA3AGT3X4FH"
accountID, err := AddressToAccountId(address)
Expect(accountID.Address()).To(Equal("GCR22L3WS7TP72S4Z27YTO6JIQYDJK2KLS2TQNHK6Y7XYPA3AGT3X4FH"))
Expect(err).ShouldNot(HaveOccurred())
_, err = AddressToAccountId("GCR22L3")
Expect(err).Should(HaveOccurred())
})
})
var _ = Describe("xdr.AccountId#ToMuxedAccount()", func() {
It("works", func() {
address := "GCR22L3WS7TP72S4Z27YTO6JIQYDJK2KLS2TQNHK6Y7XYPA3AGT3X4FH"
accountID, err := AddressToAccountId(address)
Expect(err).ShouldNot(HaveOccurred())
muxed := accountID.ToMuxedAccount()
Expect(muxed.Type).To(Equal(CryptoKeyTypeKeyTypeEd25519))
Expect(*muxed.Ed25519).To(Equal(*accountID.Ed25519))
})
})