@@ -64,18 +64,25 @@ func TestAccessManRestrictedSlots(t *testing.T) {
64
64
peerKey3 := peerPriv3 .PubKey ()
65
65
peerKeySer3 := string (peerKey3 .SerializeCompressed ())
66
66
67
+ var (
68
+ peer1PendingCount = 0
69
+ peer2PendingCount = 1
70
+ peer3PendingCount = 1
71
+ )
72
+
67
73
initPerms := func () (map [string ]channeldb.ChanCount , error ) {
68
74
return map [string ]channeldb.ChanCount {
69
75
peerKeySer1 : {
70
76
HasOpenOrClosedChan : true ,
77
+ PendingOpenCount : uint64 (peer1PendingCount ),
71
78
},
72
79
peerKeySer2 : {
73
80
HasOpenOrClosedChan : true ,
74
- PendingOpenCount : 1 ,
81
+ PendingOpenCount : uint64 ( peer2PendingCount ) ,
75
82
},
76
83
peerKeySer3 : {
77
84
HasOpenOrClosedChan : false ,
78
- PendingOpenCount : 1 ,
85
+ PendingOpenCount : uint64 ( peer3PendingCount ) ,
79
86
},
80
87
}, nil
81
88
}
@@ -101,17 +108,17 @@ func TestAccessManRestrictedSlots(t *testing.T) {
101
108
peerCount1 , ok := a .peerCounts [peerKeySer1 ]
102
109
require .True (t , ok )
103
110
require .True (t , peerCount1 .HasOpenOrClosedChan )
104
- require .Equal (t , 0 , int (peerCount1 .PendingOpenCount ))
111
+ require .Equal (t , peer1PendingCount , int (peerCount1 .PendingOpenCount ))
105
112
106
113
peerCount2 , ok := a .peerCounts [peerKeySer2 ]
107
114
require .True (t , ok )
108
115
require .True (t , peerCount2 .HasOpenOrClosedChan )
109
- require .Equal (t , 1 , int (peerCount2 .PendingOpenCount ))
116
+ require .Equal (t , peer2PendingCount , int (peerCount2 .PendingOpenCount ))
110
117
111
118
peerCount3 , ok := a .peerCounts [peerKeySer3 ]
112
119
require .True (t , ok )
113
120
require .False (t , peerCount3 .HasOpenOrClosedChan )
114
- require .Equal (t , 1 , int (peerCount3 .PendingOpenCount ))
121
+ require .Equal (t , peer3PendingCount , int (peerCount3 .PendingOpenCount ))
115
122
116
123
// We'll now start to connect the peers. We'll add a new fourth peer
117
124
// that will take up the restricted slot. The first three peers should
@@ -135,11 +142,26 @@ func TestAccessManRestrictedSlots(t *testing.T) {
135
142
require .NoError (t , err )
136
143
assertAccessState (t , a , peerKey4 , peerStatusTemporary )
137
144
145
+ // Assert that accessman's internal state is updated with peer4. We
146
+ // expect this new peer to have 1 pending open count.
147
+ peerCount4 , ok := a .peerCounts [string (peerKey4 .SerializeCompressed ())]
148
+ require .True (t , ok )
149
+ require .False (t , peerCount4 .HasOpenOrClosedChan )
150
+ require .Equal (t , 1 , int (peerCount4 .PendingOpenCount ))
151
+
138
152
// Check that an open channel promotes the temporary peer.
139
153
err = a .newOpenChan (peerKey3 )
140
154
require .NoError (t , err )
141
155
assertAccessState (t , a , peerKey3 , peerStatusProtected )
142
156
157
+ // Assert that accessman's internal state is updated with peer3. We
158
+ // expect this existing peer to decrement its pending open count and the
159
+ // flag `HasOpenOrClosedChan` should be true.
160
+ peerCount3 , ok = a .peerCounts [peerKeySer3 ]
161
+ require .True (t , ok )
162
+ require .True (t , peerCount3 .HasOpenOrClosedChan )
163
+ require .Equal (t , peer3PendingCount - 1 , int (peerCount3 .PendingOpenCount ))
164
+
143
165
// We should be able to accommodate a new peer.
144
166
peerPriv5 , err := btcec .NewPrivateKey ()
145
167
require .NoError (t , err )
@@ -151,6 +173,10 @@ func TestAccessManRestrictedSlots(t *testing.T) {
151
173
// peer.
152
174
err = a .newPendingCloseChan (peerKey4 )
153
175
require .ErrorIs (t , err , ErrNoMoreRestrictedAccessSlots )
176
+
177
+ // Assert that peer4 is removed.
178
+ _ , ok = a .peerCounts [string (peerKey4 .SerializeCompressed ())]
179
+ require .False (t , ok )
154
180
}
155
181
156
182
// TestAssignPeerPerms asserts that the peer's access status is correctly
0 commit comments