-
Notifications
You must be signed in to change notification settings - Fork 589
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9284351
commit 1f1041c
Showing
16 changed files
with
407 additions
and
183 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
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,10 @@ | ||
keeper: | ||
path: "github.com/osmosis-labs/osmosis/v13/x/valset-pref" | ||
struct: "Keeper" | ||
client_path: "github.com/osmosis-labs/osmosis/v13/x/valset-pref/client" | ||
queries: | ||
UserValidatorPreferences: | ||
proto_wrapper: | ||
query_func: "k.UserValidatorPreferences" | ||
cli: | ||
cmd: "UserValidatorPreferences" |
Binary file not shown.
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 was deleted.
Oops, something went wrong.
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,57 @@ | ||
package valsetprefcli | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/osmosis-labs/osmosis/v13/x/valset-pref/client/queryproto" | ||
"github.com/osmosis-labs/osmosis/v13/x/valset-pref/types" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// GetQueryCmd returns the cli query commands for this module. | ||
func GetQueryCmd() *cobra.Command { | ||
// Group valset queries under a subcommand | ||
cmd := &cobra.Command{ | ||
Use: types.ModuleName, | ||
Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), | ||
DisableFlagParsing: true, | ||
SuggestionsMinimumDistance: 2, | ||
RunE: client.ValidateCmd, | ||
} | ||
|
||
cmd.AddCommand(GetCmdValSetPref()) | ||
|
||
return cmd | ||
} | ||
|
||
// GetCmdValSetPref takes the address and returns the existing validator set for that address. | ||
func GetCmdValSetPref() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "val-set [address]", | ||
Short: "Query the validator set for a specific user address", | ||
|
||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
clientCtx, err := client.GetClientQueryContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
queryClient := queryproto.NewQueryClient(clientCtx) | ||
|
||
res, err := queryClient.UserValidatorPreferences(cmd.Context(), &queryproto.UserValidatorPreferencesRequest{ | ||
Address: args[0], | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return clientCtx.PrintProto(res) | ||
}, | ||
} | ||
|
||
flags.AddQueryFlagsToCmd(cmd) | ||
|
||
return cmd | ||
} |
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,83 @@ | ||
package valsetprefcli_test | ||
|
||
import ( | ||
gocontext "context" | ||
"testing" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/osmosis-labs/osmosis/v13/app/apptesting" | ||
valPref "github.com/osmosis-labs/osmosis/v13/x/valset-pref" | ||
"github.com/osmosis-labs/osmosis/v13/x/valset-pref/client/queryproto" | ||
"github.com/osmosis-labs/osmosis/v13/x/valset-pref/types" | ||
"github.com/stretchr/testify/suite" | ||
) | ||
|
||
type QueryTestSuite struct { | ||
apptesting.KeeperTestHelper | ||
queryClient queryproto.QueryClient | ||
} | ||
|
||
func (s *QueryTestSuite) SetupSuite() { | ||
s.Setup() | ||
s.queryClient = queryproto.NewQueryClient(s.QueryHelper) | ||
|
||
// setup 3 validators | ||
valAddrs := s.SetupMultipleValidators(3) | ||
delegator := sdk.AccAddress([]byte("addr1---------------")) | ||
preferences := []types.ValidatorPreference{ | ||
{ | ||
ValOperAddress: valAddrs[0], | ||
Weight: sdk.NewDecWithPrec(5, 1), | ||
}, | ||
{ | ||
ValOperAddress: valAddrs[1], | ||
Weight: sdk.NewDecWithPrec(3, 1), | ||
}, | ||
{ | ||
ValOperAddress: valAddrs[2], | ||
Weight: sdk.NewDecWithPrec(2, 1), | ||
}, | ||
} | ||
|
||
// setup message server | ||
msgServer := valPref.NewMsgServerImpl(s.App.ValidatorSetPreferenceKeeper) | ||
c := sdk.WrapSDKContext(s.Ctx) | ||
|
||
// call the create validator set preference | ||
_, err := msgServer.SetValidatorSetPreference(c, types.NewMsgSetValidatorSetPreference(delegator, preferences)) | ||
s.Require().NoError(err) | ||
|
||
// creates a test context like blockheader, blockheight and more | ||
s.Commit() | ||
} | ||
|
||
func (s *QueryTestSuite) TestQueriesNeverAlterState() { | ||
testCases := []struct { | ||
name string | ||
query string | ||
input interface{} | ||
output interface{} | ||
}{ | ||
{ | ||
"Query delegators validator set", | ||
"/osmosis.valsetpref.v1beta1.Query/UserValidatorPreferences", | ||
&queryproto.UserValidatorPreferencesRequest{Address: sdk.AccAddress([]byte("addr1---------------")).String()}, | ||
&queryproto.UserValidatorPreferenceResponse{}, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
tc := tc | ||
s.SetupSuite() | ||
|
||
s.Run(tc.name, func() { | ||
err := s.QueryHelper.Invoke(gocontext.Background(), tc.query, tc.input, tc.output) | ||
s.Require().NoError(err) | ||
s.StateNotAltered() | ||
}) | ||
} | ||
} | ||
|
||
func TestQueryTestSuite(t *testing.T) { | ||
suite.Run(t, new(QueryTestSuite)) | ||
} |
Oops, something went wrong.