lntest/itest: add key send test
This commit is contained in:
2 files changed
+45
No files matched your search
@@ -12,6 +12,8 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/lnrpc"
|
"github.com/lightningnetwork/lnd/lnrpc"
|
||||||
"github.com/lightningnetwork/lnd/lntest"
|
"github.com/lightningnetwork/lnd/lntest"
|
||||||
"github.com/lightningnetwork/lnd/lntest/wait"
|
"github.com/lightningnetwork/lnd/lntest/wait"
|
||||||
|
"github.com/lightningnetwork/lnd/lntypes"
|
||||||
|
"github.com/lightningnetwork/lnd/record"
|
||||||
)
|
)
|
||||||
|
|
||||||
func testSingleHopInvoice(net *lntest.NetworkHarness, t *harnessTest) {
|
func testSingleHopInvoice(net *lntest.NetworkHarness, t *harnessTest) {
|
||||||
@@ -138,6 +140,38 @@ func testSingleHopInvoice(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
t.Fatalf(err.Error())
|
t.Fatalf(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Next send a key send payment.
|
||||||
|
keySendPreimage := lntypes.Preimage{3, 4, 5, 11}
|
||||||
|
keySendHash := keySendPreimage.Hash()
|
||||||
|
|
||||||
|
sendReq = &lnrpc.SendRequest{
|
||||||
|
Dest: net.Bob.PubKey[:],
|
||||||
|
Amt: paymentAmt,
|
||||||
|
FinalCltvDelta: 40,
|
||||||
|
PaymentHash: keySendHash[:],
|
||||||
|
DestCustomRecords: map[uint64][]byte{
|
||||||
|
record.KeySendType: keySendPreimage[:],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||||
|
resp, err = net.Alice.SendPaymentSync(ctxt, sendReq)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unable to send payment: %v", err)
|
||||||
|
}
|
||||||
|
if resp.PaymentError != "" {
|
||||||
|
t.Fatalf("error when attempting recv: %v", resp.PaymentError)
|
||||||
|
}
|
||||||
|
|
||||||
|
// The key send payment should also have succeeded, with the balances
|
||||||
|
// being update accordingly.
|
||||||
|
err = wait.NoError(
|
||||||
|
assertAmountSent(3*paymentAmt, net.Alice, net.Bob),
|
||||||
|
3*time.Second,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
ctxt, _ = context.WithTimeout(ctxb, channelCloseTimeout)
|
ctxt, _ = context.WithTimeout(ctxb, channelCloseTimeout)
|
||||||
closeChannelAndAssert(ctxt, t, net, net.Alice, chanPoint, false)
|
closeChannelAndAssert(ctxt, t, net, net.Alice, chanPoint, false)
|
||||||
}
|
}
|
||||||
@@ -152,6 +152,8 @@ type nodeConfig struct {
|
|||||||
RPCPort int
|
RPCPort int
|
||||||
RESTPort int
|
RESTPort int
|
||||||
ProfilePort int
|
ProfilePort int
|
||||||
|
|
||||||
|
AcceptKeySend bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cfg nodeConfig) P2PAddr() string {
|
func (cfg nodeConfig) P2PAddr() string {
|
||||||
@@ -225,6 +227,10 @@ func (cfg nodeConfig) genArgs() []string {
|
|||||||
args = append(args, cfg.ExtraArgs...)
|
args = append(args, cfg.ExtraArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if cfg.AcceptKeySend {
|
||||||
|
args = append(args, "--accept-key-send")
|
||||||
|
}
|
||||||
|
|
||||||
return args
|
return args
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -304,6 +310,11 @@ func newNode(cfg nodeConfig) (*HarnessNode, error) {
|
|||||||
|
|
||||||
cfg.P2PPort, cfg.RPCPort, cfg.RESTPort, cfg.ProfilePort = generateListeningPorts()
|
cfg.P2PPort, cfg.RPCPort, cfg.RESTPort, cfg.ProfilePort = generateListeningPorts()
|
||||||
|
|
||||||
|
// Run all tests with accept key send. The key send code is very
|
||||||
|
// isolated and it is highly unlikely that it would affect regular
|
||||||
|
// itests when enabled.
|
||||||
|
cfg.AcceptKeySend = true
|
||||||
|
|
||||||
numActiveNodesMtx.Lock()
|
numActiveNodesMtx.Lock()
|
||||||
nodeNum := numActiveNodes
|
nodeNum := numActiveNodes
|
||||||
numActiveNodes++
|
numActiveNodes++
|
||||||
|
|||||||
Reference in new issue
Block a user