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:
parent
b527f5d0d6
commit
000a1326c3
@ -33,7 +33,7 @@ pub struct User {
|
|||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct Referral {
|
pub struct Referral {
|
||||||
pub credits_applied_for_referee: bool,
|
pub credits_applied_for_referee: String,
|
||||||
pub credits_applied_for_referrer: String,
|
pub credits_applied_for_referrer: String,
|
||||||
pub referral_start_date: String,
|
pub referral_start_date: String,
|
||||||
pub referred_address: Option<String>,
|
pub referred_address: Option<String>,
|
||||||
|
@ -195,10 +195,9 @@ async fn test_user_balance_decreases() {
|
|||||||
Decimal::from(0)
|
Decimal::from(0)
|
||||||
);
|
);
|
||||||
// Check that total credits incl free used is larger than 0
|
// Check that total credits incl free used is larger than 0
|
||||||
assert!(
|
let previously_free_spent =
|
||||||
Decimal::from_str(user_balance_response["total_spent"].as_str().unwrap()).unwrap()
|
Decimal::from_str(user_balance_response["total_spent"].as_str().unwrap()).unwrap();
|
||||||
> Decimal::from(0)
|
assert!(previously_free_spent > Decimal::from(0));
|
||||||
);
|
|
||||||
|
|
||||||
// Bump both user's wallet to $20
|
// Bump both user's wallet to $20
|
||||||
admin_increase_balance(
|
admin_increase_balance(
|
||||||
@ -239,7 +238,8 @@ async fn test_user_balance_decreases() {
|
|||||||
.as_str()
|
.as_str()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
)
|
)
|
||||||
.unwrap(),
|
.unwrap()
|
||||||
|
+ previously_free_spent,
|
||||||
Decimal::from_str(user_balance_response["total_spent"].as_str().unwrap()).unwrap()
|
Decimal::from_str(user_balance_response["total_spent"].as_str().unwrap()).unwrap()
|
||||||
);
|
);
|
||||||
// Get the full balance endpoint
|
// Get the full balance endpoint
|
||||||
@ -248,14 +248,14 @@ async fn test_user_balance_decreases() {
|
|||||||
assert!(user_balance_post < user_balance_pre);
|
assert!(user_balance_post < user_balance_pre);
|
||||||
|
|
||||||
// Balance should be total deposits - usage while in the paid tier
|
// Balance should be total deposits - usage while in the paid tier
|
||||||
let total_spent_outside_free_tier = Decimal::from_str(
|
let total_spent_in_paid_credits = Decimal::from_str(
|
||||||
user_balance_response["total_spent_outside_free_tier"]
|
user_balance_response["total_spent_paid_credits"]
|
||||||
.as_str()
|
.as_str()
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
total_deposits - total_spent_outside_free_tier,
|
total_deposits - total_spent_in_paid_credits,
|
||||||
user_balance_post
|
user_balance_post
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user