Skip to content

Commit 31b2456

Browse files
committed
itest: new test to check server access perms
1 parent f61b4a1 commit 31b2456

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed

itest/list_on_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,10 @@ var allTestCases = []*lntest.TestCase{
670670
Name: "fee replacement",
671671
TestFunc: testFeeReplacement,
672672
},
673+
{
674+
Name: "access perm",
675+
TestFunc: testAccessPerm,
676+
},
673677
}
674678

675679
// appendPrefixed is used to add a prefix to each test name in the subtests

itest/lnd_access_perm_test.go

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
package itest
2+
3+
import (
4+
"strconv"
5+
6+
"github.com/lightningnetwork/lnd/lnrpc"
7+
"github.com/lightningnetwork/lnd/lntest"
8+
)
9+
10+
// testAccessPerm tests that the number of restricted slots is upheld when
11+
// connecting to the server from a restrictedd peer.
12+
func testAccessPerm(ht *lntest.HarnessTest) {
13+
args := []string{
14+
"--minbackoff=5m",
15+
"--maxbackoff=5m",
16+
"--num-restricted-slots=5",
17+
}
18+
19+
alice := ht.NewNodeWithCoins("Alice", args)
20+
bob := ht.NewNodeWithCoins("Bob", args)
21+
ht.ConnectNodes(alice, bob)
22+
23+
// Open a confirmed channel to Bob. Bob will have protected access.
24+
chanPoint1 := ht.OpenChannel(
25+
alice, bob, lntest.OpenChannelParams{
26+
Amt: chanAmt,
27+
},
28+
)
29+
defer ht.CloseChannel(alice, chanPoint1)
30+
31+
// Open and close channel to Carol. Carol will have protected access.
32+
carol := ht.NewNodeWithCoins("Carol", args)
33+
ht.ConnectNodes(alice, carol)
34+
35+
chanPoint2 := ht.OpenChannel(
36+
alice, carol, lntest.OpenChannelParams{
37+
Amt: chanAmt,
38+
},
39+
)
40+
41+
ht.CloseChannel(alice, chanPoint2)
42+
43+
// Make a pending channel with Dave.
44+
dave := ht.NewNodeWithCoins("Dave", args)
45+
ht.ConnectNodes(alice, dave)
46+
47+
ht.OpenChannelAssertStream(
48+
dave, alice, lntest.OpenChannelParams{
49+
Amt: chanAmt,
50+
},
51+
)
52+
53+
// Disconnect Bob, Carol, and Dave.
54+
ht.DisconnectNodes(alice, bob)
55+
ht.AssertNotConnected(alice, bob)
56+
57+
ht.DisconnectNodes(alice, carol)
58+
ht.AssertNotConnected(alice, carol)
59+
60+
ht.DisconnectNodes(alice, dave)
61+
ht.AssertNotConnected(alice, dave)
62+
63+
// Connect 5 times to Alice. All of these connections should be
64+
// successful.
65+
for i := 0; i < 5; i++ {
66+
peer := ht.NewNode("Peer"+strconv.Itoa(i), args)
67+
ht.ConnectNodes(peer, alice)
68+
ht.AssertConnected(peer, alice)
69+
}
70+
71+
// Connect an additional time to Alice. This should fail.
72+
failedPeer := ht.NewNode("FailedPeer", args)
73+
req := &lnrpc.ConnectPeerRequest{
74+
Addr: &lnrpc.LightningAddress{
75+
Pubkey: alice.RPC.GetInfo().IdentityPubkey,
76+
Host: alice.Cfg.P2PAddr(),
77+
},
78+
}
79+
_ = failedPeer.RPC.ConnectPeer(req)
80+
ht.AssertNotConnected(failedPeer, alice)
81+
82+
// Connect nodes and assert access status.
83+
ht.ConnectNodes(alice, bob)
84+
ht.AssertConnected(alice, bob)
85+
86+
ht.ConnectNodes(alice, carol)
87+
ht.AssertConnected(alice, carol)
88+
89+
ht.ConnectNodes(alice, dave)
90+
ht.AssertConnected(alice, dave)
91+
92+
ht.MineBlocksAndAssertNumTxes(1, 1)
93+
}

0 commit comments

Comments
 (0)