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

Debugging usercredit, userprofile, balance display issues, Kenyon #346

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

pwdel
Copy link
Member

@pwdel pwdel commented Sep 27, 2024

  • Attempting to debug usercredit problem seen on Kenyon instance

@pwdel pwdel requested a review from ajlacey September 27, 2024 13:38
@pwdel pwdel self-assigned this Sep 27, 2024
@pwdel pwdel linked an issue Sep 27, 2024 that may be closed by this pull request
@pwdel
Copy link
Member Author

pwdel commented Sep 27, 2024

Tested on local after modifications, it's displaying credits as expected in the case of no wins, only investment so far, from one user, as previous. This is after having converted the integertype to int64.

image

  • Need to possibly look at building scenarios that mimic the Kenyon betting history.
  • Need to write tests for the balance display as this also seems to be a known problem.

@pwdel
Copy link
Member Author

pwdel commented Sep 27, 2024

Setup we're working with for test case:

https://github.com/ajlacey/socialpredict/blob/main/backend/setup/setup.yaml

economics:
  marketcreation:
    initialMarketProbability: 0.5
    initialMarketSubsidization: 10
    initialMarketYes: 0
    initialMarketNo: 0
  marketincentives:
    createMarketCost: 10
    traderBonus: 1
  user:
    initialAccountBalance: 0
    maximumDebtAllowed: 5000
  betting:
    minimumBet: 1
    betFees:
      initialBetFee: 1
      eachBetFee: 0
      sellSharesFee: 0

@pwdel pwdel changed the title Adding usercredit and test. Debugging usercredit, userprofile, balance display issues, Kenyon Sep 27, 2024
// user portfolio, (which is public)
router.HandleFunc("/v0/portfolio/{username}", usershandlers.GetPublicUserPortfolio).Methods("GET")
router.HandleFunc("/v0/portfolio/{username}", publicuser.GetPublicUserPortfolio).Methods("GET")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because we use the package name before calling the handler, this call looks redundant (it stutters). Consider renaming the function to Portfolio or GetPortfolio so that the call would look like publicuser.Portfolio or publicuser.GetPortfolio.

This can be applied to the other handlers that are being updated in the server as well.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider renaming this file to portfolio.go since it is a member of the publicuser package.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to add an empty test file. If you're planning to add tests, I would add this file as part of the PR that adds the tests.

Comment on lines +16 to +19
// Migrate the User model
if err := db.AutoMigrate(&models.User{}); err != nil {
t.Fatalf("Failed to migrate user model: %v", err)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NewFakeDB(t) migrates the models on creation, so this is redundant.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as publicuser_test- this isn't necessary unless you're adding tests. Since there is no new privateuser code here, I think it makes sense to add this when we create tests for the privateuser package.

@@ -0,0 +1,68 @@
package usercredit_test
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this should be a separate package. We're not exporting test functionality here.

@@ -53,12 +55,11 @@ func GetUserCreditHandler(w http.ResponseWriter, r *http.Request) {

}

func calculateUserCredit(db *gorm.DB, username string) int {
func CalculateUserCredit(db *gorm.DB, username string, maximumdebt int64) int64 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function can remain private when the testing is done in the same package.

Comment on lines +16 to +19
db := modelstesting.NewFakeDB(t)
if err := db.AutoMigrate(&models.User{}); err != nil {
t.Fatalf("Failed to migrate models: %v", err)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

db migration happens when creating the fake.

Username: test.username,
Email: test.email,
AccountBalance: test.accountBalance,
ApiKey: test.apiKey,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this field necessary to create a user? It doesn't look like it, but I may misunderstand the gorm struct tagging. If it's not necessary, I don't think we're using this field in the tests at all and can safely remove it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Credits Not Displaying Properly Under Certain Conditions
2 participants