Skip to content

Commit

Permalink
scaffold: message upload-morse-state --module migration --signer auth…
Browse files Browse the repository at this point in the history
…ority state
  • Loading branch information
bryanchriswhite committed Jan 21, 2025
1 parent 6d9c3d9 commit 34ea238
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 16 deletions.
31 changes: 19 additions & 12 deletions proto/poktroll/migration/tx.proto
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
syntax = "proto3";

package poktroll.migration;

import "amino/amino.proto";
Expand All @@ -13,29 +14,35 @@ option (gogoproto.stable_marshaler_all) = true;
// Msg defines the Msg service.
service Msg {
option (cosmos.msg.v1.service) = true;

// UpdateParams defines a (governance) operation for updating the module
// parameters. The authority defaults to the x/gov module account.
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);
rpc UpdateParams (MsgUpdateParams ) returns (MsgUpdateParamsResponse );
rpc UploadMorseState (MsgUploadMorseState) returns (MsgUploadMorseStateResponse);
}

// MsgUpdateParams is the Msg/UpdateParams request type.
message MsgUpdateParams {
option (cosmos.msg.v1.signer) = "authority";
option (amino.name) = "poktroll/x/migration/MsgUpdateParams";

option (cosmos.msg.v1.signer) = "authority";
option (amino.name) = "poktroll/x/migration/MsgUpdateParams";
// authority is the address that controls the module (defaults to x/gov unless overwritten).
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// params defines the module parameters to update.
//

// NOTE: All parameters must be supplied.
Params params = 2 [
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true
];
Params params = 2 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
}

// MsgUpdateParamsResponse defines the response structure for executing a
// MsgUpdateParams message.
message MsgUpdateParamsResponse {}
message MsgUpdateParamsResponse {}

message MsgUploadMorseState {
option (cosmos.msg.v1.signer) = "authority";
string authority = 1;
string state = 2;
}

message MsgUploadMorseStateResponse {}

18 changes: 18 additions & 0 deletions x/migration/keeper/msg_server_upload_morse_state.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package keeper

import (
"context"

"github.com/pokt-network/poktroll/x/migration/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)


func (k msgServer) UploadMorseState(goCtx context.Context, msg *types.MsgUploadMorseState) (*types.MsgUploadMorseStateResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

// TODO: Handling the message
_ = ctx

return &types.MsgUploadMorseStateResponse{}, nil
}
8 changes: 7 additions & 1 deletion x/migration/module/autocli.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
RpcMethod: "UpdateParams",
Skip: true, // skipped because authority gated
},
// this line is used by ignite scaffolding # autocli/tx
{
RpcMethod: "UploadMorseState",
Use: "upload-morse-state [state]",
Short: "Send a upload-morse-state tx",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "state"},},
},
// this line is used by ignite scaffolding # autocli/tx
},
},
}
Expand Down
27 changes: 25 additions & 2 deletions x/migration/module/simulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ var (
)

const (
// this line is used by starport scaffolding # simapp/module/const
opWeightMsgUploadMorseState = "op_weight_msg_upload_morse_state"
// TODO: Determine the simulation weight value
defaultWeightMsgUploadMorseState int = 100

// this line is used by starport scaffolding # simapp/module/const
)

// GenerateGenesisState creates a randomized GenState of the module.
Expand All @@ -46,6 +50,17 @@ func (am AppModule) RegisterStoreDecoder(_ simtypes.StoreDecoderRegistry) {}
func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation {
operations := make([]simtypes.WeightedOperation, 0)

var weightMsgUploadMorseState int
simState.AppParams.GetOrGenerate(opWeightMsgUploadMorseState, &weightMsgUploadMorseState, nil,
func(_ *rand.Rand) {
weightMsgUploadMorseState = defaultWeightMsgUploadMorseState
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgUploadMorseState,
migrationsimulation.SimulateMsgUploadMorseState(am.accountKeeper, am.bankKeeper, am.keeper),
))

// this line is used by starport scaffolding # simapp/module/operation

return operations
Expand All @@ -54,6 +69,14 @@ func (am AppModule) WeightedOperations(simState module.SimulationState) []simtyp
// ProposalMsgs returns msgs used for governance proposals for simulations.
func (am AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.WeightedProposalMsg {
return []simtypes.WeightedProposalMsg{
// this line is used by starport scaffolding # simapp/module/OpMsg
simulation.NewWeightedProposalMsg(
opWeightMsgUploadMorseState,
defaultWeightMsgUploadMorseState,
func(r *rand.Rand, ctx sdk.Context, accs []simtypes.Account) sdk.Msg {
migrationsimulation.SimulateMsgUploadMorseState(am.accountKeeper, am.bankKeeper, am.keeper)
return nil
},
),
// this line is used by starport scaffolding # simapp/module/OpMsg
}
}
29 changes: 29 additions & 0 deletions x/migration/simulation/upload_morse_state.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package simulation

import (
"math/rand"

"github.com/pokt-network/poktroll/x/migration/keeper"
"github.com/pokt-network/poktroll/x/migration/types"
"github.com/cosmos/cosmos-sdk/baseapp"
sdk "github.com/cosmos/cosmos-sdk/types"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
)

func SimulateMsgUploadMorseState(
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.MsgUploadMorseState{
Authority: simAccount.Address.String(),
}

// TODO: Handling the UploadMorseState simulation

return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "UploadMorseState simulation not implemented"), nil, nil
}
}
5 changes: 4 additions & 1 deletion x/migration/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import (
)

func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
// this line is used by starport scaffolding # 3
registry.RegisterImplementations((*sdk.Msg)(nil),
&MsgUploadMorseState{},
)
// this line is used by starport scaffolding # 3

registry.RegisterImplementations((*sdk.Msg)(nil),
&MsgUpdateParams{},
Expand Down
25 changes: 25 additions & 0 deletions x/migration/types/message_upload_morse_state.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package types

import (
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

var _ sdk.Msg = &MsgUploadMorseState{}

func NewMsgUploadMorseState(authority string, state string) *MsgUploadMorseState {
return &MsgUploadMorseState{
Authority: authority,
State: state,
}
}

func (msg *MsgUploadMorseState) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Authority)
if err != nil {
return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid authority address (%s)", err)
}
return nil
}

40 changes: 40 additions & 0 deletions x/migration/types/message_upload_morse_state_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package types

import (
"testing"

sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/stretchr/testify/require"
"github.com/pokt-network/poktroll/testutil/sample"
)

func TestMsgUploadMorseState_ValidateBasic(t *testing.T) {
tests := []struct {
name string
msg MsgUploadMorseState
err error
}{
{
name: "invalid address",
msg: MsgUploadMorseState{
Authority: "invalid_address",
},
err: sdkerrors.ErrInvalidAddress,
}, {
name: "valid address",
msg: MsgUploadMorseState{
Authority: 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)
})
}
}

0 comments on commit 34ea238

Please sign in to comment.