Skip to content

Commit

Permalink
lntest/itest: add key send test
Browse files Browse the repository at this point in the history
  • Loading branch information
joostjager committed Dec 23, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent bb1e2af commit 4273bc0
Showing 2 changed files with 45 additions and 0 deletions.
34 changes: 34 additions & 0 deletions lntest/itest/lnd_single_hop_invoice_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
11 changes: 11 additions & 0 deletions lntest/node.go
Original file line number Diff line number Diff line change
@@ -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++

0 comments on commit 4273bc0

Please sign in to comment.