github.com/iotexproject/iotex-core@v1.14.1-rc1/ioctl/newcmd/bc/bcbucket_test.go (about) 1 // Copyright (c) 2022 IoTeX Foundation 2 // This source code is provided 'as is' and no warranties are given as to title or non-infringement, merchantability 3 // or fitness for purpose and, to the extent permitted by law, all liability for your use of the code is disclaimed. 4 // This source code is governed by Apache License 2.0 that can be found in the LICENSE file. 5 6 package bc 7 8 import ( 9 "testing" 10 11 "github.com/golang/mock/gomock" 12 "github.com/iotexproject/iotex-proto/golang/iotexapi" 13 "github.com/iotexproject/iotex-proto/golang/iotexapi/mock_iotexapi" 14 "github.com/iotexproject/iotex-proto/golang/iotextypes" 15 "github.com/stretchr/testify/require" 16 "google.golang.org/protobuf/proto" 17 "google.golang.org/protobuf/types/known/timestamppb" 18 19 "github.com/iotexproject/iotex-core/ioctl/config" 20 "github.com/iotexproject/iotex-core/ioctl/util" 21 "github.com/iotexproject/iotex-core/test/mock/mock_ioctlclient" 22 "github.com/iotexproject/iotex-core/testutil" 23 ) 24 25 func TestBCBucketCmd(t *testing.T) { 26 require := require.New(t) 27 ctrl := gomock.NewController(t) 28 client := mock_ioctlclient.NewMockClient(ctrl) 29 apiServiceClient := mock_iotexapi.NewMockAPIServiceClient(ctrl) 30 client.EXPECT().SelectTranslation(gomock.Any()).Return("", config.English).Times(9) 31 32 t.Run("get total blockchain bucket count", func(t *testing.T) { 33 client.EXPECT().APIServiceClient().Return(apiServiceClient, nil).Times(2) 34 apiServiceClient.EXPECT().ReadState(gomock.Any(), gomock.All()).Return(&iotexapi.ReadStateResponse{}, nil) 35 36 cmd := NewBCBucketCmd(client) 37 result, err := util.ExecuteCmd(cmd, "max") 38 require.NoError(err) 39 require.Equal("0\n", result) 40 }) 41 42 t.Run("get active blockchain bucket count", func(t *testing.T) { 43 client.EXPECT().APIServiceClient().Return(apiServiceClient, nil).AnyTimes() 44 apiServiceClient.EXPECT().ReadState(gomock.Any(), gomock.All()).Return(&iotexapi.ReadStateResponse{}, nil) 45 46 cmd := NewBCBucketCmd(client) 47 result, err := util.ExecuteCmd(cmd, "count") 48 require.NoError(err) 49 require.Equal("0\n", result) 50 }) 51 52 t.Run("get default blockchain bucket count", func(t *testing.T) { 53 cfg := config.Config{} 54 vb := &iotextypes.VoteBucket{ 55 Index: 1, 56 StakedAmount: "10", 57 UnstakeStartTime: timestamppb.New(testutil.TimestampNow()), 58 } 59 vblist, err := proto.Marshal(&iotextypes.VoteBucketList{ 60 Buckets: []*iotextypes.VoteBucket{vb}, 61 }) 62 require.NoError(err) 63 client.EXPECT().Config().Return(cfg).AnyTimes() 64 apiServiceClient.EXPECT().ReadState(gomock.Any(), gomock.All()).Return(&iotexapi.ReadStateResponse{ 65 Data: vblist, 66 }, nil) 67 68 cmd := NewBCBucketCmd(client) 69 result, err := util.ExecuteCmd(cmd, "0") 70 require.NoError(err) 71 require.Contains(result, "index: 1") 72 }) 73 }