fix tests
This commit is contained in:
parent
f4948dcba0
commit
8ee296d130
@ -92,21 +92,21 @@ func makeTs(t *testing.T, h abi.ChainEpoch, msgcid cid.Cid) *types.TipSet {
|
||||
return ts
|
||||
}
|
||||
|
||||
func (fcs *fakeCS) ChainNotify(context.Context) (<-chan []*store.HeadChange, error) {
|
||||
out := make(chan []*store.HeadChange, 1)
|
||||
out <- []*store.HeadChange{{Type: store.HCCurrent, Val: fcs.tsc.best()}}
|
||||
func (fcs *fakeCS) ChainNotify(context.Context) (<-chan []*api.HeadChange, error) {
|
||||
out := make(chan []*api.HeadChange, 1)
|
||||
out <- []*api.HeadChange{{Type: store.HCCurrent, Val: fcs.tsc.best()}}
|
||||
|
||||
fcs.sub = func(rev, app []*types.TipSet) {
|
||||
notif := make([]*store.HeadChange, len(rev)+len(app))
|
||||
notif := make([]*api.HeadChange, len(rev)+len(app))
|
||||
|
||||
for i, r := range rev {
|
||||
notif[i] = &store.HeadChange{
|
||||
notif[i] = &api.HeadChange{
|
||||
Type: store.HCRevert,
|
||||
Val: r,
|
||||
}
|
||||
}
|
||||
for i, r := range app {
|
||||
notif[i+len(rev)] = &store.HeadChange{
|
||||
notif[i+len(rev)] = &api.HeadChange{
|
||||
Type: store.HCApply,
|
||||
Val: r,
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package main
|
||||
import (
|
||||
"container/list"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/store"
|
||||
"github.com/filecoin-project/lotus/api"
|
||||
)
|
||||
|
||||
type headBuffer struct {
|
||||
@ -21,12 +21,12 @@ func NewHeadBuffer(size int) *headBuffer {
|
||||
}
|
||||
}
|
||||
|
||||
func (h *headBuffer) Push(hc *store.HeadChange) (rethc *store.HeadChange) {
|
||||
func (h *headBuffer) Push(hc *api.HeadChange) (rethc *api.HeadChange) {
|
||||
if h.buffer.Len() == h.size {
|
||||
var ok bool
|
||||
|
||||
el := h.buffer.Front()
|
||||
rethc, ok = el.Value.(*store.HeadChange)
|
||||
rethc, ok = el.Value.(*api.HeadChange)
|
||||
if !ok {
|
||||
panic("Value from list is not the correct type")
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package main
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/store"
|
||||
"github.com/filecoin-project/lotus/api"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
@ -11,33 +11,33 @@ func TestHeadBuffer(t *testing.T) {
|
||||
|
||||
t.Run("Straight push through", func(t *testing.T) {
|
||||
hb := NewHeadBuffer(5)
|
||||
require.Nil(t, hb.Push(&store.HeadChange{Type: "1"}))
|
||||
require.Nil(t, hb.Push(&store.HeadChange{Type: "2"}))
|
||||
require.Nil(t, hb.Push(&store.HeadChange{Type: "3"}))
|
||||
require.Nil(t, hb.Push(&store.HeadChange{Type: "4"}))
|
||||
require.Nil(t, hb.Push(&store.HeadChange{Type: "5"}))
|
||||
require.Nil(t, hb.Push(&api.HeadChange{Type: "1"}))
|
||||
require.Nil(t, hb.Push(&api.HeadChange{Type: "2"}))
|
||||
require.Nil(t, hb.Push(&api.HeadChange{Type: "3"}))
|
||||
require.Nil(t, hb.Push(&api.HeadChange{Type: "4"}))
|
||||
require.Nil(t, hb.Push(&api.HeadChange{Type: "5"}))
|
||||
|
||||
hc := hb.Push(&store.HeadChange{Type: "6"})
|
||||
hc := hb.Push(&api.HeadChange{Type: "6"})
|
||||
require.Equal(t, hc.Type, "1")
|
||||
})
|
||||
|
||||
t.Run("Reverts", func(t *testing.T) {
|
||||
hb := NewHeadBuffer(5)
|
||||
require.Nil(t, hb.Push(&store.HeadChange{Type: "1"}))
|
||||
require.Nil(t, hb.Push(&store.HeadChange{Type: "2"}))
|
||||
require.Nil(t, hb.Push(&store.HeadChange{Type: "3"}))
|
||||
require.Nil(t, hb.Push(&api.HeadChange{Type: "1"}))
|
||||
require.Nil(t, hb.Push(&api.HeadChange{Type: "2"}))
|
||||
require.Nil(t, hb.Push(&api.HeadChange{Type: "3"}))
|
||||
hb.Pop()
|
||||
require.Nil(t, hb.Push(&store.HeadChange{Type: "3a"}))
|
||||
require.Nil(t, hb.Push(&api.HeadChange{Type: "3a"}))
|
||||
hb.Pop()
|
||||
require.Nil(t, hb.Push(&store.HeadChange{Type: "3b"}))
|
||||
require.Nil(t, hb.Push(&store.HeadChange{Type: "4"}))
|
||||
require.Nil(t, hb.Push(&store.HeadChange{Type: "5"}))
|
||||
require.Nil(t, hb.Push(&api.HeadChange{Type: "3b"}))
|
||||
require.Nil(t, hb.Push(&api.HeadChange{Type: "4"}))
|
||||
require.Nil(t, hb.Push(&api.HeadChange{Type: "5"}))
|
||||
|
||||
hc := hb.Push(&store.HeadChange{Type: "6"})
|
||||
hc := hb.Push(&api.HeadChange{Type: "6"})
|
||||
require.Equal(t, hc.Type, "1")
|
||||
hc = hb.Push(&store.HeadChange{Type: "7"})
|
||||
hc = hb.Push(&api.HeadChange{Type: "7"})
|
||||
require.Equal(t, hc.Type, "2")
|
||||
hc = hb.Push(&store.HeadChange{Type: "8"})
|
||||
hc = hb.Push(&api.HeadChange{Type: "8"})
|
||||
require.Equal(t, hc.Type, "3b")
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user