Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Morse->Shannon Migration] Scaffold MsgClaimMorsePOKT #1036

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,215 changes: 1,172 additions & 43 deletions api/poktroll/migration/tx.pulsar.go

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions api/poktroll/migration/tx_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions proto/poktroll/migration/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package poktroll.migration;
import "amino/amino.proto";
import "cosmos/msg/v1/msg.proto";
import "cosmos_proto/cosmos.proto";
import "cosmos/base/v1beta1/coin.proto";
import "gogoproto/gogo.proto";
import "poktroll/migration/params.proto";
import "poktroll/migration/types.proto";
Expand All @@ -20,6 +21,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 @@ -43,6 +45,7 @@ message MsgUpdateParamsResponse {}
// for subsequent migration operations on Shannon.
message MsgUploadMorseState {
option (cosmos.msg.v1.signer) = "authority";

string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
MorseAccountState state = 2 [(gogoproto.nullable) = false];
}
Expand All @@ -52,3 +55,16 @@ message MsgUploadMorseStateResponse {
uint64 num_accounts = 2 [(gogoproto.jsontag) = "num_accounts"];
}

// MsgClaimMorsePokt is used to self-claim owned POKT tokens from the "Morse migration" state.
message MsgClaimMorsePokt {
option (cosmos.msg.v1.signer) = "shannon_dest_address";

string shannon_dest_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string morse_src_address = 2;
bytes morse_signature = 3;
}

message MsgClaimMorsePoktResponse {
cosmos.base.v1beta1.Coin 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"

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/pokt-network/poktroll/x/migration/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 @@ -35,6 +35,12 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "state"}},
Skip: true, // skipped because authority gated
},
{
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
}
}
30 changes: 30 additions & 0 deletions x/migration/simulation/claim_morse_pokt.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package simulation

import (
"math/rand"

"github.com/cosmos/cosmos-sdk/baseapp"
sdk "github.com/cosmos/cosmos-sdk/types"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"

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

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 @@ -11,6 +11,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
25 changes: 25 additions & 0 deletions x/migration/types/message_claim_morse_pokt.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 = &MsgClaimMorsePokt{}

func NewMsgClaimMorsePokt(shannonDestAddress string, morseSrcAddress string, morseSignature []byte) *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
}
41 changes: 41 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,41 @@
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)
})
}
}
Loading
Loading