diff --git a/action/protocol/staking/candidate_statereader.go b/action/protocol/staking/candidate_statereader.go index 93faa954de..d2d7053682 100644 --- a/action/protocol/staking/candidate_statereader.go +++ b/action/protocol/staking/candidate_statereader.go @@ -119,27 +119,6 @@ func (c *candSR) ActiveBucketsCount() uint64 { return c.view.bucketPool.Count() } -// GetStakingStateReader returns a candidate state reader that reflects the base view -func GetStakingStateReader(sr protocol.StateReader) (CandidateStateReader, error) { - c, err := ConstructBaseView(sr) - if err != nil { - if errors.Cause(err) == protocol.ErrNoName { - // the view does not exist yet, create it - view, height, err := CreateBaseView(sr, true) - if err != nil { - return nil, err - } - return &candSR{ - StateReader: sr, - height: height, - view: view, - }, nil - } - return nil, err - } - return c, nil -} - // ConstructBaseView returns a candidate state reader that reflects the base view // it will be used read-only func ConstructBaseView(sr protocol.StateReader) (CandidateStateReader, error) { diff --git a/action/protocol/staking/candidate_statereader_test.go b/action/protocol/staking/candidate_statereader_test.go index 25d24fdda0..ab5f5f7cfe 100644 --- a/action/protocol/staking/candidate_statereader_test.go +++ b/action/protocol/staking/candidate_statereader_test.go @@ -11,6 +11,7 @@ import ( "testing" "github.com/golang/mock/gomock" + "github.com/iotexproject/iotex-core/action/protocol" "github.com/iotexproject/iotex-core/testutil/testdb" "github.com/stretchr/testify/require" ) @@ -20,11 +21,18 @@ func Test_CandidateStateReader(t *testing.T) { ctrl := gomock.NewController(t) sm := testdb.NewMockStateManager(ctrl) - csr, err := GetStakingStateReader(sm) - require.NoError(err) - h, err := sm.Height() require.NoError(err) + csr, err := ConstructBaseView(sm) + require.Equal(err, protocol.ErrNoName) + view, _, err := CreateBaseView(sm, false) + require.NoError(err) + csr = &candSR{ + StateReader: sm, + height: h, + view: view, + } + require.Equal(csr.Height(), h) require.Equal(csr.SR(), sm) require.Equal(len(csr.AllCandidates()), 0) diff --git a/action/protocol/staking/protocol.go b/action/protocol/staking/protocol.go index 8836066000..42ce247e0a 100644 --- a/action/protocol/staking/protocol.go +++ b/action/protocol/staking/protocol.go @@ -458,7 +458,7 @@ func (p *Protocol) Validate(ctx context.Context, act action.Action, sr protocol. // ActiveCandidates returns all active candidates in candidate center func (p *Protocol) ActiveCandidates(ctx context.Context, sr protocol.StateReader, height uint64) (state.CandidateList, error) { - c, err := GetStakingStateReader(sr) + c, err := ConstructBaseView(sr) if err != nil { return nil, errors.Wrap(err, "failed to get ActiveCandidates") } diff --git a/api/grpcserver_integrity_test.go b/api/grpcserver_integrity_test.go index cee9994c46..4c69387b24 100644 --- a/api/grpcserver_integrity_test.go +++ b/api/grpcserver_integrity_test.go @@ -1370,7 +1370,7 @@ func TestGrpcServer_SendActionIntegrity(t *testing.T) { for _, test := range tests { request := &iotexapi.SendActionRequest{Action: test.action} - cfg:=test.cfg() + cfg := test.cfg() cfg.API.GRPCPort = testutil.RandomPort() svr, _, _, _, _, _, file, err := createServerV2(cfg, true) require.NoError(err) diff --git a/ioctl/newcmd/action/action_test.go b/ioctl/newcmd/action/action_test.go index 8b47e41b9a..de17aba9f9 100644 --- a/ioctl/newcmd/action/action_test.go +++ b/ioctl/newcmd/action/action_test.go @@ -349,7 +349,7 @@ func TestExecute(t *testing.T) { require.Error(err, expectedErr) }) } - + func TestRead(t *testing.T) { require := require.New(t) ctrl := gomock.NewController(t)