+source +destination in payments
This commit is contained in:
@@ -5,9 +5,12 @@ import (
|
||||
|
||||
gatewayv1 "github.com/tech/sendico/pkg/proto/common/gateway/v1"
|
||||
moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1"
|
||||
endpointv1 "github.com/tech/sendico/pkg/proto/payments/endpoint/v1"
|
||||
orchestrationv2 "github.com/tech/sendico/pkg/proto/payments/orchestration/v2"
|
||||
quotationv2 "github.com/tech/sendico/pkg/proto/payments/quotation/v2"
|
||||
sharedv1 "github.com/tech/sendico/pkg/proto/payments/shared/v1"
|
||||
"github.com/tech/sendico/server/interface/api/srequest"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
func TestToUserVisibleOperationsFiltersByVisibility(t *testing.T) {
|
||||
@@ -137,6 +140,125 @@ func TestToPaymentMapsIntentComment(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestToPaymentMapsSourceAndDestination(t *testing.T) {
|
||||
sourceRaw, err := bson.Marshal(struct {
|
||||
WalletID string `bson:"walletId"`
|
||||
}{
|
||||
WalletID: "wallet-src-1",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("marshal source method data: %v", err)
|
||||
}
|
||||
destinationRaw, err := bson.Marshal(struct {
|
||||
Currency string `bson:"currency"`
|
||||
Address string `bson:"address"`
|
||||
Network string `bson:"network"`
|
||||
DestinationTag *string `bson:"destinationTag,omitempty"`
|
||||
}{
|
||||
Currency: "USDT",
|
||||
Address: "TXabc",
|
||||
Network: "TRON_MAINNET",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("marshal destination method data: %v", err)
|
||||
}
|
||||
|
||||
dto := toPayment(&orchestrationv2.Payment{
|
||||
PaymentRef: "pay-src-dst",
|
||||
State: orchestrationv2.OrchestrationState_ORCHESTRATION_STATE_CREATED,
|
||||
IntentSnapshot: "ationv2.QuoteIntent{
|
||||
Source: &endpointv1.PaymentEndpoint{
|
||||
Source: &endpointv1.PaymentEndpoint_PaymentMethod{
|
||||
PaymentMethod: &endpointv1.PaymentMethod{
|
||||
Type: endpointv1.PaymentMethodType_PAYMENT_METHOD_TYPE_WALLET,
|
||||
Data: sourceRaw,
|
||||
},
|
||||
},
|
||||
},
|
||||
Destination: &endpointv1.PaymentEndpoint{
|
||||
Source: &endpointv1.PaymentEndpoint_PaymentMethod{
|
||||
PaymentMethod: &endpointv1.PaymentMethod{
|
||||
Type: endpointv1.PaymentMethodType_PAYMENT_METHOD_TYPE_CRYPTO_ADDRESS,
|
||||
Data: destinationRaw,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
if dto == nil {
|
||||
t.Fatal("expected non-nil payment dto")
|
||||
}
|
||||
if dto.Source == nil {
|
||||
t.Fatal("expected source endpoint")
|
||||
}
|
||||
if got, want := dto.Source.Type, string(srequest.EndpointTypeWallet); got != want {
|
||||
t.Fatalf("source type mismatch: got=%q want=%q", got, want)
|
||||
}
|
||||
sourceEndpoint, ok := dto.Source.Data.(srequest.WalletEndpoint)
|
||||
if !ok {
|
||||
t.Fatalf("source endpoint payload type mismatch: got=%T", dto.Source.Data)
|
||||
}
|
||||
if got, want := sourceEndpoint.WalletID, "wallet-src-1"; got != want {
|
||||
t.Fatalf("source wallet id mismatch: got=%q want=%q", got, want)
|
||||
}
|
||||
if dto.Destination == nil {
|
||||
t.Fatal("expected destination endpoint")
|
||||
}
|
||||
if got, want := dto.Destination.Type, string(srequest.EndpointTypeExternalChain); got != want {
|
||||
t.Fatalf("destination type mismatch: got=%q want=%q", got, want)
|
||||
}
|
||||
destinationEndpoint, ok := dto.Destination.Data.(srequest.ExternalChainEndpoint)
|
||||
if !ok {
|
||||
t.Fatalf("destination endpoint payload type mismatch: got=%T", dto.Destination.Data)
|
||||
}
|
||||
if got, want := destinationEndpoint.Address, "TXabc"; got != want {
|
||||
t.Fatalf("destination address mismatch: got=%q want=%q", got, want)
|
||||
}
|
||||
if destinationEndpoint.Asset == nil {
|
||||
t.Fatal("expected destination asset")
|
||||
}
|
||||
if got, want := destinationEndpoint.Asset.TokenSymbol, "USDT"; got != want {
|
||||
t.Fatalf("destination token mismatch: got=%q want=%q", got, want)
|
||||
}
|
||||
if got, want := destinationEndpoint.Asset.Chain, srequest.ChainNetworkTronMainnet; got != want {
|
||||
t.Fatalf("destination chain mismatch: got=%q want=%q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestToPaymentMapsEndpointRefs(t *testing.T) {
|
||||
dto := toPayment(&orchestrationv2.Payment{
|
||||
PaymentRef: "pay-refs",
|
||||
State: orchestrationv2.OrchestrationState_ORCHESTRATION_STATE_CREATED,
|
||||
IntentSnapshot: "ationv2.QuoteIntent{
|
||||
Source: &endpointv1.PaymentEndpoint{
|
||||
Source: &endpointv1.PaymentEndpoint_PaymentMethodRef{
|
||||
PaymentMethodRef: "pm-123",
|
||||
},
|
||||
},
|
||||
Destination: &endpointv1.PaymentEndpoint{
|
||||
Source: &endpointv1.PaymentEndpoint_PayeeRef{
|
||||
PayeeRef: "payee-777",
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
if dto == nil {
|
||||
t.Fatal("expected non-nil payment dto")
|
||||
}
|
||||
if dto.Source == nil {
|
||||
t.Fatal("expected source endpoint")
|
||||
}
|
||||
if got, want := dto.Source.PaymentMethodRef, "pm-123"; got != want {
|
||||
t.Fatalf("source payment_method_ref mismatch: got=%q want=%q", got, want)
|
||||
}
|
||||
if dto.Destination == nil {
|
||||
t.Fatal("expected destination endpoint")
|
||||
}
|
||||
if got, want := dto.Destination.PayeeRef, "payee-777"; got != want {
|
||||
t.Fatalf("destination payee_ref mismatch: got=%q want=%q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestToPaymentQuote_MapsIntentRef(t *testing.T) {
|
||||
dto := toPaymentQuote("ationv2.PaymentQuote{
|
||||
QuoteRef: "quote-1",
|
||||
|
||||
Reference in New Issue
Block a user