Skip to content
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

chore: Refactor and Add tests for AddToExistingLock #1979

Merged
merged 12 commits into from
Aug 10, 2022

Conversation

mattverse
Copy link
Member

sub-component of: #1838

What is the purpose of the change

AddToExistingLock had a bad design of returning array of locks, and then only using the first index out of the given array.
There's no need to return an array here, but simply return the lock that we've added the token to. This PR changes the returning values of AddToExistingLock from an array to a single lock(not pointer referenced).

This PR also includes changing tests for AddToExistingLock to be TDD, adding some edge cases to the tests.

Brief Changelog

  • Change return values of AddToExistingLock
  • Change tests for AddToExistingLock to be TDD

Testing and Verifying

This change added tests

Documentation and Release Note

  • Does this pull request introduce a new feature or user-facing behavior changes? no
  • Is a relevant changelog entry added to the Unreleased section in CHANGELOG.md? no
  • How is the feature or change documented? not documented

@mattverse mattverse requested a review from a team July 6, 2022 10:05
@mattverse mattverse mentioned this pull request Jul 6, 2022
7 tasks
x/lockup/keeper/lock.go Outdated Show resolved Hide resolved
Copy link
Member

@p0mvn p0mvn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work. I worry that we might be returning an old lock from AddToExistingLock. Could you please confirm if that is the case?

We should make assertions on the contents of the lock returned by AddToExistingLock

x/lockup/keeper/lock.go Outdated Show resolved Hide resolved
x/lockup/keeper/lock.go Outdated Show resolved Hide resolved
x/lockup/keeper/lock.go Outdated Show resolved Hide resolved
x/lockup/keeper/lock_test.go Outdated Show resolved Hide resolved
Copy link
Member

@p0mvn p0mvn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New return with lock id LGTM, nice work!

On another look, thought about adding an extra check. Let me know what you think

x/lockup/keeper/lock_test.go Outdated Show resolved Hide resolved
x/lockup/keeper/lock_test.go Outdated Show resolved Hide resolved
x/lockup/keeper/lock_test.go Outdated Show resolved Hide resolved
x/lockup/keeper/lock.go Outdated Show resolved Hide resolved
x/lockup/keeper/lock.go Outdated Show resolved Hide resolved
x/lockup/keeper/lock.go Outdated Show resolved Hide resolved
x/lockup/keeper/lock_test.go Outdated Show resolved Hide resolved
x/lockup/keeper/lock_test.go Show resolved Hide resolved
x/lockup/keeper/lock_test.go Show resolved Hide resolved
Copy link
Contributor

@AlpinYukseloglu AlpinYukseloglu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All my comments/questions have been addressed – LGTM!

Copy link
Member

@p0mvn p0mvn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - thanks for fighting all the weird edge cases!

I think that it makes sense to return an error when there are no locks in AddToExistingLock, despite this change being state-breaking. However, leaving the final call to you @mattverse 👍

@mattverse
Copy link
Member Author

agreed with you on adding error when there's no lock druing AddToExistingLock,changing it + adding a changlog entry and requesting a final review

@mattverse mattverse requested a review from p0mvn July 20, 2022 05:57
@github-actions github-actions bot added the C:docs Improvements or additions to documentation label Jul 20, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Aug 4, 2022

This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. Thank you!

@github-actions github-actions bot added the Stale label Aug 4, 2022
x/lockup/keeper/lock.go Outdated Show resolved Hide resolved
x/lockup/keeper/lock.go Outdated Show resolved Hide resolved
@github-actions github-actions bot removed the Stale label Aug 9, 2022
@mattverse mattverse requested a review from p0mvn August 9, 2022 07:20
Copy link
Member

@p0mvn p0mvn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for working out all edge cases here @mattverse

x/lockup/keeper/lock.go Outdated Show resolved Hide resolved
// curBalance := suite.App.BankKeeper.GetAllBalances(cacheCtx, addr1)
_, err = suite.App.LockupKeeper.AddTokensToLockByID(cacheCtx, 1111, addr1, addCoins)
suite.Require().Error(err)
if tc.expectAddTokensToLockSuccess {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the difference between expectError and expectAddTokensToLockSuccess? Can we use only expectError?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, the original intent was to create a separate case for lock failing and adding to lock failing, but these can be grouped to one. Changed to removing the field!

@mattverse mattverse merged commit 08669da into main Aug 10, 2022
@mattverse mattverse deleted the mattverse/lock-testing-2 branch August 10, 2022 04:22
@czarcas7ic czarcas7ic mentioned this pull request Aug 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:docs Improvements or additions to documentation C:x/lockup
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants