From 94374aa93d4ef3fb6174e6d6422352599dccc894 Mon Sep 17 00:00:00 2001 From: Nikola Divic Date: Fri, 11 Feb 2022 18:30:07 +0100 Subject: [PATCH] test: sync checkpoint cli command --- cli/sync_test.go | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/cli/sync_test.go b/cli/sync_test.go index 85b05fa5c..174279d08 100644 --- a/cli/sync_test.go +++ b/cli/sync_test.go @@ -8,7 +8,9 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/lotus/api" + "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/types/mock" + "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" ) @@ -136,3 +138,44 @@ func TestSyncCheckBad(t *testing.T) { assert.Contains(t, buf.String(), reason) }) } + +func TestSyncCheckpoint(t *testing.T) { + t.Run("tipset", func(t *testing.T) { + app, mockApi, _, done := NewMockAppWithFullAPI(t, WithCategory("sync", SyncCheckpointCmd)) + defer done() + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + blk := mock.MkBlock(nil, 0, 0) + ts := mock.TipSet(blk) + + gomock.InOrder( + mockApi.EXPECT().ChainGetBlock(ctx, blk.Cid()).Return(blk, nil), + mockApi.EXPECT().SyncCheckpoint(ctx, ts.Key()).Return(nil), + ) + + err := app.Run([]string{"sync", "checkpoint", blk.Cid().String()}) + assert.NoError(t, err) + }) + + t.Run("epoch", func(t *testing.T) { + app, mockApi, _, done := NewMockAppWithFullAPI(t, WithCategory("sync", SyncCheckpointCmd)) + defer done() + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + epoch := abi.ChainEpoch(0) + blk := mock.MkBlock(nil, 0, 0) + ts := mock.TipSet(blk) + + gomock.InOrder( + mockApi.EXPECT().ChainGetTipSetByHeight(ctx, epoch, types.EmptyTSK).Return(ts, nil), + mockApi.EXPECT().SyncCheckpoint(ctx, ts.Key()).Return(nil), + ) + + err := app.Run([]string{"sync", "checkpoint", fmt.Sprintf("-epoch=%d", epoch)}) + assert.NoError(t, err) + }) +}