diff --git a/BTCPayServer.Tests/TestAccount.cs b/BTCPayServer.Tests/TestAccount.cs index 21a75deaa..9787e233f 100644 --- a/BTCPayServer.Tests/TestAccount.cs +++ b/BTCPayServer.Tests/TestAccount.cs @@ -46,12 +46,15 @@ namespace BTCPayServer.Tests Assert.IsType(await store.RequestPairing(pairingCode.ToString())); await store.Pair(pairingCode.ToString(), StoreId); } - public StoresController CreateStore(string cryptoCode = "BTC") + public StoresController CreateStore(string cryptoCode = null) { return CreateStoreAsync(cryptoCode).GetAwaiter().GetResult(); } - public async Task CreateStoreAsync(string cryptoCode = "BTC") + + public string CryptoCode { get; set; } = "BTC"; + public async Task CreateStoreAsync(string cryptoCode = null) { + cryptoCode = cryptoCode ?? CryptoCode; SupportedNetwork = parent.NetworkProvider.GetNetwork(cryptoCode); ExtKey = new ExtKey().GetWif(SupportedNetwork.NBitcoinNetwork); var store = parent.PayTester.GetController(UserId); @@ -65,7 +68,7 @@ namespace BTCPayServer.Tests await store.AddDerivationScheme(StoreId, new DerivationSchemeViewModel() { - CryptoCurrency = "BTC", + CryptoCurrency = cryptoCode, DerivationSchemeFormat = "BTCPay", DerivationScheme = DerivationScheme.ToString(), }, "Save"); diff --git a/BTCPayServer.Tests/UnitTest1.cs b/BTCPayServer.Tests/UnitTest1.cs index 643af58f9..9b9127665 100644 --- a/BTCPayServer.Tests/UnitTest1.cs +++ b/BTCPayServer.Tests/UnitTest1.cs @@ -392,6 +392,64 @@ namespace BTCPayServer.Tests } } + [Fact] + public void CanHaveLTCOnlyStore() + { + using (var tester = ServerTester.Create()) + { + tester.Start(); + var user = tester.NewAccount(); + user.CryptoCode = "LTC"; + user.GrantAccess(); + + // First we try payment with a merchant having only BTC + var invoice = user.BitPay.CreateInvoice(new Invoice() + { + Price = 500, + Currency = "USD", + PosData = "posData", + OrderId = "orderId", + ItemDesc = "Some description", + FullNotifications = true + }, Facade.Merchant); + + Assert.Single(invoice.CryptoInfo); + Assert.Equal("LTC", invoice.CryptoInfo[0].CryptoCode); + var cashCow = tester.LTCExplorerNode; + var invoiceAddress = BitcoinAddress.Create(invoice.CryptoInfo[0].Address, cashCow.Network); + var firstPayment = Money.Coins(0.1m); + cashCow.SendToAddress(invoiceAddress, firstPayment); + Eventually(() => + { + invoice = user.BitPay.GetInvoice(invoice.Id); + Assert.Equal(firstPayment, invoice.CryptoInfo[0].Paid); + }); + + Assert.Single(invoice.CryptoInfo); // Only BTC should be presented + + var controller = tester.PayTester.GetController(null); + var checkout = (Models.InvoicingModels.PaymentModel)((JsonResult)controller.GetStatus(invoice.Id, null).GetAwaiter().GetResult()).Value; + Assert.Single(checkout.AvailableCryptos); + Assert.Equal("LTC", checkout.CryptoCode); + + ////////////////////// + + // Despite it is called BitcoinAddress it should be LTC because BTC is not available + Assert.Null(invoice.BitcoinAddress); + Assert.NotEqual(invoice.BtcDue, invoice.CryptoInfo[0].Due); // Should be BTC rate + cashCow.SendToAddress(invoiceAddress, invoice.CryptoInfo[0].Due); + + Eventually(() => + { + invoice = user.BitPay.GetInvoice(invoice.Id); + Assert.Equal("paid", invoice.Status); + checkout = (Models.InvoicingModels.PaymentModel)((JsonResult)controller.GetStatus(invoice.Id, null).GetAwaiter().GetResult()).Value; + Assert.Equal("paid", checkout.Status); + }); + + } + } + [Fact] public void CanPayWithTwoCurrencies() { diff --git a/BTCPayServer.Tests/docker-compose.yml b/BTCPayServer.Tests/docker-compose.yml index c91176ab7..6b31309d5 100644 --- a/BTCPayServer.Tests/docker-compose.yml +++ b/BTCPayServer.Tests/docker-compose.yml @@ -37,7 +37,7 @@ services: - postgres nbxplorer: - image: nicolasdorier/nbxplorer:1.0.0.65 + image: nicolasdorier/nbxplorer:1.0.0.67 ports: - "32838:32838" expose: diff --git a/BTCPayServer/BTCPayServer.csproj b/BTCPayServer/BTCPayServer.csproj index b2c8b1932..c0e3cbf2e 100644 --- a/BTCPayServer/BTCPayServer.csproj +++ b/BTCPayServer/BTCPayServer.csproj @@ -2,7 +2,7 @@ Exe netcoreapp2.0 - 1.0.0.77 + 1.0.0.78 diff --git a/BTCPayServer/Controllers/InvoiceController.cs b/BTCPayServer/Controllers/InvoiceController.cs index 64e2a5e5d..98578b558 100644 --- a/BTCPayServer/Controllers/InvoiceController.cs +++ b/BTCPayServer/Controllers/InvoiceController.cs @@ -172,8 +172,6 @@ namespace BTCPayServer.Controllers entity.TxFee = GetTxFee(storeBlob, await gettingFee); entity.Rate = await gettingRate; } - // So users does not crash if they check depositAddress is not set - entity.DepositAddress = cryptoDatas.First().Value.DepositAddress; #pragma warning restore CS0618 }