@@ -64,6 +64,11 @@ type poolTestPeer struct {
6464 inactiveAllowed bool
6565}
6666
67+ func testStateMachine () * nodestate.NodeStateMachine {
68+ return nodestate .NewNodeStateMachine (nil , nil , mclock.System {}, serverSetup )
69+
70+ }
71+
6772func newPoolTestPeer (i int , disconnCh chan int ) * poolTestPeer {
6873 return & poolTestPeer {
6974 index : i ,
@@ -91,7 +96,7 @@ func (i *poolTestPeer) allowInactive() bool {
9196}
9297
9398func getBalance (pool * clientPool , p * poolTestPeer ) (pos , neg uint64 ) {
94- temp := pool .ns .GetField (p .node , clientField ) == nil
99+ temp := pool .ns .GetField (p .node , clientInfoField ) == nil
95100 if temp {
96101 pool .ns .SetField (p .node , connAddressField , p .freeClientId ())
97102 }
@@ -128,8 +133,9 @@ func testClientPool(t *testing.T, activeLimit, clientCount, paidCount int, rando
128133 disconnFn = func (id enode.ID ) {
129134 disconnCh <- int (id [0 ]) + int (id [1 ])<< 8
130135 }
131- pool = newClientPool (db , 1 , 0 , & clock , disconnFn )
136+ pool = newClientPool (testStateMachine (), db , 1 , 0 , & clock , disconnFn )
132137 )
138+ pool .ns .Start ()
133139
134140 pool .setLimits (activeLimit , uint64 (activeLimit ))
135141 pool .setDefaultFactors (lps.PriceFactors {TimeFactor : 1 , CapacityFactor : 0 , RequestFactor : 1 }, lps.PriceFactors {TimeFactor : 1 , CapacityFactor : 0 , RequestFactor : 1 })
@@ -233,7 +239,8 @@ func TestConnectPaidClient(t *testing.T) {
233239 clock mclock.Simulated
234240 db = rawdb .NewMemoryDatabase ()
235241 )
236- pool := newClientPool (db , 1 , defaultConnectedBias , & clock , func (id enode.ID ) {})
242+ pool := newClientPool (testStateMachine (), db , 1 , defaultConnectedBias , & clock , func (id enode.ID ) {})
243+ pool .ns .Start ()
237244 defer pool .stop ()
238245 pool .setLimits (10 , uint64 (10 ))
239246 pool .setDefaultFactors (lps.PriceFactors {TimeFactor : 1 , CapacityFactor : 0 , RequestFactor : 1 }, lps.PriceFactors {TimeFactor : 1 , CapacityFactor : 0 , RequestFactor : 1 })
@@ -248,7 +255,8 @@ func TestConnectPaidClientToSmallPool(t *testing.T) {
248255 clock mclock.Simulated
249256 db = rawdb .NewMemoryDatabase ()
250257 )
251- pool := newClientPool (db , 1 , defaultConnectedBias , & clock , func (id enode.ID ) {})
258+ pool := newClientPool (testStateMachine (), db , 1 , defaultConnectedBias , & clock , func (id enode.ID ) {})
259+ pool .ns .Start ()
252260 defer pool .stop ()
253261 pool .setLimits (10 , uint64 (10 )) // Total capacity limit is 10
254262 pool .setDefaultFactors (lps.PriceFactors {TimeFactor : 1 , CapacityFactor : 0 , RequestFactor : 1 }, lps.PriceFactors {TimeFactor : 1 , CapacityFactor : 0 , RequestFactor : 1 })
@@ -266,7 +274,8 @@ func TestConnectPaidClientToFullPool(t *testing.T) {
266274 db = rawdb .NewMemoryDatabase ()
267275 )
268276 removeFn := func (enode.ID ) {} // Noop
269- pool := newClientPool (db , 1 , defaultConnectedBias , & clock , removeFn )
277+ pool := newClientPool (testStateMachine (), db , 1 , defaultConnectedBias , & clock , removeFn )
278+ pool .ns .Start ()
270279 defer pool .stop ()
271280 pool .setLimits (10 , uint64 (10 )) // Total capacity limit is 10
272281 pool .setDefaultFactors (lps.PriceFactors {TimeFactor : 1 , CapacityFactor : 0 , RequestFactor : 1 }, lps.PriceFactors {TimeFactor : 1 , CapacityFactor : 0 , RequestFactor : 1 })
@@ -295,7 +304,8 @@ func TestPaidClientKickedOut(t *testing.T) {
295304 removeFn := func (id enode.ID ) {
296305 kickedCh <- int (id [0 ])
297306 }
298- pool := newClientPool (db , 1 , defaultConnectedBias , & clock , removeFn )
307+ pool := newClientPool (testStateMachine (), db , 1 , defaultConnectedBias , & clock , removeFn )
308+ pool .ns .Start ()
299309 pool .bt .SetExpirationTCs (0 , 0 )
300310 defer pool .stop ()
301311 pool .setLimits (10 , uint64 (10 )) // Total capacity limit is 10
@@ -325,7 +335,8 @@ func TestConnectFreeClient(t *testing.T) {
325335 clock mclock.Simulated
326336 db = rawdb .NewMemoryDatabase ()
327337 )
328- pool := newClientPool (db , 1 , defaultConnectedBias , & clock , func (id enode.ID ) {})
338+ pool := newClientPool (testStateMachine (), db , 1 , defaultConnectedBias , & clock , func (id enode.ID ) {})
339+ pool .ns .Start ()
329340 defer pool .stop ()
330341 pool .setLimits (10 , uint64 (10 ))
331342 pool .setDefaultFactors (lps.PriceFactors {TimeFactor : 1 , CapacityFactor : 0 , RequestFactor : 1 }, lps.PriceFactors {TimeFactor : 1 , CapacityFactor : 0 , RequestFactor : 1 })
@@ -341,7 +352,8 @@ func TestConnectFreeClientToFullPool(t *testing.T) {
341352 db = rawdb .NewMemoryDatabase ()
342353 )
343354 removeFn := func (enode.ID ) {} // Noop
344- pool := newClientPool (db , 1 , defaultConnectedBias , & clock , removeFn )
355+ pool := newClientPool (testStateMachine (), db , 1 , defaultConnectedBias , & clock , removeFn )
356+ pool .ns .Start ()
345357 defer pool .stop ()
346358 pool .setLimits (10 , uint64 (10 )) // Total capacity limit is 10
347359 pool .setDefaultFactors (lps.PriceFactors {TimeFactor : 1 , CapacityFactor : 0 , RequestFactor : 1 }, lps.PriceFactors {TimeFactor : 1 , CapacityFactor : 0 , RequestFactor : 1 })
@@ -370,7 +382,8 @@ func TestFreeClientKickedOut(t *testing.T) {
370382 kicked = make (chan int , 100 )
371383 )
372384 removeFn := func (id enode.ID ) { kicked <- int (id [0 ]) }
373- pool := newClientPool (db , 1 , defaultConnectedBias , & clock , removeFn )
385+ pool := newClientPool (testStateMachine (), db , 1 , defaultConnectedBias , & clock , removeFn )
386+ pool .ns .Start ()
374387 defer pool .stop ()
375388 pool .setLimits (10 , uint64 (10 )) // Total capacity limit is 10
376389 pool .setDefaultFactors (lps.PriceFactors {TimeFactor : 1 , CapacityFactor : 0 , RequestFactor : 1 }, lps.PriceFactors {TimeFactor : 1 , CapacityFactor : 0 , RequestFactor : 1 })
@@ -411,7 +424,8 @@ func TestPositiveBalanceCalculation(t *testing.T) {
411424 kicked = make (chan int , 10 )
412425 )
413426 removeFn := func (id enode.ID ) { kicked <- int (id [0 ]) } // Noop
414- pool := newClientPool (db , 1 , defaultConnectedBias , & clock , removeFn )
427+ pool := newClientPool (testStateMachine (), db , 1 , defaultConnectedBias , & clock , removeFn )
428+ pool .ns .Start ()
415429 defer pool .stop ()
416430 pool .setLimits (10 , uint64 (10 )) // Total capacity limit is 10
417431 pool .setDefaultFactors (lps.PriceFactors {TimeFactor : 1 , CapacityFactor : 0 , RequestFactor : 1 }, lps.PriceFactors {TimeFactor : 1 , CapacityFactor : 0 , RequestFactor : 1 })
@@ -434,7 +448,8 @@ func TestDowngradePriorityClient(t *testing.T) {
434448 kicked = make (chan int , 10 )
435449 )
436450 removeFn := func (id enode.ID ) { kicked <- int (id [0 ]) } // Noop
437- pool := newClientPool (db , 1 , defaultConnectedBias , & clock , removeFn )
451+ pool := newClientPool (testStateMachine (), db , 1 , defaultConnectedBias , & clock , removeFn )
452+ pool .ns .Start ()
438453 defer pool .stop ()
439454 pool .setLimits (10 , uint64 (10 )) // Total capacity limit is 10
440455 pool .setDefaultFactors (lps.PriceFactors {TimeFactor : 1 , CapacityFactor : 0 , RequestFactor : 1 }, lps.PriceFactors {TimeFactor : 1 , CapacityFactor : 0 , RequestFactor : 1 })
@@ -468,7 +483,8 @@ func TestNegativeBalanceCalculation(t *testing.T) {
468483 clock mclock.Simulated
469484 db = rawdb .NewMemoryDatabase ()
470485 )
471- pool := newClientPool (db , 1 , defaultConnectedBias , & clock , func (id enode.ID ) {})
486+ pool := newClientPool (testStateMachine (), db , 1 , defaultConnectedBias , & clock , func (id enode.ID ) {})
487+ pool .ns .Start ()
472488 defer pool .stop ()
473489 pool .setLimits (10 , uint64 (10 )) // Total capacity limit is 10
474490 pool .setDefaultFactors (lps.PriceFactors {TimeFactor : 1e-3 , CapacityFactor : 0 , RequestFactor : 1 }, lps.PriceFactors {TimeFactor : 1e-3 , CapacityFactor : 0 , RequestFactor : 1 })
@@ -503,7 +519,8 @@ func TestInactiveClient(t *testing.T) {
503519 clock mclock.Simulated
504520 db = rawdb .NewMemoryDatabase ()
505521 )
506- pool := newClientPool (db , 1 , defaultConnectedBias , & clock , func (id enode.ID ) {})
522+ pool := newClientPool (testStateMachine (), db , 1 , defaultConnectedBias , & clock , func (id enode.ID ) {})
523+ pool .ns .Start ()
507524 defer pool .stop ()
508525 pool .setLimits (2 , uint64 (2 ))
509526
0 commit comments