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

Staking: multitest improvements #50

Merged
merged 56 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
9bdb24b
Stake: Remove unused helpers from multitest suite
ueco-jb Feb 9, 2024
0d7653b
stake: fixes the compilation issues in suite.rs
gangov Feb 22, 2024
5e4d85a
Stake: Replace transfer in multitest suite to native bank message
ueco-jb Feb 22, 2024
81806ce
stake: replaces cw20 implementation
gangov Feb 23, 2024
264c5bc
stake: fixes the wrongly used msg type
gangov Feb 23, 2024
3997a56
stake: fixes the first test in delegate
gangov Feb 26, 2024
b5a7161
stake: more tests for delegate
gangov Feb 26, 2024
4b00e2e
stake: removes unnecessary test
gangov Feb 27, 2024
7b40bdf
stake: multitest/delegate.rs lints
gangov Feb 27, 2024
275c799
stake: interrim state
gangov Feb 27, 2024
2e79051
removes a commit from suite.rs
gangov Feb 27, 2024
12072a4
removes hardcoded value for AMOUNT from delegate.rs
gangov Feb 27, 2024
0e617bf
stake: staking_rewards first 3 tests done
gangov Feb 28, 2024
21772a1
stake: staking_rewards removes a few tests for rebond and fixes anoth…
gangov Feb 28, 2024
6da71d1
stake: staking_rewards: query_all_staked fixed
gangov Feb 28, 2024
bb8c42c
stake: fixes the final test
gangov Feb 28, 2024
9db122d
stake: lints staking_rewards and enables unbond_all.rs
gangov Feb 28, 2024
3237f89
stake: unbond_all - first test
gangov Feb 29, 2024
105056a
stake: unbond_all - second test
gangov Feb 29, 2024
ba3a552
stake: unbond_all - next test done
gangov Feb 29, 2024
2299681
stake: unbond_all - removes an unnecessary test
gangov Feb 29, 2024
e15e2f2
stake: unbond_all - removes more unnecessary tests
gangov Feb 29, 2024
ca04c8e
stake: unbond_all - comments out the final test
gangov Feb 29, 2024
4767b26
stake: enables distribution.rs
gangov Feb 29, 2024
22ccbff
stake: distribution.rs - I finally got it
gangov Feb 29, 2024
fa6fd94
stake: distribution.rs - removes a test and fixes another one
gangov Feb 29, 2024
857f59d
stake: distribution.rs - partial_payouts_by_rate done
gangov Feb 29, 2024
c59ef6f
stake: distribution.rs - divisible_amount_distributed_with_rate done
gangov Feb 29, 2024
2372d79
stake: distribution.rs - addition to divisible_amount_distributed_wit…
gangov Feb 29, 2024
65cb42c
stake: distribution.rs - calculate_apr done
gangov Feb 29, 2024
851c629
stake: distribution.rs - removes a cw20 test
gangov Feb 29, 2024
372d3fe
stake: distribution.rs - simple_apr_simulation done
gangov Feb 29, 2024
d800285
stake: distribution.rs - divisible_amount_distributed done
gangov Feb 29, 2024
ec47bad
stake: distribution.rs - divisible_amount_distributed_twice done
gangov Feb 29, 2024
e2e5971
stake: distribution.rs - couple of more tests done
gangov Feb 29, 2024
e2d7f0b
stake: distribution.rs - 3 more
gangov Feb 29, 2024
6ae736d
stake: distribution.rs - adds more tests
gangov Feb 29, 2024
bc2baee
stkae: distribution.rs - all tests done
gangov Feb 29, 2024
6cfc416
stake: lints distribution.rs and enables migration.rs
gangov Feb 29, 2024
e07f3db
stake: staking_rewards - fixes the final test
gangov Feb 29, 2024
82f89f9
stake: unbond_all.rs - removes a test scenario that is already tested
gangov Feb 29, 2024
a25629b
stake: quick_unbond.rs - better initial_setup()
gangov Feb 29, 2024
ccfb398
stake: quick_unbond.rs - removes an unnecessary test
gangov Feb 29, 2024
b793564
stake: quick_unbond.rs: fixes and removes tests
gangov Feb 29, 2024
2f5115b
stake: ready for review
gangov Feb 29, 2024
c3b4200
stake: lints
gangov Feb 29, 2024
76086f5
stake: distribution.rs - adds a test that should not have been deleted
gangov Mar 1, 2024
6dd1a56
stake: distribution.rs adds and renames cw20_apr to native_apr
gangov Mar 1, 2024
ba47d72
stake: distribution.rs lints
gangov Mar 1, 2024
88ae912
stake: remove migration.rs and adds 3 tests to staking_rewards.rs
gangov Mar 1, 2024
4aefdc4
stake: better namingn for test
gangov Mar 1, 2024
536a747
stake: unbond_all - adds back delegate_with_unbond_all_flag
gangov Mar 1, 2024
3b89d08
stake: unbond_all.rs adds one more test back
gangov Mar 1, 2024
9818bd9
stake: unbond_all.rs adds back multiple_distribution_flows
gangov Mar 1, 2024
ac02f6b
stake: removes artifacts
gangov Mar 14, 2024
89db1e2
stake: returns an assertion
gangov Mar 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 1 addition & 6 deletions contracts/stake/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,22 @@ library = []

