add tests, do not returns bitcoinAddress field if not supported by the invoice

This commit is contained in:
nicolas.dorier
2018-01-13 22:01:09 +09:00
parent e3cc589ebb
commit 6b4eeff3f1
5 changed files with 66 additions and 7 deletions

View File

@@ -46,12 +46,15 @@ namespace BTCPayServer.Tests
Assert.IsType<ViewResult>(await store.RequestPairing(pairingCode.ToString())); Assert.IsType<ViewResult>(await store.RequestPairing(pairingCode.ToString()));
await store.Pair(pairingCode.ToString(), StoreId); await store.Pair(pairingCode.ToString(), StoreId);
} }
public StoresController CreateStore(string cryptoCode = "BTC") public StoresController CreateStore(string cryptoCode = null)
{ {
return CreateStoreAsync(cryptoCode).GetAwaiter().GetResult(); return CreateStoreAsync(cryptoCode).GetAwaiter().GetResult();
} }
public async Task<StoresController> CreateStoreAsync(string cryptoCode = "BTC")
public string CryptoCode { get; set; } = "BTC";
public async Task<StoresController> CreateStoreAsync(string cryptoCode = null)
{ {
cryptoCode = cryptoCode ?? CryptoCode;
SupportedNetwork = parent.NetworkProvider.GetNetwork(cryptoCode); SupportedNetwork = parent.NetworkProvider.GetNetwork(cryptoCode);
ExtKey = new ExtKey().GetWif(SupportedNetwork.NBitcoinNetwork); ExtKey = new ExtKey().GetWif(SupportedNetwork.NBitcoinNetwork);
var store = parent.PayTester.GetController<StoresController>(UserId); var store = parent.PayTester.GetController<StoresController>(UserId);
@@ -65,7 +68,7 @@ namespace BTCPayServer.Tests
await store.AddDerivationScheme(StoreId, new DerivationSchemeViewModel() await store.AddDerivationScheme(StoreId, new DerivationSchemeViewModel()
{ {
CryptoCurrency = "BTC", CryptoCurrency = cryptoCode,
DerivationSchemeFormat = "BTCPay", DerivationSchemeFormat = "BTCPay",
DerivationScheme = DerivationScheme.ToString(), DerivationScheme = DerivationScheme.ToString(),
}, "Save"); }, "Save");

View File

@@ -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<InvoiceController>(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] [Fact]
public void CanPayWithTwoCurrencies() public void CanPayWithTwoCurrencies()
{ {

View File

@@ -37,7 +37,7 @@ services:
- postgres - postgres
nbxplorer: nbxplorer:
image: nicolasdorier/nbxplorer:1.0.0.65 image: nicolasdorier/nbxplorer:1.0.0.67
ports: ports:
- "32838:32838" - "32838:32838"
expose: expose:

View File

@@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework> <TargetFramework>netcoreapp2.0</TargetFramework>
<Version>1.0.0.77</Version> <Version>1.0.0.78</Version>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Compile Remove="Build\dockerfiles\**" /> <Compile Remove="Build\dockerfiles\**" />

View File

@@ -172,8 +172,6 @@ namespace BTCPayServer.Controllers
entity.TxFee = GetTxFee(storeBlob, await gettingFee); entity.TxFee = GetTxFee(storeBlob, await gettingFee);
entity.Rate = await gettingRate; 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 #pragma warning restore CS0618
} }