-
Notifications
You must be signed in to change notification settings - Fork 0
/
mock_store.go
75 lines (62 loc) · 1.98 KB
/
mock_store.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
package neutrino
import (
"fmt"
"github.com/bcext/cashwallet/waddrmgr"
"github.com/bcext/gcash/blockchain"
"github.com/bcext/gcash/chaincfg/chainhash"
"github.com/bcext/gcash/wire"
"github.com/bcext/neutrino/headerfs"
)
// mockBlockHeaderStore is an implementation of the BlockHeaderStore backed by
// a simple map.
type mockBlockHeaderStore struct {
headers map[chainhash.Hash]wire.BlockHeader
}
// A compile-time check to ensure the mockBlockHeaderStore adheres to the
// BlockHeaderStore interface.
var _ headerfs.BlockHeaderStore = (*mockBlockHeaderStore)(nil)
// NewMockBlockHeaderStore returns a version of the BlockHeaderStore that's
// backed by an in-memory map. This instance is meant to be used by callers
// outside the package to unit test components that require a BlockHeaderStore
// interface.
func newMockBlockHeaderStore() headerfs.BlockHeaderStore {
return &mockBlockHeaderStore{
headers: make(map[chainhash.Hash]wire.BlockHeader),
}
}
func (m *mockBlockHeaderStore) ChainTip() (*wire.BlockHeader,
uint32, error) {
return nil, 0, nil
}
func (m *mockBlockHeaderStore) LatestBlockLocator() (
blockchain.BlockLocator, error) {
return nil, nil
}
func (m *mockBlockHeaderStore) FetchHeaderByHeight(height uint32) (
*wire.BlockHeader, error) {
return nil, nil
}
func (m *mockBlockHeaderStore) FetchHeaderAncestors(uint32,
*chainhash.Hash) ([]wire.BlockHeader, uint32, error) {
return nil, 0, nil
}
func (m *mockBlockHeaderStore) HeightFromHash(*chainhash.Hash) (uint32, error) {
return 0, nil
}
func (m *mockBlockHeaderStore) RollbackLastBlock() (*waddrmgr.BlockStamp,
error) {
return nil, nil
}
func (m *mockBlockHeaderStore) FetchHeader(h *chainhash.Hash) (
*wire.BlockHeader, uint32, error) {
if header, ok := m.headers[*h]; ok {
return &header, 0, nil
}
return nil, 0, fmt.Errorf("not found")
}
func (m *mockBlockHeaderStore) WriteHeaders(headers ...headerfs.BlockHeader) error {
for _, h := range headers {
m.headers[h.BlockHash()] = *h.BlockHeader
}
return nil
}