mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-22 08:24:22 +01:00
Simplified version, with less validation
This commit is contained in:
@@ -127,117 +127,6 @@ namespace BTCPayServer.Tests
|
|||||||
#pragma warning restore CS0618
|
#pragma warning restore CS0618
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void CanPayWithLightningWhenInvoiceTotalUnderLightningMaxValueWhenOnChainMinValueIsGreater()
|
|
||||||
{
|
|
||||||
|
|
||||||
#pragma warning disable CS0618
|
|
||||||
|
|
||||||
//Given
|
|
||||||
var store = new StoreBlob
|
|
||||||
{
|
|
||||||
OnChainMinValue = new CurrencyValue() {Value = 100.00m, Currency = "USD"},
|
|
||||||
LightningMaxValue = new CurrencyValue() {Value = 50.00m, Currency = "USD"}
|
|
||||||
};
|
|
||||||
var paymentMethodId = new PaymentMethodId("BTC", PaymentTypes.LightningLike);
|
|
||||||
|
|
||||||
//When
|
|
||||||
var totalInvoiceAmount = new Money(80m, MoneyUnit.BTC);
|
|
||||||
|
|
||||||
//Then
|
|
||||||
var errorMessage = handlerLN.IsPaymentMethodAllowedBasedOnInvoiceAmount(store, currencyPairRateResult,
|
|
||||||
totalInvoiceAmount, paymentMethodId);
|
|
||||||
|
|
||||||
Assert.Equal(errorMessage.Result, string.Empty);
|
|
||||||
|
|
||||||
#pragma warning restore CS0618
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void CanPayWithLightningWhenInvoiceTotalUnderLightningMaxValueWhenOnChainMinValueIsLower()
|
|
||||||
{
|
|
||||||
|
|
||||||
#pragma warning disable CS0618
|
|
||||||
|
|
||||||
//Given
|
|
||||||
var store = new StoreBlob
|
|
||||||
{
|
|
||||||
OnChainMinValue = new CurrencyValue() {Value = 50.00m, Currency = "USD"},
|
|
||||||
LightningMaxValue = new CurrencyValue() {Value = 100.00m, Currency = "USD"}
|
|
||||||
};
|
|
||||||
var paymentMethodId = new PaymentMethodId("BTC", PaymentTypes.LightningLike);
|
|
||||||
|
|
||||||
//When
|
|
||||||
var totalInvoiceAmount = new Money(80m, MoneyUnit.BTC);
|
|
||||||
|
|
||||||
//Then
|
|
||||||
var errorMessage = handlerLN.IsPaymentMethodAllowedBasedOnInvoiceAmount(store, currencyPairRateResult,
|
|
||||||
totalInvoiceAmount, paymentMethodId);
|
|
||||||
|
|
||||||
Assert.Equal(errorMessage.Result, string.Empty);
|
|
||||||
|
|
||||||
#pragma warning restore CS0618
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void CannotPayWithLightningWhenInvoiceTotalUnderLightningMaxValueWhenOnChainMinValueIsGreater()
|
|
||||||
{
|
|
||||||
|
|
||||||
#pragma warning disable CS0618
|
|
||||||
|
|
||||||
//Given
|
|
||||||
var store = new StoreBlob
|
|
||||||
{
|
|
||||||
OnChainMinValue = new CurrencyValue() {Value = 100.00m, Currency = "USD"},
|
|
||||||
LightningMaxValue = new CurrencyValue() {Value = 50.00m, Currency = "USD"}
|
|
||||||
};
|
|
||||||
var paymentMethodId = new PaymentMethodId("BTC", PaymentTypes.LightningLike);
|
|
||||||
|
|
||||||
//When
|
|
||||||
var totalInvoiceAmount = new Money(105m, MoneyUnit.BTC);
|
|
||||||
|
|
||||||
//Then
|
|
||||||
var errorMessage = handlerLN.IsPaymentMethodAllowedBasedOnInvoiceAmount(store, currencyPairRateResult,
|
|
||||||
totalInvoiceAmount, paymentMethodId);
|
|
||||||
|
|
||||||
Assert.NotEqual(errorMessage.Result, string.Empty);
|
|
||||||
|
|
||||||
#pragma warning restore CS0618
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void CannotPayWithLightningWhenInvoiceTotalUnderLightningMaxValueWhenOnChainMinValueIsLower()
|
|
||||||
{
|
|
||||||
|
|
||||||
#pragma warning disable CS0618
|
|
||||||
|
|
||||||
//Given
|
|
||||||
var store = new StoreBlob
|
|
||||||
{
|
|
||||||
OnChainMinValue = new CurrencyValue() {Value = 50.00m, Currency = "USD"},
|
|
||||||
LightningMaxValue = new CurrencyValue() {Value = 100.00m, Currency = "USD"}
|
|
||||||
};
|
|
||||||
var paymentMethodId = new PaymentMethodId("BTC", PaymentTypes.LightningLike);
|
|
||||||
|
|
||||||
//When
|
|
||||||
var totalInvoiceAmount = new Money(105m, MoneyUnit.BTC);
|
|
||||||
|
|
||||||
//Then
|
|
||||||
var errorMessage = handlerLN.IsPaymentMethodAllowedBasedOnInvoiceAmount(store, currencyPairRateResult,
|
|
||||||
totalInvoiceAmount, paymentMethodId);
|
|
||||||
|
|
||||||
Assert.NotEqual(errorMessage.Result, string.Empty);
|
|
||||||
|
|
||||||
#pragma warning restore CS0618
|
|
||||||
}
|
|
||||||
|
|
||||||
//----
|
|
||||||
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void CanPayWithBitcoinWhenInvoiceTotalAboveOnChainMinValue()
|
public void CanPayWithBitcoinWhenInvoiceTotalAboveOnChainMinValue()
|
||||||
{
|
{
|
||||||
@@ -319,87 +208,6 @@ namespace BTCPayServer.Tests
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void CanPayWithBitcoinWhenInvoiceTotalAboveOnchainMinValueWhenLightningMaxValueIsLower()
|
|
||||||
{
|
|
||||||
|
|
||||||
#pragma warning disable CS0618
|
|
||||||
|
|
||||||
//Given
|
|
||||||
var store = new StoreBlob
|
|
||||||
{
|
|
||||||
OnChainMinValue = new CurrencyValue() {Value = 100.00m, Currency = "USD"},
|
|
||||||
LightningMaxValue = new CurrencyValue() {Value = 50.00m, Currency = "USD"}
|
|
||||||
};
|
|
||||||
var paymentMethodId = new PaymentMethodId("BTC", PaymentTypes.BTCLike);
|
|
||||||
|
|
||||||
//When
|
|
||||||
var totalInvoiceAmount = new Money(80m, MoneyUnit.BTC);
|
|
||||||
|
|
||||||
//Then
|
|
||||||
var errorMessage = handlerBTC.IsPaymentMethodAllowedBasedOnInvoiceAmount(store, currencyPairRateResult,
|
|
||||||
totalInvoiceAmount, paymentMethodId);
|
|
||||||
|
|
||||||
Assert.Equal(errorMessage.Result, string.Empty);
|
|
||||||
|
|
||||||
#pragma warning restore CS0618
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void CanPayWithBitcoinWhenInvoiceTotalAboveOnChainMinValueWhenLightningMaxValueIsGreater()
|
|
||||||
{
|
|
||||||
|
|
||||||
#pragma warning disable CS0618
|
|
||||||
|
|
||||||
//Given
|
|
||||||
var store = new StoreBlob
|
|
||||||
{
|
|
||||||
OnChainMinValue = new CurrencyValue() {Value = 50.00m, Currency = "USD"},
|
|
||||||
LightningMaxValue = new CurrencyValue() {Value = 100.00m, Currency = "USD"}
|
|
||||||
};
|
|
||||||
var paymentMethodId = new PaymentMethodId("BTC", PaymentTypes.BTCLike);
|
|
||||||
|
|
||||||
//When
|
|
||||||
var totalInvoiceAmount = new Money(80m, MoneyUnit.BTC);
|
|
||||||
|
|
||||||
//Then
|
|
||||||
var errorMessage = handlerBTC.IsPaymentMethodAllowedBasedOnInvoiceAmount(store, currencyPairRateResult,
|
|
||||||
totalInvoiceAmount, paymentMethodId);
|
|
||||||
|
|
||||||
Assert.Equal(errorMessage.Result, string.Empty);
|
|
||||||
|
|
||||||
#pragma warning restore CS0618
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void CannotPayWithBitcoinWhenInvoiceTotalUnderOnChainMinValueWhenLightningMaxValueIsLower()
|
|
||||||
{
|
|
||||||
|
|
||||||
#pragma warning disable CS0618
|
|
||||||
|
|
||||||
//Given
|
|
||||||
var store = new StoreBlob
|
|
||||||
{
|
|
||||||
OnChainMinValue = new CurrencyValue() {Value = 100.00m, Currency = "USD"},
|
|
||||||
LightningMaxValue = new CurrencyValue() {Value = 50.00m, Currency = "USD"}
|
|
||||||
};
|
|
||||||
var paymentMethodId = new PaymentMethodId("BTC", PaymentTypes.BTCLike);
|
|
||||||
|
|
||||||
//When
|
|
||||||
var totalInvoiceAmount = new Money(45m, MoneyUnit.BTC);
|
|
||||||
|
|
||||||
//Then
|
|
||||||
var errorMessage = handlerBTC.IsPaymentMethodAllowedBasedOnInvoiceAmount(store, currencyPairRateResult,
|
|
||||||
totalInvoiceAmount, paymentMethodId);
|
|
||||||
|
|
||||||
Assert.NotEqual(errorMessage.Result, string.Empty);
|
|
||||||
|
|
||||||
#pragma warning restore CS0618
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void CannotPayWithBitcoinWhenInvoiceTotalUnderOnChainMinValueWhenLightningMaxValueIsGreater()
|
public void CannotPayWithBitcoinWhenInvoiceTotalUnderOnChainMinValueWhenLightningMaxValueIsGreater()
|
||||||
{
|
{
|
||||||
@@ -426,5 +234,6 @@ namespace BTCPayServer.Tests
|
|||||||
#pragma warning restore CS0618
|
#pragma warning restore CS0618
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,38 +74,11 @@ namespace BTCPayServer.Payments.Bitcoin
|
|||||||
CurrencyValue limitValue = null;
|
CurrencyValue limitValue = null;
|
||||||
string errorMessage = null;
|
string errorMessage = null;
|
||||||
|
|
||||||
if (paymentMethodId.PaymentType == PaymentTypes.BTCLike)
|
if (storeBlob.OnChainMinValue != null)
|
||||||
{
|
{
|
||||||
if (storeBlob.LightningMaxValue == null &&
|
compare = (value, limit) => value < limit;
|
||||||
storeBlob.OnChainMinValue != null)
|
limitValue = storeBlob.OnChainMinValue;
|
||||||
{
|
errorMessage = "The amount of the invoice is too low to be paid on chain";
|
||||||
compare = (value, limit) => value < limit;
|
|
||||||
limitValue = storeBlob.OnChainMinValue;
|
|
||||||
errorMessage = "The amount of the invoice is too low to be paid on chain";
|
|
||||||
}
|
|
||||||
else if (storeBlob.LightningMaxValue != null &&
|
|
||||||
storeBlob.OnChainMinValue != null)
|
|
||||||
{
|
|
||||||
if (storeBlob.LightningMaxValue.Currency == storeBlob.OnChainMinValue.Currency &&
|
|
||||||
storeBlob.LightningMaxValue.Value <= storeBlob.OnChainMinValue.Value)
|
|
||||||
{
|
|
||||||
//Case where both fields are set but OnChainMinValue is greater
|
|
||||||
// --> then use LightningMaxValue as limit
|
|
||||||
compare = (value, limit) => value < limit;
|
|
||||||
limitValue = storeBlob.LightningMaxValue;
|
|
||||||
errorMessage = "The amount of the invoice is too low to be paid on chain";
|
|
||||||
}
|
|
||||||
else if (storeBlob.LightningMaxValue.Currency == storeBlob.OnChainMinValue.Currency &&
|
|
||||||
storeBlob.LightningMaxValue.Value > storeBlob.OnChainMinValue.Value)
|
|
||||||
{
|
|
||||||
//Case where both fields are set but LightningMaxValue is greater
|
|
||||||
// --> then use OnChainMinValue as limit
|
|
||||||
// (Otherwise a gap of price value with no payment method is possible)
|
|
||||||
compare = (value, limit) => value < limit;
|
|
||||||
limitValue = storeBlob.OnChainMinValue;
|
|
||||||
errorMessage = "The amount of the invoice is too low to be paid on chain";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -151,38 +151,11 @@ namespace BTCPayServer.Payments.Lightning
|
|||||||
CurrencyValue limitValue = null;
|
CurrencyValue limitValue = null;
|
||||||
string errorMessage = null;
|
string errorMessage = null;
|
||||||
|
|
||||||
if (paymentMethodId.PaymentType == PaymentTypes.LightningLike)
|
if (storeBlob.LightningMaxValue != null)
|
||||||
{
|
{
|
||||||
if (storeBlob.LightningMaxValue != null &&
|
compare = (value, limit) => value > limit;
|
||||||
storeBlob.OnChainMinValue == null)
|
limitValue = storeBlob.LightningMaxValue;
|
||||||
{
|
errorMessage = "The amount of the invoice is too high to be paid with lightning";
|
||||||
compare = (value, limit) => value > limit;
|
|
||||||
limitValue = storeBlob.LightningMaxValue;
|
|
||||||
errorMessage = "The amount of the invoice is too high to be paid with lightning";
|
|
||||||
}
|
|
||||||
else if (storeBlob.LightningMaxValue != null &&
|
|
||||||
storeBlob.OnChainMinValue != null)
|
|
||||||
{
|
|
||||||
if (storeBlob.LightningMaxValue.Currency == storeBlob.OnChainMinValue.Currency &&
|
|
||||||
storeBlob.LightningMaxValue.Value >= storeBlob.OnChainMinValue.Value)
|
|
||||||
{
|
|
||||||
//Case where both fields are set but LightningMaxValue is greater
|
|
||||||
// --> then use LightningMaxValue as limit
|
|
||||||
compare = (value, limit) => value > limit;
|
|
||||||
limitValue = storeBlob.LightningMaxValue;
|
|
||||||
errorMessage = "The amount of the invoice is too high to be paid with lightning";
|
|
||||||
}
|
|
||||||
else if (storeBlob.LightningMaxValue.Currency == storeBlob.OnChainMinValue.Currency &&
|
|
||||||
storeBlob.LightningMaxValue.Value < storeBlob.OnChainMinValue.Value)
|
|
||||||
{
|
|
||||||
//Case where both fields are set but OnChainMinValue is greater
|
|
||||||
// --> then use OnChainMinValue as limit
|
|
||||||
// (Otherwise a gap of price value with no payment method is possible)
|
|
||||||
compare = (value, limit) => value > limit;
|
|
||||||
limitValue = storeBlob.OnChainMinValue;
|
|
||||||
errorMessage = "The amount of the invoice is too high to be paid with lightning";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user