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