-
Notifications
You must be signed in to change notification settings - Fork 609
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
Return lock id from BeginForceUnlock #4059
Conversation
x/lockup/keeper/lock.go
Outdated
// the lock has a synthetic lock or not before unlocking. | ||
func (k Keeper) BeginForceUnlock(ctx sdk.Context, lockID uint64, coins sdk.Coins) error { | ||
func (k Keeper) BeginForceUnlock(ctx sdk.Context, lockID uint64, coins sdk.Coins) (uint64, error) { |
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.
Lets add a comment for what is the uint64 being returned
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.
|| named returned parameters!
} | ||
|
||
// beginUnlock unlocks specified tokens from the given lock. Existing lock refs | ||
// of not unlocking queue are deleted and new lock refs are then added. | ||
// EndTime of the lock is set within this method. | ||
// Coins provided as the parameter does not require to have all the tokens in the lock, | ||
// as we allow partial unlockings of a lock. | ||
func (k Keeper) beginUnlock(ctx sdk.Context, lock types.PeriodLock, coins sdk.Coins) error { | ||
func (k Keeper) beginUnlock(ctx sdk.Context, lock types.PeriodLock, coins sdk.Coins) (uint64, error) { |
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.
Lets add a comment for what is being returned. Needs to document what happens in both the case of a lock being split and not split.
Thank you for the PR! Can you please add a test case for this? |
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.
LGTM. Nice work
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.
Amazing. LGTM once minor comments are addressed
x/lockup/keeper/lock_test.go
Outdated
{ | ||
name: "new lock id is returned if the lock was split", | ||
coins: coins, | ||
unlockCoins: sdk.Coins{sdk.NewInt64Coin("stake", 1)}, |
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: while not a problem here, using the constructor is preferable because it does coin validation
unlockCoins: sdk.Coins{sdk.NewInt64Coin("stake", 1)}, | |
unlockCoins: sdk.NewCoins(sdk.NewInt64Coin("stake", 1)), |
x/lockup/keeper/lock_test.go
Outdated
for _, tc := range testCases { | ||
suite.SetupTest() |
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.
For each test case, let's create a separate environment for it with suite.`Run(...). Similar to:
osmosis/x/gamm/keeper/pool_service_test.go
Lines 302 to 303 in 6286934
test := test | |
suite.Run(test.name, func() { |
I know this is not done in most of the test cases in the file. However, this is the correct way that enables a separate test environment for each table-driven test case.
x/lockup/keeper/lock_test.go
Outdated
locks, err = suite.App.LockupKeeper.GetPeriodLocks(suite.Ctx) | ||
suite.Require().NoError(err) | ||
|
||
for _, lock := range locks { |
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.
suggest checking that the locks length is not zero here. If we don't check and it happens so that 0 locks are returned, we would skip all the validations in the for loop completely
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.
lgtm. Thank you.
Will leave it open for now if anyone else would like to review it. If no updates, will merge tomorrow
Merging since no more eyes so far. Other reviewers can take a look later. Thank you @t4sk |
* return lock id from BeginForceUnlock * refactor and comment to BeginForceUnlock * unit test BeginForceUnlock * table driven test BeginForceUnlock * update unit test for BeginForceUnlock (cherry picked from commit 6ca0a56)
* return lock id from BeginForceUnlock * refactor and comment to BeginForceUnlock * unit test BeginForceUnlock * table driven test BeginForceUnlock * update unit test for BeginForceUnlock (cherry picked from commit 6ca0a56) Co-authored-by: t4sk <[email protected]>
What is the purpose of the change
Return lock id from
BeginForceUnlock
. This PR is 1st part of implementing partial withdraw from super fluid#3830
Algorithm for SF partial withdraw is the following
This PR makes step 2 possible.
Brief Changelog
BeginForceUnlock
Testing and Verifying
(Please pick one of the following options)
Documentation and Release Note
Unreleased
section inCHANGELOG.md
? (no)