From 000a1326c3ccdcfe357a02f3e0a7303d02feb95c Mon Sep 17 00:00:00 2001 From: David Date: Sun, 9 Jul 2023 22:43:44 -0400 Subject: [PATCH] New Balance Logic (#174) * WIP will work on locks * added concurrent test for referral, numbers rn still add up * will change balance table to be a view instead of a table * merged in devel. will proceed with migrations for rpc_stats_v2 and referral * WIP * WIP * WIP compiling * gotta add the balance_v2 view * about to add balance view * stupid missing closing param * compiles again, now i will just have to implement the raw sql * need to paste the real query and play with it * ok now on to testing * addresses many comments in PR * app works for simple unauthorized access. will look into tests * some tests pass, referral logic tests fail * not sure why the test is failing * invalidate cache for admin, will check for more possible targets * user balance decrease test works * all tests pass --- web3_proxy/tests/common/referral.rs | 2 +- web3_proxy/tests/test_users.rs | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/web3_proxy/tests/common/referral.rs b/web3_proxy/tests/common/referral.rs index 639d3a8d..b40a86ca 100644 --- a/web3_proxy/tests/common/referral.rs +++ b/web3_proxy/tests/common/referral.rs @@ -33,7 +33,7 @@ pub struct User { #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Referral { - pub credits_applied_for_referee: bool, + pub credits_applied_for_referee: String, pub credits_applied_for_referrer: String, pub referral_start_date: String, pub referred_address: Option, diff --git a/web3_proxy/tests/test_users.rs b/web3_proxy/tests/test_users.rs index 82d8c000..7218082a 100644 --- a/web3_proxy/tests/test_users.rs +++ b/web3_proxy/tests/test_users.rs @@ -195,10 +195,9 @@ async fn test_user_balance_decreases() { Decimal::from(0) ); // Check that total credits incl free used is larger than 0 - assert!( - Decimal::from_str(user_balance_response["total_spent"].as_str().unwrap()).unwrap() - > Decimal::from(0) - ); + let previously_free_spent = + Decimal::from_str(user_balance_response["total_spent"].as_str().unwrap()).unwrap(); + assert!(previously_free_spent > Decimal::from(0)); // Bump both user's wallet to $20 admin_increase_balance( @@ -239,7 +238,8 @@ async fn test_user_balance_decreases() { .as_str() .unwrap() ) - .unwrap(), + .unwrap() + + previously_free_spent, Decimal::from_str(user_balance_response["total_spent"].as_str().unwrap()).unwrap() ); // Get the full balance endpoint @@ -248,14 +248,14 @@ async fn test_user_balance_decreases() { assert!(user_balance_post < user_balance_pre); // Balance should be total deposits - usage while in the paid tier - let total_spent_outside_free_tier = Decimal::from_str( - user_balance_response["total_spent_outside_free_tier"] + let total_spent_in_paid_credits = Decimal::from_str( + user_balance_response["total_spent_paid_credits"] .as_str() .unwrap(), ) .unwrap(); assert_eq!( - total_deposits - total_spent_outside_free_tier, + total_deposits - total_spent_in_paid_credits, user_balance_post );