Skip to content

Commit

Permalink
scaffold: message claim-morse-pokt --module migration --signer shanno…
Browse files Browse the repository at this point in the history
…n_dest_address morse_src_address morse_sign

ature --response balance
  • Loading branch information
bryanchriswhite committed Jan 20, 2025
1 parent c341402 commit 5a48d9f
Show file tree
Hide file tree
Showing 8 changed files with 158 additions and 1 deletion.
14 changes: 13 additions & 1 deletion proto/poktroll/migration/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ service Msg {
// parameters. The authority defaults to the x/gov module account.
rpc UpdateParams (MsgUpdateParams ) returns (MsgUpdateParamsResponse );
rpc UploadMorseState (MsgUploadMorseState) returns (MsgUploadMorseStateResponse);
rpc ClaimMorsePokt (MsgClaimMorsePokt ) returns (MsgClaimMorsePoktResponse );
}
// MsgUpdateParams is the Msg/UpdateParams request type.
message MsgUpdateParams {
Expand All @@ -42,8 +43,19 @@ message MsgUpdateParamsResponse {}
message MsgUploadMorseState {
option (cosmos.msg.v1.signer) = "authority";
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
bytes state = 2;
bytes state = 2;
}

message MsgUploadMorseStateResponse {}

message MsgClaimMorsePokt {
option (cosmos.msg.v1.signer) = "shannonDestAddress";
string shannonDestAddress = 1;
string morseSrcAddress = 2;
string morseSignature = 3;
}

message MsgClaimMorsePoktResponse {
string balance = 1;
}

18 changes: 18 additions & 0 deletions x/migration/keeper/msg_server_claim_morse_pokt.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) ClaimMorsePokt(goCtx context.Context, msg *types.MsgClaimMorsePokt) (*types.MsgClaimMorsePoktResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

// TODO: Handling the message
_ = ctx

return &types.MsgClaimMorsePoktResponse{}, nil
}
6 changes: 6 additions & 0 deletions x/migration/module/autocli.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
Short: "Send a upload-morse-state tx",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "state"},},
},
{
RpcMethod: "ClaimMorsePokt",
Use: "claim-morse-pokt [morse-src-address] [morse-signature]",
Short: "Send a claim-morse-pokt tx",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "morseSrcAddress"}, {ProtoField: "morseSignature"},},
},
// this line is used by ignite scaffolding # autocli/tx
},
},
Expand Down
23 changes: 23 additions & 0 deletions x/migration/module/simulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ const (
// TODO: Determine the simulation weight value
defaultWeightMsgUploadMorseState int = 100

opWeightMsgClaimMorsePokt = "op_weight_msg_claim_morse_pokt"
// TODO: Determine the simulation weight value
defaultWeightMsgClaimMorsePokt int = 100

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

Expand Down Expand Up @@ -61,6 +65,17 @@ func (am AppModule) WeightedOperations(simState module.SimulationState) []simtyp
migrationsimulation.SimulateMsgUploadMorseState(am.accountKeeper, am.bankKeeper, am.keeper),
))

var weightMsgClaimMorsePokt int
simState.AppParams.GetOrGenerate(opWeightMsgClaimMorsePokt, &weightMsgClaimMorsePokt, nil,
func(_ *rand.Rand) {
weightMsgClaimMorsePokt = defaultWeightMsgClaimMorsePokt
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgClaimMorsePokt,
migrationsimulation.SimulateMsgClaimMorsePokt(am.accountKeeper, am.bankKeeper, am.keeper),
))

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

return operations
Expand All @@ -77,6 +92,14 @@ func (am AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.Wei
return nil
},
),
simulation.NewWeightedProposalMsg(
opWeightMsgClaimMorsePokt,
defaultWeightMsgClaimMorsePokt,
func(r *rand.Rand, ctx sdk.Context, accs []simtypes.Account) sdk.Msg {
migrationsimulation.SimulateMsgClaimMorsePokt(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/claim_morse_pokt.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 SimulateMsgClaimMorsePokt(
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.MsgClaimMorsePokt{
ShannonDestAddress: simAccount.Address.String(),
}

// TODO: Handling the ClaimMorsePokt simulation

return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "ClaimMorsePokt simulation not implemented"), nil, nil
}
}
3 changes: 3 additions & 0 deletions x/migration/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
registry.RegisterImplementations((*sdk.Msg)(nil),
&MsgUploadMorseState{},
)
registry.RegisterImplementations((*sdk.Msg)(nil),
&MsgClaimMorsePokt{},
)
// this line is used by starport scaffolding # 3

registry.RegisterImplementations((*sdk.Msg)(nil),
Expand Down
26 changes: 26 additions & 0 deletions x/migration/types/message_claim_morse_pokt.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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 = &MsgClaimMorsePokt{}

func NewMsgClaimMorsePokt(shannonDestAddress string, morseSrcAddress string, morseSignature string) *MsgClaimMorsePokt {
return &MsgClaimMorsePokt{
ShannonDestAddress: shannonDestAddress,
MorseSrcAddress: morseSrcAddress,
MorseSignature: morseSignature,
}
}

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

40 changes: 40 additions & 0 deletions x/migration/types/message_claim_morse_pokt_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 TestMsgClaimMorsePokt_ValidateBasic(t *testing.T) {
tests := []struct {
name string
msg MsgClaimMorsePokt
err error
}{
{
name: "invalid address",
msg: MsgClaimMorsePokt{
ShannonDestAddress: "invalid_address",
},
err: sdkerrors.ErrInvalidAddress,
}, {
name: "valid address",
msg: MsgClaimMorsePokt{
ShannonDestAddress: 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 5a48d9f

Please sign in to comment.