loop/looprpc/client_test.go
Slyghtning e772f8ccfa
instantout: enforce the accepted swap fee
Carry the accepted quote into each request, persist it, and reject
invoices above that limit. Preserve compatibility for requests that
omit the cap while distinguishing an explicit zero.
2026-08-11 21:27:35 +02:00

32 lines
1 KiB
Go

package looprpc
import (
"testing"
"google.golang.org/protobuf/proto"
)
// TestInstantOutMaxSwapFeePresence verifies that an omitted fee cap remains
// distinguishable from an explicitly encoded zero while retaining the scalar
// field's original wire representation.
func TestInstantOutMaxSwapFeePresence(t *testing.T) {
request := &InstantOutRequest{}
if err := proto.Unmarshal(nil, request); err != nil {
t.Fatalf("unable to unmarshal omitted cap: %v", err)
}
if request.GetMaxSwapFee() != nil {
t.Fatal("omitted cap unexpectedly has presence")
}
// Field four, encoded as a varint with value zero. This is the same wire
// representation used before the field gained presence semantics.
if err := proto.Unmarshal([]byte{0x20, 0x00}, request); err != nil {
t.Fatalf("unable to unmarshal explicit zero cap: %v", err)
}
if request.GetMaxSwapFee() == nil {
t.Fatal("explicit zero cap lost presence")
}
if request.GetMaxSwapFeeSat() != 0 {
t.Fatalf("expected zero cap, got %d", request.GetMaxSwapFeeSat())
}
}