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
This commit is contained in:
David 2023-07-09 22:43:44 -04:00 committed by GitHub
parent b527f5d0d6
commit 000a1326c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 9 deletions

@ -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<String>,

@ -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
);