Skip to content

Commit

Permalink
test: e2e bet
Browse files Browse the repository at this point in the history
  • Loading branch information
scorpioborn committed May 20, 2024
1 parent 8139438 commit e5452cd
Show file tree
Hide file tree
Showing 3 changed files with 585 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/e2e/bet/cli_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package client_test

import (
"testing"

"github.com/stretchr/testify/suite"

client "github.com/sge-network/sge/tests/e2e/bet"
"github.com/sge-network/sge/testutil/network"
)

func TestE2ETestSuite(t *testing.T) {
cfg := network.DefaultConfig()
cfg.NumValidators = 1
suite.Run(t, client.NewE2ETestSuite(cfg))
}
106 changes: 106 additions & 0 deletions tests/e2e/bet/grpc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package client

import (
"fmt"

"github.com/cosmos/gogoproto/proto"

"github.com/cosmos/cosmos-sdk/testutil"
grpctypes "github.com/cosmos/cosmos-sdk/types/grpc"
"github.com/cosmos/cosmos-sdk/types/query"

"github.com/sge-network/sge/x/bet/types"
)

func (s *E2ETestSuite) TestBetsGRPCHandler() {
val := s.network.Validators[0]
baseURL := val.APIAddress

testCases := []struct {
name string
url string
headers map[string]string
respType proto.Message
expected proto.Message
}{
{
"test GRPC Bet by UID",
fmt.Sprintf("%s/sge/bet/%s/%s", baseURL, dummyBetCreator, dummyBetUID),
map[string]string{
grpctypes.GRPCBlockHeightHeader: "1",
},
&types.QueryBetResponse{},
&types.QueryBetResponse{
Bet: genesis.BetList[0],
Market: dummyMarket,
},
},
{
"test GRPC sorted Bet by creator",
fmt.Sprintf("%s/sge/bet/creator/%s/bets", baseURL, dummyBetCreator),
map[string]string{
grpctypes.GRPCBlockHeightHeader: "1",
},
&types.QueryBetsByCreatorResponse{},
&types.QueryBetsByCreatorResponse{
Bet: genesis.BetList,
Pagination: &query.PageResponse{
Total: 1,
},
},
},
{
"test GRPC Bet by UID",
fmt.Sprintf("%s/sge/bet/bets", baseURL),
map[string]string{
grpctypes.GRPCBlockHeightHeader: "1",
},
&types.QueryBetsResponse{},
&types.QueryBetsResponse{
Bet: genesis.BetList,
Pagination: &query.PageResponse{
Total: 1,
},
},
},
{
"test GRPC pending bets by market",
fmt.Sprintf("%s/sge/bet/bets/pending/%s", baseURL, dummyMarketUID),
map[string]string{
grpctypes.GRPCBlockHeightHeader: "1",
},
&types.QueryPendingBetsResponse{},
&types.QueryPendingBetsResponse{
Bet: genesis.BetList,
Pagination: &query.PageResponse{
Total: 1,
},
},
},
{
"test GRPC settled bets by market",
fmt.Sprintf("%s/sge/bet/bets/settled/%d", baseURL, 1),
map[string]string{
grpctypes.GRPCBlockHeightHeader: "1",
},
&types.QuerySettledBetsOfHeightResponse{},
&types.QuerySettledBetsOfHeightResponse{
Bet: genesis.BetList,
Pagination: &query.PageResponse{
Total: 1,
},
},
},
}

for _, tc := range testCases {
tc := tc
s.Run(tc.name, func() {
resp, err := testutil.GetRequestWithHeaders(tc.url, tc.headers)
s.Require().NoError(err)

s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(resp, tc.respType))
s.Require().Equal(tc.expected.String(), tc.respType.String())
})
}
}
Loading

0 comments on commit e5452cd

Please sign in to comment.