-
Notifications
You must be signed in to change notification settings - Fork 1
/
walletDBO_test.go
109 lines (97 loc) · 2.5 KB
/
walletDBO_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
package wallet_test
import (
"strings"
"testing"
"github.com/FactomProject/wallet/v2"
)
func TestWalletDBO(t *testing.T) {
db := wallet.NewMapDB()
seed, err := db.GetOrCreateDBSeed()
if err != nil {
t.Errorf("%v", err)
}
seed.MnemonicSeed = "yellow yellow yellow yellow yellow yellow yellow yellow yellow yellow yellow yellow"
err = db.InsertDBSeed(seed)
if err != nil {
t.Errorf("%v", err)
}
ec, err := db.GetNextECAddress()
if err != nil {
t.Errorf("%v", err)
}
if ec.String() != "EC2KnJQN86MYq4pQyeSGTHSiVdkhRCPXS3udzD4im6BXRBjZFMmR" {
t.Errorf("%v", ec.String())
}
ec, err = db.GetNextECAddress()
if err != nil {
t.Errorf("%v", err)
}
if ec.String() != "EC2UNG5LztGN3BNiVMEgkBP8ra8ud3HjjWWXKjrQozJ98rTvXKYy" {
t.Errorf("%v", ec.String())
}
f, err := db.GetNextFCTAddress()
if err != nil {
t.Errorf("%v", err)
}
if f.String() != "FA22de5NSG2FA2HmMaD4h8qSAZAJyztmmnwgLPghCQKoSekwYYct" {
t.Errorf("%v", f.String())
}
f, err = db.GetNextFCTAddress()
if err != nil {
t.Errorf("%v", err)
}
if f.String() != "FA3heCmxKCk1tCCfiAMDmX8Ctg6XTQjRRaJrF5Jagc9rbo7wqQLV" {
t.Errorf("%v", f.String())
}
}
func TestDBSeed(t *testing.T) {
seed, err := wallet.NewRandomSeed()
if err != nil {
t.Errorf("%v", err)
}
if seed.MnemonicSeed == "" {
t.Errorf("Empty mnemonic seed returned")
}
l := len(strings.Fields(seed.MnemonicSeed))
if l < 12 {
t.Errorf("Not enough words in mnemonic. Expecitng 12, found %d", l)
}
if l > 12 {
t.Errorf("Too many words in mnemonic. Expecitng 12, found %d", l)
}
seed.MnemonicSeed = "yellow yellow yellow yellow yellow yellow yellow yellow yellow yellow yellow yellow"
ec, err := seed.NextECAddress()
if err != nil {
t.Errorf("%v", err)
}
if ec.String() != "EC2KnJQN86MYq4pQyeSGTHSiVdkhRCPXS3udzD4im6BXRBjZFMmR" {
t.Errorf("%v", ec.String())
}
ec, err = seed.NextECAddress()
if err != nil {
t.Errorf("%v", err)
}
if ec.String() != "EC2UNG5LztGN3BNiVMEgkBP8ra8ud3HjjWWXKjrQozJ98rTvXKYy" {
t.Errorf("%v", ec.String())
}
f, err := seed.NextFCTAddress()
if err != nil {
t.Errorf("%v", err)
}
if f.String() != "FA22de5NSG2FA2HmMaD4h8qSAZAJyztmmnwgLPghCQKoSekwYYct" {
t.Errorf("%v", f.String())
}
f, err = seed.NextFCTAddress()
if err != nil {
t.Errorf("%v", err)
}
if f.String() != "FA3heCmxKCk1tCCfiAMDmX8Ctg6XTQjRRaJrF5Jagc9rbo7wqQLV" {
t.Errorf("%v", f.String())
}
if seed.NextFactoidAddressIndex != 2 {
t.Errorf("Wrong NextFactoidAddressIndex")
}
if seed.NextECAddressIndex != 2 {
t.Errorf("Wrong NextECAddressIndex")
}
}