-
Notifications
You must be signed in to change notification settings - Fork 12
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
[Gateway] Enforce minimum stake when staking #843
Changes from all commits
d1cd5e6
91eecfc
ef62280
f7a6e5b
8957f1c
3016ca3
899effb
83c1d74
55e6a31
ddd68bb
fa8caf6
ae006e2
e92e3b1
b2e1267
0373fa2
da7894a
015c537
1ac6c48
db366f6
60bef17
a21687f
7e9f857
4340590
4b8e95b
0839ae4
34b0d6d
f48fa66
6c5e13f
a77877b
9f65d25
28962ba
891a858
08e99ba
ccc3f53
47e0993
b29843e
8c25061
3f59041
4e259c9
2808925
3280142
c256eae
0d36e0f
00914b0
1c309b8
e7ff959
1257f6e
4d2c2d9
5ba2a48
3e4ef9e
cd5e420
65158ad
698991a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,51 +4,52 @@ 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/gateway/keeper" | ||
"github.com/pokt-network/poktroll/x/gateway/types" | ||
gatewaytypes "github.com/pokt-network/poktroll/x/gateway/types" | ||
) | ||
|
||
func TestMsgServer_StakeGateway_SuccessfulCreateAndUpdate(t *testing.T) { | ||
k, ctx := keepertest.GatewayKeeper(t) | ||
srv := keeper.NewMsgServerImpl(k) | ||
|
||
// Generate an address for the gateway | ||
// Generate an address for the gateway. | ||
addr := sample.AccAddress() | ||
|
||
// Verify that the gateway does not exist yet | ||
// Verify that the gateway does not exist yet. | ||
_, isGatewayFound := k.GetGateway(ctx, addr) | ||
require.False(t, isGatewayFound) | ||
|
||
// Prepare the gateway | ||
initialStake := sdk.NewCoin("upokt", math.NewInt(100)) | ||
stakeMsg := &types.MsgStakeGateway{ | ||
// Prepare the gateway. | ||
initialStake := cosmostypes.NewCoin("upokt", math.NewInt(100)) | ||
stakeMsg := &gatewaytypes.MsgStakeGateway{ | ||
Address: addr, | ||
Stake: &initialStake, | ||
} | ||
|
||
// Stake the gateway | ||
// Stake the gateway. | ||
_, err := srv.StakeGateway(ctx, stakeMsg) | ||
require.NoError(t, err) | ||
|
||
// Verify that the gateway exists | ||
// Verify that the gateway exists. | ||
foundGateway, isGatewayFound := k.GetGateway(ctx, addr) | ||
require.True(t, isGatewayFound) | ||
require.Equal(t, addr, foundGateway.Address) | ||
require.Equal(t, initialStake.Amount, foundGateway.Stake.Amount) | ||
|
||
// Prepare an updated gateway with a higher stake | ||
updatedStake := sdk.NewCoin("upokt", math.NewInt(200)) | ||
updateMsg := &types.MsgStakeGateway{ | ||
// Prepare an updated gateway with a higher stake. | ||
updatedStake := cosmostypes.NewCoin("upokt", math.NewInt(200)) | ||
updateMsg := &gatewaytypes.MsgStakeGateway{ | ||
Address: addr, | ||
Stake: &updatedStake, | ||
} | ||
|
||
// Update the staked gateway | ||
// Update the staked gateway. | ||
_, err = srv.StakeGateway(ctx, updateMsg) | ||
require.NoError(t, err) | ||
foundGateway, isGatewayFound = k.GetGateway(ctx, addr) | ||
|
@@ -60,33 +61,61 @@ func TestMsgServer_StakeGateway_FailLoweringStake(t *testing.T) { | |
k, ctx := keepertest.GatewayKeeper(t) | ||
srv := keeper.NewMsgServerImpl(k) | ||
|
||
// Prepare the gateway | ||
// Prepare the gateway. | ||
addr := sample.AccAddress() | ||
initialStake := sdk.NewCoin("upokt", math.NewInt(100)) | ||
stakeMsg := &types.MsgStakeGateway{ | ||
initialStake := cosmostypes.NewCoin("upokt", math.NewInt(100)) | ||
stakeMsg := &gatewaytypes.MsgStakeGateway{ | ||
Address: addr, | ||
Stake: &initialStake, | ||
} | ||
|
||
// Stake the gateway & verify that the gateway exists | ||
// Stake the gateway & verify that the gateway exists. | ||
_, err := srv.StakeGateway(ctx, stakeMsg) | ||
require.NoError(t, err) | ||
_, isGatewayFound := k.GetGateway(ctx, addr) | ||
require.True(t, isGatewayFound) | ||
|
||
// Prepare an updated gateway with a lower stake | ||
updatedStake := sdk.NewCoin("upokt", math.NewInt(50)) | ||
updateMsg := &types.MsgStakeGateway{ | ||
// Prepare an updated gateway with a lower stake. | ||
updatedStake := cosmostypes.NewCoin("upokt", math.NewInt(50)) | ||
updateMsg := &gatewaytypes.MsgStakeGateway{ | ||
Address: addr, | ||
Stake: &updatedStake, | ||
} | ||
|
||
// Verify that it fails | ||
// Verify that it fails. | ||
_, err = srv.StakeGateway(ctx, updateMsg) | ||
require.Error(t, err) | ||
|
||
// Verify that the gateway stake is unchanged | ||
// Verify that the gateway stake is unchanged. | ||
gatewayFound, isGatewayFound := k.GetGateway(ctx, addr) | ||
require.True(t, isGatewayFound) | ||
require.Equal(t, initialStake.Amount, gatewayFound.Stake.Amount) | ||
} | ||
|
||
func TestMsgServer_StakeGateway_FailBelowMinStake(t *testing.T) { | ||
k, ctx := keepertest.GatewayKeeper(t) | ||
srv := keeper.NewMsgServerImpl(k) | ||
|
||
addr := sample.AccAddress() | ||
gatewayStake := cosmostypes.NewInt64Coin(volatile.DenomuPOKT, 100) | ||
minStake := gatewayStake.AddAmount(math.NewInt(1)) | ||
expectedErr := gatewaytypes.ErrGatewayInvalidStake.Wrapf("gateway %q must stake at least %s", addr, minStake) | ||
|
||
// Set the minimum stake to be greater than the gateway stake. | ||
params := k.GetParams(ctx) | ||
params.MinStake = &minStake | ||
err := k.SetParams(ctx, params) | ||
require.NoError(t, err) | ||
|
||
// Prepare the gateway. | ||
stakeMsg := &gatewaytypes.MsgStakeGateway{ | ||
Address: addr, | ||
Stake: &gatewayStake, | ||
} | ||
|
||
// Attempt to stake the gateway & verify that the gateway does NOT exist. | ||
_, err = srv.StakeGateway(ctx, stakeMsg) | ||
require.ErrorContains(t, err, expectedErr.Error()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Personally, I think that checking if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My personal preference is that the test be sensitive to the error message changing as this could be indicative of a couple things:
|
||
_, isGatewayFound := k.GetGateway(ctx, addr) | ||
require.False(t, isGatewayFound) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling out to revisit the
logger.Info
vslogger.Debug
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've opened #856