83 lines
2.2 KiB
Go
83 lines
2.2 KiB
Go
package main
|
|
|
|
import "testing"
|
|
|
|
func TestConfigValidateAllowsDefaultLocalConfig(t *testing.T) {
|
|
cfg := loadConfig()
|
|
cfg.ChainID = 84532
|
|
cfg.RequireOnchainTxVerify = false
|
|
cfg.ChainRPCURL = ""
|
|
if err := cfg.Validate(); err != nil {
|
|
t.Fatalf("expected default-like config valid, got %v", err)
|
|
}
|
|
}
|
|
|
|
func TestConfigValidateRejectsStrictVerificationWithoutRPC(t *testing.T) {
|
|
cfg := loadConfig()
|
|
cfg.RequireOnchainTxVerify = true
|
|
cfg.ChainRPCURL = ""
|
|
if err := cfg.Validate(); err == nil {
|
|
t.Fatalf("expected strict verification config validation failure")
|
|
}
|
|
}
|
|
|
|
func TestConfigValidateRejectsNonPositiveChainID(t *testing.T) {
|
|
cfg := loadConfig()
|
|
cfg.ChainID = 0
|
|
if err := cfg.Validate(); err == nil {
|
|
t.Fatalf("expected chain id validation failure")
|
|
}
|
|
}
|
|
|
|
func TestConfigValidateAllowsETHWhenDecimalsMatch(t *testing.T) {
|
|
cfg := loadConfig()
|
|
cfg.MintCurrency = "ETH"
|
|
cfg.MintDecimals = 18
|
|
cfg.MintAmountAtomic = "1"
|
|
if err := cfg.Validate(); err != nil {
|
|
t.Fatalf("expected ETH config to validate, got %v", err)
|
|
}
|
|
}
|
|
|
|
func TestConfigValidateRejectsETHWhenDecimalsMismatch(t *testing.T) {
|
|
cfg := loadConfig()
|
|
cfg.MintCurrency = "ETH"
|
|
cfg.MintDecimals = 6
|
|
if err := cfg.Validate(); err == nil {
|
|
t.Fatalf("expected ETH decimal validation failure")
|
|
}
|
|
}
|
|
|
|
func TestConfigValidateRejectsUSDCWhenDecimalsMismatch(t *testing.T) {
|
|
cfg := loadConfig()
|
|
cfg.MintCurrency = "USDC"
|
|
cfg.MintDecimals = 18
|
|
if err := cfg.Validate(); err == nil {
|
|
t.Fatalf("expected USDC decimal validation failure")
|
|
}
|
|
}
|
|
|
|
func TestConfigValidateRejectsInvalidMintAmount(t *testing.T) {
|
|
cfg := loadConfig()
|
|
cfg.MintAmountAtomic = "not-a-number"
|
|
if err := cfg.Validate(); err == nil {
|
|
t.Fatalf("expected mint amount validation failure")
|
|
}
|
|
}
|
|
|
|
func TestLoadConfigDefaultsWalletSessionRequired(t *testing.T) {
|
|
t.Setenv("SECRET_API_REQUIRE_WALLET_SESSION", "")
|
|
cfg := loadConfig()
|
|
if !cfg.RequireWalletSession {
|
|
t.Fatalf("expected wallet session to be required by default")
|
|
}
|
|
}
|
|
|
|
func TestLoadConfigWalletSessionCanBeDisabled(t *testing.T) {
|
|
t.Setenv("SECRET_API_REQUIRE_WALLET_SESSION", "false")
|
|
cfg := loadConfig()
|
|
if cfg.RequireWalletSession {
|
|
t.Fatalf("expected wallet session requirement to be disabled by env override")
|
|
}
|
|
}
|