Skip to content

Commit

Permalink
Merge pull request #394 from sge-network/test/e2e
Browse files Browse the repository at this point in the history
Test/ End to End Bet, House and Market
  • Loading branch information
scorpioborn authored Jun 6, 2024
2 parents 7de8d41 + b09a9f2 commit 1e1afbb
Show file tree
Hide file tree
Showing 22 changed files with 2,615 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 0

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/proto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@master
- uses: actions/checkout@v4
- uses: technote-space/get-diff-action@v4
with:
PATTERNS: |
Expand Down
36 changes: 19 additions & 17 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ jobs:
arch: arm64

steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Get git diff
uses: technote-space/get-diff-action@v6.1.2
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: 1.22
- uses: technote-space/get-diff-action@v4
id: git_diff
with:
PATTERNS: |
**/**.wasm
Expand Down Expand Up @@ -82,23 +84,23 @@ jobs:
go-version: 1.22
- uses: actions/checkout@v4
- name: Create a file with all the pkgs
run: go list ./... > pkgs.txt
run: go list ./... | grep -E -v 'tests/e2e' > pkgs.txt
- name: Split pkgs into 4 files
run: split -d -n l/4 pkgs.txt pkgs.txt.part.
# cache multiple
- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v4
with:
name: "${{ github.sha }}-00"
path: ./pkgs.txt.part.00
- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v4
with:
name: "${{ github.sha }}-01"
path: ./pkgs.txt.part.01
- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v4
with:
name: "${{ github.sha }}-02"
path: ./pkgs.txt.part.02
- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v4
with:
name: "${{ github.sha }}-03"
path: ./pkgs.txt.part.03
Expand All @@ -121,15 +123,15 @@ jobs:
**/**.go
go.mod
go.sum
- uses: actions/download-artifact@v2
- uses: actions/download-artifact@v4
with:
name: "${{ github.sha }}-${{ matrix.part }}"
if: env.GIT_DIFF
- name: test & coverage report creation
run: |
cat pkgs.txt.part.${{ matrix.part }} | xargs go test -mod=readonly -timeout 30m -coverprofile=${{ matrix.part }}profile.out -covermode=atomic -tags='norace ledger test_ledger_mock'
if: env.GIT_DIFF
- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v4
with:
name: "${{ github.sha }}-${{ matrix.part }}-coverage"
path: ./${{ matrix.part }}profile.out
Expand All @@ -145,19 +147,19 @@ jobs:
**/**.go
go.mod
go.sum
- uses: actions/download-artifact@v2
- uses: actions/download-artifact@v4
with:
name: "${{ github.sha }}-00-coverage"
if: env.GIT_DIFF
- uses: actions/download-artifact@v2
- uses: actions/download-artifact@v4
with:
name: "${{ github.sha }}-01-coverage"
if: env.GIT_DIFF
- uses: actions/download-artifact@v2
- uses: actions/download-artifact@v4
with:
name: "${{ github.sha }}-02-coverage"
if: env.GIT_DIFF
- uses: actions/download-artifact@v2
- uses: actions/download-artifact@v4
with:
name: "${{ github.sha }}-03-coverage"
if: env.GIT_DIFF
Expand Down Expand Up @@ -199,15 +201,15 @@ jobs:
**/**.go
go.mod
go.sum
- uses: actions/download-artifact@v2
- uses: actions/download-artifact@v4
with:
name: "${{ github.sha }}-${{ matrix.part }}"
if: env.GIT_DIFF
- name: test & coverage report creation
run: |
xargs --arg-file=pkgs.txt.part.${{ matrix.part }} go test -mod=readonly -timeout 30m -race -tags='cgo ledger test_ledger_mock'
if: env.GIT_DIFF
- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v4
with:
name: "${{ github.sha }}-${{ matrix.part }}-race-output"
path: ./${{ matrix.part }}-race-output.txt
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 1e1afbb

Please sign in to comment.