github.com/iotexproject/iotex-core@v1.14.1-rc1/action/protocol/staking/candidate_statereader_test.go (about) 1 // Copyright (c) 2020 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 staking 7 8 import ( 9 "math/big" 10 "testing" 11 12 "github.com/golang/mock/gomock" 13 "github.com/iotexproject/iotex-core/action/protocol" 14 "github.com/iotexproject/iotex-core/testutil/testdb" 15 "github.com/stretchr/testify/require" 16 ) 17 18 func Test_CandidateStateReader(t *testing.T) { 19 require := require.New(t) 20 21 ctrl := gomock.NewController(t) 22 sm := testdb.NewMockStateManager(ctrl) 23 h, err := sm.Height() 24 require.NoError(err) 25 csr, err := ConstructBaseView(sm) 26 require.Equal(err, protocol.ErrNoName) 27 view, _, err := CreateBaseView(sm, false) 28 require.NoError(err) 29 csr = &candSR{ 30 StateReader: sm, 31 height: h, 32 view: view, 33 } 34 35 require.Equal(csr.Height(), h) 36 require.Equal(csr.SR(), sm) 37 require.Equal(len(csr.AllCandidates()), 0) 38 require.Equal(csr.TotalStakedAmount(), big.NewInt(0)) 39 require.Equal(csr.ActiveBucketsCount(), uint64(0)) 40 }