[dependencies]
dex = { workspace = true }
# cw-plus
cw-utils = { workspace = true }
cw2 = { workspace = true }
cw20 = { workspace = true }
cw-controllers = { workspace = true }
cw-storage-plus = { workspace = true }
# core cosmwasm
cosmwasm-std = { workspace = true }
coreum-wasm-sdk = { workspace = true }
# standard libs
cosmwasm-schema = { workspace = true }
serde = { workspace = true }
thiserror = { workspace = true }
wynd-curve-utils = { workspace = true }

[dev-dependencies]
# cw-plus
cw-multi-test = { workspace = true }
cw20-base = { workspace = true }
# core cosmwasm
cosmwasm-schema = { workspace = true }
# standard libs
bindings-test = { workspace = true }
anyhow = { workspace = true }
test-case = { workspace = true }
4 changes: 2 additions & 2 deletions contracts/stake/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ pub mod msg;
/// state on the blockchain
pub mod state;

// #[cfg(test)]
// mod multitest;
#[cfg(test)]
mod multitest;
/// some helper functions
mod utils;
pub use crate::error::ContractError;
11 changes: 5 additions & 6 deletions contracts/stake/src/multitest.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// mod delegate;
// mod distribution;
// mod migration;
// mod quick_unbond;
// mod staking_rewards;
mod delegate;
mod distribution;
mod quick_unbond;
mod staking_rewards;
mod suite;
// mod unbond_all;
mod unbond_all;
114 changes: 35 additions & 79 deletions contracts/stake/src/multitest/delegate.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
use super::suite::{SuiteBuilder, SEVEN_DAYS};
use cosmwasm_std::Uint128;
use cw_controllers::Claim;

use super::suite::{SuiteBuilder, SEVEN_DAYS};
const DENOM: &str = "VEST";
const USER: &str = "user_addr_0000";

