120 lines
3.9 KiB
Go
120 lines
3.9 KiB
Go
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")
|
|
}
|
|
}
|
|
|
|
func TestDefaultRuleConfigPassesValidation(t *testing.T) {
|
|
config := DefaultRuleConfig("hyapp", "pool_v2")
|
|
config.Enabled = true
|
|
|
|
if err := validateRuleConfig(config); err != nil {
|
|
t.Fatalf("default v2 lucky gift config should be publishable: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestValidateRuleConfigRejectsPercentSubmittedAsPPM(t *testing.T) {
|
|
config := DefaultRuleConfig("hyapp", "pool_bad_rtp")
|
|
config.TargetRTPPPM = 95
|
|
|
|
if err := validateRuleConfig(config); err == nil {
|
|
t.Fatalf("expected raw percent value in ppm field to be rejected")
|
|
}
|
|
}
|
|
|
|
func TestValidateRuleConfigRejectsStageWeightMismatch(t *testing.T) {
|
|
config := DefaultRuleConfig("hyapp", "pool_bad_weight")
|
|
config.Stages[0].Tiers[0].BaseWeightPPM = 299_999
|
|
|
|
if err := validateRuleConfig(config); err == nil {
|
|
t.Fatalf("expected stage probability sum mismatch to be rejected")
|
|
}
|
|
}
|
|
|
|
func TestValidateRuleConfigRejectsMissingRiskCaps(t *testing.T) {
|
|
config := DefaultRuleConfig("hyapp", "pool_bad_cap")
|
|
config.RoomHourlyPayoutCap = 0
|
|
|
|
if err := validateRuleConfig(config); err == nil {
|
|
t.Fatalf("expected missing v2 risk cap to be rejected")
|
|
}
|
|
}
|
|
|
|
func TestValidateRuleConfigRejectsInvalidEquivalentDrawThresholds(t *testing.T) {
|
|
config := DefaultRuleConfig("hyapp", "pool_bad_stage_threshold")
|
|
config.NormalMaxEquivalentDraws = config.NoviceMaxEquivalentDraws - 1
|
|
|
|
if err := validateRuleConfig(config); err == nil {
|
|
t.Fatalf("expected invalid equivalent draw thresholds to be rejected")
|
|
}
|
|
}
|
|
|
|
func TestValidateRuleConfigRequiresExplicitZeroTier(t *testing.T) {
|
|
config := DefaultRuleConfig("hyapp", "pool_no_zero")
|
|
config.Stages[1].Tiers = config.Stages[1].Tiers[1:]
|
|
|
|
if err := validateRuleConfig(config); err == nil {
|
|
t.Fatalf("expected stage without 0x tier to be rejected")
|
|
}
|
|
}
|