-
Notifications
You must be signed in to change notification settings - Fork 7
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
Acammm/unit tests -- Add more unit tests feat @cnek #118
Conversation
}, | ||
Err(error) => { | ||
match error { | ||
UxdError::ProgramError(_) => todo!(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still a few things to iron out
/// order_price between 0$ and 100_000 | ||
/// slippage between 0.01% and 100% | ||
#[test] | ||
fn test_check_effective_order_price_versus_limit_price_mint(perp_price in 0.0f64..10f64, order_price in 0.0f64..10f64, slippage in 1..SLIPPAGE_BASIS) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the range shd be 100_000 * 10^9 here for generate a random price in lamport according to the comments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
slippage in 1..SLIPPAGE_BASIS here is equivalent to 0.1% -> 100%
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great tests! :)
} else { | ||
assert!(true); | ||
} | ||
assert!(ret.is_ok()); | ||
} | ||
|
||
// REDEEM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should remove this comment, or sort the tests and insert two comments:
// MINT
// REDEEM
@@ -60,183 +66,183 @@ pub fn check_effective_order_price_versus_limit_price( | |||
Err(throw_err!(UxdErrorCode::SlippageReached)) | |||
} | |||
|
|||
// Non regression tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do you define a test as a non regression test versus a regular unit test?
|
||
#[test] | ||
pub fn test_check_effective_order_price_versus_limit_price_mint_valid_zslip() { | ||
pub fn test_check_effective_order_price_versus_limit_price_mint_valid_small_slippage() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
may be interesting to wrap the tests into a dedicated mod:
mod check_effective_order_price_versus_limit_price {
use super::*;
#[test]
pub fn test_mint_valid_small_slippage() {
// Order.price must be below the perpInfo.price within slippage
let perp_info = mocked_perp_info(0.09000);
let order = mocked_order(&perp_info, 0.09000, Side::Bid).unwrap();
let ret = check_effective_order_price_versus_limit_price(
&perp_info, &order, 1, // 0.1%
);
assert!(ret.is_ok());
}
#[test]
pub fn test_mint_valid() {
let perp_info = mocked_perp_info(0.090);
let order = mocked_order(&perp_info, 0.08911, Side::Bid).unwrap();
let ret = check_effective_order_price_versus_limit_price(
&perp_info, &order, 10, // 1%
);
assert!(ret.is_ok());
}
#[test]
pub fn test_redeem_valid_small_slippage() {
let perp_info = mocked_perp_info(0.090);
let order = mocked_order(&perp_info, 0.09000, Side::Ask).unwrap();
let ret = check_effective_order_price_versus_limit_price(
&perp_info, &order, 1, // 0.1%
);
assert!(ret.is_ok());
}
#[test]
pub fn test_mint_invalid() {
let perp_info = mocked_perp_info(0.090);
let order = mocked_order(&perp_info, 0.08909, Side::Bid).unwrap();
let ret = check_effective_order_price_versus_limit_price(
&perp_info, &order, 10, // 1%
);
assert!(ret.is_err());
}
#[test]
pub fn test_redeem_valid() {
let perp_info = mocked_perp_info(0.090);
let order = mocked_order(&perp_info, 0.09089, Side::Ask).unwrap();
let ret = check_effective_order_price_versus_limit_price(
&perp_info, &order, 10, // 1%
);
assert!(ret.is_ok());
}
#[test]
pub fn test_redeem_invalid() {
let perp_info = mocked_perp_info(0.090);
let order = mocked_order(&perp_info, 0.09091, Side::Ask).unwrap();
let ret = check_effective_order_price_versus_limit_price(
&perp_info, &order, 10, // 1%
);
assert!(ret.is_err());
}
}
Produce the given output:
test mango_utils::limit_utils::tests::check_effective_order_price_versus_limit_price::test_mint_invalid ... ok
test mango_utils::limit_utils::tests::check_effective_order_price_versus_limit_price::test_mint_valid ... ok
test mango_utils::limit_utils::tests::check_effective_order_price_versus_limit_price::test_mint_valid_small_slippage ... ok
test mango_utils::limit_utils::tests::check_effective_order_price_versus_limit_price::test_redeem_invalid ... ok
test mango_utils::limit_utils::tests::check_effective_order_price_versus_limit_price::test_redeem_valid ... ok
test mango_utils::limit_utils::tests::check_effective_order_price_versus_limit_price::test_redeem_valid_small_slippage ... ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to do some edits btw. I'll tend to these but free to add anything
thinking... may even use:
|
match uxd_error_code { | ||
UxdErrorCode::MathError => prop_assert!(true), | ||
UxdErrorCode::SlippageReached => { | ||
prop_assert!(order_price <= limit_price); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shd be just <
match uxd_error_code { | ||
UxdErrorCode::MathError => prop_assert!(true), | ||
UxdErrorCode::SlippageReached => { | ||
prop_assert!(order_price >= limit_price); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shd be just >
UxdError::UxdErrorCode { uxd_error_code, line: _, source_file_id } => { | ||
prop_assert_eq!(source_file_id, SourceFileId::MangoUtilsLimitUtils); | ||
match uxd_error_code { | ||
UxdErrorCode::MathError => prop_assert!(true), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shdn't expect any MathError for any value received here in the legit range,
better assert false here,
and add them to the seed for failure cases of proptest,
and fix the actual program
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similar comments for all proptest in this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've not sent value in the "legit range" iirc
Ok makes sense
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I go back to CI and let you have a look at discussed
* feat: moved function validation from lib.rs to each instruction file (#91) * feat: moved function validation from lib.rs to each instruction file * Integration Tests and CI improvements (#92) * Several small improvments * Test now use container wallet without any ties to other executions. The previous wallet now became the bank. * Update devnet id * feat: moved function validation from lib.rs to each instruction file (#91) * feat: moved function validation from lib.rs to each instruction file * cleanup * Update CI * Fix sol transfer * Remove fees from the moved amount * Fix CI * Update CI * CI * CI * CI * ci * trigger build * Update CI * CI * Remove small values in test that are offsetted by the rent and fee until we implement payer/signer in the mint/redeem * Fees * Actually wait for TX to be confirmed before going further to prevent unreliable results * Move await to the API * Increase fee offset toprevent issues Increase crank interval for devnet Cleanup * - Upgrade to latest UXD Client - fix collapsed group - fix display in insurance tests * - fix authority typo * Test close * fix lamports * Fix Cleanup * Sol not lamports in CI transfer * Remove small amount tests * remove unneeded provider Co-authored-by: Lexington Brill <[email protected]> * Use a fresh provider each time for test * 2.0.1 - Improve computing + IDL update for typo (#95) * + Cleanup + remove msg! + improve computing used mango anchor wrapper * Update version due to IDL change * Fix typo "roty" * Update client to 4.16 * Update UXD-client to 4.17.0 * fixed version uxd-client * commented emit * - Remove warning with unused import - Comment about commenting out the events emits * Add missing error (It was using the other slippage error, which is not the correct one!) Co-authored-by: cnek <[email protected]> * Multi Collateral Testing (#99) * Not all tests passing, need to improve the ones with the redeemable_soft cap cause it's different for SOL, BTC and ETH * Update client * Update mangoDepositoryIntegrationSuite.ts * Fixing tests * Added more test cases * Add BTC and ETH to CI market making * Update uxd-client * Update tests * unit test + prop test (#98) * prop test trial * test limit_price from mango_utils (#88) * test limit_price * minor * limit price test 2 (#94) * wip * wip * i80f48 cal test * rm * updated workflow file Co-authored-by: Acammm <[email protected]> * Have the SOL tests back * Fix missing insurance parameter in tests * Feature/add payer to mint and redeem (#100) * Add a payer to mint and redeem * Working * Add changelog + update version * Trigger CI * Trigger CI * Update UXD-Client * Update UXD-Client * ETH integration tests. (#102) * Eth testing * Missing return for ETH * Fix CI with multiple MM accounts (#105) * Update solana version to latest cluster-version * New accounts on mango * enhancement/soteria_ci (#108) * try 2. copy pasted from drift * no cd * working * Rebalancing-lite (#107) * WIP No tests - no settlement of PNL (maybe todo) * FIx stack blowup + 3.0.0 idl * Controller not mutable in the migrate IX * Update IDL * Remove uneeded mut of controller in some instances (harmeless but useless) + update IDL * Add sec checks to depository account in migrate * Add depository version check for the rebalance call + upgrade idl * Migrate + tests OK * Fix migrate test * Use BOX to prevent stackoverflow * Working tests pre rebalance testing * wip rebalancing * Mocha awsome + reog tests.. (not the place but I was having some issues. Too much work, easier to pack) Rebalancing tests WIP * Provider -> Connection Readme * Payer .publicKey * More refactoring. Almost there * Fix readme * Working tests for rebalancing * Updates devnets and Readme * Working * Upgrade tests * Improve tests * Remove print * Update changelog * Tag version as beta. Add tests * Fix tests * Unlock regular tests * Upgrade anchor version * Fix slippage display * Fix tests * Update Mango + fix tests * Use functions * v2.1.0 - Hotfix/mango-taker-fee-changes (#112) * Dependencies update to match mango - update to mango v3.3.5 - update solana to 1.9.1 (to do as mango, they use 1.9.1) - update anchor-lang to 0.20.1 (required by mango) - update anchor-spl to 0.20.1 (required by mango) * Owner now passed as signer always. Remove the additional owner passed twice. This was done to support multisig in a previous version of their code IIRC It's not deprecated and breaking since their last update as they have a new optional account that takes the first spot. * Upgrade version to 2.1.0 * Add changelog * Update cargo lock and dependencies after rebasing * Improve integration tests - better redeem and mint maths - rebalancing improved * Remove only tests * Fix the redeem min amount test (#114) * reversed sub/add * naming * acammm/move-unit-tests-to-another-ci (#115) * Separate workflows + tweaks * Update unit tests CI * Split test and test-bpf + simplications * Cleanup + add lint and audit * Add color on audit + fix cluster * Update funding for e2e tests * Remove anchor test from CI too costy and failish * Fix errors from cargo fmt -- --check * Disable clippy * Add flag for fixing clippy * trigger anchor test * Trigger ci anchor test * Test fund.sh * Test fund.sh * Fix env variable capitalization * Test fund.sh * Test fund.sh * Trigger ci * reduce funding amount * update uxd-client to 5.0.0-beta3 send extras to bank instead of faucet * Add suites in describe for easy skip (#116) * Fix and rework the ci so that it's faster and more reliable (#117) * Update CI to use 2 wallets for MM and deployments * Fix env variable name * Trigger ci * Use current cluster version * Solana version change * Update wrap up code in ci * Workspace lint lingo * Improved performances for CI * Fix CI * Fix CI * Fix CI * fix ci * Solana install fix * Fix ci * Fix ci * Fix CI * Fix ci * dev do something * hehe * Fix CI * Add some clippy stuff * ci trigger * Without the trigger of audit and all * Please clippy * Please clippy * CI * clippy * more ci * ci fix * Updated * Fix ci * Mega CI * CI * ibakkk * Fix ci * Fix rebalancing * Update CI * Upgrade readme * Ok * CI * Ci * ci * Ci * Update ci * build up * CI * Optim for solana cache in tests * ww * qq * bpf * Rebalancing print issues hwen negative * Fix bpf * ci * Fix Tests * trigger ci * CI * ci * CI * CI fix * Anchor * Skip BTC Test in the BTC CI * Acammm/unit tests -- Add more unit tests feat @cnek (#118) * cleanup regression tests * Add prop tests * misc * Order unit test * Cleanup * fix warning * Add more tests * Remive todos * Add tests for order_delta * Update number format for readability * Refactor tests names * restructure * fixed fmt * minor udates on assertion * run rustup updates * fixed up * fixed up Co-authored-by: cnek <[email protected]> * Acammm/upgrade anchor 0.21.0 (cherry picking @cnek work) (#120) * Updgrade anchor version * updated anchor * Updated Anchor + use new ci program due to layout change between last rebalancing implementation * And use a new program ID * Please Clippy and fmt * Add back some prints + cleanup old ones * Fix cargo.toml * Update IDL and uxd-client * fmt Co-authored-by: cnek <[email protected]> * Update doc and client * Changelog * Fix CI triggers * Upgrade CI resident program * Add sleep to keep alive the MM job in CI * - Fix the mint redeem amount - add badge for ci on mangomarkets - remove size from Order as it's unused - tests tweaks * Remove the sleep on MM bots in CI * Fix cargo tests * Moves bots to other jobs * Update tests names * Trigger CI * Disable Anchor Events in mint and redeem for computing savings * Fix clippy + update rust toolchain version in CI * Reduce sol used by e2e tests * - new default test - add logs to mint and redeem * - get_best_order_for_quote_lot_amount and get_best_order_for_base_lot_quantity now return the correct error when order not found - get_best_order_for_base_lot_quantity not return the order with the proper side (was unused) - Tests E2E tweaks - More explicit names for order books related operations * Added comments for each input accounts (#122) * acammm/lighter-minting (#123) * - take 0 slippage as invalid for simplification for now. Front end dont take 0 as input. - the minting now just do an euclidian division to remove the oddlots and place that order with the worst price. - It does check afterward for slippage - updated unit tests * Cleanups * Fix tests + some comments * Fix Comment type @cnek * Add comments for accounts # * - fix rebalancing sides - simplify PerpInfo * Typos * Add PnL settlement * Save computing for redeem * Trigger CI * Trigger CI * Latest mocha for dependabot alerts * Fix polarity issue and overflow of i128 + fix tests for rebalancing * Upgrade resident program ID (CI), and add a script to do so * acammm/proper-support-mango-ref-fees (#124) * - fix rebalancing positive PnL tests - remove euclidian division (seems to have a very tiny leftover sometimes not sure why - support for new ref fees * Add a payer in the wrapped sol call to not mess with the tests - add logs in mint since a lot of computing left (and no CPI possible due to size) * Remove janky calculus with micro leftovers * Fix tests + rebalancing * Use right test in anchor.toml * User https://api.devnet.solana.com * Update CI * Save computing for rebalancing * fmt * Mint/redeem a bit amove min size to not fail CI on price changes * Remove useless I80F48 conversion * Add missing initialisation for the total amount rebalanced + test improvments * Add badges * Add badges Co-authored-by: Lexington Brill <[email protected]> Co-authored-by: cnek <[email protected]>
As titled.