github.com/Finschia/finschia-sdk@v0.48.1/client/grpc/tmservice/block_test.go (about)

     1  package tmservice_test
     2  
     3  import (
     4  	tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
     5  
     6  	"github.com/Finschia/finschia-sdk/client/grpc/tmservice"
     7  	"github.com/Finschia/finschia-sdk/simapp"
     8  )
     9  
    10  func (s IntegrationTestSuite) TestGetProtoBlock() {
    11  	val := s.network.Validators[0]
    12  	app := simapp.Setup(false)
    13  	ctx := app.BaseApp.NewContext(false, tmproto.Header{})
    14  
    15  	height := int64(-1)
    16  	blockID, block, err := tmservice.GetProtoBlock(ctx.Context(), val.ClientCtx, &height)
    17  	s.Require().Equal(tmproto.BlockID{}, blockID)
    18  	s.Require().Nil(block)
    19  	s.Require().Error(err)
    20  
    21  	height = int64(1)
    22  	_, _, err = tmservice.GetProtoBlock(ctx.Context(), val.ClientCtx, &height)
    23  	s.Require().NoError(err)
    24  }
    25  
    26  func (s IntegrationTestSuite) TestGetBlocksByHash() {
    27  	val := s.network.Validators[0]
    28  	app := simapp.Setup(false)
    29  	ctx := app.BaseApp.NewContext(false, tmproto.Header{})
    30  
    31  	height := int64(1)
    32  	blockResult, err := tmservice.GetBlock(ctx.Context(), val.ClientCtx, &height)
    33  	s.Require().NoError(err)
    34  
    35  	blockHash := blockResult.Block.Hash()
    36  	blockResult2, err := tmservice.GetBlockByHash(val.ClientCtx, blockHash)
    37  	s.Require().NoError(err)
    38  	s.Require().Equal(blockResult2.Block.Height, blockResult.Block.Height)
    39  }
    40  
    41  func (s IntegrationTestSuite) TestGetBlockResultsByHeight() {
    42  	val := s.network.Validators[0]
    43  
    44  	height := int64(1)
    45  	blockResult, err := tmservice.GetBlockResultsByHeight(val.ClientCtx, &height)
    46  	s.Require().NoError(err)
    47  	s.Require().Equal(height, blockResult.Height)
    48  	s.Require().NotNil(blockResult.BeginBlockEvents)
    49  	s.Require().Nil(blockResult.EndBlockEvents)
    50  	s.Require().Nil(blockResult.ValidatorUpdates)
    51  }