forked from solarlabsteam/cosmos-exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: handle gov proposal v1 and v1beta1
- Loading branch information
Showing
4 changed files
with
2,922 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
"testing" | ||
|
||
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" | ||
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" | ||
"github.com/stretchr/testify/require" | ||
"google.golang.org/grpc" | ||
) | ||
|
||
func queryGov(conn *grpc.ClientConn) error { | ||
// Handle v1beta1 | ||
govv1beta1Client := govv1beta1.NewQueryClient(conn) | ||
{ | ||
proposals, err := govv1beta1Client.Proposals(context.Background(), &govv1beta1.QueryProposalsRequest{ | ||
ProposalStatus: govv1beta1.StatusVotingPeriod, | ||
}) | ||
if err != nil { | ||
if !strings.Contains(err.Error(), `invalid type: can't convert a gov/v1 Proposal to gov/v1beta1 Proposal`) { | ||
return err | ||
} | ||
} else if err == nil { | ||
pp := proposals.GetProposals() | ||
fmt.Printf("proposals: %T\n", proposals) | ||
fmt.Printf("proposals: %v\n", len(pp)) | ||
return nil | ||
} | ||
} | ||
|
||
govv1Client := govv1.NewQueryClient(conn) | ||
{ | ||
proposals, err := govv1Client.Proposals(context.Background(), &govv1.QueryProposalsRequest{ | ||
ProposalStatus: govv1.StatusVotingPeriod, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
pp := proposals.GetProposals() | ||
fmt.Printf("proposals: %T\n", proposals) | ||
fmt.Printf("proposals: %v\n", len(pp)) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func TestGetActiveProposalsJUNO(t *testing.T) { | ||
conn, err := grpc.Dial( | ||
"juno-grpc.nysa.network:9090", | ||
grpc.WithInsecure(), | ||
) | ||
require.NoError(t, err) | ||
|
||
defer conn.Close() | ||
|
||
err = queryGov(conn) | ||
require.NoError(t, err) | ||
} | ||
|
||
func TestGetActiveProposalsArchway(t *testing.T) { | ||
conn, err := grpc.Dial( | ||
"archway-grpc.nysa.network:9090", | ||
grpc.WithInsecure(), | ||
) | ||
require.NoError(t, err) | ||
|
||
defer conn.Close() | ||
|
||
err = queryGov(conn) | ||
require.NoError(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.