-
Notifications
You must be signed in to change notification settings - Fork 211
/
atxdb_mock.go
55 lines (46 loc) · 1.35 KB
/
atxdb_mock.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
package mesh
import (
"fmt"
"github.com/spacemeshos/go-spacemesh/common/types"
)
// AtxDbMock is a mock of an activation DB
type AtxDbMock struct {
db map[types.ATXID]*types.ActivationTx
nipsts map[types.ATXID]*types.NIPST
ProcCnt int
}
// NewAtxDbMock returns a new AtxDbMock
func NewAtxDbMock() *AtxDbMock {
return &AtxDbMock{
db: make(map[types.ATXID]*types.ActivationTx),
nipsts: make(map[types.ATXID]*types.NIPST),
}
}
// GetAtxHeader returns a new ActivationTxHeader
func (t *AtxDbMock) GetAtxHeader(id types.ATXID) (*types.ActivationTxHeader, error) {
if id == *types.EmptyATXID {
return nil, fmt.Errorf("trying to fetch empty atx id")
}
if atx, ok := t.db[id]; ok {
return atx.ActivationTxHeader, nil
}
return nil, fmt.Errorf("cannot find atx")
}
// GetFullAtx returns a full ATX
func (t *AtxDbMock) GetFullAtx(id types.ATXID) (*types.ActivationTx, error) {
return t.db[id], nil
}
// AddAtx stores an ATX for later retrieval
func (t *AtxDbMock) AddAtx(id types.ATXID, atx *types.ActivationTx) {
t.db[id] = atx
t.nipsts[id] = atx.Nipst
}
// ProcessAtxs counts how many ATXs were processed
func (t *AtxDbMock) ProcessAtxs(atxs []*types.ActivationTx) error {
t.ProcCnt += len(atxs)
return nil
}
// SyntacticallyValidateAtx always returns no error
func (AtxDbMock) SyntacticallyValidateAtx(*types.ActivationTx) error {
return nil
}