Fix tests and rename type=lnd to type=lnd-rest

This commit is contained in:
nicolas.dorier 2018-07-08 15:33:42 +09:00
parent a4ecf070b0
commit 0879895678
7 changed files with 27 additions and 28 deletions

View file

@ -85,7 +85,7 @@ namespace BTCPayServer.Tests
public void PrepareLightning(LightningConnectionType lndBackend)
{
ILightningInvoiceClient client = MerchantCharge.Client;
if (lndBackend == LightningConnectionType.Lnd)
if (lndBackend == LightningConnectionType.LndREST)
client = MerchantLnd.Client;
PrepareLightningAsync(client).GetAwaiter().GetResult();

View file

@ -132,8 +132,8 @@ namespace BTCPayServer.Tests
connectionString = "type=charge;server=" + parent.MerchantCharge.Client.Uri.AbsoluteUri;
else if (connectionType == LightningConnectionType.CLightning)
connectionString = "type=clightning;server=" + parent.MerchantLightningD.Address.AbsoluteUri;
else if (connectionType == LightningConnectionType.Lnd)
connectionString = $"type=lnd;server={parent.MerchantLnd.Swagger.BaseUrl}";
else if (connectionType == LightningConnectionType.LndREST)
connectionString = $"type=lnd-rest;server={parent.MerchantLnd.Swagger.BaseUrl}";
else
throw new NotSupportedException(connectionType.ToString());

View file

@ -515,11 +515,11 @@ namespace BTCPayServer.Tests
var macaroon = "0201036c6e640247030a10b0dbbde28f009f83d330bde05075ca251201301a160a0761646472657373120472656164120577726974651a170a08696e766f6963657312047265616412057772697465000006200ae088692e67cf14e767c3d2a4a67ce489150bf810654ff980e1b7a7e263d5e8";
var tls = "2d2d2d2d2d424547494e2043455254494649434154452d2d2d2d2d0a4d494942396a4343415a7967417749424167495156397a62474252724e54716b4e4b55676d72524d377a414b42676771686b6a4f50515144416a41784d5238770a485159445651514b45785a73626d5167595856306232646c626d56795958526c5a43426a5a584a304d51347744415944565151444577564754304e56557a41650a467730784f4441304d6a55794d7a517a4d6a4261467730784f5441324d6a41794d7a517a4d6a42614d444578487a416442674e5642416f54466d78755a4342680a645852765a3256755a584a686447566b49474e6c636e5178446a414d42674e5642414d5442555a50513156544d466b77457759484b6f5a497a6a3043415159490a4b6f5a497a6a304441516344516741454b7557424568564f75707965434157476130766e713262712f59396b41755a78616865646d454553482b753936436d450a397577486b4b2b4a7667547a66385141783550513741357254637155374b57595170303175364f426c5443426b6a414f42674e56485138424166384542414d430a4171517744775944565230544151482f42415577417745422f7a427642674e56485245456144426d6767564754304e565534494a6247396a5957786f62334e300a6877522f4141414268784141414141414141414141414141414141414141414268775373474f69786877514b41457342687753702f717473687754417141724c0a687753702f6d4a72687753702f754f77687753702f714e59687753702f6874436877514b70514157687753702f6c42514d416f4743437147534d343942414d430a413067414d45554349464866716d595a5043647a4a5178386b47586859473834394c31766541364c784d6f7a4f5774356d726835416945413662756e51556c710a6558553070474168776c3041654d726a4d4974394c7652736179756162565a593278343d0a2d2d2d2d2d454e442043455254494649434154452d2d2d2d2d0a";
var lndUri = $"type=lnd;server=https://lnd:lnd@127.0.0.1:53280/;macaroon={macaroon};tls={tls}";
var lndUri = $"type=lnd-rest;server=https://lnd:lnd@127.0.0.1:53280/;macaroon={macaroon};tls={tls}";
Assert.True(LightningConnectionString.TryParse(lndUri, false, out conn));
Assert.Equal(lndUri, conn.ToString());
Assert.Equal(LightningConnectionType.Lnd, conn.ConnectionType);
Assert.Equal(LightningConnectionType.LndREST, conn.ConnectionType);
Assert.Equal(macaroon, Encoders.Hex.EncodeData(conn.Macaroon));
Assert.Equal(tls, Encoders.Hex.EncodeData(conn.Tls));
}
@ -539,7 +539,7 @@ namespace BTCPayServer.Tests
[Fact]
public void CanSendLightningPaymentLnd()
{
ProcessLightningPayment(LightningConnectionType.Lnd);
ProcessLightningPayment(LightningConnectionType.LndREST);
}
void ProcessLightningPayment(LightningConnectionType type)
@ -1342,8 +1342,9 @@ namespace BTCPayServer.Tests
Assert.NotNull(vm.SelectedAppType);
Assert.Null(vm.Name);
vm.Name = "test";
vm.SelectedAppType = AppType.PointOfSale.ToString();
var redirectToAction = Assert.IsType<RedirectToActionResult>(apps.CreateApp(vm).Result);
Assert.Equal(nameof(apps.ListApps), redirectToAction.ActionName);
Assert.Equal(nameof(apps.UpdatePointOfSale), redirectToAction.ActionName);
var appList = Assert.IsType<ListAppsViewModel>(Assert.IsType<ViewResult>(apps.ListApps().Result).Model);
var appList2 = Assert.IsType<ListAppsViewModel>(Assert.IsType<ViewResult>(apps2.ListApps().Result).Model);
Assert.Single(appList.Apps);

