-
Notifications
You must be signed in to change notification settings - Fork 208
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
add inner bounds #938
Merged
Merged
add inner bounds #938
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
6158058
boilerplate
asalzmann 130d735
Merge branch 'main' into tight-bounds
asalzmann f0b2cff
add setter
asalzmann 98a304d
Merge branch 'main' into tight-bounds
asalzmann a71c932
tight -> inner
asalzmann ee41b40
Merge branch 'tight-bounds' of github.com:Stride-Labs/stride into tig…
asalzmann e36328d
rm nil return
asalzmann 392859d
default inner bounds to outer bounds upon registration
asalzmann 66d2008
comment
asalzmann 643f720
address sam comments
asalzmann 9a98d4d
add GetInnerSafetyBounds
asalzmann 98a762b
fix unittests
asalzmann c82e0fc
add unittests, fix validate basic bug
asalzmann 7cb07de
add script, fix cli command
asalzmann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 111 additions & 1 deletion
112
x/stakeibc/keeper/msg_server_update_inner_redemption_rate_bounds_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,111 @@ | ||
package keeper | ||
package keeper_test | ||
|
||
import ( | ||
"fmt" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
_ "github.com/stretchr/testify/suite" | ||
|
||
stakeibctypes "github.com/Stride-Labs/stride/v14/x/stakeibc/types" | ||
) | ||
|
||
type UpdateInnerRedemptionRateBoundsTestCase struct { | ||
validMsg stakeibctypes.MsgUpdateInnerRedemptionRateBounds | ||
zone stakeibctypes.HostZone | ||
} | ||
|
||
func (s *KeeperTestSuite) SetupUpdateInnerRedemptionRateBounds() UpdateInnerRedemptionRateBoundsTestCase { | ||
// Register a host zone | ||
hostZone := stakeibctypes.HostZone{ | ||
ChainId: HostChainId, | ||
HostDenom: Atom, | ||
IbcDenom: IbcAtom, | ||
RedemptionRate: sdk.NewDec(1.0), | ||
MinRedemptionRate: sdk.NewDec(9).Quo(sdk.NewDec(10)), | ||
MaxRedemptionRate: sdk.NewDec(15).Quo(sdk.NewDec(10)), | ||
} | ||
|
||
s.App.StakeibcKeeper.SetHostZone(s.Ctx, hostZone) | ||
|
||
defaultMsg := stakeibctypes.MsgUpdateInnerRedemptionRateBounds{ | ||
// TODO: does this need to be the admin address? | ||
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. I don't think so cause I don't think validate basic is run when you call the msg server function directly |
||
Creator: s.TestAccs[0].String(), | ||
ChainId: HostChainId, | ||
MinInnerRedemptionRate: sdk.NewDec(1), | ||
MaxInnerRedemptionRate: sdk.NewDec(11).Quo(sdk.NewDec(10)), | ||
} | ||
|
||
return UpdateInnerRedemptionRateBoundsTestCase{ | ||
validMsg: defaultMsg, | ||
zone: hostZone, | ||
} | ||
} | ||
|
||
// Verify that bounds can be set successfully | ||
func (s *KeeperTestSuite) TestUpdateInnerRedemptionRateBounds_Success() { | ||
tc := s.SetupUpdateInnerRedemptionRateBounds() | ||
|
||
// Set the inner bounds on the host zone | ||
_, err := s.GetMsgServer().UpdateInnerRedemptionRateBounds(s.Ctx, &tc.validMsg) | ||
s.Require().NoError(err, "should not throw an error") | ||
|
||
// Confirm the inner bounds were set | ||
zone, found := s.App.StakeibcKeeper.GetHostZone(s.Ctx, HostChainId) | ||
s.Require().True(found, "host zone should be in the store") | ||
s.Require().Equal(tc.validMsg.MinInnerRedemptionRate, zone.MinInnerRedemptionRate, "min inner redemption rate should be set") | ||
s.Require().Equal(tc.validMsg.MaxInnerRedemptionRate, zone.MaxInnerRedemptionRate, "max inner redemption rate should be set") | ||
} | ||
|
||
// Setting inner bounds outside of outer bounds should throw an error | ||
func (s *KeeperTestSuite) TestUpdateInnerRedemptionRateBounds_OutOfBounds() { | ||
tc := s.SetupUpdateInnerRedemptionRateBounds() | ||
|
||
// Set the min inner bound to be less than the min outer bound | ||
tc.validMsg.MinInnerRedemptionRate = sdk.NewDec(0) | ||
|
||
// Set the inner bounds on the host zone | ||
_, err := s.GetMsgServer().UpdateInnerRedemptionRateBounds(s.Ctx, &tc.validMsg) | ||
// verify it throws an error | ||
errMsg := fmt.Sprintf("inner min safety threshold (%s) is less than outer min safety threshold (%s)", tc.validMsg.MinInnerRedemptionRate, sdk.NewDec(9).Quo(sdk.NewDec(10))) | ||
s.Require().ErrorContains(err, errMsg) | ||
|
||
// Set the min inner bound to be valid, but the max inner bound to be greater than the max outer bound | ||
tc.validMsg.MinInnerRedemptionRate = sdk.NewDec(1) | ||
tc.validMsg.MaxInnerRedemptionRate = sdk.NewDec(3) | ||
// Set the inner bounds on the host zone | ||
_, err = s.GetMsgServer().UpdateInnerRedemptionRateBounds(s.Ctx, &tc.validMsg) | ||
// verify it throws an error | ||
errMsg = fmt.Sprintf("inner max safety threshold (%s) is greater than outer max safety threshold (%s)", tc.validMsg.MaxInnerRedemptionRate, sdk.NewDec(15).Quo(sdk.NewDec(10))) | ||
s.Require().ErrorContains(err, errMsg) | ||
} | ||
|
||
// Validate basic tests | ||
func (s *KeeperTestSuite) TestUpdateInnerRedemptionRateBounds_InvalidMsg() { | ||
tc := s.SetupUpdateInnerRedemptionRateBounds() | ||
|
||
// Set the min inner bound to be greater than than the max inner bound | ||
invalidMsg := tc.validMsg | ||
invalidMsg.MinInnerRedemptionRate = sdk.NewDec(2) | ||
|
||
err := invalidMsg.ValidateBasic() | ||
|
||
// Verify the error | ||
errMsg := fmt.Sprintf("Inner max safety threshold (%s) is less than inner min safety threshold (%s)", invalidMsg.MaxInnerRedemptionRate, invalidMsg.MinInnerRedemptionRate) | ||
s.Require().ErrorContains(err, errMsg) | ||
} | ||
|
||
// Verify that if inner bounds end up outside of outer bounds (somehow), the outer bounds are returned | ||
func (s *KeeperTestSuite) TestGetInnerSafetyBounds() { | ||
tc := s.SetupUpdateInnerRedemptionRateBounds() | ||
|
||
// Set the inner bounds outside the outer bounds on the host zone directly | ||
tc.zone.MinInnerRedemptionRate = sdk.NewDec(0) | ||
tc.zone.MaxInnerRedemptionRate = sdk.NewDec(3) | ||
// Set the host zone | ||
s.App.StakeibcKeeper.SetHostZone(s.Ctx, tc.zone) | ||
|
||
// Get the inner bounds and verify the outer bounds are used | ||
innerMinSafetyThreshold, innerMaxSafetyThreshold := s.App.StakeibcKeeper.GetInnerSafetyBounds(s.Ctx, tc.zone) | ||
s.Require().Equal(tc.zone.MinRedemptionRate, innerMinSafetyThreshold, "min inner redemption rate should be set") | ||
s.Require().Equal(tc.zone.MaxRedemptionRate, innerMaxSafetyThreshold, "max inner redemption rate should be set") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nit: it's a bit easier to read if you create these with
MustNewDecFromStr