Summary
Replace hardcoded magic numbers with named constants — Hardcoded values like a 45 ms dummy latency, Soroban poll attempt counts, and password hash cost are scattered without explanation or named constants.
Social Media Link
Let's collaborate on Discord. And ensure to star our repo.
Problem Statement
Confirmed in project-portal/project-portal-backend/internal/integration/service.go, project-portal/project-portal-backend/internal/financing/tokenization/stellar_client.go, and project-portal/project-portal-backend/internal/auth/service.go:
-
Hardcoded dummy latency in integration health checks: TestConnection in integration/service.go sets LatencyMs: 45, // Dummy value with no named constant and no real measurement of the request round-trip.
-
Hardcoded default poll attempts: newRealClientFromEnv in stellar_client.go sets pollAttempts := 15 inline before checking CARBON_ASSET_POLL_ATTEMPTS — the fallback value has no named constant.
-
Hardcoded poll interval: RealStellarClient.pollInterval is set to a literal 2 * time.Second in newRealClientFromEnv with no named constant or environment override.
-
Hardcoded transaction timeout: txnbuild.NewTimeout(300) appears twice in stellar_client.go (simulation and submit transactions) as a bare literal 300 with no named constant explaining the 300-second choice.
-
Hardcoded default password hash cost: NewService in auth/service.go falls back to hashCost = 12 when hashCost == 0 is passed in, with no named constant documenting why 12 rounds was chosen.
-
Hardcoded default methodology mock start token: NewContractClientFromEnv-equivalent logic in the methodology client defaults startToken := 1000 inline (mirrors the same pattern as stellar_client.go's literals).
-
Hardcoded email/password-reset token expiry: generateAuthToken in auth/service.go defaults expiry to 24 * time.Hour when zero, and callers pass 24*time.Hour / 1*time.Hour literals directly rather than named constants (EmailVerificationTokenTTL, PasswordResetTokenTTL).
-
Webhook health check default latency has no unit-documented constant: The 45 in LatencyMs: 45 is unitless at the call site beyond the field name — a named constant with a comment would make the placeholder nature explicit and easy to grep for.
-
No single location for tunable defaults: These values (poll attempts, poll interval, timeout, hash cost, token TTLs) are scattered across three unrelated packages instead of being defined as named constants near their usage or in a shared internal constants package.
-
Magic numbers make placeholder code harder to find: Because 45 (dummy latency) is a bare literal, a future contributor removing mock/placeholder behavior (tracked in other issues) cannot grep for a named constant like DummyLatencyMs to find every such placeholder.
-
No tests pin these defaults: Because the values are inline literals, there are no unit tests asserting DefaultPollAttempts == 15 or DefaultPasswordHashCost == 12, so a future refactor could silently change behavior.
-
Inconsistent style with adjacent code: stellar_client.go already uses named constants for DefaultCarbonAssetContractID and defaultSorobanRPCURL — the poll attempts/interval/timeout literals sit right next to these named constants without the same treatment.
Required Changes
-
Add a named constant DefaultPollAttempts = 15 in stellar_client.go, replacing the inline literal.
-
Add a named constant DefaultPollInterval = 2 * time.Second, replacing the inline literal.
-
Add a named constant MintTransactionTimeoutSeconds = 300 (or time.Duration), replacing both txnbuild.NewTimeout(300) call sites.
-
Add a named constant DefaultPasswordHashCost = 12 in auth/service.go, replacing the inline fallback.
-
Add named constants EmailVerificationTokenTTL = 24 * time.Hour and PasswordResetTokenTTL = 1 * time.Hour, replacing literal call-site durations.
-
Add a named constant DefaultMethodologyMockStartToken = 1000 in the methodology contract client, replacing the inline literal.
-
Add a named constant PlaceholderHealthCheckLatencyMs = 45 with a comment explaining it is a temporary placeholder pending real latency measurement in TestConnection.
-
Consolidate related defaults (poll/timeout/hash-cost/TTL constants) at the top of their respective files, grouped and commented, consistent with the existing DefaultCarbonAssetContractID style.
-
Add unit tests asserting the named constants retain their expected default values.
-
Grep the rest of internal/ and pkg/ for similarly undocumented magic numbers introduced by the same author/PR pattern and apply the same treatment where found.
Acceptance Criteria
- No bare numeric literal remains for poll attempts, poll interval, or transaction timeout in
stellar_client.go.
- Password hash cost default is a named, documented constant.
- Email verification and password reset token TTLs are named constants.
- The dummy health-check latency is a named constant with a comment marking it as a placeholder.
- Methodology mock start token default is a named constant.
- All new constants are grouped consistently with existing constants in each file.
- Unit tests pin the value of each new constant.
- Behavior is unchanged — only naming/documentation improves, no functional regression.
Directory to Work on:
project-portal/project-portal-backend/
Summary
Replace hardcoded magic numbers with named constants — Hardcoded values like a
45ms dummy latency, Soroban poll attempt counts, and password hash cost are scattered without explanation or named constants.Social Media Link
Let's collaborate on Discord. And ensure to star our repo.
Problem Statement
Confirmed in
project-portal/project-portal-backend/internal/integration/service.go,project-portal/project-portal-backend/internal/financing/tokenization/stellar_client.go, andproject-portal/project-portal-backend/internal/auth/service.go:Hardcoded dummy latency in integration health checks:
TestConnectioninintegration/service.gosetsLatencyMs: 45, // Dummy valuewith no named constant and no real measurement of the request round-trip.Hardcoded default poll attempts:
newRealClientFromEnvinstellar_client.gosetspollAttempts := 15inline before checkingCARBON_ASSET_POLL_ATTEMPTS— the fallback value has no named constant.Hardcoded poll interval:
RealStellarClient.pollIntervalis set to a literal2 * time.SecondinnewRealClientFromEnvwith no named constant or environment override.Hardcoded transaction timeout:
txnbuild.NewTimeout(300)appears twice instellar_client.go(simulation and submit transactions) as a bare literal300with no named constant explaining the 300-second choice.Hardcoded default password hash cost:
NewServiceinauth/service.gofalls back tohashCost = 12whenhashCost == 0is passed in, with no named constant documenting why 12 rounds was chosen.Hardcoded default methodology mock start token:
NewContractClientFromEnv-equivalent logic in the methodology client defaultsstartToken := 1000inline (mirrors the same pattern asstellar_client.go's literals).Hardcoded email/password-reset token expiry:
generateAuthTokeninauth/service.godefaultsexpiryto24 * time.Hourwhen zero, and callers pass24*time.Hour/1*time.Hourliterals directly rather than named constants (EmailVerificationTokenTTL,PasswordResetTokenTTL).Webhook health check default latency has no unit-documented constant: The
45inLatencyMs: 45is unitless at the call site beyond the field name — a named constant with a comment would make the placeholder nature explicit and easy to grep for.No single location for tunable defaults: These values (poll attempts, poll interval, timeout, hash cost, token TTLs) are scattered across three unrelated packages instead of being defined as named constants near their usage or in a shared internal constants package.
Magic numbers make placeholder code harder to find: Because
45(dummy latency) is a bare literal, a future contributor removing mock/placeholder behavior (tracked in other issues) cannotgrepfor a named constant likeDummyLatencyMsto find every such placeholder.No tests pin these defaults: Because the values are inline literals, there are no unit tests asserting
DefaultPollAttempts == 15orDefaultPasswordHashCost == 12, so a future refactor could silently change behavior.Inconsistent style with adjacent code:
stellar_client.goalready uses named constants forDefaultCarbonAssetContractIDanddefaultSorobanRPCURL— the poll attempts/interval/timeout literals sit right next to these named constants without the same treatment.Required Changes
Add a named constant
DefaultPollAttempts = 15instellar_client.go, replacing the inline literal.Add a named constant
DefaultPollInterval = 2 * time.Second, replacing the inline literal.Add a named constant
MintTransactionTimeoutSeconds = 300(ortime.Duration), replacing bothtxnbuild.NewTimeout(300)call sites.Add a named constant
DefaultPasswordHashCost = 12inauth/service.go, replacing the inline fallback.Add named constants
EmailVerificationTokenTTL = 24 * time.HourandPasswordResetTokenTTL = 1 * time.Hour, replacing literal call-site durations.Add a named constant
DefaultMethodologyMockStartToken = 1000in the methodology contract client, replacing the inline literal.Add a named constant
PlaceholderHealthCheckLatencyMs = 45with a comment explaining it is a temporary placeholder pending real latency measurement inTestConnection.Consolidate related defaults (poll/timeout/hash-cost/TTL constants) at the top of their respective files, grouped and commented, consistent with the existing
DefaultCarbonAssetContractIDstyle.Add unit tests asserting the named constants retain their expected default values.
Grep the rest of
internal/andpkg/for similarly undocumented magic numbers introduced by the same author/PR pattern and apply the same treatment where found.Acceptance Criteria
stellar_client.go.Directory to Work on:
project-portal/project-portal-backend/