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

Tests for external staking #42

Merged
merged 2 commits into from
Jun 2, 2023
Merged

Tests for external staking #42

merged 2 commits into from
Jun 2, 2023

Conversation

hashedone
Copy link
Collaborator

@hashedone hashedone commented Jun 1, 2023

Follow up of #39

Closes #13

Implements only the third task mentioned in #13 (comment).

Next - distribution.

Multitests + minor bugfixes found by tests.

@hashedone hashedone force-pushed the external-staking-test branch from a170058 to eb1a3b6 Compare June 1, 2023 20:57
Copy link
Collaborator

@ethanfrey ethanfrey left a comment

Choose a reason for hiding this comment

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

Great stuff.

Left a few comments on typos. Please fix and merge

@@ -36,6 +36,9 @@ thiserror = { workspace = true }
sylvia = { workspace = true, features = ["mt"] }
cw-multi-test = { workspace = true }
anyhow = { workspace = true }
mesh-vault = { workspace = true, features = ["mt"] }
mesh-native-staking-proxy = { workspace = true, features = ["mt"] }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Cool you test those, but do you need native staking in the external staking tests?
Or is this just for initialization of the vault?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Only vault initialization. I was looking for a way to fake it somehow, but I need to pass the proper message and so on, so I decided to add them and just instantiate - doesn't hurt for tests.

@@ -263,6 +263,22 @@ impl VaultContract<'_> {
Ok(resp)
}

/// Returns a singl claim between the user and lienholder
Copy link
Collaborator

Choose a reason for hiding this comment

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

singl -> single


use anyhow::Result as AnyResult;

const OSMO: &str = "OSMO";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: if you want to be closer to reality, use uosmo here (OSMO only exists in UIs not on the chain)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It completely does not matter, but will change just for consistency.

fn staking() {
let users = ["user1", "user2"];

let app = MtApp::new(|router, _api, storage| {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Minor note for Sylvia:
It would be nice to add some helper for the simple setup of just setting balances (and only use closure for more important cases). Like keep MtApp:::new as is, but something like this, which takes balances: &[(&str, Vec<Coin>])

let app = MtApp::with_balances(&[
  (users[0], coins(300, OSMO)),
  (users[1], coins(300, OSMO))
];

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In general, what would happen for sure:

  1. App::new() would be changed to match the App::new(...) from multitest - will take instantiation closure
  2. AppBuilder would be created to mimic the one from MT - allowing setting up custom modules
  3. There would be an additional layer between the builder and the app - AppConfig which would have some additional functions knowing what modules are used. Eg. when default BankKeeper is used it would have function like initial_balances(...) - exactly what you said. It would be another builder state, so when there is another config option it doesn't add a dozen of functions passing it in different combinations. Obviously Builder would still be able to return an App directly if we don't want to config it.
  4. There would be added From<cw_multi_test::App> fo sylvia::App implementation, so it would still be possible to create mt app manually and then convert to sylvia one - in case some MT feature would be added, and we will not update sylvia automatically.

.call(users[1])
.unwrap();

vault
Copy link
Collaborator

Choose a reason for hiding this comment

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

Great stuff.

For completeness, I would add one more stake, and ensure it returns an error (no more collateral left for lien)

.call(users[1])
.unwrap();

// Properly unstake some tokens
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice cases and error checking here

.unwrap();
assert_eq!(stake.stake.u128(), 0);

// Another timetravel - just enough for first bathc of stakes to release,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice setup for the withdrawing process and ensuring this works with multiple batches pending.

Small typo: bathc -> batch

@ethanfrey ethanfrey mentioned this pull request Jun 2, 2023
10 tasks
Copy link
Collaborator

@maurolacy maurolacy left a comment

Choose a reason for hiding this comment

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

LGTM.

@@ -49,13 +49,13 @@ impl Stake {
};

// First item is still not ready for release
if self.pending_unbonds[0].release_at < info.time {
if self.pending_unbonds[0].release_at > info.time {
Copy link
Collaborator

Choose a reason for hiding this comment

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

That's what tests are for.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yup, that is why I really didn't check it 100 times before, as it would be burned time - I knew I am writing tests for it in next PR and it would be verified there.

assert_eq!(stake.stake.u128(), 0);

// Another timetravel - just enough for first bathc of stakes to release,
// to early for second batch
Copy link
Collaborator

Choose a reason for hiding this comment

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

to -> too

contract.withdraw_unbonded().call(users[0]).unwrap();
contract.withdraw_unbonded().call(users[1]).unwrap();

// Now claims on vauld got reduced, but only for first batch amount
Copy link
Collaborator

Choose a reason for hiding this comment

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

vauld -> vault.

.unwrap();
assert_eq!(claim.amount.u128(), 240);

// Moving forward more, passign through second bath pending duration
Copy link
Collaborator

Choose a reason for hiding this comment

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

passign -> passing

@hashedone hashedone merged commit 4a8ba0f into main Jun 2, 2023
@maurolacy maurolacy deleted the external-staking-test branch November 6, 2023 08:27
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.

Implement Remote Staking contract (no rewards)
3 participants