-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtxdatabase_test.go
105 lines (95 loc) · 2.05 KB
/
txdatabase_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
// Copyright 2016 Factom Foundation
// Use of this source code is governed by the MIT
// license that can be found in the LICENSE file.
package wallet_test
import (
"testing"
"github.com/FactomProject/factomd/common/interfaces"
"github.com/FactomProject/factomd/testHelper"
"github.com/FactomProject/wallet/v2"
)
func TestTXDatabaseOverlay(t *testing.T) {
db1 := wallet.NewTXMapDB()
fblock := fblockHead()
if err := db1.InsertFBlockHead(fblock); err != nil {
t.Error(err)
}
if f, err := db1.GetFBlock(fblock.GetKeyMR().String()); err != nil {
t.Error(err)
} else if f == nil {
t.Errorf("Fblock not found in db")
}
}
/*
func TestGetAllTXs(t *testing.T) {
db1 := NewTXMapDB()
txs, err := db1.GetAllTXs()
if err != nil {
t.Error(err)
}
t.Logf("got %d txs", len(txs))
}
func TestGetTXAddress(t *testing.T) {
db1 := NewTXMapDB()
adr := "FA2jK2HcLnRdS94dEcU27rF3meoJfpUcZPSinpb7AwQvPRY6RL1Q"
txs, err := db1.GetTXAddress(adr)
if err != nil {
t.Error(err)
}
t.Logf("got %d txs", len(txs))
}
*/
//func TestGetAllTXs(t *testing.T) {
// dbpath := os.TempDir() + "/test_txdb-01"
// db1, err := NewTXLevelDB(dbpath)
// if err != nil {
// t.Error(err)
// }
// defer db1.Close()
//
// txs := make(chan interfaces.ITransaction, 500)
// errs := make(chan error)
// output := make(chan string)
//
// go db1.GetAllTXs(txs, errs)
//
// go func() {
// for tx := range txs {
// output <- fmt.Sprint("Got TX:", tx)
// }
// output <- fmt.Sprint("end of txs")
// }()
//
// go func() {
// for err := range errs {
// output <- fmt.Sprintln("Got error:", err)
// }
// output <- fmt.Sprint("end of errs")
// }()
//
// for {
// fmt.Println(<-output)
// }
//
//// for {
//// select {
//// case tx, ok := <-txs:
//// fmt.Println("Got TX:", tx)
//// if !ok {
//// txs = nil
//// }
//// case err, ok := <-errs:
//// if !ok {
//// errs = nil
//// }
//// }
////
//// if txs == nil && errs == nil {
//// break
//// }
//// }
//}
// fblockHead gets the most recent fblock.
func fblockHead() interfaces.IFBlock {
return testHelper.CreateTestFactoidBlock(nil)
}