x402/go/errors_test.go
Andrew Reder 3d142fd228
feat(coinbase-x402): add error messages to Verify/Settle schemas (#1030)
* add messages to error schemas

* refactor go error handling

* lint fix

* testing

* update ts and python

* update ts and python error returns
2026-01-27 13:28:37 -08:00

32 lines
1.1 KiB
Go

package x402
import "testing"
func TestVerifyErrorMessageFormatting(t *testing.T) {
withMessage := NewVerifyError("invalid_signature", "0xabc", "signature did not match")
expected := "invalid_signature: signature did not match"
if withMessage.Error() != expected {
t.Fatalf("expected %q, got %q", expected, withMessage.Error())
}
withoutMessage := NewVerifyError("missing_signature", "0xabc", "")
expected = "missing_signature"
if withoutMessage.Error() != expected {
t.Fatalf("expected %q, got %q", expected, withoutMessage.Error())
}
}
func TestSettleErrorMessageFormatting(t *testing.T) {
withMessage := NewSettleError("transaction_failed", "0xabc", "eip155:1", "0xtx", "execution reverted")
expected := "transaction_failed: execution reverted"
if withMessage.Error() != expected {
t.Fatalf("expected %q, got %q", expected, withMessage.Error())
}
withoutMessage := NewSettleError("insufficient_funds", "0xabc", "eip155:1", "0xtx", "")
expected = "insufficient_funds"
if withoutMessage.Error() != expected {
t.Fatalf("expected %q, got %q", expected, withoutMessage.Error())
}
}