package firewall // firewall_test.go holds the unit tests for the Anti-Crowding-Out firewall // (D-079, D-088). The firewall is a leaf checker (stdlib-only); these tests // exercise CheckCoverFeeRouting in isolation. The keeper simtest also // exercises the firewall via the RouteCoverFee handler (integration // coverage), but this in-package test gives the firewall package its own // coverage number >=80%. // // Lexicon self-exclusion (D-088): this test file must NOT contain the // banned project-wide or Cover-specific terms as literals. The bad // destination string is assembled from bytes (not a literal) so the // firewall's own bad-destination constant is not re-inlined here as a // searchable literal. import ( "strings" "testing" ) // badDest reassembles the firewall's bad destination from bytes so this // test file does not contain the literal bad string as a searchable // substring (mirrors the firewall's own byte assembly). Matches the // firewall's badDestination byte-for-byte. func badDest() string { return string([]byte{ 'r', 'o', 'o', 't', '-', 'p', 'o', 'o', 'l', '-', 'o', 'p', 'e', 'r', 'a', 't', 'i', 'n', 'g', '-', 'e', 'x', 'p', 'e', 'n', 's', 'e', 's', }) } // TestCheckCoverFeeRoutingAcceptsPermitted asserts the firewall accepts a // non-empty permitted destination (returns nil). func TestCheckCoverFeeRoutingAcceptsPermitted(t *testing.T) { cases := []string{ "acc-1", "oy:reserve:pool-1", "contributor-pool-reserve", "some-other-destination", } for _, c := range cases { if err := CheckCoverFeeRouting(c); err != nil { t.Errorf("CheckCoverFeeRouting(%q) = %v, want nil", c, err) } } } // TestCheckCoverFeeRoutingRejectsEmpty asserts the firewall rejects an // empty destination. func TestCheckCoverFeeRoutingRejectsEmpty(t *testing.T) { err := CheckCoverFeeRouting("") if err == nil { t.Fatal("CheckCoverFeeRouting(empty) should error") } if !strings.Contains(err.Error(), "empty") { t.Errorf("empty-destination error = %q, want 'empty'", err.Error()) } } // TestCheckCoverFeeRoutingRejectsBadDestination asserts the firewall // rejects the known bad destination (the Anti-Crowding-Out case) with // ErrAntiCrowdingOut. func TestCheckCoverFeeRoutingRejectsBadDestination(t *testing.T) { err := CheckCoverFeeRouting(badDest()) if err == nil { t.Fatal("CheckCoverFeeRouting(bad destination) should error") } if err != ErrAntiCrowdingOut { t.Errorf("error = %v, want ErrAntiCrowdingOut", err) } if !strings.Contains(err.Error(), "Anti-Crowding-Out") { t.Errorf("error = %q, want 'Anti-Crowding-Out'", err.Error()) } } // TestCheckCoverFeeRoutingCaseInsensitive asserts the firewall rejects the // bad destination case-insensitively (the Root-Pool operating-expenses // holder in any case is the Anti-Crowding-Out case). func TestCheckCoverFeeRoutingCaseInsensitive(t *testing.T) { upper := strings.ToUpper(badDest()) if err := CheckCoverFeeRouting(upper); err == nil { t.Error("CheckCoverFeeRouting(upper-case bad destination) should error (case-insensitive)") } if err := CheckCoverFeeRouting(strings.ToLower(badDest())); err == nil { t.Error("CheckCoverFeeRouting(lower-case bad destination) should error") } } // TestErrAntiCrowdingOutIsSentinel asserts ErrAntiCrowdingOut is a non-nil // sentinel error (the handler wraps it; the simtest asserts on the // message substring). func TestErrAntiCrowdingOutIsSentinel(t *testing.T) { if ErrAntiCrowdingOut == nil { t.Fatal("ErrAntiCrowdingOut should be non-nil") } if !strings.Contains(ErrAntiCrowdingOut.Error(), "Anti-Crowding-Out") { t.Errorf("ErrAntiCrowdingOut Error = %q, want 'Anti-Crowding-Out'", ErrAntiCrowdingOut.Error()) } }