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