diff --git a/x/application/keeper/msg_server_delegate_to_gateway_test.go b/x/application/keeper/msg_server_delegate_to_gateway_test.go index 722fc8e39..a0f8ec98b 100644 --- a/x/application/keeper/msg_server_delegate_to_gateway_test.go +++ b/x/application/keeper/msg_server_delegate_to_gateway_test.go @@ -4,14 +4,13 @@ import ( "fmt" "testing" - "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" keepertest "github.com/pokt-network/poktroll/testutil/keeper" "github.com/pokt-network/poktroll/testutil/sample" "github.com/pokt-network/poktroll/x/application/keeper" - "github.com/pokt-network/poktroll/x/application/types" + apptypes "github.com/pokt-network/poktroll/x/application/types" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" ) @@ -28,9 +27,9 @@ func TestMsgServer_DelegateToGateway_SuccessfullyDelegate(t *testing.T) { keepertest.AddGatewayToStakedGatewayMap(t, gatewayAddr2) // Prepare the application - stakeMsg := &types.MsgStakeApplication{ + stakeMsg := &apptypes.MsgStakeApplication{ Address: appAddr, - Stake: &sdk.Coin{Denom: "upokt", Amount: math.NewInt(100)}, + Stake: &apptypes.DefaultMinStake, Services: []*sharedtypes.ApplicationServiceConfig{ { ServiceId: "svc1", @@ -45,7 +44,7 @@ func TestMsgServer_DelegateToGateway_SuccessfullyDelegate(t *testing.T) { require.True(t, isAppFound) // Prepare the delegation message - delegateMsg := &types.MsgDelegateToGateway{ + delegateMsg := &apptypes.MsgDelegateToGateway{ AppAddress: appAddr, GatewayAddress: gatewayAddr1, } @@ -72,7 +71,7 @@ func TestMsgServer_DelegateToGateway_SuccessfullyDelegate(t *testing.T) { require.Equal(t, gatewayAddr1, foundApp.DelegateeGatewayAddresses[0]) // Prepare a second delegation message - delegateMsg2 := &types.MsgDelegateToGateway{ + delegateMsg2 := &apptypes.MsgDelegateToGateway{ AppAddress: appAddr, GatewayAddress: gatewayAddr2, } @@ -108,9 +107,9 @@ func TestMsgServer_DelegateToGateway_FailDuplicate(t *testing.T) { keepertest.AddGatewayToStakedGatewayMap(t, gatewayAddr) // Prepare the application - stakeMsg := &types.MsgStakeApplication{ + stakeMsg := &apptypes.MsgStakeApplication{ Address: appAddr, - Stake: &sdk.Coin{Denom: "upokt", Amount: math.NewInt(100)}, + Stake: &apptypes.DefaultMinStake, Services: []*sharedtypes.ApplicationServiceConfig{ { ServiceId: "svc1", @@ -125,7 +124,7 @@ func TestMsgServer_DelegateToGateway_FailDuplicate(t *testing.T) { require.True(t, isAppFound) // Prepare the delegation message - delegateMsg := &types.MsgDelegateToGateway{ + delegateMsg := &apptypes.MsgDelegateToGateway{ AppAddress: appAddr, GatewayAddress: gatewayAddr, } @@ -152,14 +151,14 @@ func TestMsgServer_DelegateToGateway_FailDuplicate(t *testing.T) { require.Equal(t, gatewayAddr, foundApp.DelegateeGatewayAddresses[0]) // Prepare a second delegation message - delegateMsg2 := &types.MsgDelegateToGateway{ + delegateMsg2 := &apptypes.MsgDelegateToGateway{ AppAddress: appAddr, GatewayAddress: gatewayAddr, } // Attempt to delegate the application to the gateway again _, err = srv.DelegateToGateway(ctx, delegateMsg2) - require.ErrorIs(t, err, types.ErrAppAlreadyDelegated) + require.ErrorIs(t, err, apptypes.ErrAppAlreadyDelegated) events = sdkCtx.EventManager().Events() require.Equal(t, 1, len(events)) foundApp, isAppFound = k.GetApplication(ctx, appAddr) @@ -177,9 +176,9 @@ func TestMsgServer_DelegateToGateway_FailGatewayNotStaked(t *testing.T) { gatewayAddr := sample.AccAddress() // Prepare the application - stakeMsg := &types.MsgStakeApplication{ + stakeMsg := &apptypes.MsgStakeApplication{ Address: appAddr, - Stake: &sdk.Coin{Denom: "upokt", Amount: math.NewInt(100)}, + Stake: &apptypes.DefaultMinStake, Services: []*sharedtypes.ApplicationServiceConfig{ { ServiceId: "svc1", @@ -194,14 +193,14 @@ func TestMsgServer_DelegateToGateway_FailGatewayNotStaked(t *testing.T) { require.True(t, isAppFound) // Prepare the delegation message - delegateMsg := &types.MsgDelegateToGateway{ + delegateMsg := &apptypes.MsgDelegateToGateway{ AppAddress: appAddr, GatewayAddress: gatewayAddr, } // Attempt to delegate the application to the unstaked gateway _, err = srv.DelegateToGateway(ctx, delegateMsg) - require.ErrorIs(t, err, types.ErrAppGatewayNotFound) + require.ErrorIs(t, err, apptypes.ErrAppGatewayNotFound) foundApp, isAppFound := k.GetApplication(ctx, appAddr) require.True(t, isAppFound) require.Equal(t, 0, len(foundApp.DelegateeGatewayAddresses)) @@ -215,9 +214,9 @@ func TestMsgServer_DelegateToGateway_FailMaxReached(t *testing.T) { appAddr := sample.AccAddress() // Prepare the application - stakeMsg := &types.MsgStakeApplication{ + stakeMsg := &apptypes.MsgStakeApplication{ Address: appAddr, - Stake: &sdk.Coin{Denom: "upokt", Amount: math.NewInt(100)}, + Stake: &apptypes.DefaultMinStake, Services: []*sharedtypes.ApplicationServiceConfig{ { ServiceId: "svc1", @@ -240,7 +239,7 @@ func TestMsgServer_DelegateToGateway_FailMaxReached(t *testing.T) { gatewayAddresses[i] = gatewayAddr // Mock the gateway being staked via the staked gateway map keepertest.AddGatewayToStakedGatewayMap(t, gatewayAddr) - delegateMsg := &types.MsgDelegateToGateway{ + delegateMsg := &apptypes.MsgDelegateToGateway{ AppAddress: appAddr, GatewayAddress: gatewayAddr, } @@ -270,14 +269,14 @@ func TestMsgServer_DelegateToGateway_FailMaxReached(t *testing.T) { keepertest.AddGatewayToStakedGatewayMap(t, gatewayAddr) // Prepare the delegation message - delegateMsg := &types.MsgDelegateToGateway{ + delegateMsg := &apptypes.MsgDelegateToGateway{ AppAddress: appAddr, GatewayAddress: gatewayAddr, } // Attempt to delegate the application when the max is already reached _, err = srv.DelegateToGateway(ctx, delegateMsg) - require.ErrorIs(t, err, types.ErrAppMaxDelegatedGateways) + require.ErrorIs(t, err, apptypes.ErrAppMaxDelegatedGateways) events = sdkCtx.EventManager().Events() require.Equal(t, int(maxDelegatedParam), len(events)) foundApp, isStakedAppFound := k.GetApplication(ctx, appAddr) diff --git a/x/application/keeper/msg_server_stake_application.go b/x/application/keeper/msg_server_stake_application.go index a5a778da7..f9e9e65db 100644 --- a/x/application/keeper/msg_server_stake_application.go +++ b/x/application/keeper/msg_server_stake_application.go @@ -5,6 +5,8 @@ import ( "fmt" sdk "github.com/cosmos/cosmos-sdk/types" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" "github.com/pokt-network/poktroll/telemetry" "github.com/pokt-network/poktroll/x/application/types" @@ -23,7 +25,7 @@ func (k msgServer) StakeApplication(ctx context.Context, msg *types.MsgStakeAppl if err := msg.ValidateBasic(); err != nil { logger.Error(fmt.Sprintf("invalid MsgStakeApplication: %v", err)) - return nil, err + return nil, status.Error(codes.InvalidArgument, err.Error()) } // Check if the application already exists or not @@ -38,13 +40,13 @@ func (k msgServer) StakeApplication(ctx context.Context, msg *types.MsgStakeAppl logger.Info(fmt.Sprintf("Application found. About to try and update application for address %q", msg.Address)) currAppStake := *foundApp.Stake if err = k.updateApplication(ctx, &foundApp, msg); err != nil { - logger.Error(fmt.Sprintf("could not update application for address %q due to error %v", msg.Address, err)) - return nil, err + logger.Info(fmt.Sprintf("could not update application for address %q due to error %v", msg.Address, err)) + return nil, status.Error(codes.InvalidArgument, err.Error()) } coinsToEscrow, err = (*msg.Stake).SafeSub(currAppStake) if err != nil { - logger.Error(fmt.Sprintf("could not calculate coins to escrow due to error %v", err)) - return nil, err + logger.Info(fmt.Sprintf("could not calculate coins to escrow due to error %v", err)) + return nil, status.Error(codes.InvalidArgument, err.Error()) } logger.Info(fmt.Sprintf("Application is going to escrow an additional %+v coins", coinsToEscrow)) @@ -52,24 +54,40 @@ func (k msgServer) StakeApplication(ctx context.Context, msg *types.MsgStakeAppl foundApp.UnstakeSessionEndHeight = types.ApplicationNotUnstaking } - // Must always stake or upstake (> 0 delta) + // MUST ALWAYS stake or upstake (> 0 delta) if coinsToEscrow.IsZero() { logger.Warn(fmt.Sprintf("Application %q must escrow more than 0 additional coins", msg.Address)) - return nil, types.ErrAppInvalidStake.Wrapf("application %q must escrow more than 0 additional coins", msg.Address) + return nil, status.Error( + codes.InvalidArgument, + types.ErrAppInvalidStake.Wrapf( + "application %q must escrow more than 0 additional coins", + msg.Address, + ).Error()) + } + + // MUST ALWAYS have at least minimum stake. + minStake := k.GetParams(ctx).MinStake + if msg.Stake.Amount.LT(minStake.Amount) { + errFmt := "application %q must stake at least %s" + logger.Info(fmt.Sprintf(errFmt, msg.Address, minStake)) + return nil, status.Error( + codes.InvalidArgument, + types.ErrAppInvalidStake.Wrapf(errFmt, msg.Address, minStake).Error(), + ) } // Retrieve the address of the application appAddress, err := sdk.AccAddressFromBech32(msg.Address) if err != nil { - logger.Error(fmt.Sprintf("could not parse address %q", msg.Address)) - return nil, err + logger.Info(fmt.Sprintf("could not parse address %q", msg.Address)) + return nil, status.Error(codes.InvalidArgument, err.Error()) } // Send the coins from the application to the staked application pool err = k.bankKeeper.SendCoinsFromAccountToModule(ctx, appAddress, types.ModuleName, []sdk.Coin{coinsToEscrow}) if err != nil { logger.Error(fmt.Sprintf("could not send %v coins from %q to %q module account due to %v", coinsToEscrow, appAddress, types.ModuleName, err)) - return nil, err + return nil, status.Error(codes.Internal, err.Error()) } logger.Info(fmt.Sprintf("Successfully escrowed %v coins from %q to %q module account", coinsToEscrow, appAddress, types.ModuleName)) diff --git a/x/application/keeper/msg_server_stake_application_test.go b/x/application/keeper/msg_server_stake_application_test.go index 81049bc59..6ed4316ff 100644 --- a/x/application/keeper/msg_server_stake_application_test.go +++ b/x/application/keeper/msg_server_stake_application_test.go @@ -4,13 +4,14 @@ import ( "testing" "cosmossdk.io/math" - sdk "github.com/cosmos/cosmos-sdk/types" + cosmostypes "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" + "github.com/pokt-network/poktroll/app/volatile" keepertest "github.com/pokt-network/poktroll/testutil/keeper" "github.com/pokt-network/poktroll/testutil/sample" "github.com/pokt-network/poktroll/x/application/keeper" - "github.com/pokt-network/poktroll/x/application/types" + apptypes "github.com/pokt-network/poktroll/x/application/types" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" ) @@ -26,9 +27,10 @@ func TestMsgServer_StakeApplication_SuccessfulCreateAndUpdate(t *testing.T) { require.False(t, isAppFound) // Prepare the application - stakeMsg := &types.MsgStakeApplication{ + initialStake := apptypes.DefaultMinStake + stakeMsg := &apptypes.MsgStakeApplication{ Address: appAddr, - Stake: &sdk.Coin{Denom: "upokt", Amount: math.NewInt(100)}, + Stake: &initialStake, Services: []*sharedtypes.ApplicationServiceConfig{ {ServiceId: "svc1"}, }, @@ -42,14 +44,19 @@ func TestMsgServer_StakeApplication_SuccessfulCreateAndUpdate(t *testing.T) { foundApp, isAppFound := k.GetApplication(ctx, appAddr) require.True(t, isAppFound) require.Equal(t, appAddr, foundApp.Address) - require.Equal(t, int64(100), foundApp.Stake.Amount.Int64()) + require.Truef(t, + initialStake.Amount.Equal(foundApp.Stake.Amount), + "expected %d, got %d", + initialStake.Amount.Int64(), foundApp.Stake.Amount.Int64(), + ) require.Len(t, foundApp.ServiceConfigs, 1) require.Equal(t, "svc1", foundApp.ServiceConfigs[0].ServiceId) // Prepare an updated application with a higher stake and another service - updateStakeMsg := &types.MsgStakeApplication{ + upStake := initialStake.AddAmount(math.NewInt(100)) + updateStakeMsg := &apptypes.MsgStakeApplication{ Address: appAddr, - Stake: &sdk.Coin{Denom: "upokt", Amount: math.NewInt(200)}, + Stake: &upStake, Services: []*sharedtypes.ApplicationServiceConfig{ {ServiceId: "svc1"}, {ServiceId: "svc2"}, @@ -61,7 +68,11 @@ func TestMsgServer_StakeApplication_SuccessfulCreateAndUpdate(t *testing.T) { require.NoError(t, err) foundApp, isAppFound = k.GetApplication(ctx, appAddr) require.True(t, isAppFound) - require.Equal(t, int64(200), foundApp.Stake.Amount.Int64()) + require.Truef(t, + upStake.Amount.Equal(foundApp.Stake.Amount), + "expected %d, got %d", + upStake.Amount.Int64(), foundApp.Stake.Amount.Int64(), + ) require.Len(t, foundApp.ServiceConfigs, 2) require.Equal(t, "svc1", foundApp.ServiceConfigs[0].ServiceId) require.Equal(t, "svc2", foundApp.ServiceConfigs[1].ServiceId) @@ -74,9 +85,10 @@ func TestMsgServer_StakeApplication_FailRestakingDueToInvalidServices(t *testing appAddr := sample.AccAddress() // Prepare the application stake message - stakeMsg := &types.MsgStakeApplication{ + initialStake := apptypes.DefaultMinStake + stakeMsg := &apptypes.MsgStakeApplication{ Address: appAddr, - Stake: &sdk.Coin{Denom: "upokt", Amount: math.NewInt(100)}, + Stake: &initialStake, Services: []*sharedtypes.ApplicationServiceConfig{ {ServiceId: "svc1"}, }, @@ -87,9 +99,10 @@ func TestMsgServer_StakeApplication_FailRestakingDueToInvalidServices(t *testing require.NoError(t, err) // Prepare the application stake message without any services - updateStakeMsg := &types.MsgStakeApplication{ + upStake := initialStake.AddAmount(math.NewInt(100)) + updateStakeMsg := &apptypes.MsgStakeApplication{ Address: appAddr, - Stake: &sdk.Coin{Denom: "upokt", Amount: math.NewInt(100)}, + Stake: &upStake, Services: []*sharedtypes.ApplicationServiceConfig{}, } @@ -105,9 +118,9 @@ func TestMsgServer_StakeApplication_FailRestakingDueToInvalidServices(t *testing require.Equal(t, "svc1", foundApp.ServiceConfigs[0].ServiceId) // Prepare the application stake message with an invalid service ID - updateStakeMsg = &types.MsgStakeApplication{ + updateStakeMsg = &apptypes.MsgStakeApplication{ Address: appAddr, - Stake: &sdk.Coin{Denom: "upokt", Amount: math.NewInt(100)}, + Stake: &upStake, Services: []*sharedtypes.ApplicationServiceConfig{ {ServiceId: "svc1 INVALID ! & *"}, }, @@ -130,10 +143,11 @@ func TestMsgServer_StakeApplication_FailLoweringStake(t *testing.T) { srv := keeper.NewMsgServerImpl(k) // Prepare the application + initialStake := apptypes.DefaultMinStake appAddr := sample.AccAddress() - stakeMsg := &types.MsgStakeApplication{ + stakeMsg := &apptypes.MsgStakeApplication{ Address: appAddr, - Stake: &sdk.Coin{Denom: "upokt", Amount: math.NewInt(100)}, + Stake: &initialStake, Services: []*sharedtypes.ApplicationServiceConfig{ {ServiceId: "svc1"}, }, @@ -146,9 +160,10 @@ func TestMsgServer_StakeApplication_FailLoweringStake(t *testing.T) { require.True(t, isAppFound) // Prepare an updated application with a lower stake - updateMsg := &types.MsgStakeApplication{ + downStake := initialStake.SubAmount(math.NewInt(1000)) + updateMsg := &apptypes.MsgStakeApplication{ Address: appAddr, - Stake: &sdk.Coin{Denom: "upokt", Amount: math.NewInt(50)}, + Stake: &downStake, Services: []*sharedtypes.ApplicationServiceConfig{ {ServiceId: "svc1"}, }, @@ -161,5 +176,40 @@ func TestMsgServer_StakeApplication_FailLoweringStake(t *testing.T) { // Verify that the application stake is unchanged foundApp, isAppFound := k.GetApplication(ctx, appAddr) require.True(t, isAppFound) - require.Equal(t, int64(100), foundApp.Stake.Amount.Int64()) + require.Truef(t, + initialStake.Amount.Equal(foundApp.Stake.Amount), + "expected %d, got %d", + initialStake.Amount.Int64(), foundApp.Stake.Amount.Int64(), + ) +} + +func TestMsgServer_StakeApplication_FailBelowMinStake(t *testing.T) { + k, ctx := keepertest.ApplicationKeeper(t) + srv := keeper.NewMsgServerImpl(k) + + addr := sample.AccAddress() + appStake := cosmostypes.NewInt64Coin(volatile.DenomuPOKT, 100) + minStake := appStake.AddAmount(math.NewInt(1)) + expectedErr := apptypes.ErrAppInvalidStake.Wrapf("application %q must stake at least %s", addr, minStake) + + // Set the minimum stake to be greater than the application stake. + params := k.GetParams(ctx) + params.MinStake = &minStake + err := k.SetParams(ctx, params) + require.NoError(t, err) + + // Prepare the application. + stakeMsg := &apptypes.MsgStakeApplication{ + Address: addr, + Stake: &appStake, + Services: []*sharedtypes.ApplicationServiceConfig{ + {ServiceId: "svc1"}, + }, + } + + // Attempt to stake the application & verify that the application does NOT exist. + _, err = srv.StakeApplication(ctx, stakeMsg) + require.ErrorContains(t, err, expectedErr.Error()) + _, isGatewayFound := k.GetApplication(ctx, addr) + require.False(t, isGatewayFound) } diff --git a/x/application/keeper/msg_server_transfer_application_stake_test.go b/x/application/keeper/msg_server_transfer_application_stake_test.go index b3b47bf3b..e64c28759 100644 --- a/x/application/keeper/msg_server_transfer_application_stake_test.go +++ b/x/application/keeper/msg_server_transfer_application_stake_test.go @@ -3,8 +3,6 @@ package keeper_test import ( "testing" - "cosmossdk.io/math" - cosmostypes "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" keepertest "github.com/pokt-network/poktroll/testutil/keeper" @@ -26,7 +24,7 @@ func TestMsgServer_TransferApplication_Success(t *testing.T) { _, isSrcFound := k.GetApplication(ctx, srcAddr) require.False(t, isSrcFound) - expectedAppStake := &cosmostypes.Coin{Denom: "upokt", Amount: math.NewInt(100)} + expectedAppStake := &apptypes.DefaultMinStake // Prepare the application. stakeMsg := &apptypes.MsgStakeApplication{ @@ -89,7 +87,7 @@ func TestMsgServer_TransferApplication_Error_DestinationExists(t *testing.T) { _, isDstFound := k.GetApplication(ctx, dstAddr) require.False(t, isDstFound) - expectedAppStake := &cosmostypes.Coin{Denom: "upokt", Amount: math.NewInt(100)} + expectedAppStake := &apptypes.DefaultMinStake // Prepare and stake the source application. appStakeMsg := &apptypes.MsgStakeApplication{ @@ -130,7 +128,11 @@ func TestMsgServer_TransferApplication_Error_DestinationExists(t *testing.T) { foundApp, isSrcFound = k.GetApplication(ctx, srcAddr) require.True(t, isSrcFound) require.Equal(t, srcAddr, foundApp.Address) - require.Equal(t, int64(100), foundApp.Stake.Amount.Int64()) + require.Truef(t, + expectedAppStake.Amount.Equal(foundApp.Stake.Amount), + "expected %d, got %d", + expectedAppStake.Amount.Int64(), foundApp.Stake.Amount.Int64(), + ) require.Len(t, foundApp.ServiceConfigs, 1) require.Equal(t, "svc1", foundApp.ServiceConfigs[0].ServiceId) } diff --git a/x/application/keeper/msg_server_undelegate_from_gateway_test.go b/x/application/keeper/msg_server_undelegate_from_gateway_test.go index 7f4785ace..a3f1abf8b 100644 --- a/x/application/keeper/msg_server_undelegate_from_gateway_test.go +++ b/x/application/keeper/msg_server_undelegate_from_gateway_test.go @@ -5,7 +5,6 @@ import ( "fmt" "testing" - "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" @@ -39,7 +38,7 @@ func TestMsgServer_UndelegateFromGateway_SuccessfullyUndelegate(t *testing.T) { // Prepare the application stakeMsg := &types.MsgStakeApplication{ Address: appAddr, - Stake: &sdk.Coin{Denom: "upokt", Amount: math.NewInt(100)}, + Stake: &apptypes.DefaultMinStake, Services: []*sharedtypes.ApplicationServiceConfig{ {ServiceId: "svc1"}, }, @@ -131,7 +130,7 @@ func TestMsgServer_UndelegateFromGateway_FailNotDelegated(t *testing.T) { // Prepare the application stakeMsg := &types.MsgStakeApplication{ Address: appAddr, - Stake: &sdk.Coin{Denom: "upokt", Amount: math.NewInt(100)}, + Stake: &apptypes.DefaultMinStake, Services: []*sharedtypes.ApplicationServiceConfig{ {ServiceId: "svc1"}, }, @@ -206,7 +205,7 @@ func TestMsgServer_UndelegateFromGateway_SuccessfullyUndelegateFromUnstakedGatew // Prepare the application stakeMsg := &types.MsgStakeApplication{ Address: appAddr, - Stake: &sdk.Coin{Denom: "upokt", Amount: math.NewInt(100)}, + Stake: &apptypes.DefaultMinStake, Services: []*sharedtypes.ApplicationServiceConfig{ {ServiceId: "svc1"}, }, @@ -514,7 +513,7 @@ func createAppStakeDelegateAndUndelegate( appAddr := sample.AccAddress() stakeMsg := &types.MsgStakeApplication{ Address: appAddr, - Stake: &sdk.Coin{Denom: "upokt", Amount: math.NewInt(100)}, + Stake: &apptypes.DefaultMinStake, Services: []*sharedtypes.ApplicationServiceConfig{ {ServiceId: "svc1"}, }, diff --git a/x/application/keeper/msg_server_unstake_application_test.go b/x/application/keeper/msg_server_unstake_application_test.go index 442b65a98..a5ed5801f 100644 --- a/x/application/keeper/msg_server_unstake_application_test.go +++ b/x/application/keeper/msg_server_unstake_application_test.go @@ -3,14 +3,13 @@ package keeper_test import ( "testing" - "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" keepertest "github.com/pokt-network/poktroll/testutil/keeper" "github.com/pokt-network/poktroll/testutil/sample" "github.com/pokt-network/poktroll/x/application/keeper" - "github.com/pokt-network/poktroll/x/application/types" + apptypes "github.com/pokt-network/poktroll/x/application/types" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" ) @@ -27,7 +26,7 @@ func TestMsgServer_UnstakeApplication_Success(t *testing.T) { require.False(t, isAppFound) // Prepare the application - initialStake := int64(100) + initialStake := apptypes.DefaultMinStake.Amount.Int64() stakeMsg := createAppStakeMsg(unstakingAppAddr, initialStake) // Stake the application @@ -54,7 +53,7 @@ func TestMsgServer_UnstakeApplication_Success(t *testing.T) { require.True(t, isAppFound) // Unstake the application - unstakeMsg := &types.MsgUnstakeApplication{Address: unstakingAppAddr} + unstakeMsg := &apptypes.MsgUnstakeApplication{Address: unstakingAppAddr} _, err = srv.UnstakeApplication(ctx, unstakeMsg) require.NoError(t, err) @@ -64,7 +63,7 @@ func TestMsgServer_UnstakeApplication_Success(t *testing.T) { require.True(t, foundApp.IsUnbonding()) // Move block height to the end of the unbonding period - unbondingHeight := types.GetApplicationUnbondingHeight(&sharedParams, &foundApp) + unbondingHeight := apptypes.GetApplicationUnbondingHeight(&sharedParams, &foundApp) ctx = keepertest.SetBlockHeight(ctx, unbondingHeight) // Run the endblocker to unbond applications @@ -91,7 +90,7 @@ func TestMsgServer_UnstakeApplication_CancelUnbondingIfRestaked(t *testing.T) { appAddr := sample.AccAddress() // Stake the application - initialStake := int64(100) + initialStake := apptypes.DefaultMinStake.Amount.Int64() stakeMsg := createAppStakeMsg(appAddr, initialStake) _, err := srv.StakeApplication(ctx, stakeMsg) require.NoError(t, err) @@ -102,7 +101,7 @@ func TestMsgServer_UnstakeApplication_CancelUnbondingIfRestaked(t *testing.T) { require.False(t, foundApp.IsUnbonding()) // Initiate the application unstaking - unstakeMsg := &types.MsgUnstakeApplication{Address: appAddr} + unstakeMsg := &apptypes.MsgUnstakeApplication{Address: appAddr} _, err = srv.UnstakeApplication(ctx, unstakeMsg) require.NoError(t, err) @@ -111,7 +110,7 @@ func TestMsgServer_UnstakeApplication_CancelUnbondingIfRestaked(t *testing.T) { require.True(t, isAppFound) require.True(t, foundApp.IsUnbonding()) - unbondingHeight := types.GetApplicationUnbondingHeight(&sharedParams, &foundApp) + unbondingHeight := apptypes.GetApplicationUnbondingHeight(&sharedParams, &foundApp) // Stake the application again stakeMsg = createAppStakeMsg(appAddr, initialStake+1) @@ -147,10 +146,10 @@ func TestMsgServer_UnstakeApplication_FailIfNotStaked(t *testing.T) { require.False(t, isAppFound) // Unstake the application - unstakeMsg := &types.MsgUnstakeApplication{Address: appAddr} + unstakeMsg := &apptypes.MsgUnstakeApplication{Address: appAddr} _, err := srv.UnstakeApplication(ctx, unstakeMsg) require.Error(t, err) - require.ErrorIs(t, err, types.ErrAppNotFound) + require.ErrorIs(t, err, apptypes.ErrAppNotFound) _, isAppFound = applicationModuleKeepers.GetApplication(ctx, appAddr) require.False(t, isAppFound) @@ -164,13 +163,13 @@ func TestMsgServer_UnstakeApplication_FailIfCurrentlyUnstaking(t *testing.T) { appAddr := sample.AccAddress() // Stake the application - initialStake := int64(100) + initialStake := apptypes.DefaultMinStake.Amount.Int64() stakeMsg := createAppStakeMsg(appAddr, initialStake) _, err := srv.StakeApplication(ctx, stakeMsg) require.NoError(t, err) // Initiate the application unstaking - unstakeMsg := &types.MsgUnstakeApplication{Address: appAddr} + unstakeMsg := &apptypes.MsgUnstakeApplication{Address: appAddr} _, err = srv.UnstakeApplication(ctx, unstakeMsg) require.NoError(t, err) @@ -179,13 +178,13 @@ func TestMsgServer_UnstakeApplication_FailIfCurrentlyUnstaking(t *testing.T) { // Verify that the application cannot unstake if it is already unstaking. _, err = srv.UnstakeApplication(ctx, unstakeMsg) - require.ErrorIs(t, err, types.ErrAppIsUnstaking) + require.ErrorIs(t, err, apptypes.ErrAppIsUnstaking) } -func createAppStakeMsg(appAddr string, stakeAmount int64) *types.MsgStakeApplication { - initialStake := sdk.NewCoin("upokt", math.NewInt(stakeAmount)) +func createAppStakeMsg(appAddr string, stakeAmount int64) *apptypes.MsgStakeApplication { + initialStake := sdk.NewInt64Coin("upokt", stakeAmount) - return &types.MsgStakeApplication{ + return &apptypes.MsgStakeApplication{ Address: appAddr, Stake: &initialStake, Services: []*sharedtypes.ApplicationServiceConfig{