51 lines
1.5 KiB
Go
51 lines
1.5 KiB
Go
package model
|
|
|
|
import (
|
|
"github.com/tech/sendico/pkg/discovery"
|
|
"testing"
|
|
|
|
"github.com/shopspring/decimal"
|
|
)
|
|
|
|
func TestIsGatewayEligible_AllowsMatchingGateway(t *testing.T) {
|
|
gw := &GatewayInstanceDescriptor{
|
|
ID: "gw-1",
|
|
InstanceID: "inst-1",
|
|
Rail: discovery.RailCrypto,
|
|
Network: "TRON",
|
|
Currencies: []string{"USDT"},
|
|
Operations: []RailOperation{discovery.RailOperationSend, discovery.RailOperationExternalCredit},
|
|
IsEnabled: true,
|
|
}
|
|
|
|
err := IsGatewayEligible(gw, discovery.RailCrypto, "TRON", "USDT", discovery.RailOperationSend, GatewayDirectionOut, decimal.RequireFromString("10"))
|
|
if err != nil {
|
|
t.Fatalf("expected gateway to be eligible, got err=%v", err)
|
|
}
|
|
}
|
|
|
|
func TestIsGatewayEligible_RejectsNetworkMismatch(t *testing.T) {
|
|
gw := &GatewayInstanceDescriptor{
|
|
ID: "gw-1",
|
|
InstanceID: "inst-1",
|
|
Rail: discovery.RailCrypto,
|
|
Network: "ETH",
|
|
Currencies: []string{"USDT"},
|
|
Operations: []RailOperation{discovery.RailOperationSend},
|
|
IsEnabled: true,
|
|
}
|
|
|
|
err := IsGatewayEligible(gw, discovery.RailCrypto, "TRON", "USDT", discovery.RailOperationSend, GatewayDirectionOut, decimal.RequireFromString("10"))
|
|
if err == nil {
|
|
t.Fatalf("expected network mismatch error")
|
|
}
|
|
}
|
|
|
|
func TestNoEligibleGatewayMessage(t *testing.T) {
|
|
got := NoEligibleGatewayMessage("tron", "usdt", discovery.RailOperationSend, GatewayDirectionOut)
|
|
want := "plan builder: no eligible gateway found for TRON USDT SEND for direction out"
|
|
if got != want {
|
|
t.Fatalf("unexpected message: got=%q want=%q", got, want)
|
|
}
|
|
}
|