-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
269 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package itest | ||
|
||
import ( | ||
"log" | ||
"time" | ||
|
||
"github.com/breez/lntest" | ||
"github.com/breez/lspd/lsps2" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func testLsps2Cltv(p *testParams) { | ||
alice := lntest.NewClnNode(p.h, p.m, "Alice") | ||
alice.Start() | ||
alice.Fund(10000000) | ||
p.lsp.LightningNode().Fund(10000000) | ||
|
||
log.Print("Opening channel between Alice and the lsp") | ||
channel := alice.OpenChannel(p.lsp.LightningNode(), &lntest.OpenChannelOptions{ | ||
AmountSat: publicChanAmount, | ||
}) | ||
aliceLspScid := alice.WaitForChannelReady(channel) | ||
|
||
log.Print("Connecting bob to lspd") | ||
p.BreezClient().Node().ConnectPeer(p.lsp.LightningNode()) | ||
|
||
log.Printf("Calling lsps2.get_info") | ||
info := Lsps2GetInfo(p.BreezClient(), p.Lsp(), lsps2.GetInfoRequest{ | ||
Token: &WorkingToken, | ||
}) | ||
|
||
outerAmountMsat := uint64(2100000) | ||
innerAmountMsat := lsps2CalculateInnerAmountMsat(p.lsp, outerAmountMsat, info.OpeningFeeParamsMenu[0]) | ||
p.BreezClient().SetHtlcAcceptor(innerAmountMsat) | ||
|
||
log.Printf("Calling lsps2.buy") | ||
buyResp := Lsps2Buy(p.BreezClient(), p.Lsp(), lsps2.BuyRequest{ | ||
OpeningFeeParams: *info.OpeningFeeParamsMenu[0], | ||
PaymentSizeMsat: &outerAmountMsat, | ||
}) | ||
|
||
log.Printf("Adding bob's invoices") | ||
description := "Please pay me" | ||
_, outerInvoice := GenerateLsps2Invoices(p.BreezClient(), | ||
generateInvoicesRequest{ | ||
innerAmountMsat: innerAmountMsat, | ||
outerAmountMsat: outerAmountMsat, | ||
description: description, | ||
lsp: p.lsp, | ||
}, | ||
buyResp.JitChannelScid) | ||
|
||
// TODO: Fix race waiting for htlc interceptor. | ||
log.Printf("Waiting %v to allow htlc interceptor to activate.", htlcInterceptorDelay) | ||
<-time.After(htlcInterceptorDelay) | ||
log.Printf("Alice paying") | ||
route := constructRoute(p.Lsp().LightningNode(), p.BreezClient().Node(), aliceLspScid, lntest.NewShortChanIDFromString(buyResp.JitChannelScid), outerAmountMsat) | ||
|
||
// Increment the delay by one (should be incremented by 2), so the cltv delta is too little. | ||
route.Hops[0].Delay++ | ||
_, err := alice.PayViaRoute(outerAmountMsat, outerInvoice.paymentHash, outerInvoice.paymentSecret, route) | ||
assert.Contains(p.t, err.Error(), "WIRE_INCORRECT_CLTV_EXPIRY") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package itest | ||
|
||
import ( | ||
"log" | ||
"time" | ||
|
||
"github.com/breez/lntest" | ||
"github.com/breez/lspd/lsps2" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func testLsps2NoBalance(p *testParams) { | ||
alice := lntest.NewClnNode(p.h, p.m, "Alice") | ||
alice.Start() | ||
alice.Fund(10000000) | ||
|
||
log.Print("Opening channel between Alice and the lsp") | ||
channel := alice.OpenChannel(p.lsp.LightningNode(), &lntest.OpenChannelOptions{ | ||
AmountSat: publicChanAmount, | ||
}) | ||
aliceLspScid := alice.WaitForChannelReady(channel) | ||
|
||
log.Print("Connecting bob to lspd") | ||
p.BreezClient().Node().ConnectPeer(p.lsp.LightningNode()) | ||
|
||
log.Printf("Calling lsps2.get_info") | ||
info := Lsps2GetInfo(p.BreezClient(), p.Lsp(), lsps2.GetInfoRequest{ | ||
Token: &WorkingToken, | ||
}) | ||
|
||
outerAmountMsat := uint64(2100000) | ||
innerAmountMsat := lsps2CalculateInnerAmountMsat(p.lsp, outerAmountMsat, info.OpeningFeeParamsMenu[0]) | ||
p.BreezClient().SetHtlcAcceptor(innerAmountMsat) | ||
|
||
log.Printf("Calling lsps2.buy") | ||
buyResp := Lsps2Buy(p.BreezClient(), p.Lsp(), lsps2.BuyRequest{ | ||
OpeningFeeParams: *info.OpeningFeeParamsMenu[0], | ||
PaymentSizeMsat: &outerAmountMsat, | ||
}) | ||
|
||
log.Printf("Adding bob's invoices") | ||
description := "Please pay me" | ||
_, outerInvoice := GenerateLsps2Invoices(p.BreezClient(), | ||
generateInvoicesRequest{ | ||
innerAmountMsat: innerAmountMsat, | ||
outerAmountMsat: outerAmountMsat, | ||
description: description, | ||
lsp: p.lsp, | ||
}, | ||
buyResp.JitChannelScid) | ||
|
||
// TODO: Fix race waiting for htlc interceptor. | ||
log.Printf("Waiting %v to allow htlc interceptor to activate.", htlcInterceptorDelay) | ||
<-time.After(htlcInterceptorDelay) | ||
log.Printf("Alice paying") | ||
route := constructRoute(p.Lsp().LightningNode(), p.BreezClient().Node(), aliceLspScid, lntest.NewShortChanIDFromString(buyResp.JitChannelScid), outerAmountMsat) | ||
|
||
// Increment the delay by two to support the spec | ||
route.Hops[0].Delay += 2 | ||
_, err := alice.PayViaRoute(outerAmountMsat, outerInvoice.paymentHash, outerInvoice.paymentSecret, route) | ||
assert.Contains(p.t, err.Error(), "WIRE_TEMPORARY_CHANNEL_FAILURE") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package itest | ||
|
||
import ( | ||
"log" | ||
"time" | ||
|
||
"github.com/breez/lntest" | ||
"github.com/breez/lspd/config" | ||
"github.com/breez/lspd/lsps2" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func testLsps2ZeroConfUtxo(p *testParams) { | ||
alice := lntest.NewClnNode(p.h, p.m, "Alice") | ||
alice.Start() | ||
alice.Fund(10000000) | ||
|
||
minConfs := uint32(0) | ||
lsp := p.lspFunc(p.h, p.m, p.mem, &config.NodeConfig{MinConfs: &minConfs}) | ||
lsp.Start() | ||
|
||
log.Print("Opening channel between Alice and the lsp") | ||
channel := alice.OpenChannel(lsp.LightningNode(), &lntest.OpenChannelOptions{ | ||
AmountSat: publicChanAmount, | ||
}) | ||
channelId := alice.WaitForChannelReady(channel) | ||
|
||
tempaddr := lsp.LightningNode().GetNewAddress() | ||
p.m.SendToAddress(tempaddr, 210000) | ||
p.m.MineBlocks(6) | ||
lsp.LightningNode().WaitForSync() | ||
|
||
initialHeight := p.m.GetBlockHeight() | ||
addr := lsp.LightningNode().GetNewAddress() | ||
lsp.LightningNode().SendToAddress(addr, 200000) | ||
|
||
log.Print("Connecting bob to lspd") | ||
p.BreezClient().Node().ConnectPeer(p.lsp.LightningNode()) | ||
|
||
log.Printf("Calling lsps2.get_info") | ||
info := Lsps2GetInfo(p.BreezClient(), p.Lsp(), lsps2.GetInfoRequest{ | ||
Token: &WorkingToken, | ||
}) | ||
|
||
outerAmountMsat := uint64(2100000) | ||
innerAmountMsat := lsps2CalculateInnerAmountMsat(p.lsp, outerAmountMsat, info.OpeningFeeParamsMenu[0]) | ||
p.BreezClient().SetHtlcAcceptor(innerAmountMsat) | ||
|
||
log.Printf("Calling lsps2.buy") | ||
buyResp := Lsps2Buy(p.BreezClient(), p.Lsp(), lsps2.BuyRequest{ | ||
OpeningFeeParams: *info.OpeningFeeParamsMenu[0], | ||
PaymentSizeMsat: &outerAmountMsat, | ||
}) | ||
|
||
log.Printf("Adding bob's invoices") | ||
description := "Please pay me" | ||
_, outerInvoice := GenerateLsps2Invoices(p.BreezClient(), | ||
generateInvoicesRequest{ | ||
innerAmountMsat: innerAmountMsat, | ||
outerAmountMsat: outerAmountMsat, | ||
description: description, | ||
lsp: p.lsp, | ||
}, | ||
buyResp.JitChannelScid) | ||
|
||
// TODO: Fix race waiting for htlc interceptor. | ||
log.Printf("Waiting %v to allow htlc interceptor to activate.", htlcInterceptorDelay) | ||
<-time.After(htlcInterceptorDelay) | ||
log.Printf("Alice paying") | ||
route := constructRoute(lsp.LightningNode(), p.BreezClient().Node(), channelId, lntest.NewShortChanIDFromString(buyResp.JitChannelScid), outerAmountMsat) | ||
payResp, err := alice.PayViaRoute(outerAmountMsat, outerInvoice.paymentHash, outerInvoice.paymentSecret, route) | ||
lntest.CheckError(p.t, err) | ||
bobInvoice := p.BreezClient().Node().GetInvoice(payResp.PaymentHash) | ||
|
||
assert.Equal(p.t, payResp.PaymentPreimage, bobInvoice.PaymentPreimage) | ||
assert.Equal(p.t, innerAmountMsat, bobInvoice.AmountReceivedMsat) | ||
|
||
// Make sure there's not accidently a block mined in between | ||
finalHeight := p.m.GetBlockHeight() | ||
assert.Equal(p.t, initialHeight, finalHeight) | ||
} |