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

     1  //go:build norace
     2  // +build norace
     3  
     4  package client_test
     5  
     6  import (
     7  	"fmt"
     8  
     9  	abci "github.com/tendermint/tendermint/abci/types"
    10  
    11  	banktypes "github.com/Finschia/finschia-sdk/x/bank/types"
    12  )
    13  
    14  func (s *IntegrationTestSuite) TestQueryABCIHeight() {
    15  	testCases := []struct {
    16  		name      string
    17  		reqHeight int64
    18  		ctxHeight int64
    19  		expHeight int64
    20  	}{
    21  		{
    22  			name:      "non zero request height",
    23  			reqHeight: 3,
    24  			ctxHeight: 1, // query at height 1 or 2 would cause an error
    25  			expHeight: 3,
    26  		},
    27  		{
    28  			name:      "empty request height - use context height",
    29  			reqHeight: 0,
    30  			ctxHeight: 3,
    31  			expHeight: 3,
    32  		},
    33  		{
    34  			name:      "empty request height and context height - use latest height",
    35  			reqHeight: 0,
    36  			ctxHeight: 0,
    37  			expHeight: 5,
    38  		},
    39  	}
    40  
    41  	for _, tc := range testCases {
    42  		s.Run(tc.name, func() {
    43  			s.network.WaitForHeight(tc.expHeight)
    44  
    45  			val := s.network.Validators[0]
    46  
    47  			clientCtx := val.ClientCtx
    48  			clientCtx = clientCtx.WithHeight(tc.ctxHeight)
    49  
    50  			req := abci.RequestQuery{
    51  				Path:   fmt.Sprintf("store/%s/key", banktypes.StoreKey),
    52  				Height: tc.reqHeight,
    53  				Data:   banktypes.CreateAccountBalancesPrefix(val.Address),
    54  				Prove:  true,
    55  			}
    56  
    57  			res, err := clientCtx.QueryABCI(req)
    58  			s.Require().NoError(err)
    59  
    60  			s.Require().LessOrEqual(tc.expHeight, res.Height)
    61  		})
    62  	}
    63  }