lntest/itest: add key send test

This commit is contained in:
Joost Jager 2019-12-12 11:06:00 +01:00
parent bb1e2afc9f
commit 4273bc0ba2
No known key found for this signature in database
GPG Key ID: A61B9D4C393C59C7
2 changed files with 45 additions and 0 deletions

View File

@ -12,6 +12,8 @@ import (
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lntest"
"github.com/lightningnetwork/lnd/lntest/wait"
"github.com/lightningnetwork/lnd/lntypes"
"github.com/lightningnetwork/lnd/record"
)
func testSingleHopInvoice(net *lntest.NetworkHarness, t *harnessTest) {
@ -138,6 +140,38 @@ func testSingleHopInvoice(net *lntest.NetworkHarness, t *harnessTest) {
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)
closeChannelAndAssert(ctxt, t, net, net.Alice, chanPoint, false)
}

View File

@ -152,6 +152,8 @@ type nodeConfig struct {
RPCPort int
RESTPort int
ProfilePort int
AcceptKeySend bool
}
func (cfg nodeConfig) P2PAddr() string {
@ -225,6 +227,10 @@ func (cfg nodeConfig) genArgs() []string {
args = append(args, cfg.ExtraArgs...)
}
if cfg.AcceptKeySend {
args = append(args, "--accept-key-send")
}
return args
}
@ -304,6 +310,11 @@ func newNode(cfg nodeConfig) (*HarnessNode, error) {
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()
nodeNum := numActiveNodes
numActiveNodes++