github.com/cosmos/cosmos-sdk@v0.50.10/client/fuzz_test.go (about) 1 package client_test 2 3 import ( 4 "context" 5 "testing" 6 7 "google.golang.org/grpc" 8 "google.golang.org/grpc/metadata" 9 10 "github.com/cosmos/cosmos-sdk/testutil/testdata" 11 sdk "github.com/cosmos/cosmos-sdk/types" 12 "github.com/cosmos/cosmos-sdk/x/bank/types" 13 ) 14 15 type fuzzSuite struct { 16 IntegrationTestSuite 17 } 18 19 func (fz *fuzzSuite) FuzzQueryBalance(f *testing.F) { 20 if testing.Short() { 21 f.Skip("In -short mode") 22 } 23 24 // gRPC query to test service should work 25 testRes, err := fz.testClient.Echo(context.Background(), &testdata.EchoRequest{Message: "hello"}) 26 fz.Require().NoError(err) 27 fz.Require().Equal("hello", testRes.Message) 28 29 // 1. Generate some seeds. 30 bz, err := fz.cdc.Marshal(&types.QueryBalanceRequest{ 31 Address: fz.genesisAccount.GetAddress().String(), 32 Denom: sdk.DefaultBondDenom, 33 }) 34 fz.Require().NoError(err) 35 f.Add(bz) 36 37 // 2. Now fuzz it and ensure that we don't get any panics. 38 ctx := context.Background() 39 f.Fuzz(func(t *testing.T, in []byte) { 40 qbReq := new(types.QueryBalanceRequest) 41 if err := fz.cdc.Unmarshal(in, qbReq); err != nil { 42 return 43 } 44 45 // gRPC query to bank service should work 46 var header metadata.MD 47 _, _ = fz.bankClient.Balance( 48 ctx, 49 qbReq, 50 grpc.Header(&header), 51 ) 52 }) 53 } 54 55 func FuzzQueryBalance(f *testing.F) { 56 fzs := new(fuzzSuite) 57 fzs.SetT(new(testing.T)) 58 fzs.SetupSuite() 59 fzs.FuzzQueryBalance(f) 60 }