{"schema_version":"1.0","publisher":"Primitive SDKs","canonical_url":"https://test.abhinandan.one/go-sdk-development","markdown_url":"https://test.abhinandan.one/go-sdk-development.md","article":{"id":"80db1be4-7de1-4c15-8b67-a31fad91f5f0","article_slug":"go-sdk-development","parent_article_slug":null,"parent_article_title":null,"kind":"troubleshooting","published_at":"2026-08-11T18:55:02.328698+00:00","keywords":["go test./...","TestSharedCompatibilityFixtures","gofmt -w","make go-generate","make go-check","make go-build"],"meta_description":"Fixes for Go SDK test, build, and formatting failures, including go test./... gofmt drift, and shared cross-SDK fixture mismatches.","og_image_url":null,"source_file_paths":["sdk-go/README.md","sdk-go/x402_test.go"],"recording_id":null,"replayable":false,"task_name":"Go SDK Testing and Development","category":"Go SDK","summary":null,"description":"Run the Go SDK's local test suite, shared cross-language compatibility fixtures, and formatting/build checks, either from sdk-go directly or via the root Makefile.","content_kind":"repo_page","content_markdown":"## Running the test suite locally\n\nFrom the `sdk-go` directory, run the full package test suite:\n\n```bash\ncd sdk-go\ngo test ./...\n```\n\nThis runs everything, including the x402 signing tests in `x402_test.go` (nonce derivation, validity-window computation, `PrivateKeySigner` round-trips, and the mock-server `X402Client` tests).\n\n## Running the shared cross-SDK compatibility fixtures\n\n`TestSharedCompatibilityFixtures` runs the fixtures in `test-fixtures/` that assert Go's webhook signature verification, auth classification, sender trust, and schema validation behavior match the Node and Python SDKs byte-for-byte. Run it in isolation:\n\n```bash\ncd sdk-go\ngo test -run TestSharedCompatibilityFixtures ./...\n```\n\nIf this test fails after you change webhook parsing, signing, or trust logic, the fix is almost always to bring Go's behavior back in line with the other two SDKs rather than to edit the fixture. The shared fixture contract, and when it's correct to update the fixtures themselves, is documented in [Monorepo Structure and Release Process](monorepo-and-releases).\n\n## gofmt diff / formatting check fails\n\n`gofmt` enforces canonical formatting across the package. If CI or `make go-check` reports a formatting diff, apply it directly:\n\n```bash\ncd sdk-go\ngofmt -w .\n```\n\nRe-run `go test ./...` afterward; `gofmt -w` only rewrites whitespace and layout, it never changes behavior, so a passing test suite before the fix should still pass after.\n\n## Running checks from the monorepo root instead\n\nEvery one of the commands above has a root-level equivalent that wraps the same underlying tooling. Prefer these when you're touching more than just `sdk-go`, since they're what CI runs:\n\n```bash\nmake go-generate   # regenerate the embedded webhook schema + sdk-go/api client from openapi/primitive-api.yaml\nmake go-check       # go test ./... + go test -run TestSharedCompatibilityFixtures ./... + gofmt check\nmake go-build       # verify the module builds\n```\n\nRun `make go-generate` after any change to `openapi/primitive-api.yaml` or `json-schema/email-received-event.schema.json`, per the regeneration workflow in [Regenerating SDK Code from the OpenAPI Spec](codegen-workflow). Committing regenerated Go output without also regenerating Node and Python leaves the three SDKs out of sync with the shared contract.\n\n## Normative nonce vector mismatch in x402 tests\n\n`x402_test.go` locks EIP-3009 nonce derivation to a normative test vector (`normativeNonce = \"0xc955a08812ab83f9e25c92e5162267b913957c3cc8678de1cf1449f77b516c6e\"`), computed from a fixed `NonceBinding` (`canonicalInteractionID`, `canonicalChallengeStepID`, `canonicalChallengeNonce`). `TestDeriveEIP3009Nonce_NormativeVector` fails if `DeriveEIP3009Nonce`'s byte layout changes even slightly, for example a swapped separator or a different case-folding rule for `interactionId`/`challengeStepId`.\n\nThis test failing is a hard stop, not something to patch around by updating the expected constant: the platform verifier recomputes the same nonce independently, and a Go-side layout change that isn't mirrored server-side makes every real payment fail signature verification. If you need to change nonce derivation, coordinate the change with the platform and the Node/Python SDKs' equivalent normative vectors first.\n\n## Address / signature round-trip test failures\n\n`TestPrivateKeySigner_Address`, `TestPrivateKeySigner_PersonalSignRoundTrip`, and `TestPrivateKeySigner_EIP712RoundTrip` all derive from the same fixed test key (`testPrivateKey`) and expect it to recover to `testAddress`. A failure here almost always means a change to `PrivateKeySigner.SignTypedData` or `SignMessage`'s recovery-id normalization (the `v ∈ {27, 28}` adjustment), not a key or address typo. Check that the signature's last byte is still normalized to Ethereum's canonical recovery id before comparing against `go-ethereum`'s recovery output.\n\n## Validity window errors: \"authorization window too wide\" / \"about to expire\"\n\n`ComputePaymentValidityWindow` enforces a band on `validBefore`: at least `DefaultMinSettlementHeadroomSec` (60s) past now, and at most `DefaultMaxWindowSec` (24h) past `validAfter`. By default (`Clamp` nil or `true`) an out-of-band window is silently clamped into the band, so you won't see either error unless you explicitly pin `ValidBeforeSec`/`ValidAfterSec` with `Clamp: false`.\n\nIf your own test or code hits one of these errors:\n\n- **\"is below the minimum settlement headroom\"**: your pinned `ValidBeforeSec` is too close to now. Either drop the pin and let the default derivation (`ChallengeExpiresAtSec + SettlementMarginSec`) compute it, or move the pin further out.\n- **\"the authorization window is too wide\"**: your pinned `ValidBeforeSec` exceeds `ValidAfterSec + MaxWindowSec`. Either drop the pin or set `Clamp` back to its default so the SDK lands it inside the cap for you.\n\nSee [x402 Signing Primitives](go-x402-signing-primitives) for the full parameter reference.\n\n## Test-only HTTP server assertions failing (`X402Client` tests)\n\nThe `TestX402Client_*` tests spin up an `httptest.Server` and assert on the exact request path, method, and body the client sends (for example `/v1/x402/challenges/{id}/pay`, or the `authorization: Bearer k` header). If these fail after a client change, diff the actual captured request against the assertion rather than adjusting the assertion: these tests exist specifically to catch wire-format drift between `X402Client` and the platform's expected request shape, mirroring the Node SDK's `x402` client byte-for-byte.","canonical_base_url":"https://test.abhinandan.one","seo_indexing_enabled":true,"last_modified":"2026-08-21T18:22:43.359885+00:00","video_url":null,"voiceover_url":null,"tools_used":[],"demonstrated_by":[],"steps":[],"related_links":[],"intro":null,"prerequisites":[],"verification":[],"troubleshooting":[],"suggest_edit_url":"https://github.com/abhi-browzer/primitive-sdks/edit/main/sdk-go/README.md","raise_issue_url":"https://github.com/abhi-browzer/primitive-sdks/issues/new?title=Docs+feedback%3A+Go+SDK+Testing+and+Development&body=Page%3A+https%3A%2F%2Ftest.abhinandan.one%2Fgo-sdk-development","page_feedback_enabled":true,"verified_ref":null,"verified_at":"2026-08-11T18:38:45.205849+00:00"}}