looprpc: expose static loop-in monitor state

This commit is contained in:
Gustavo Stingelin 2026-07-08 23:35:19 -03:00
parent 4bb7d5ee29
commit 4c03e46928
No known key found for this signature in database
GPG key ID: 15CBADFE29F2017B
5 changed files with 246 additions and 129 deletions

View file

@ -400,9 +400,16 @@ func rpcToFee(req *clientrpc.LiquidityParameters) (FeeLimit, error) {
// rpcToRule switches on rpc rule type to convert to our rule interface.
func rpcToRule(rule *clientrpc.LiquidityRule) (*SwapRule, error) {
swapType := swap.TypeOut
if rule.SwapType == clientrpc.SwapType_LOOP_IN {
var swapType swap.Type
switch rule.SwapType {
case clientrpc.SwapType_LOOP_OUT:
swapType = swap.TypeOut
case clientrpc.SwapType_LOOP_IN:
swapType = swap.TypeIn
default:
return nil, fmt.Errorf("unknown swap type: %v", rule.SwapType)
}
switch rule.Type {

View file

@ -3,9 +3,62 @@ package liquidity
import (
"testing"
clientrpc "github.com/lightninglabs/loop/looprpc"
"github.com/lightninglabs/loop/swap"
"github.com/stretchr/testify/require"
)
// TestRPCToRuleSwapType verifies RPC swap type conversion.
func TestRPCToRuleSwapType(t *testing.T) {
tests := []struct {
name string
swapType clientrpc.SwapType
wantType swap.Type
wantErr bool
}{
{
name: "loop out",
swapType: clientrpc.SwapType_LOOP_OUT,
wantType: swap.TypeOut,
},
{
name: "loop in",
swapType: clientrpc.SwapType_LOOP_IN,
wantType: swap.TypeIn,
},
{
name: "static loop in rejected",
swapType: clientrpc.SwapType_STATIC_LOOP_IN,
wantErr: true,
},
{
name: "unknown swap type rejected",
swapType: clientrpc.SwapType(99),
wantErr: true,
},
}
for _, testCase := range tests {
t.Run(testCase.name, func(t *testing.T) {
rpcRule := &clientrpc.LiquidityRule{
Type: clientrpc.LiquidityRuleType_THRESHOLD,
IncomingThreshold: 10,
OutgoingThreshold: 20,
SwapType: testCase.swapType,
}
got, err := rpcToRule(rpcRule)
if testCase.wantErr {
require.Error(t, err)
return
}
require.NoError(t, err)
require.Equal(t, testCase.wantType, got.Type)
})
}
}
// TestValidateRestrictions tests validating client restrictions against a set
// of server restrictions.
func TestValidateRestrictions(t *testing.T) {