Skip to content

Commit

Permalink
[Code Health] refactor: rename ApplicationTransfer msgs (#788)
Browse files Browse the repository at this point in the history
## Summary

- Renaming the application module `TransferApplicationStake` messages to
`TransferApplication`

## Depends on 

- #743

## Dependents

- #789

## Issue

- #657

## Type of change

Select one or more:

- [ ] New feature, functionality or library
- [ ] Bug fix
- [x] Code health or cleanup
- [ ] Documentation
- [ ] Other (specify)

## Testing

- [ ] **Documentation**: `make docusaurus_start`; only needed if you
make doc changes
- [ ] **Unit Tests**: `make go_develop_and_test`
- [ ] **LocalNet E2E Tests**: `make test_e2e`
- [ ] **DevNet E2E Tests**: Add the `devnet-test-e2e` label to the PR.

## Sanity Checklist

- [x] I have tested my changes using the available tooling
- [ ] I have commented my code
- [x] I have performed a self-review of my own code; both comments &
source code
- [ ] I create and reference any new tickets, if applicable
- [ ] I have left TODOs throughout the codebase, if applicable

---------

Co-authored-by: Daniel Olshansky <olshansky.daniel@gmail.com>
  • Loading branch information
bryanchriswhite and Olshansk authored Sep 23, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent c1e5167 commit 1cf73ca
Showing 14 changed files with 422 additions and 422 deletions.
493 changes: 246 additions & 247 deletions api/poktroll/application/tx.pulsar.go

Large diffs are not rendered by default.

40 changes: 20 additions & 20 deletions api/poktroll/application/tx_grpc.pb.go

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

2 changes: 1 addition & 1 deletion e2e/tests/stake_app_transfer.feature
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ Feature: App Stake Transfer Namespace
Then the user should be able to see standard output containing "txhash:"
And the user should be able to see standard output containing "code: 0"
And the pocketd binary should exit without error
And the user should wait for the "application" module "TransferApplicationStake" message to be submitted
And the user should wait for the "application" module "TransferApplication" message to be submitted
And the "application" for account "app3" is staked with "1000070" uPOKT
And the account balance of "app3" should be "0" uPOKT "less" than before
And the user verifies the "application" for account "app2" is not staked
6 changes: 3 additions & 3 deletions proto/poktroll/application/tx.proto
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ service Msg {
rpc UnstakeApplication (MsgUnstakeApplication) returns (MsgUnstakeApplicationResponse);
rpc DelegateToGateway (MsgDelegateToGateway) returns (MsgDelegateToGatewayResponse);
rpc UndelegateFromGateway (MsgUndelegateFromGateway) returns (MsgUndelegateFromGatewayResponse);
rpc TransferApplicationStake (MsgTransferApplicationStake) returns (MsgTransferApplicationStakeResponse);
rpc TransferApplication (MsgTransferApplication) returns (MsgTransferApplicationResponse);
}
// MsgUpdateParams is the Msg/UpdateParams request type.
message MsgUpdateParams {
@@ -83,13 +83,13 @@ message MsgUndelegateFromGateway {

message MsgUndelegateFromGatewayResponse {}

message MsgTransferApplicationStake {
message MsgTransferApplication {
option (cosmos.msg.v1.signer) = "source_address";
string source_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string destination_address = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}

message MsgTransferApplicationStakeResponse {
message MsgTransferApplicationResponse {
poktroll.application.Application application = 1;
}

10 changes: 5 additions & 5 deletions x/application/keeper/msg_server_transfer_application_stake.go
Original file line number Diff line number Diff line change
@@ -8,17 +8,17 @@ import (
"github.com/pokt-network/poktroll/x/application/types"
)

// TransferApplicationStake transfers the stake (held in escrow in the application
// TransferApplication transfers the stake (held in escrow in the application
// module account) from a source to a (new) destination application account .
func (k msgServer) TransferApplicationStake(ctx context.Context, msg *types.MsgTransferApplicationStake) (*types.MsgTransferApplicationStakeResponse, error) {
func (k msgServer) TransferApplication(ctx context.Context, msg *types.MsgTransferApplication) (*types.MsgTransferApplicationResponse, error) {
isSuccessful := false
defer telemetry.EventSuccessCounter(
"transfer_application_stake",
telemetry.DefaultCounterFn,
func() bool { return isSuccessful },
)

logger := k.Logger().With("method", "TransferApplicationStake")
logger := k.Logger().With("method", "TransferApplication")

if err := msg.ValidateBasic(); err != nil {
return nil, err
@@ -62,7 +62,7 @@ func (k msgServer) TransferApplicationStake(ctx context.Context, msg *types.MsgT

isSuccessful = true

return &types.MsgTransferApplicationStakeResponse{
Application: &dstApp,
return &types.MsgTransferApplicationResponse{
Application: &srcApp,
}, nil
}
20 changes: 10 additions & 10 deletions x/application/keeper/msg_server_transfer_application_stake_test.go
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ import (
sharedtypes "github.com/pokt-network/poktroll/x/shared/types"
)

func TestMsgServer_TransferApplicationStake_Success(t *testing.T) {
func TestMsgServer_TransferApplication_Success(t *testing.T) {
k, ctx := keepertest.ApplicationKeeper(t)
srv := appkeeper.NewMsgServerImpl(k)

@@ -52,29 +52,29 @@ func TestMsgServer_TransferApplicationStake_Success(t *testing.T) {
require.Equal(t, "svc1", srcApp.ServiceConfigs[0].ServiceId)

// Transfer the application stake from the source to the destination application address.
transferStakeMsg := apptypes.NewMsgTransferApplicationStake(srcAddr, dstAddr)
transferStakeMsg := apptypes.NewMsgTransferApplication(srcAddr, dstAddr)

transferAppStakeRes, stakeTransferErr := srv.TransferApplicationStake(ctx, transferStakeMsg)
transferAppStakeRes, stakeTransferErr := srv.TransferApplication(ctx, transferStakeMsg)
require.NoError(t, stakeTransferErr)

// Verify that the destination app was created with the correct state.
srcApp, isSrcFound = k.GetApplication(ctx, dstAddr)
require.True(t, isSrcFound)

dstApp, isDstFound := k.GetApplication(ctx, dstAddr)
require.True(t, isDstFound)
require.Equal(t, dstAddr, dstApp.Address)
require.Equal(t, expectedAppStake, dstApp.Stake)
require.Len(t, dstApp.ServiceConfigs, 1)
require.EqualValues(t, &srcApp, transferAppStakeRes.Application)

srcApp.Address = ""
dstApp.Address = ""
require.EqualValues(t, srcApp, dstApp)
require.EqualValues(t, &dstApp, transferAppStakeRes.Application)

// Verify that the source app was unstaked.
srcApp, isSrcFound = k.GetApplication(ctx, srcAddr)
require.False(t, isSrcFound)
}

func TestMsgServer_TransferApplicationStake_Error_DestinationExists(t *testing.T) {
func TestMsgServer_TransferApplication_Error_DestinationExists(t *testing.T) {
k, ctx := keepertest.ApplicationKeeper(t)
srv := appkeeper.NewMsgServerImpl(k)

@@ -120,9 +120,9 @@ func TestMsgServer_TransferApplicationStake_Error_DestinationExists(t *testing.T
require.NoError(t, err)

// Attempt to transfer the source application stake to the destination.
transferStakeMsg := apptypes.NewMsgTransferApplicationStake(srcAddr, dstAddr)
transferStakeMsg := apptypes.NewMsgTransferApplication(srcAddr, dstAddr)

_, err = srv.TransferApplicationStake(ctx, transferStakeMsg)
_, err = srv.TransferApplication(ctx, transferStakeMsg)
require.ErrorContains(t, err, apptypes.ErrAppDuplicateAddress.Wrapf("destination application (%q) exists", dstAddr).Error())

// Verify that the original application still exists.
4 changes: 2 additions & 2 deletions x/application/module/autocli.go
Original file line number Diff line number Diff line change
@@ -98,9 +98,9 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
// PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "gateway_address"}},
// },
{
RpcMethod: "TransferApplicationStake",
RpcMethod: "TransferApplication",
Use: "transfer [source app address] [destination app address]",
Short: "Transfer the application stake from [source app address] to [destination app address] and unstake the source application",
Short: "Transfer the application from [source app address] to [destination app address] and remove the source application",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "source_address"}, {ProtoField: "destination_address"}},
},
// this line is used by ignite scaffolding # autocli/tx
20 changes: 10 additions & 10 deletions x/application/module/simulation.go
Original file line number Diff line number Diff line change
@@ -39,9 +39,9 @@ const (
// TODO: Determine the simulation weight value
defaultWeightMsgUndelegateFromGateway int = 100

opWeightMsgTransferApplicationStake = "op_weight_msg_transfer_application_stake"
opWeightMsgTransferApplication = "op_weight_msg_transfer_application"
// TODO: Determine the simulation weight value
defaultWeightMsgTransferApplicationStake int = 100
defaultWeightMsgTransferApplication int = 100

// this line is used by starport scaffolding # simapp/module/const
)
@@ -115,15 +115,15 @@ func (am AppModule) WeightedOperations(simState module.SimulationState) []simtyp
applicationsimulation.SimulateMsgUndelegateFromGateway(am.accountKeeper, am.bankKeeper, am.applicationKeeper),
))

var weightMsgTransferApplicationStake int
simState.AppParams.GetOrGenerate(opWeightMsgTransferApplicationStake, &weightMsgTransferApplicationStake, nil,
var weightMsgTransferApplication int
simState.AppParams.GetOrGenerate(opWeightMsgTransferApplication, &weightMsgTransferApplication, nil,
func(_ *rand.Rand) {
weightMsgTransferApplicationStake = defaultWeightMsgTransferApplicationStake
weightMsgTransferApplication = defaultWeightMsgTransferApplication
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgTransferApplicationStake,
applicationsimulation.SimulateMsgTransferApplicationStake(am.accountKeeper, am.bankKeeper, am.applicationKeeper),
weightMsgTransferApplication,
applicationsimulation.SimulateMsgTransferApplication(am.accountKeeper, am.bankKeeper, am.applicationKeeper),
))

// this line is used by starport scaffolding # simapp/module/operation
@@ -167,10 +167,10 @@ func (am AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.Wei
},
),
simulation.NewWeightedProposalMsg(
opWeightMsgTransferApplicationStake,
defaultWeightMsgTransferApplicationStake,
opWeightMsgTransferApplication,
defaultWeightMsgTransferApplication,
func(r *rand.Rand, ctx sdk.Context, accs []simtypes.Account) sdk.Msg {
applicationsimulation.SimulateMsgTransferApplicationStake(am.accountKeeper, am.bankKeeper, am.applicationKeeper)
applicationsimulation.SimulateMsgTransferApplication(am.accountKeeper, am.bankKeeper, am.applicationKeeper)
return nil
},
),
8 changes: 4 additions & 4 deletions x/application/simulation/transfer_application_stake.go
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ import (
"github.com/pokt-network/poktroll/x/application/types"
)

func SimulateMsgTransferApplicationStake(
func SimulateMsgTransferApplication(
ak types.AccountKeeper,
bk types.BankKeeper,
k keeper.Keeper,
@@ -20,13 +20,13 @@ func SimulateMsgTransferApplicationStake(
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
simSrcAppAccount, _ := simtypes.RandomAcc(r, accs)
simDstAppAccount, _ := simtypes.RandomAcc(r, accs)
msg := &types.MsgTransferApplicationStake{
msg := &types.MsgTransferApplication{
SourceAddress: simSrcAppAccount.Address.String(),
DestinationAddress: simDstAppAccount.Address.String(),
}

// TODO: Handling the TransferApplicationStake simulation
// TODO: Handling the TransferApplication simulation

return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "TransferApplicationStake simulation not implemented"), nil, nil
return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "TransferApplication simulation not implemented"), nil, nil
}
}
2 changes: 1 addition & 1 deletion x/application/types/codec.go
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
&MsgUndelegateFromGateway{},
)
registry.RegisterImplementations((*sdk.Msg)(nil),
&MsgTransferApplicationStake{},
&MsgTransferApplication{},
)
// this line is used by starport scaffolding # 3

8 changes: 4 additions & 4 deletions x/application/types/message_transfer_application_stake.go
Original file line number Diff line number Diff line change
@@ -4,16 +4,16 @@ import (
cosmostypes "github.com/cosmos/cosmos-sdk/types"
)

var _ cosmostypes.Msg = (*MsgTransferApplicationStake)(nil)
var _ cosmostypes.Msg = (*MsgTransferApplication)(nil)

func NewMsgTransferApplicationStake(srcAddr string, dstAddr string) *MsgTransferApplicationStake {
return &MsgTransferApplicationStake{
func NewMsgTransferApplication(srcAddr string, dstAddr string) *MsgTransferApplication {
return &MsgTransferApplication{
SourceAddress: srcAddr,
DestinationAddress: dstAddr,
}
}

func (msg *MsgTransferApplicationStake) ValidateBasic() error {
func (msg *MsgTransferApplication) ValidateBasic() error {
if msg.GetSourceAddress() == "" {
return ErrAppInvalidAddress.Wrap("empty source application address")
}
12 changes: 6 additions & 6 deletions x/application/types/message_transfer_application_stake_test.go
Original file line number Diff line number Diff line change
@@ -9,41 +9,41 @@ import (
"github.com/pokt-network/poktroll/testutil/sample"
)

func TestMsgTransferApplicationStake_ValidateBasic(t *testing.T) {
func TestMsgTransferApplication_ValidateBasic(t *testing.T) {
dupAddr := sample.AccAddress()

tests := []struct {
name string
msg MsgTransferApplicationStake
msg MsgTransferApplication
err error
}{
{
name: "invalid duplicate source address",
msg: MsgTransferApplicationStake{
msg: MsgTransferApplication{
SourceAddress: dupAddr,
DestinationAddress: dupAddr,
},
err: ErrAppDuplicateAddress,
},
{
name: "invalid bech32 source address",
msg: MsgTransferApplicationStake{
msg: MsgTransferApplication{
SourceAddress: "invalid_address",
DestinationAddress: sample.AccAddress(),
},
err: ErrAppInvalidAddress,
},
{
name: "invalid bech32 destination address",
msg: MsgTransferApplicationStake{
msg: MsgTransferApplication{
SourceAddress: sample.AccAddress(),
DestinationAddress: "invalid_address",
},
err: ErrAppInvalidAddress,
},
{
name: "valid source and destination addresses",
msg: MsgTransferApplicationStake{
msg: MsgTransferApplication{
SourceAddress: sample.AccAddress(),
DestinationAddress: sample.AccAddress(),
},
Loading

0 comments on commit 1cf73ca

Please sign in to comment.