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

84 lines
2.4 KiB
Go

package client
import (
"context"
"encoding/json"
"errors"
"net/http"
"net/http/httptest"
"strings"
"sync/atomic"
"testing"
"github.com/hanzo-fi/payments/pkg/domain/httpwrapper"
)
func TestListBlockchainsPaginatesUsingCursor(t *testing.T) {
t.Parallel()
var calls atomic.Int32
var capturedQueries []string
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
capturedQueries = append(capturedQueries, r.URL.RawQuery)
w.Header().Set("Content-Type", "application/json")
switch calls.Add(1) {
case 1:
_ = json.NewEncoder(w).Encode(BlockchainsResponse{
Data: []Blockchain{
{ID: "chain-1", LegacyID: "ETH", Onchain: &BlockchainOnchain{Test: false}},
{ID: "chain-2", LegacyID: "ETH_TEST5", Onchain: &BlockchainOnchain{Test: true}},
},
Next: "cursor-2",
})
default:
_ = json.NewEncoder(w).Encode(BlockchainsResponse{
Data: []Blockchain{{ID: "chain-3", LegacyID: "BTC"}},
Next: "",
})
}
}))
defer server.Close()
c := newTestClient(t, server.URL)
chains, err := c.ListBlockchains(context.Background())
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if got := len(chains); got != 3 {
t.Fatalf("expected 3 blockchains across 2 pages, got %d", got)
}
if calls.Load() != 2 {
t.Fatalf("expected 2 HTTP calls, got %d", calls.Load())
}
if !strings.Contains(capturedQueries[0], "pageSize=500") || strings.Contains(capturedQueries[0], "pageCursor=") {
t.Fatalf("first request should have pageSize and no cursor, got %q", capturedQueries[0])
}
if !strings.Contains(capturedQueries[1], "pageCursor=cursor-2") {
t.Fatalf("second request should carry pageCursor=cursor-2, got %q", capturedQueries[1])
}
}
func TestListBlockchainsWrapsServerError(t *testing.T) {
t.Parallel()
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusInternalServerError)
_, _ = w.Write([]byte(`{"message":"boom","code":500}`))
}))
defer server.Close()
c := newTestClient(t, server.URL)
_, err := c.ListBlockchains(context.Background())
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 blockchains") {
t.Fatalf("expected wrapping prefix, got %v", err)
}
}