github.com/vipernet-xyz/tendermint-core@v0.32.0/rpc/client/mock/status_test.go (about)

     1  package mock_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  	"github.com/stretchr/testify/require"
     8  
     9  	"github.com/tendermint/tendermint/libs/bytes"
    10  	"github.com/tendermint/tendermint/rpc/client/mock"
    11  	ctypes "github.com/tendermint/tendermint/rpc/core/types"
    12  )
    13  
    14  func TestStatus(t *testing.T) {
    15  	assert, require := assert.New(t), require.New(t)
    16  
    17  	m := &mock.StatusMock{
    18  		Call: mock.Call{
    19  			Response: &ctypes.ResultStatus{
    20  				SyncInfo: ctypes.SyncInfo{
    21  					LatestBlockHash:   bytes.HexBytes("block"),
    22  					LatestAppHash:     bytes.HexBytes("app"),
    23  					LatestBlockHeight: 10,
    24  				},
    25  			}},
    26  	}
    27  
    28  	r := mock.NewStatusRecorder(m)
    29  	require.Equal(0, len(r.Calls))
    30  
    31  	// make sure response works proper
    32  	status, err := r.Status()
    33  	require.Nil(err, "%+v", err)
    34  	assert.EqualValues("block", status.SyncInfo.LatestBlockHash)
    35  	assert.EqualValues(10, status.SyncInfo.LatestBlockHeight)
    36  
    37  	// make sure recorder works properly
    38  	require.Equal(1, len(r.Calls))
    39  	rs := r.Calls[0]
    40  	assert.Equal("status", rs.Name)
    41  	assert.Nil(rs.Args)
    42  	assert.Nil(rs.Error)
    43  	require.NotNil(rs.Response)
    44  	st, ok := rs.Response.(*ctypes.ResultStatus)
    45  	require.True(ok)
    46  	assert.EqualValues("block", st.SyncInfo.LatestBlockHash)
    47  	assert.EqualValues(10, st.SyncInfo.LatestBlockHeight)
    48  }