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

Test: withdraw unit tests #529

Merged
merged 19 commits into from
Jan 5, 2023
Merged

Test: withdraw unit tests #529

merged 19 commits into from
Jan 5, 2023

Conversation

paterson1
Copy link
Contributor

@paterson1 paterson1 commented Nov 28, 2022

Context

Closes #491

Changes proposed in this pull request

Added Withdraw event to StakingPool contract and withdrawNXMStakeAndRewards method to TokenControllerMock. Also in setup update master address for tokenController.

Test plan

Added unit tests to StakingPool/withdraw.js.

Checklist

  • Rebased the base branch
  • Attached corresponding Github issue
  • Prefixed the name with the type of change (i.e. feat, chore, test)
  • Performed a self-review of my own code
  • Followed the style guidelines of this project
  • Made corresponding changes to the documentation
  • Didn't generate new warnings
  • Didn't generate failures on existing tests
  • Added tests that prove my fix is effective or that my feature works

Review

When reviewing a PR, please indicate intention in comments using the following emojis:

  • 🍰 = Nice to have but not essential.
  • 💡 = Suggestion or a comment based on personal opinion
  • 🔨 = I believe this should be changed.
  • 🤔 = I don’t understand something, do you mind giving me more context?
  • 🚀 = Feedback

@paterson1 paterson1 requested review from shark0der, roxdanila, patitonar and danoctavian and removed request for shark0der and roxdanila November 28, 2022 23:36
@shark0der shark0der changed the title test/withdraw unit tests Test: withdraw unit tests Nov 29, 2022
@roxdanila roxdanila linked an issue Nov 29, 2022 that may be closed by this pull request
10 tasks
@paterson1 paterson1 marked this pull request as ready for review December 2, 2022 13:22
Copy link
Contributor

@shark0der shark0der left a comment

Choose a reason for hiding this comment

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

Pushed a failed test. We need to test all values properly and not only replicate the formulas in the contract.

@patitonar
Copy link
Contributor

Pushed a failed test.

While reviewing this test I noticed that the total amount of minted rewards was not being distributed to the users and manager, there was a small amount that remained locked in the contract. After debugging I found that the cause of this small amount was a precision loss in the calculation of accNxmPerRewardsShare.

As it is calculated with the following formula elapsed * _rewardPerSecond / _rewardsSharesSupply there were a lot of decimals truncated causing the accumulated value to be less than the actual amount to distribute. The solution I thought for this was to calculate and store the accumulator with an increased precision of ONE_NXM and then scale back the value when calculating the amount of the rewards to transfer.

I applied that change in the commit Increase accNxmPerRewardsShare precision

Let me know your thoughts on this @shark0der

@shark0der
Copy link
Contributor

The accNxmPerRewardsShare fix looks good to me. In terms of semantics I think the previous value was:

the accumulated nxm per 1 reward share

where "1" was actually "1 wei"

The new value represents

the accmuluated nxm per 1e18 reward shares

which makes perfect sense and solves the precision loss issue.

Copy link
Contributor

@shark0der shark0der left a comment

Choose a reason for hiding this comment

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

Right now it seems to me that all tests are using a single staker (unless I missed something). Could you please add a new test where 2+ stakers would deposit and withdraw their stake and rewards? I'm not expecting to discover any issues, but just in case, you know!

@shark0der shark0der merged commit 2b4d436 into nexus-v2 Jan 5, 2023
@shark0der shark0der deleted the test/stakingPool-withdraw branch January 5, 2023 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

StakingPool unit tests: withdraw
4 participants