View file

@ -20,7 +20,7 @@ services:
TEST_MERCHANTLIGHTNINGD: "type=clightning;server=/etc/merchant_lightningd_datadir/lightning-rpc"
TEST_CUSTOMERLIGHTNINGD: "type=clightning;server=/etc/customer_lightningd_datadir/lightning-rpc"
TEST_MERCHANTCHARGE: "type=charge;server=http://lightning-charged:9112/;api-token=foiewnccewuify"
TEST_MERCHANTLND: "type=lnd;server=http://lnd:lnd@127.0.0.1:53280/"
TEST_MERCHANTLND: "type=lnd-rest;server=http://lnd:lnd@127.0.0.1:53280/"
TESTS_INCONTAINER: "true"
expose:
- "80"

View file

@ -82,7 +82,7 @@ namespace BTCPayServer.Configuration
throw new ConfigException($"Invalid setting {net.CryptoCode}.lightning, " + Environment.NewLine +
$"If you have a lightning server use: 'type=clightning;server=/root/.lightning/lightning-rpc', " + Environment.NewLine +
$"If you have a lightning charge server: 'type=charge;server=https://charge.example.com;api-token=yourapitoken'" + Environment.NewLine +
$"If you have a lnd server: 'type=lnd;server=https://lnd:lnd@lnd.example.com;macaron=abf239...;tls=2abdf302...'");
$"If you have a lnd server: 'type=lnd-rest;server=https://lnd:lnd@lnd.example.com;macaron=abf239...;tls=2abdf302...'");
}
if(connectionString.IsLegacy)
{

View file

@ -28,7 +28,7 @@ namespace BTCPayServer.Payments.Lightning
return new CLightningRPCClient(connString.ToUri(false), network);
}
else if (connString.ConnectionType == LightningConnectionType.Lnd)
else if (connString.ConnectionType == LightningConnectionType.LndREST)
{
var swagger = LndSwaggerClientCustomHttp.Create(connString.BaseUri, network, connString.Tls, connString.Macaroon);
return new LndInvoiceClient(swagger);

View file

@ -13,7 +13,7 @@ namespace BTCPayServer.Payments.Lightning
{
Charge,
CLightning,
Lnd
LndREST
}
public class LightningConnectionString
{
@ -24,7 +24,7 @@ namespace BTCPayServer.Payments.Lightning
typeMapping = new Dictionary<string, LightningConnectionType>();
typeMapping.Add("clightning", LightningConnectionType.CLightning);
typeMapping.Add("charge", LightningConnectionType.Charge);
typeMapping.Add("lnd", LightningConnectionType.Lnd);
typeMapping.Add("lnd-rest", LightningConnectionType.LndREST);
typeMappingReverse = new Dictionary<LightningConnectionType, string>();
foreach (var kv in typeMapping)
{
@ -158,7 +158,7 @@ namespace BTCPayServer.Payments.Lightning
result.BaseUri = uri;
}
break;
case LightningConnectionType.Lnd:
case LightningConnectionType.LndREST:
{
var server = Take(keyValues, "server");
if (server == null)
@ -181,20 +181,18 @@ namespace BTCPayServer.Payments.Lightning
result.BaseUri = new UriBuilder(uri) { UserName = "", Password = "" }.Uri;
var macaroon = Take(keyValues, "macaroon");
//if(macaroon == null)
//{
// error = $"The key 'macaroon' is mandatory for lnd connection strings";
// return false;
//}
//try
//{
// result.Macaroon = Encoder.DecodeData(macaroon);
//}
//catch
//{
// error = $"The key 'macaroon' format should be in hex";
// return false;
//}
if (macaroon != null)
{
try
{
result.Macaroon = Encoder.DecodeData(macaroon);
}
catch
{
error = $"The key 'macaroon' format should be in hex";
return false;
}
}
try
{
var tls = Take(keyValues, "tls");
@ -337,7 +335,7 @@ namespace BTCPayServer.Payments.Lightning
case LightningConnectionType.CLightning:
builder.Append($";server={BaseUri}");
break;
case LightningConnectionType.Lnd:
case LightningConnectionType.LndREST:
if (Username == null)
{
builder.Append($";server={BaseUri}");