fix tests

This commit is contained in:
vyzo 2023-03-13 05:51:33 +02:00 committed by Maciej Witowski
parent e682036cef
commit 02797bb578

View File

@ -154,17 +154,13 @@ func verifyIndex(t *testing.T, cs *mockChainStore, msgIndex MsgIndex) {
tsCid, err := ts.Key().Cid() tsCid, err := ts.Key().Cid()
require.NoError(t, err) require.NoError(t, err)
xindex := 0 msgs, err := cs.MessagesForTipset(context.Background(), ts)
for _, blk := range blks { require.NoError(t, err)
msgs, _, _ := cs.MessagesForBlock(context.Background(), blk) for _, m := range msgs {
for _, m := range msgs { minfo, err := msgIndex.GetMsgInfo(context.Background(), m.Cid())
minfo, err := msgIndex.GetMsgInfo(context.Background(), m.Cid()) require.NoError(t, err)
require.NoError(t, err) require.Equal(t, tsCid, minfo.TipSet)
require.Equal(t, tsCid, minfo.TipSet) require.Equal(t, ts.Height(), minfo.Epoch)
require.Equal(t, ts.Height(), minfo.Epoch)
require.Equal(t, xindex, minfo.Index)
xindex++
}
} }
parents := ts.Parents() parents := ts.Parents()
@ -175,12 +171,11 @@ func verifyIndex(t *testing.T, cs *mockChainStore, msgIndex MsgIndex) {
func verifyMissing(t *testing.T, cs *mockChainStore, msgIndex MsgIndex, missing ...*types.TipSet) { func verifyMissing(t *testing.T, cs *mockChainStore, msgIndex MsgIndex, missing ...*types.TipSet) {
for _, ts := range missing { for _, ts := range missing {
for _, blk := range ts.Blocks() { msgs, err := cs.MessagesForTipset(context.Background(), ts)
msgs, _, _ := cs.MessagesForBlock(context.Background(), blk) require.NoError(t, err)
for _, m := range msgs { for _, m := range msgs {
_, err := msgIndex.GetMsgInfo(context.Background(), m.Cid()) _, err := msgIndex.GetMsgInfo(context.Background(), m.Cid())
require.Equal(t, ErrNotFound, err) require.Equal(t, ErrNotFound, err)
}
} }
} }
} }
@ -188,9 +183,9 @@ func verifyMissing(t *testing.T, cs *mockChainStore, msgIndex MsgIndex, missing
type mockChainStore struct { type mockChainStore struct {
notify store.ReorgNotifee notify store.ReorgNotifee
curTs *types.TipSet curTs *types.TipSet
tipsets map[types.TipSetKey]*types.TipSet tipsets map[types.TipSetKey]*types.TipSet
blockMsgs map[cid.Cid][]*types.Message msgs map[types.TipSetKey][]types.ChainMsg
nonce uint64 nonce uint64
} }
@ -207,15 +202,15 @@ func init() {
func newMockChainStore() *mockChainStore { func newMockChainStore() *mockChainStore {
return &mockChainStore{ return &mockChainStore{
tipsets: make(map[types.TipSetKey]*types.TipSet), tipsets: make(map[types.TipSetKey]*types.TipSet),
blockMsgs: make(map[cid.Cid][]*types.Message), msgs: make(map[types.TipSetKey][]types.ChainMsg),
} }
} }
func (cs *mockChainStore) genesis() { func (cs *mockChainStore) genesis() {
genBlock := mock.MkBlock(nil, 0, 0) genBlock := mock.MkBlock(nil, 0, 0)
cs.blockMsgs[genBlock.Cid()] = nil
genTs := mock.TipSet(genBlock) genTs := mock.TipSet(genBlock)
cs.msgs[genTs.Key()] = nil
cs.setHead(genTs) cs.setHead(genTs)
} }
@ -252,11 +247,13 @@ func (cs *mockChainStore) makeBlk() *types.TipSet {
blk := mock.MkBlock(cs.curTs, uint64(height), uint64(height)) blk := mock.MkBlock(cs.curTs, uint64(height), uint64(height))
blk.Messages = cs.makeGarbageCid() blk.Messages = cs.makeGarbageCid()
ts := mock.TipSet(blk)
msg1 := cs.makeMsg() msg1 := cs.makeMsg()
msg2 := cs.makeMsg() msg2 := cs.makeMsg()
cs.blockMsgs[blk.Cid()] = []*types.Message{msg1, msg2} cs.msgs[ts.Key()] = []types.ChainMsg{msg1, msg2}
return mock.TipSet(blk) return ts
} }
func (cs *mockChainStore) makeMsg() *types.Message { func (cs *mockChainStore) makeMsg() *types.Message {
@ -274,13 +271,13 @@ func (cs *mockChainStore) SubscribeHeadChanges(f store.ReorgNotifee) {
cs.notify = f cs.notify = f
} }
func (cs *mockChainStore) MessagesForBlock(ctx context.Context, b *types.BlockHeader) ([]*types.Message, []*types.SignedMessage, error) { func (cs *mockChainStore) MessagesForTipset(ctx context.Context, ts *types.TipSet) ([]types.ChainMsg, error) {
msgs, ok := cs.blockMsgs[b.Cid()] msgs, ok := cs.msgs[ts.Key()]
if !ok { if !ok {
return nil, nil, errors.New("unknown block") return nil, errors.New("unknown tipset")
} }
return msgs, nil, nil return msgs, nil
} }
func (cs *mockChainStore) GetHeaviestTipSet() *types.TipSet { func (cs *mockChainStore) GetHeaviestTipSet() *types.TipSet {