#[test]
fn delegate_and_unbond_tokens_still_vested() {
let user = "user";
let balances = vec![(USER, 100_000u128)];
let mut suite = SuiteBuilder::new()
.with_initial_balances(vec![(user, 100_000)])
.with_native_balances(DENOM, balances)
.with_lp_share_denom(DENOM.to_string())
.build();

assert_eq!(
suite.query_balance_vesting_contract(user).unwrap(),
suite.query_balance_vesting_contract(USER).unwrap(),
100_000u128
);

// delegate half of the tokens, ensure they are staked
suite.delegate(user, 50_000u128, None).unwrap();
assert_eq!(suite.query_staked(user, None).unwrap(), 50_000u128);
suite.delegate(USER, 50_000u128, None).unwrap();
assert_eq!(suite.query_staked(USER, None).unwrap(), 50_000u128);
assert_eq!(
suite.query_balance_vesting_contract(user).unwrap(),
suite.query_balance_vesting_contract(USER).unwrap(),
50_000u128
);
assert_eq!(
Expand All @@ -30,16 +33,16 @@ fn delegate_and_unbond_tokens_still_vested() {
);

// undelegate and unbond all
suite.unbond(user, 50_000u128, None).unwrap();
suite.unbond(USER, 50_000u128, None).unwrap();
// nothing is staked
assert_eq!(suite.query_staked(user, None).unwrap(), 0u128);
assert_eq!(suite.query_staked(USER, None).unwrap(), 0u128);
// Balance is the same until claim is available
assert_eq!(
suite.query_balance_vesting_contract(user).unwrap(),
suite.query_balance_vesting_contract(USER).unwrap(),
50_000u128
);

let claims = suite.query_claims(user).unwrap();
let claims = suite.query_claims(USER).unwrap();
assert_eq!(claims.len(), 1);
assert!(matches!(
claims[0],
Expand All @@ -50,53 +53,56 @@ fn delegate_and_unbond_tokens_still_vested() {
));

suite.update_time(SEVEN_DAYS * 2); // update height to simulate passing time
suite.claim(user).unwrap();
let claims = suite.query_claims(user).unwrap();
suite.claim(USER).unwrap();
let claims = suite.query_claims(USER).unwrap();
assert_eq!(claims.len(), 0);
// after expiration time passed, tokens can be claimed and transferred back to user account
assert_eq!(
suite.query_balance_vesting_contract(user).unwrap(),
suite.query_balance_vesting_contract(USER).unwrap(),
100_000u128
);
}

#[test]
fn mixed_vested_liquid_delegate_and_transfer_remaining() {
let user = "user";
let balances = vec![(USER, 100_000u128)];
let mut suite = SuiteBuilder::new()
.with_initial_balances(vec![(user, 100_000)])
.with_native_balances(DENOM, balances)
.with_lp_share_denom(DENOM.to_string())
.build();

assert_eq!(
suite.query_balance_vesting_contract(user).unwrap(),
suite.query_balance_vesting_contract(USER).unwrap(),
100_000u128
);

suite.delegate(user, 60_000u128, None).unwrap(); // delegate some of vested tokens as well
assert_eq!(suite.query_staked(user, None).unwrap(), 60_000u128);
suite.delegate(USER, 60_000u128, None).unwrap(); // delegate some of vested tokens as well
assert_eq!(suite.query_staked(USER, None).unwrap(), 60_000u128);
assert_eq!(
suite.query_balance_vesting_contract(user).unwrap(),
suite.query_balance_vesting_contract(USER).unwrap(),
40_000u128
);

// transfer remaining 40_000 to a different address, to show that vested tokens are delegated
// first
assert_eq!(
suite.query_balance_vesting_contract(user).unwrap(),
suite.query_balance_vesting_contract(USER).unwrap(),
40_000u128
);
suite.transfer(user, "random_user", 40_000u128).unwrap();
suite
.transfer(USER, "random_user", (40_000u128, DENOM.to_string()))
.unwrap();

assert_eq!(suite.query_balance_vesting_contract(user).unwrap(), 0u128); // user has empty
assert_eq!(suite.query_balance_vesting_contract(USER).unwrap(), 0u128); // user has empty
// account now

// undelegate some of the tokens
suite.unbond(user, 20_000u128, None).unwrap();
assert_eq!(suite.query_staked(user, None).unwrap(), 40_000u128); // 60_000 delegated - 20_000
suite.unbond(USER, 20_000u128, None).unwrap();
assert_eq!(suite.query_staked(USER, None).unwrap(), 40_000u128); // 60_000 delegated - 20_000
// unbonded
assert_eq!(suite.query_balance_vesting_contract(user).unwrap(), 0u128);
assert_eq!(suite.query_balance_vesting_contract(USER).unwrap(), 0u128);

let claims = suite.query_claims(user).unwrap();
let claims = suite.query_claims(USER).unwrap();
assert!(matches!(
claims[0],
Claim {
Expand All @@ -106,59 +112,9 @@ fn mixed_vested_liquid_delegate_and_transfer_remaining() {
));

suite.update_time(SEVEN_DAYS); // update height to simulate passing time
suite.claim(user).unwrap();
suite.claim(USER).unwrap();
assert_eq!(
suite.query_balance_vesting_contract(user).unwrap(),
suite.query_balance_vesting_contract(USER).unwrap(),
20_000u128
);
}

#[test]
fn delegate_as_properly_assigned() {
let user = "factory";
let user2 = "client";
let mut suite = SuiteBuilder::new()
.with_initial_balances(vec![(user, 100_000)])
.build();

assert_eq!(
suite.query_balance_vesting_contract(user).unwrap(),
100_000u128
);

// delegate half of the tokens, ensure they are staked
suite
.delegate_as(user, 50_000u128, None, Some(user2))
.unwrap();
assert_eq!(suite.query_staked(user, None).unwrap(), 0u128);
assert_eq!(suite.query_staked(user2, None).unwrap(), 50_000u128);
assert_eq!(
suite.query_balance_vesting_contract(user).unwrap(),
50_000u128
);
}

#[test]
fn mass_delegation_simple_case() {
let user = "factory";
let user2 = "client";
let mut suite = SuiteBuilder::new()
.with_initial_balances(vec![(user, 100_000)])
.build();

assert_eq!(
suite.query_balance_vesting_contract(user).unwrap(),
100_000u128
);

// delegate half of the tokens, ensure they are staked
suite
.mass_delegate(user, 50_000u128, None, &[(user2, 50_000u128)])
.unwrap();
assert_eq!(suite.query_staked(user, None).unwrap(), 0u128);
assert_eq!(suite.query_staked(user2, None).unwrap(), 50_000u128);
assert_eq!(
suite.query_balance_vesting_contract(user).unwrap(),
50_000u128
);
}
Loading
Loading