package luckygift import ( "testing" ) func TestDefaultConfigPassesValidation(t *testing.T) { config := DefaultConfig("hyapp", "pool_95") config.Enabled = true if err := validateConfig(config); err != nil { t.Fatalf("default lucky gift config should be publishable: %v", err) } } func TestValidateConfigAcceptsIndependentPoolScope(t *testing.T) { config := DefaultConfig("hyapp", "pool_98") config.Enabled = true if err := validateConfig(config); err != nil { t.Fatalf("expected pool scoped lucky gift config to pass: %v", err) } } func TestNormalizeTiersBuildsMultiplierDrivenTiers(t *testing.T) { tiers, multipliers := normalizeTiers(nil, []int64{0, 500_000, 2_000_000}, 500, 100) if len(multipliers) != 3 || multipliers[1] != 500_000 || multipliers[2] != 2_000_000 { t.Fatalf("expected normalized multiplier list, got %#v", multipliers) } if len(tiers) != 9 { t.Fatalf("expected three pools times three multipliers, got %d", len(tiers)) } for _, tier := range tiers { if !tier.Enabled || tier.Weight != 0 { t.Fatalf("tier should be enabled with runtime-generated weight: %#v", tier) } if tier.MultiplierPPM == 500_000 && tier.RewardCoins != 250 { t.Fatalf("expected 0.5x reward to follow reference cost, got %#v", tier) } } } func TestNormalizeTiersDoesNotForceZeroMultiplier(t *testing.T) { tiers, multipliers := normalizeTiers(nil, []int64{1_000_000, 2_000_000}, 500, 100) if len(multipliers) != 2 || multipliers[0] != 1_000_000 || multipliers[1] != 2_000_000 { t.Fatalf("expected positive-only multiplier list to stay positive-only, got %#v", multipliers) } for _, tier := range tiers { if tier.MultiplierPPM == 0 || tier.RewardCoins == 0 { t.Fatalf("positive-only test config must not generate none tier: %#v", tier) } } } func TestValidateConfigRejectsMultiplierListBelowTargetRTP(t *testing.T) { config := DefaultConfig("hyapp", "pool_low") config.MultiplierPPMs = []int64{0, 500_000} config.Tiers, config.MultiplierPPMs = normalizeTiers(nil, config.MultiplierPPMs, config.GiftPrice, config.HighMultiplier) if err := validateConfig(config); err == nil { t.Fatalf("expected max multiplier below RTP to be rejected") } }