forked from Stride-Labs/stride
-
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.
ignite scaffold message query-exchangerate chainID --module interchai…
…nquery
- Loading branch information
1 parent
0edf336
commit cb06054
Showing
24 changed files
with
727 additions
and
72 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,42 @@ | ||
package cli | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/Stride-Labs/stride/x/interchainquery/types" | ||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/cosmos/cosmos-sdk/client/tx" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var _ = strconv.Itoa(0) | ||
|
||
func CmdQueryExchangerate() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "query-exchangerate [chain-id]", | ||
Short: "Broadcast message query-exchangerate", | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) (err error) { | ||
argChainID := args[0] | ||
|
||
clientCtx, err := client.GetClientTxContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
msg := types.NewMsgQueryExchangerate( | ||
clientCtx.GetFromAddress().String(), | ||
argChainID, | ||
) | ||
if err := msg.ValidateBasic(); err != nil { | ||
return err | ||
} | ||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) | ||
}, | ||
} | ||
|
||
flags.AddTxFlagsToCmd(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
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,17 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/Stride-Labs/stride/x/interchainquery/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
func (k msgServer) QueryExchangerate(goCtx context.Context, msg *types.MsgQueryExchangerate) (*types.MsgQueryExchangerateResponse, error) { | ||
ctx := sdk.UnwrapSDKContext(goCtx) | ||
|
||
// TODO: Handling the message | ||
_ = ctx | ||
|
||
return &types.MsgQueryExchangerateResponse{}, nil | ||
} |
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,79 @@ | ||
package interchainquery | ||
|
||
import ( | ||
"math/rand" | ||
|
||
"github.com/Stride-Labs/stride/testutil/sample" | ||
interchainquerysimulation "github.com/Stride-Labs/stride/x/interchainquery/simulation" | ||
"github.com/Stride-Labs/stride/x/interchainquery/types" | ||
"github.com/cosmos/cosmos-sdk/baseapp" | ||
simappparams "github.com/cosmos/cosmos-sdk/simapp/params" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/module" | ||
simtypes "github.com/cosmos/cosmos-sdk/types/simulation" | ||
"github.com/cosmos/cosmos-sdk/x/simulation" | ||
) | ||
|
||
// avoid unused import issue | ||
var ( | ||
_ = sample.AccAddress | ||
_ = interchainquerysimulation.FindAccount | ||
_ = simappparams.StakePerAccount | ||
_ = simulation.MsgEntryKind | ||
_ = baseapp.Paramspace | ||
) | ||
|
||
const ( | ||
opWeightMsgQueryExchangerate = "op_weight_msg_query_exchangerate" | ||
// TODO: Determine the simulation weight value | ||
defaultWeightMsgQueryExchangerate int = 100 | ||
|
||
// this line is used by starport scaffolding # simapp/module/const | ||
) | ||
|
||
// GenerateGenesisState creates a randomized GenState of the module | ||
func (AppModule) GenerateGenesisState(simState *module.SimulationState) { | ||
accs := make([]string, len(simState.Accounts)) | ||
for i, acc := range simState.Accounts { | ||
accs[i] = acc.Address.String() | ||
} | ||
interchainqueryGenesis := types.GenesisState{ | ||
Params: types.DefaultParams(), | ||
// this line is used by starport scaffolding # simapp/module/genesisState | ||
} | ||
simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(&interchainqueryGenesis) | ||
} | ||
|
||
// ProposalContents doesn't return any content functions for governance proposals | ||
func (AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedProposalContent { | ||
return nil | ||
} | ||
|
||
// RandomizedParams creates randomized param changes for the simulator | ||
func (am AppModule) RandomizedParams(_ *rand.Rand) []simtypes.ParamChange { | ||
|
||
return []simtypes.ParamChange{} | ||
} | ||
|
||
// RegisterStoreDecoder registers a decoder | ||
func (am AppModule) RegisterStoreDecoder(_ sdk.StoreDecoderRegistry) {} | ||
|
||
// WeightedOperations returns the all the gov module operations with their respective weights. | ||
func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation { | ||
operations := make([]simtypes.WeightedOperation, 0) | ||
|
||
var weightMsgQueryExchangerate int | ||
simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgQueryExchangerate, &weightMsgQueryExchangerate, nil, | ||
func(_ *rand.Rand) { | ||
weightMsgQueryExchangerate = defaultWeightMsgQueryExchangerate | ||
}, | ||
) | ||
operations = append(operations, simulation.NewWeightedOperation( | ||
weightMsgQueryExchangerate, | ||
interchainquerysimulation.SimulateMsgQueryExchangerate(am.accountKeeper, am.bankKeeper, am.keeper), | ||
)) | ||
|
||
// this line is used by starport scaffolding # simapp/module/operation | ||
|
||
return operations | ||
} |
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,29 @@ | ||
package simulation | ||
|
||
import ( | ||
"math/rand" | ||
|
||
"github.com/Stride-Labs/stride/x/interchainquery/keeper" | ||
"github.com/Stride-Labs/stride/x/interchainquery/types" | ||
"github.com/cosmos/cosmos-sdk/baseapp" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
simtypes "github.com/cosmos/cosmos-sdk/types/simulation" | ||
) | ||
|
||
func SimulateMsgQueryExchangerate( | ||
ak types.AccountKeeper, | ||
bk types.BankKeeper, | ||
k keeper.Keeper, | ||
) simtypes.Operation { | ||
return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, | ||
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { | ||
simAccount, _ := simtypes.RandomAcc(r, accs) | ||
msg := &types.MsgQueryExchangerate{ | ||
Creator: simAccount.Address.String(), | ||
} | ||
|
||
// TODO: Handling the QueryExchangerate simulation | ||
|
||
return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "QueryExchangerate simulation not implemented"), nil, nil | ||
} | ||
} |
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,15 @@ | ||
package simulation | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
simtypes "github.com/cosmos/cosmos-sdk/types/simulation" | ||
) | ||
|
||
// FindAccount find a specific address from an account list | ||
func FindAccount(accs []simtypes.Account, address string) (simtypes.Account, bool) { | ||
creator, err := sdk.AccAddressFromBech32(address) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return simtypes.FindAccount(accs, creator) | ||
} |
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,46 @@ | ||
package types | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
) | ||
|
||
const TypeMsgQueryExchangerate = "query_exchangerate" | ||
|
||
var _ sdk.Msg = &MsgQueryExchangerate{} | ||
|
||
func NewMsgQueryExchangerate(creator string, chainID string) *MsgQueryExchangerate { | ||
return &MsgQueryExchangerate{ | ||
Creator: creator, | ||
ChainID: chainID, | ||
} | ||
} | ||
|
||
func (msg *MsgQueryExchangerate) Route() string { | ||
return RouterKey | ||
} | ||
|
||
func (msg *MsgQueryExchangerate) Type() string { | ||
return TypeMsgQueryExchangerate | ||
} | ||
|
||
func (msg *MsgQueryExchangerate) GetSigners() []sdk.AccAddress { | ||
creator, err := sdk.AccAddressFromBech32(msg.Creator) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return []sdk.AccAddress{creator} | ||
} | ||
|
||
func (msg *MsgQueryExchangerate) GetSignBytes() []byte { | ||
bz := ModuleCdc.MustMarshalJSON(msg) | ||
return sdk.MustSortJSON(bz) | ||
} | ||
|
||
func (msg *MsgQueryExchangerate) ValidateBasic() error { | ||
_, err := sdk.AccAddressFromBech32(msg.Creator) | ||
if err != nil { | ||
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) | ||
} | ||
return nil | ||
} |
40 changes: 40 additions & 0 deletions
40
x/interchainquery/types/message_query_exchangerate_test.go
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,40 @@ | ||
package types | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/Stride-Labs/stride/testutil/sample" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestMsgQueryExchangerate_ValidateBasic(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
msg MsgQueryExchangerate | ||
err error | ||
}{ | ||
{ | ||
name: "invalid address", | ||
msg: MsgQueryExchangerate{ | ||
Creator: "invalid_address", | ||
}, | ||
err: sdkerrors.ErrInvalidAddress, | ||
}, { | ||
name: "valid address", | ||
msg: MsgQueryExchangerate{ | ||
Creator: sample.AccAddress(), | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
err := tt.msg.ValidateBasic() | ||
if tt.err != nil { | ||
require.ErrorIs(t, err, tt.err) | ||
return | ||
} | ||
require.NoError(t, err) | ||
}) | ||
} | ||
} |
Oops, something went wrong.