Files
zeekay 7d727874d5 chore: rebrand Formance Payments -> Hanzo Payments (hanzo-fi)
- go.mod module path + all self-imports: github.com/formancehq/payments -> github.com/hanzo-fi/payments
  (1590 .go files / 3152 refs; 20 modules: root, pkg/client, pkg/domain, 18 ce/plugins).
  External dep kept: formancehq/go-libs.
- plugins: each ce/plugins/* consumed a *published* pkg/domain; added local
  'replace .../pkg/domain => ../../../pkg/domain' (consistent with root) so every
  standalone plugin module builds in-monorepo. compile-plugin.sh MOD var rebranded too.
- branding: README, LICENSE (dual MIT+EE; upstream copyright retained + Hanzo added),
  goreleaser (release images -> registry.hanzo.ai/hanzo-fi, OCI labels, homepage),
  proto go_package, renovate, speakeasy gen.yaml, connector-template *.gotpl.
- CI: removed Numary/Formance workflows + composite action; added canonical hanzo.yml +
  cicd.yml (hanzoai/ci, gated HANZO_CI_ENABLED) + secretless ci.yml (go build/vet).
- kept as data/compat keys: wire capability enums ALLOW_FORMANCE_*, generated SDK type
  client.Formance, domain field FormanceRedirectURL, OTEL_SERVICE_NAME, upstream base image.
- verified: go build ./... (default + -tags ee) + all 20 nested modules green.
2026-07-05 13:08:55 -07:00

113 lines
3.1 KiB
Go

package client
import (
"context"
"encoding/json"
"errors"
"net/http"
"net/http/httptest"
"strings"
"testing"
"github.com/hanzo-fi/payments/pkg/domain/httpwrapper"
)
func TestListTransactionsPinsAfterOneOnFirstSync(t *testing.T) {
t.Parallel()
var capturedQuery string
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
capturedQuery = r.URL.RawQuery
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`[]`))
}))
defer server.Close()
c := newTestClient(t, server.URL)
if _, err := c.ListTransactions(context.Background(), 0, 50); err != nil {
t.Fatalf("unexpected error: %v", err)
}
// after=1 bypasses Fireblocks' "last 90 days" default.
if !strings.Contains(capturedQuery, "after=1") {
t.Fatalf("expected after=1 on initial sync, got %q", capturedQuery)
}
for _, want := range []string{"limit=50", "orderBy=createdAt", "sort=ASC"} {
if !strings.Contains(capturedQuery, want) {
t.Fatalf("expected query to contain %q, got %q", want, capturedQuery)
}
}
}
func TestListTransactionsForwardsStateCursor(t *testing.T) {
t.Parallel()
var capturedQuery string
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
capturedQuery = r.URL.RawQuery
_, _ = w.Write([]byte(`[]`))
}))
defer server.Close()
c := newTestClient(t, server.URL)
if _, err := c.ListTransactions(context.Background(), 1234567890, 50); err != nil {
t.Fatalf("unexpected error: %v", err)
}
if !strings.Contains(capturedQuery, "after=1234567890") {
t.Fatalf("expected after=1234567890, got %q", capturedQuery)
}
}
func TestListTransactionsRoundTripsTransactions(t *testing.T) {
t.Parallel()
body := []Transaction{
{ID: "tx-1", AssetID: "BTC", Operation: "TRANSFER", Status: "COMPLETED", CreatedAt: 1700000000000},
{ID: "tx-2", AssetID: "ETH", Operation: "TRANSFER", Status: "PENDING_SIGNATURE", CreatedAt: 1700000001000},
}
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(body)
}))
defer server.Close()
c := newTestClient(t, server.URL)
txs, err := c.ListTransactions(context.Background(), 0, 50)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if got := len(txs); got != 2 {
t.Fatalf("expected 2 transactions, got %d", got)
}
if txs[0].ID != "tx-1" || txs[1].ID != "tx-2" {
t.Fatalf("unexpected ids: %+v", txs)
}
}
func TestListTransactionsWrapsServerError(t *testing.T) {
t.Parallel()
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusBadGateway)
_, _ = w.Write([]byte(`{"message":"boom","code":500}`))
}))
defer server.Close()
c := newTestClient(t, server.URL)
_, err := c.ListTransactions(context.Background(), 0, 50)
if err == nil {
t.Fatal("expected error, got nil")
}
if !errors.Is(err, httpwrapper.ErrStatusCodeServerError) {
t.Fatalf("expected wrapped server-error, got %v", err)
}
if !strings.Contains(err.Error(), "failed to list transactions") {
t.Fatalf("expected wrapping prefix, got %v", err)
}
}