-
Notifications
You must be signed in to change notification settings - Fork 211
/
atxdb_mock.go
57 lines (47 loc) · 1.41 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
56
57
package mesh
import (
"context"
"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
niposts map[types.ATXID]*types.NIPost
ProcCnt int
}
// NewAtxDbMock returns a new AtxDbMock.
func NewAtxDbMock() *AtxDbMock {
return &AtxDbMock{
db: make(map[types.ATXID]*types.ActivationTx),
niposts: make(map[types.ATXID]*types.NIPost),
}
}
// 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.niposts[id] = atx.NIPost
}
// ProcessAtxs counts how many ATXs were processed.
func (t *AtxDbMock) ProcessAtxs(_ context.Context, atxs []*types.ActivationTx) error {
t.ProcCnt += len(atxs)
return nil
}
// SyntacticallyValidateAtx always returns no error.
func (AtxDbMock) SyntacticallyValidateAtx(context.Context, *types.ActivationTx) error {
return nil
}