mirror of
https://github.com/aljazceru/lspd.git
synced 2025-12-19 14:54:22 +01:00
shared testparams
This commit is contained in:
2
go.mod
2
go.mod
@@ -43,6 +43,7 @@ require (
|
|||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/Yawning/aez v0.0.0-20211027044916-e49e68abd344 // indirect
|
||||||
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da // indirect
|
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da // indirect
|
||||||
github.com/aead/siphash v1.0.1 // indirect
|
github.com/aead/siphash v1.0.1 // indirect
|
||||||
github.com/andybalholm/brotli v1.0.3 // indirect
|
github.com/andybalholm/brotli v1.0.3 // indirect
|
||||||
@@ -136,6 +137,7 @@ require (
|
|||||||
github.com/ulikunitz/xz v0.5.10 // indirect
|
github.com/ulikunitz/xz v0.5.10 // indirect
|
||||||
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
|
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
|
||||||
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect
|
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect
|
||||||
|
gitlab.com/yawning/bsaes.git v0.0.0-20190805113838-0a714cd429ec // indirect
|
||||||
go.etcd.io/bbolt v1.3.6 // indirect
|
go.etcd.io/bbolt v1.3.6 // indirect
|
||||||
go.etcd.io/etcd/api/v3 v3.5.0 // indirect
|
go.etcd.io/etcd/api/v3 v3.5.0 // indirect
|
||||||
go.etcd.io/etcd/client/pkg/v3 v3.5.0 // indirect
|
go.etcd.io/etcd/client/pkg/v3 v3.5.0 // indirect
|
||||||
|
|||||||
@@ -8,19 +8,17 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/breez/lntest"
|
"github.com/breez/lntest"
|
||||||
btcec "github.com/btcsuite/btcd/btcec/v2"
|
"github.com/btcsuite/btcd/btcec/v2"
|
||||||
"github.com/btcsuite/btcd/btcec/v2/ecdsa"
|
"github.com/btcsuite/btcd/btcec/v2/ecdsa"
|
||||||
"github.com/btcsuite/btcd/chaincfg"
|
"github.com/btcsuite/btcd/chaincfg"
|
||||||
"github.com/decred/dcrd/dcrec/secp256k1/v4"
|
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/lightningnetwork/lnd/zpay32"
|
"github.com/lightningnetwork/lnd/zpay32"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ZeroConfNode struct {
|
type breezClient struct {
|
||||||
name string
|
name string
|
||||||
harness *lntest.TestHarness
|
harness *lntest.TestHarness
|
||||||
lightningNode *lntest.CoreLightningNode
|
lightningNode lntest.LightningNode
|
||||||
privKey *secp256k1.PrivateKey
|
|
||||||
scriptDir string
|
scriptDir string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,12 +48,7 @@ pip install pyln-client > /dev/null 2>&1
|
|||||||
python %s
|
python %s
|
||||||
`
|
`
|
||||||
|
|
||||||
func NewZeroConfNode(h *lntest.TestHarness, m *lntest.Miner, name string) *ZeroConfNode {
|
func newClnBreezClient(h *lntest.TestHarness, m *lntest.Miner, name string) *breezClient {
|
||||||
privKey, err := btcec.NewPrivateKey()
|
|
||||||
lntest.CheckError(h.T, err)
|
|
||||||
|
|
||||||
s := privKey.Serialize()
|
|
||||||
|
|
||||||
scriptDir, err := os.MkdirTemp(h.Dir, name)
|
scriptDir, err := os.MkdirTemp(h.Dir, name)
|
||||||
lntest.CheckError(h.T, err)
|
lntest.CheckError(h.T, err)
|
||||||
pythonFilePath := filepath.Join(scriptDir, "zero_conf_plugin.py")
|
pythonFilePath := filepath.Join(scriptDir, "zero_conf_plugin.py")
|
||||||
@@ -88,7 +81,6 @@ func NewZeroConfNode(h *lntest.TestHarness, m *lntest.Miner, name string) *ZeroC
|
|||||||
h,
|
h,
|
||||||
m,
|
m,
|
||||||
name,
|
name,
|
||||||
fmt.Sprintf("--dev-force-privkey=%x", s),
|
|
||||||
fmt.Sprintf("--plugin=%s", pluginFilePath),
|
fmt.Sprintf("--plugin=%s", pluginFilePath),
|
||||||
// NOTE: max-concurrent-htlcs is 30 on mainnet by default. In cln V22.11
|
// NOTE: max-concurrent-htlcs is 30 on mainnet by default. In cln V22.11
|
||||||
// there is a check for 'all dust' commitment transactions. The max
|
// there is a check for 'all dust' commitment transactions. The max
|
||||||
@@ -99,12 +91,20 @@ func NewZeroConfNode(h *lntest.TestHarness, m *lntest.Miner, name string) *ZeroC
|
|||||||
"--max-concurrent-htlcs=30",
|
"--max-concurrent-htlcs=30",
|
||||||
)
|
)
|
||||||
|
|
||||||
return &ZeroConfNode{
|
return &breezClient{
|
||||||
name: name,
|
name: name,
|
||||||
harness: h,
|
harness: h,
|
||||||
lightningNode: node,
|
lightningNode: node,
|
||||||
scriptDir: scriptDir,
|
scriptDir: scriptDir,
|
||||||
privKey: privKey,
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func newLndBreezClient(h *lntest.TestHarness, m *lntest.Miner, name string) *breezClient {
|
||||||
|
lnd := lntest.NewLndNode(h, m, name)
|
||||||
|
return &breezClient{
|
||||||
|
name: name,
|
||||||
|
harness: h,
|
||||||
|
lightningNode: lnd,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,7 +122,7 @@ type invoice struct {
|
|||||||
paymentPreimage []byte
|
paymentPreimage []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *ZeroConfNode) GenerateInvoices(req generateInvoicesRequest) (invoice, invoice) {
|
func (n *breezClient) GenerateInvoices(req generateInvoicesRequest) (invoice, invoice) {
|
||||||
preimage, err := GenerateRandomBytes(32)
|
preimage, err := GenerateRandomBytes(32)
|
||||||
lntest.CheckError(n.harness.T, err)
|
lntest.CheckError(n.harness.T, err)
|
||||||
|
|
||||||
@@ -153,7 +153,7 @@ func (n *ZeroConfNode) GenerateInvoices(req generateInvoicesRequest) (invoice, i
|
|||||||
outerInvoice, err := outerInvoiceRaw.Encode(zpay32.MessageSigner{
|
outerInvoice, err := outerInvoiceRaw.Encode(zpay32.MessageSigner{
|
||||||
SignCompact: func(msg []byte) ([]byte, error) {
|
SignCompact: func(msg []byte) ([]byte, error) {
|
||||||
hash := sha256.Sum256(msg)
|
hash := sha256.Sum256(msg)
|
||||||
return ecdsa.SignCompact(n.privKey, hash[:], true)
|
return ecdsa.SignCompact(n.lightningNode.PrivateKey(), hash[:], true)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
lntest.CheckError(n.harness.T, err)
|
lntest.CheckError(n.harness.T, err)
|
||||||
@@ -8,15 +8,13 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func testOpenZeroConfChannelOnReceive(h *lntest.TestHarness, lsp LspNode, miner *lntest.Miner) {
|
func testOpenZeroConfChannelOnReceive(p *testParams) {
|
||||||
alice := lntest.NewCoreLightningNode(h, miner, "Alice")
|
alice := lntest.NewCoreLightningNode(p.h, p.m, "Alice")
|
||||||
bob := NewZeroConfNode(h, miner, "Bob")
|
|
||||||
|
|
||||||
alice.Fund(10000000)
|
alice.Fund(10000000)
|
||||||
lsp.LightningNode().Fund(10000000)
|
p.lsp.LightningNode().Fund(10000000)
|
||||||
|
|
||||||
log.Print("Opening channel between Alice and the lsp")
|
log.Print("Opening channel between Alice and the lsp")
|
||||||
channel := alice.OpenChannel(lsp.LightningNode(), &lntest.OpenChannelOptions{
|
channel := alice.OpenChannel(p.lsp.LightningNode(), &lntest.OpenChannelOptions{
|
||||||
AmountSat: 1000000,
|
AmountSat: 1000000,
|
||||||
})
|
})
|
||||||
alice.WaitForChannelReady(channel)
|
alice.WaitForChannelReady(channel)
|
||||||
@@ -25,50 +23,49 @@ func testOpenZeroConfChannelOnReceive(h *lntest.TestHarness, lsp LspNode, miner
|
|||||||
outerAmountMsat := uint64(2100000)
|
outerAmountMsat := uint64(2100000)
|
||||||
innerAmountMsat := uint64(2100000)
|
innerAmountMsat := uint64(2100000)
|
||||||
description := "Please pay me"
|
description := "Please pay me"
|
||||||
innerInvoice, outerInvoice := bob.GenerateInvoices(generateInvoicesRequest{
|
innerInvoice, outerInvoice := p.BreezClient().GenerateInvoices(generateInvoicesRequest{
|
||||||
innerAmountMsat: innerAmountMsat,
|
innerAmountMsat: innerAmountMsat,
|
||||||
outerAmountMsat: outerAmountMsat,
|
outerAmountMsat: outerAmountMsat,
|
||||||
description: description,
|
description: description,
|
||||||
lsp: lsp,
|
lsp: p.lsp,
|
||||||
})
|
})
|
||||||
|
|
||||||
log.Print("Connecting bob to lspd")
|
log.Print("Connecting bob to lspd")
|
||||||
bob.lightningNode.ConnectPeer(lsp.LightningNode())
|
p.BreezClient().lightningNode.ConnectPeer(p.lsp.LightningNode())
|
||||||
|
|
||||||
// NOTE: We pretend to be paying fees to the lsp, but actually we won't.
|
// NOTE: We pretend to be paying fees to the lsp, but actually we won't.
|
||||||
log.Printf("Registering payment with lsp")
|
log.Printf("Registering payment with lsp")
|
||||||
pretendAmount := outerAmountMsat - 2000000
|
pretendAmount := outerAmountMsat - 2000000
|
||||||
RegisterPayment(lsp, &lspd.PaymentInformation{
|
RegisterPayment(p.lsp, &lspd.PaymentInformation{
|
||||||
PaymentHash: innerInvoice.paymentHash,
|
PaymentHash: innerInvoice.paymentHash,
|
||||||
PaymentSecret: innerInvoice.paymentSecret,
|
PaymentSecret: innerInvoice.paymentSecret,
|
||||||
Destination: bob.lightningNode.NodeId(),
|
Destination: p.BreezClient().lightningNode.NodeId(),
|
||||||
IncomingAmountMsat: int64(outerAmountMsat),
|
IncomingAmountMsat: int64(outerAmountMsat),
|
||||||
OutgoingAmountMsat: int64(pretendAmount),
|
OutgoingAmountMsat: int64(pretendAmount),
|
||||||
})
|
})
|
||||||
|
|
||||||
log.Printf("Alice paying")
|
log.Printf("Alice paying")
|
||||||
payResp := alice.Pay(outerInvoice.bolt11)
|
payResp := alice.Pay(outerInvoice.bolt11)
|
||||||
bobInvoice := bob.lightningNode.GetInvoice(payResp.PaymentHash)
|
bobInvoice := p.BreezClient().lightningNode.GetInvoice(payResp.PaymentHash)
|
||||||
|
|
||||||
assert.Equal(h.T, payResp.PaymentPreimage, bobInvoice.PaymentPreimage)
|
assert.Equal(p.t, payResp.PaymentPreimage, bobInvoice.PaymentPreimage)
|
||||||
assert.Equal(h.T, outerAmountMsat, bobInvoice.AmountReceivedMsat)
|
assert.Equal(p.t, outerAmountMsat, bobInvoice.AmountReceivedMsat)
|
||||||
|
|
||||||
// Make sure capacity is correct
|
// Make sure capacity is correct
|
||||||
chans := bob.lightningNode.GetChannels()
|
chans := p.BreezClient().lightningNode.GetChannels()
|
||||||
assert.Len(h.T, chans, 1)
|
assert.Len(p.t, chans, 1)
|
||||||
c := chans[0]
|
c := chans[0]
|
||||||
AssertChannelCapacity(h.T, outerAmountMsat, c.CapacityMsat)
|
AssertChannelCapacity(p.t, outerAmountMsat, c.CapacityMsat)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testOpenZeroConfSingleHtlc(h *lntest.TestHarness, lsp LspNode, miner *lntest.Miner) {
|
func testOpenZeroConfSingleHtlc(p *testParams) {
|
||||||
alice := lntest.NewCoreLightningNode(h, miner, "Alice")
|
alice := lntest.NewCoreLightningNode(p.h, p.m, "Alice")
|
||||||
bob := NewZeroConfNode(h, miner, "Bob")
|
|
||||||
|
|
||||||
alice.Fund(10000000)
|
alice.Fund(10000000)
|
||||||
lsp.LightningNode().Fund(10000000)
|
p.lsp.LightningNode().Fund(10000000)
|
||||||
|
|
||||||
log.Print("Opening channel between Alice and the lsp")
|
log.Print("Opening channel between Alice and the lsp")
|
||||||
channel := alice.OpenChannel(lsp.LightningNode(), &lntest.OpenChannelOptions{
|
channel := alice.OpenChannel(p.lsp.LightningNode(), &lntest.OpenChannelOptions{
|
||||||
AmountSat: 1000000,
|
AmountSat: 1000000,
|
||||||
})
|
})
|
||||||
channelId := alice.WaitForChannelReady(channel)
|
channelId := alice.WaitForChannelReady(channel)
|
||||||
@@ -77,40 +74,40 @@ func testOpenZeroConfSingleHtlc(h *lntest.TestHarness, lsp LspNode, miner *lntes
|
|||||||
outerAmountMsat := uint64(2100000)
|
outerAmountMsat := uint64(2100000)
|
||||||
innerAmountMsat := uint64(2100000)
|
innerAmountMsat := uint64(2100000)
|
||||||
description := "Please pay me"
|
description := "Please pay me"
|
||||||
innerInvoice, outerInvoice := bob.GenerateInvoices(generateInvoicesRequest{
|
innerInvoice, outerInvoice := p.BreezClient().GenerateInvoices(generateInvoicesRequest{
|
||||||
innerAmountMsat: innerAmountMsat,
|
innerAmountMsat: innerAmountMsat,
|
||||||
outerAmountMsat: outerAmountMsat,
|
outerAmountMsat: outerAmountMsat,
|
||||||
description: description,
|
description: description,
|
||||||
lsp: lsp,
|
lsp: p.lsp,
|
||||||
})
|
})
|
||||||
|
|
||||||
log.Print("Connecting bob to lspd")
|
log.Print("Connecting bob to lspd")
|
||||||
bob.lightningNode.ConnectPeer(lsp.LightningNode())
|
p.BreezClient().lightningNode.ConnectPeer(p.lsp.LightningNode())
|
||||||
|
|
||||||
// NOTE: We pretend to be paying fees to the lsp, but actually we won't.
|
// NOTE: We pretend to be paying fees to the lsp, but actually we won't.
|
||||||
log.Printf("Registering payment with lsp")
|
log.Printf("Registering payment with lsp")
|
||||||
pretendAmount := outerAmountMsat - 2000000
|
pretendAmount := outerAmountMsat - 2000000
|
||||||
RegisterPayment(lsp, &lspd.PaymentInformation{
|
RegisterPayment(p.lsp, &lspd.PaymentInformation{
|
||||||
PaymentHash: innerInvoice.paymentHash,
|
PaymentHash: innerInvoice.paymentHash,
|
||||||
PaymentSecret: innerInvoice.paymentSecret,
|
PaymentSecret: innerInvoice.paymentSecret,
|
||||||
Destination: bob.lightningNode.NodeId(),
|
Destination: p.BreezClient().lightningNode.NodeId(),
|
||||||
IncomingAmountMsat: int64(outerAmountMsat),
|
IncomingAmountMsat: int64(outerAmountMsat),
|
||||||
OutgoingAmountMsat: int64(pretendAmount),
|
OutgoingAmountMsat: int64(pretendAmount),
|
||||||
})
|
})
|
||||||
|
|
||||||
log.Printf("Alice paying")
|
log.Printf("Alice paying")
|
||||||
route := constructRoute(lsp.LightningNode(), bob.lightningNode, channelId, lntest.NewShortChanIDFromString("1x0x0"), outerAmountMsat)
|
route := constructRoute(p.lsp.LightningNode(), p.BreezClient().lightningNode, channelId, lntest.NewShortChanIDFromString("1x0x0"), outerAmountMsat)
|
||||||
payResp := alice.PayViaRoute(outerAmountMsat, outerInvoice.paymentHash, outerInvoice.paymentSecret, route)
|
payResp := alice.PayViaRoute(outerAmountMsat, outerInvoice.paymentHash, outerInvoice.paymentSecret, route)
|
||||||
bobInvoice := bob.lightningNode.GetInvoice(payResp.PaymentHash)
|
bobInvoice := p.BreezClient().lightningNode.GetInvoice(payResp.PaymentHash)
|
||||||
|
|
||||||
assert.Equal(h.T, payResp.PaymentPreimage, bobInvoice.PaymentPreimage)
|
assert.Equal(p.t, payResp.PaymentPreimage, bobInvoice.PaymentPreimage)
|
||||||
assert.Equal(h.T, outerAmountMsat, bobInvoice.AmountReceivedMsat)
|
assert.Equal(p.t, outerAmountMsat, bobInvoice.AmountReceivedMsat)
|
||||||
|
|
||||||
// Make sure capacity is correct
|
// Make sure capacity is correct
|
||||||
chans := bob.lightningNode.GetChannels()
|
chans := p.BreezClient().lightningNode.GetChannels()
|
||||||
assert.Len(h.T, chans, 1)
|
assert.Len(p.t, chans, 1)
|
||||||
c := chans[0]
|
c := chans[0]
|
||||||
AssertChannelCapacity(h.T, outerAmountMsat, c.CapacityMsat)
|
AssertChannelCapacity(p.t, outerAmountMsat, c.CapacityMsat)
|
||||||
}
|
}
|
||||||
|
|
||||||
func constructRoute(
|
func constructRoute(
|
||||||
|
|||||||
@@ -13,25 +13,25 @@ var defaultTimeout time.Duration = time.Second * 120
|
|||||||
|
|
||||||
func TestLspd(t *testing.T) {
|
func TestLspd(t *testing.T) {
|
||||||
testCases := allTestCases
|
testCases := allTestCases
|
||||||
// runTests(t, testCases, "LND-lspd", func(h *lntest.TestHarness, m *lntest.Miner) LspNode {
|
// runTests(t, testCases, "LND-lspd", func(h *lntest.TestHarness, m *lntest.Miner) (LspNode, *breezClient) {
|
||||||
// return NewLndLspdNode(h, m, "lsp")
|
// return NewLndLspdNode(h, m, "lsp"), newLndBreezClient(h, m, "breez-client")
|
||||||
// })
|
// })
|
||||||
|
|
||||||
runTests(t, testCases, "CLN-lspd", func(h *lntest.TestHarness, m *lntest.Miner) LspNode {
|
runTests(t, testCases, "CLN-lspd", func(h *lntest.TestHarness, m *lntest.Miner) (LspNode, *breezClient) {
|
||||||
return NewClnLspdNode(h, m, "lsp")
|
return NewClnLspdNode(h, m, "lsp"), newClnBreezClient(h, m, "breez-client")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func runTests(t *testing.T, testCases []*testCase, prefix string, lspFunc func(h *lntest.TestHarness, m *lntest.Miner) LspNode) {
|
func runTests(t *testing.T, testCases []*testCase, prefix string, nodesFunc func(h *lntest.TestHarness, m *lntest.Miner) (LspNode, *breezClient)) {
|
||||||
for _, testCase := range testCases {
|
for _, testCase := range testCases {
|
||||||
testCase := testCase
|
testCase := testCase
|
||||||
t.Run(fmt.Sprintf("%s: %s", prefix, testCase.name), func(t *testing.T) {
|
t.Run(fmt.Sprintf("%s: %s", prefix, testCase.name), func(t *testing.T) {
|
||||||
runTest(t, testCase, prefix, lspFunc)
|
runTest(t, testCase, prefix, nodesFunc)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func runTest(t *testing.T, testCase *testCase, prefix string, lspFunc func(h *lntest.TestHarness, m *lntest.Miner) LspNode) {
|
func runTest(t *testing.T, testCase *testCase, prefix string, nodesFunc func(h *lntest.TestHarness, m *lntest.Miner) (LspNode, *breezClient)) {
|
||||||
log.Printf("%s: Running test case '%s'", prefix, testCase.name)
|
log.Printf("%s: Running test case '%s'", prefix, testCase.name)
|
||||||
var dd time.Duration
|
var dd time.Duration
|
||||||
to := testCase.timeout
|
to := testCase.timeout
|
||||||
@@ -42,20 +42,26 @@ func runTest(t *testing.T, testCase *testCase, prefix string, lspFunc func(h *ln
|
|||||||
deadline := time.Now().Add(to)
|
deadline := time.Now().Add(to)
|
||||||
log.Printf("Using deadline %v", deadline.String())
|
log.Printf("Using deadline %v", deadline.String())
|
||||||
|
|
||||||
harness := lntest.NewTestHarness(t, deadline)
|
h := lntest.NewTestHarness(t, deadline)
|
||||||
defer harness.TearDown()
|
defer h.TearDown()
|
||||||
|
|
||||||
log.Printf("Creating miner")
|
log.Printf("Creating miner")
|
||||||
miner := lntest.NewMiner(harness)
|
miner := lntest.NewMiner(h)
|
||||||
log.Printf("Creating lsp")
|
log.Printf("Creating lsp")
|
||||||
lsp := lspFunc(harness, miner)
|
lsp, c := nodesFunc(h, miner)
|
||||||
log.Printf("Run testcase")
|
log.Printf("Run testcase")
|
||||||
testCase.test(harness, lsp, miner)
|
testCase.test(&testParams{
|
||||||
|
t: t,
|
||||||
|
h: h,
|
||||||
|
m: miner,
|
||||||
|
c: c,
|
||||||
|
lsp: lsp,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
type testCase struct {
|
type testCase struct {
|
||||||
name string
|
name string
|
||||||
test func(h *lntest.TestHarness, lsp LspNode, miner *lntest.Miner)
|
test func(t *testParams)
|
||||||
timeout time.Duration
|
timeout time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
35
itest/test_params.go
Normal file
35
itest/test_params.go
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
package itest
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/breez/lntest"
|
||||||
|
)
|
||||||
|
|
||||||
|
type testParams struct {
|
||||||
|
t *testing.T
|
||||||
|
h *lntest.TestHarness
|
||||||
|
m *lntest.Miner
|
||||||
|
c *breezClient
|
||||||
|
lsp LspNode
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *testParams) T() *testing.T {
|
||||||
|
return h.t
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *testParams) Miner() *lntest.Miner {
|
||||||
|
return h.m
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *testParams) Lsp() LspNode {
|
||||||
|
return h.lsp
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *testParams) Harness() *lntest.TestHarness {
|
||||||
|
return h.h
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *testParams) BreezClient() *breezClient {
|
||||||
|
return h.c
|
||||||
|
}
|
||||||
@@ -8,15 +8,13 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func testZeroReserve(h *lntest.TestHarness, lsp LspNode, miner *lntest.Miner) {
|
func testZeroReserve(p *testParams) {
|
||||||
alice := lntest.NewCoreLightningNode(h, miner, "Alice")
|
alice := lntest.NewCoreLightningNode(p.h, p.m, "Alice")
|
||||||
bob := NewZeroConfNode(h, miner, "Bob")
|
|
||||||
|
|
||||||
alice.Fund(10000000)
|
alice.Fund(10000000)
|
||||||
lsp.LightningNode().Fund(10000000)
|
p.lsp.LightningNode().Fund(10000000)
|
||||||
|
|
||||||
log.Print("Opening channel between Alice and the lsp")
|
log.Print("Opening channel between Alice and the lsp")
|
||||||
channel := alice.OpenChannel(lsp.LightningNode(), &lntest.OpenChannelOptions{
|
channel := alice.OpenChannel(p.lsp.LightningNode(), &lntest.OpenChannelOptions{
|
||||||
AmountSat: 1000000,
|
AmountSat: 1000000,
|
||||||
})
|
})
|
||||||
channelId := alice.WaitForChannelReady(channel)
|
channelId := alice.WaitForChannelReady(channel)
|
||||||
@@ -25,36 +23,36 @@ func testZeroReserve(h *lntest.TestHarness, lsp LspNode, miner *lntest.Miner) {
|
|||||||
outerAmountMsat := uint64(2100000)
|
outerAmountMsat := uint64(2100000)
|
||||||
innerAmountMsat := uint64(2100000)
|
innerAmountMsat := uint64(2100000)
|
||||||
description := "Please pay me"
|
description := "Please pay me"
|
||||||
innerInvoice, outerInvoice := bob.GenerateInvoices(generateInvoicesRequest{
|
innerInvoice, outerInvoice := p.BreezClient().GenerateInvoices(generateInvoicesRequest{
|
||||||
innerAmountMsat: innerAmountMsat,
|
innerAmountMsat: innerAmountMsat,
|
||||||
outerAmountMsat: outerAmountMsat,
|
outerAmountMsat: outerAmountMsat,
|
||||||
description: description,
|
description: description,
|
||||||
lsp: lsp,
|
lsp: p.lsp,
|
||||||
})
|
})
|
||||||
|
|
||||||
log.Print("Connecting bob to lspd")
|
log.Print("Connecting bob to lspd")
|
||||||
bob.lightningNode.ConnectPeer(lsp.LightningNode())
|
p.BreezClient().lightningNode.ConnectPeer(p.lsp.LightningNode())
|
||||||
|
|
||||||
// NOTE: We pretend to be paying fees to the lsp, but actually we won't.
|
// NOTE: We pretend to be paying fees to the lsp, but actually we won't.
|
||||||
log.Printf("Registering payment with lsp")
|
log.Printf("Registering payment with lsp")
|
||||||
pretendAmount := outerAmountMsat - 2000000
|
pretendAmount := outerAmountMsat - 2000000
|
||||||
RegisterPayment(lsp, &lspd.PaymentInformation{
|
RegisterPayment(p.lsp, &lspd.PaymentInformation{
|
||||||
PaymentHash: innerInvoice.paymentHash,
|
PaymentHash: innerInvoice.paymentHash,
|
||||||
PaymentSecret: innerInvoice.paymentSecret,
|
PaymentSecret: innerInvoice.paymentSecret,
|
||||||
Destination: bob.lightningNode.NodeId(),
|
Destination: p.BreezClient().lightningNode.NodeId(),
|
||||||
IncomingAmountMsat: int64(outerAmountMsat),
|
IncomingAmountMsat: int64(outerAmountMsat),
|
||||||
OutgoingAmountMsat: int64(pretendAmount),
|
OutgoingAmountMsat: int64(pretendAmount),
|
||||||
})
|
})
|
||||||
|
|
||||||
log.Printf("Alice paying")
|
log.Printf("Alice paying")
|
||||||
route := constructRoute(lsp.LightningNode(), bob.lightningNode, channelId, lntest.NewShortChanIDFromString("1x0x0"), outerAmountMsat)
|
route := constructRoute(p.lsp.LightningNode(), p.BreezClient().lightningNode, channelId, lntest.NewShortChanIDFromString("1x0x0"), outerAmountMsat)
|
||||||
alice.PayViaRoute(outerAmountMsat, outerInvoice.paymentHash, outerInvoice.paymentSecret, route)
|
alice.PayViaRoute(outerAmountMsat, outerInvoice.paymentHash, outerInvoice.paymentSecret, route)
|
||||||
|
|
||||||
// Make sure balance is correct
|
// Make sure balance is correct
|
||||||
chans := bob.lightningNode.GetChannels()
|
chans := p.BreezClient().lightningNode.GetChannels()
|
||||||
assert.Len(h.T, chans, 1)
|
assert.Len(p.t, chans, 1)
|
||||||
|
|
||||||
c := chans[0]
|
c := chans[0]
|
||||||
assert.Equal(h.T, c.RemoteReserveMsat, c.CapacityMsat/100)
|
assert.Equal(p.t, c.RemoteReserveMsat, c.CapacityMsat/100)
|
||||||
assert.Zero(h.T, c.LocalReserveMsat)
|
assert.Zero(p.t, c.LocalReserveMsat)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user