package transfer import "testing" func TestIsValidTransition(t *testing.T) { allowed := map[string][]string{ StatePending: {StateAccepted, StateP2PActive, StateRelayActive, StateCancelled, StateFailed}, StateAccepted: {StateP2PActive, StateRelayActive, StateDone, StateCancelled, StateFailed}, StateP2PActive: {StateRelayActive, StateDone, StateFailed, StateCancelled}, StateRelayActive: {StateDone, StateFailed, StateCancelled}, } all := []string{StatePending, StateAccepted, StateP2PActive, StateRelayActive, StateDone, StateFailed, StateCancelled} for from, tos := range allowed { ok := map[string]bool{} for _, to := range tos { ok[to] = true } for _, to := range all { got := IsValidTransition(from, to) want := ok[to] if got != want { t.Errorf("transition %s→%s: got %v, want %v", from, to, got, want) } } } // Terminals reject all outbound. for _, term := range []string{StateDone, StateFailed, StateCancelled} { for _, to := range all { if IsValidTransition(term, to) { t.Errorf("terminal %s should not allow transition to %s", term, to) } } } } func TestIsTerminal(t *testing.T) { cases := map[string]bool{ StatePending: false, StateAccepted: false, StateP2PActive: false, StateRelayActive: false, StateDone: true, StateFailed: true, StateCancelled: true, } for s, want := range cases { if got := IsTerminal(s); got != want { t.Errorf("IsTerminal(%s): got %v, want %v", s, got, want) } } }