Skip to content

Commit

Permalink
refactor: simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
rootulp committed Jul 10, 2024
1 parent c5b4277 commit 7771571
Showing 1 changed file with 4 additions and 25 deletions.
29 changes: 4 additions & 25 deletions app/test/testnode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,46 +11,25 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/grpc"
"google.golang.org/grpc/connectivity"
"google.golang.org/grpc/credentials/insecure"
)

func Test_testnode(t *testing.T) {
t.Run("testnode can start a network with default chain ID", func(t *testing.T) {
testnode.NewNetwork(t, testnode.DefaultConfig())
})
t.Run("testnode can start with a custom MinGasPrice", func(t *testing.T) {
want := "0.003utia"
appConfig := testnode.DefaultAppConfig()
appConfig.MinGasPrices = "0.003utia"

appConfig.MinGasPrices = want
config := testnode.DefaultConfig().WithAppConfig(appConfig)
cctx, _, grpcAddr := testnode.NewNetwork(t, config)

grpcConn := createGrpcConnection(t, cctx.GoContext(), grpcAddr)
got, err := queryMinimumGasPrice(cctx.GoContext(), grpcConn)
cctx, _, _ := testnode.NewNetwork(t, config)
got, err := queryMinimumGasPrice(cctx.GoContext(), cctx.GRPCClient)
require.NoError(t, err)
assert.Equal(t, float64(0.003), got)
})
}

func createGrpcConnection(t *testing.T, ctx context.Context, grpcAddr string) *grpc.ClientConn {
client, err := grpc.NewClient(
grpcAddr,
grpc.WithTransportCredentials(insecure.NewCredentials()),
)
require.NoError(t, err)

// this ensures we can't start the node without core connection
client.Connect()
if !client.WaitForStateChange(ctx, connectivity.Ready) {
// hits the case when context is canceled
t.Fatalf("couldn't connect to core endpoint(%s): %v", grpcAddr, ctx.Err())
}
return client
}

func queryMinimumGasPrice(ctx context.Context, grpcConn *grpc.ClientConn) (float64, error) {

cfgRsp, err := nodeservice.NewServiceClient(grpcConn).Config(ctx, &nodeservice.ConfigRequest{})
if err != nil {
return 0, err
Expand Down

0 comments on commit 7771571

Please sign in to comment.