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

Split accounts test #258

Merged
merged 3 commits into from
Nov 8, 2023
Merged

Split accounts test #258

merged 3 commits into from
Nov 8, 2023

Conversation

jayantk
Copy link
Collaborator

@jayantk jayantk commented Nov 7, 2023

two changes per our conversation:

  1. disallow splitting accounts that have positions. This means you have to unstake before you can split.
  2. test the vesting account splitting logic.

I didn't add the check that all tokens in the account are locked because it turns out that check doesn't help with the vesting account splitting logic.

@jayantk jayantk requested a review from guibescos as a code owner November 7, 2023 21:32
Copy link

vercel bot commented Nov 7, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
staking ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 8, 2023 4:10pm
staking-devnet ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 8, 2023 4:10pm

@@ -71,6 +71,9 @@ pub enum ErrorCode {
SplitTooManyTokens,
#[msg("Sanity check failed")] // 6033
SanityCheckFailed,
#[msg("Other")] //6031
#[msg("Other")] //6034
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd just move Other to be the last error

// This check allows us to create an empty positions account on behalf of the recipient and
// not worry about moving positions from the source account to the new account.
require!(
source_stake_account_positions.num_positions()? == 0,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's better to use source_stake_account_metadata.next_index == 0

// all of these fields should be preserved in the result
start_date: 203,
period_duration: 100,
num_periods: 12,
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps use the parameters we're going to use in the real vesting schedules for this test

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I didn't do this one because it makes the invariant test below much more expensive. I don't think the length of the start_date or duration should matter for the splitting logic though, so i think it's better to have the invariant test and not have this.

match (remaining_schedule, transferred_schedule) {
(
PeriodicVesting {
initial_balance: r, ..
Copy link
Contributor

@guibescos guibescos Nov 8, 2023

Choose a reason for hiding this comment

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

I'd like to see a test that for an arbitrary t
if schedule.get_unvested_balance(t) <= total then
transfered_schedule.get_unvested_balance(t) <= transferred
and transfered_schedule.get_unvested_balance(t) <= total - transferred
This proves that the invariants are preserved by this transformation.

@@ -709,6 +714,28 @@ pub mod tests {
}
}

for timestamp in 0..(START_TIMESTAMP + (PERIOD_DURATION * NUM_PERIODS + 1) as i64) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You could change the increment of this for loop to be PERIOD_DURATION and then it would run fast for big values of PERIOD_DURATION

@jayantk jayantk merged commit a75183d into split-accounts-3 Nov 8, 2023
2 checks passed
@jayantk jayantk deleted the split-accounts-3-jayant branch November 8, 2023 17:03
guibescos added a commit that referenced this pull request Nov 10, 2023
* Draft

* Add authority

* Clippy

* Checkpoint

* Do it

* Rename error

* Update stuff

* Use epoch_of_snapshot

* Checkpoint

* Scaffolding

* Checkpoint

* Cleanup

* Cleanup test

* Another round

* Cleanup

* Restore all tests

* add todos

* Cleanup idls

* Throw error since it's not implemented

* Add some comments

* Box everything

* Add soruce

* Add more comments

* Add another comment

* First implementation

* Delete current request

* add bumps

* Fix bug

* Tests works

* Update idls

* Clippy

* Clippy

* Add actual tests

* Clippy

* Cleanup

* Fix tests

* Split accounts test (#258)

* vesting tests

* more tests

* better invariant tests

* minor cleanups

* cleanup implementation

* idl

* ok fix the ts tests

* refactor

* refactor

* fix

* cleanup

* pr comments

* minor

* Cleanup

* Comment

* Add another test with full amount

* Sorry

---------

Co-authored-by: Jayant Krishnamurthy <[email protected]>
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.

2 participants