@@ -41,6 +41,7 @@ func TestAgent(t *testing.T) {
4141 limit uint64
4242 expectedCalls bool
4343 balance * big.Int
44+ doubling uint8
4445 }{{
4546 name : "3 blocks per phase, same block number returns twice" ,
4647 blocksPerRound : 9 ,
@@ -49,6 +50,7 @@ func TestAgent(t *testing.T) {
4950 expectedCalls : true ,
5051 limit : 108 , // computed with blocksPerRound * (exptectedCalls + 2)
5152 balance : bigBalance ,
53+ doubling : 1 ,
5254 }, {
5355 name : "3 blocks per phase, block number returns every block" ,
5456 blocksPerRound : 9 ,
@@ -57,6 +59,7 @@ func TestAgent(t *testing.T) {
5759 expectedCalls : true ,
5860 limit : 108 ,
5961 balance : bigBalance ,
62+ doubling : 0 ,
6063 }, {
6164 name : "no expected calls - block number returns late after each phase" ,
6265 blocksPerRound : 9 ,
@@ -65,6 +68,7 @@ func TestAgent(t *testing.T) {
6568 expectedCalls : false ,
6669 limit : 108 ,
6770 balance : bigBalance ,
71+ doubling : 0 ,
6872 }, {
6973 name : "4 blocks per phase, block number returns every other block" ,
7074 blocksPerRound : 12 ,
@@ -73,6 +77,7 @@ func TestAgent(t *testing.T) {
7377 expectedCalls : true ,
7478 limit : 144 ,
7579 balance : bigBalance ,
80+ doubling : 1 ,
7681 }, {
7782 // This test case is based on previous, but this time agent will not have enough
7883 // balance to participate in the game so no calls are going to be made.
@@ -83,6 +88,7 @@ func TestAgent(t *testing.T) {
8388 expectedCalls : false ,
8489 limit : 144 ,
8590 balance : big .NewInt (0 ),
91+ doubling : 1 ,
8692 },
8793 }
8894
@@ -106,9 +112,12 @@ func TestAgent(t *testing.T) {
106112 block : tc .blocksPerRound ,
107113 balance : tc .balance ,
108114 }
109- contract := & mockContract {}
110115
111- service , _ := createService (t , addr , backend , contract , tc .blocksPerRound , tc .blocksPerPhase )
116+ var radius uint8 = 8
117+
118+ contract := & mockContract {t : t , expectedRadius : radius + tc .doubling }
119+
120+ service , _ := createService (t , addr , backend , contract , tc .blocksPerRound , tc .blocksPerPhase , radius , tc .doubling )
112121 testutil .CleanupCloser (t , service )
113122
114123 <- wait
@@ -156,7 +165,10 @@ func createService(
156165 backend storageincentives.ChainBackend ,
157166 contract redistribution.Contract ,
158167 blocksPerRound uint64 ,
159- blocksPerPhase uint64 ) (* storageincentives.Agent , error ) {
168+ blocksPerPhase uint64 ,
169+ radius uint8 ,
170+ doubling uint8 ,
171+ ) (* storageincentives.Agent , error ) {
160172 t .Helper ()
161173
162174 postageContract := contractMock .New (contractMock .WithExpiresBatchesFunc (func (context.Context ) error {
@@ -168,7 +180,7 @@ func createService(
168180 }))
169181
170182 reserve := resMock .NewReserve (
171- resMock .WithRadius (0 ),
183+ resMock .WithRadius (radius ),
172184 resMock .WithSample (storer .RandSample (t , nil )),
173185 )
174186
@@ -189,6 +201,7 @@ func createService(
189201 transactionmock .New (),
190202 & mockHealth {},
191203 log .Noop ,
204+ doubling ,
192205 )
193206}
194207
@@ -257,15 +270,20 @@ const (
257270)
258271
259272type mockContract struct {
260- callsList []contractCall
261- mtx sync.Mutex
273+ callsList []contractCall
274+ mtx sync.Mutex
275+ expectedRadius uint8
276+ t * testing.T
262277}
263278
264279func (m * mockContract ) ReserveSalt (context.Context ) ([]byte , error ) {
265280 return nil , nil
266281}
267282
268- func (m * mockContract ) IsPlaying (context.Context , uint8 ) (bool , error ) {
283+ func (m * mockContract ) IsPlaying (_ context.Context , r uint8 ) (bool , error ) {
284+ if r != m .expectedRadius {
285+ m .t .Fatalf ("isPlaying: expected radius %d, got %d" , m .expectedRadius , r )
286+ }
269287 return true , nil
270288}
271289
@@ -290,9 +308,14 @@ func (m *mockContract) Commit(context.Context, []byte, uint64) (common.Hash, err
290308 return common.Hash {}, nil
291309}
292310
293- func (m * mockContract ) Reveal (context.Context , uint8 , []byte , []byte ) (common.Hash , error ) {
311+ func (m * mockContract ) Reveal (_ context.Context , r uint8 , _ []byte , _ []byte ) (common.Hash , error ) {
294312 m .mtx .Lock ()
295313 defer m .mtx .Unlock ()
314+
315+ if r != m .expectedRadius {
316+ m .t .Fatalf ("reveal: expected radius %d, got %d" , m .expectedRadius , r )
317+ }
318+
296319 m .callsList = append (m .callsList , revealCall )
297320 return common.Hash {}, nil
298321}
0 commit comments