4
4
"context"
5
5
"errors"
6
6
"fmt"
7
+ "slices"
7
8
"sort"
8
9
"testing"
9
10
"testing/quick"
@@ -128,7 +129,7 @@ type handlerMocks struct {
128
129
mValidator * MocknipostValidator
129
130
mbeacon * MockAtxReceiver
130
131
mtortoise * mocks.MockTortoise
131
- mMalPublish * MockmalfeasancePublisher
132
+ mMalPublish * MockatxMalfeasancePublisher
132
133
}
133
134
134
135
type testHandler struct {
@@ -159,6 +160,7 @@ func (h *handlerMocks) expectAtxV1(atx *wire.ActivationTxV1, nodeId types.NodeID
159
160
}
160
161
h .mockFetch .EXPECT ().RegisterPeerHashes (gomock .Any (), gomock .Any ())
161
162
h .mockFetch .EXPECT ().GetPoetProof (gomock .Any (), types .BytesToHash (atx .NIPost .PostMetadata .Challenge ))
163
+ deps := []types.ATXID {atx .PrevATXID , atx .PositioningATXID }
162
164
if atx .PrevATXID == types .EmptyATXID {
163
165
h .mValidator .EXPECT ().InitialNIPostChallengeV1 (gomock .Any (), gomock .Any (), h .goldenATXID )
164
166
h .mValidator .EXPECT ().
@@ -170,9 +172,17 @@ func (h *handlerMocks) expectAtxV1(atx *wire.ActivationTxV1, nodeId types.NodeID
170
172
time .Sleep (settings .postVerificationDuration )
171
173
return nil
172
174
})
175
+ deps = append (deps , * atx .CommitmentATXID )
173
176
} else {
174
177
h .mValidator .EXPECT ().NIPostChallengeV1 (gomock .Any (), gomock .Any (), nodeId )
175
178
}
179
+ deps = slices .Compact (deps )
180
+ deps = slices .DeleteFunc (deps , func (dep types.ATXID ) bool {
181
+ return dep == types .EmptyATXID || dep == h .goldenATXID
182
+ })
183
+ if len (deps ) > 0 {
184
+ h .mockFetch .EXPECT ().GetAtxs (gomock .Any (), deps , gomock .Any ())
185
+ }
176
186
h .mValidator .EXPECT ().PositioningAtx (atx .PositioningATXID , gomock .Any (), h .goldenATXID , atx .PublishEpoch )
177
187
h .mValidator .EXPECT ().
178
188
NIPost (gomock .Any (), nodeId , h .goldenATXID , gomock .Any (), gomock .Any (), atx .NumUnits , gomock .Any ()).
@@ -194,7 +204,7 @@ func newTestHandlerMocks(tb testing.TB, golden types.ATXID) handlerMocks {
194
204
mValidator : NewMocknipostValidator (ctrl ),
195
205
mbeacon : NewMockAtxReceiver (ctrl ),
196
206
mtortoise : mocks .NewMockTortoise (ctrl ),
197
- mMalPublish : NewMockmalfeasancePublisher (ctrl ),
207
+ mMalPublish : NewMockatxMalfeasancePublisher (ctrl ),
198
208
}
199
209
}
200
210
@@ -205,6 +215,8 @@ func newTestHandler(tb testing.TB, goldenATXID types.ATXID, opts ...HandlerOptio
205
215
edVerifier := signing .NewEdVerifier ()
206
216
207
217
mocks := newTestHandlerMocks (tb , goldenATXID )
218
+ // TODO(mafa): make mandatory parameter when real publisher is available
219
+ opts = append (opts , func (h * Handler ) { h .v2 .malPublisher = mocks .mMalPublish })
208
220
atxHdlr := NewHandler (
209
221
"localID" ,
210
222
cdb ,
@@ -341,7 +353,6 @@ func TestHandler_ProcessAtxStoresNewVRFNonce(t *testing.T) {
341
353
atx2 .VRFNonce = (* uint64 )(& nonce2 )
342
354
atx2 .Sign (sig )
343
355
atxHdlr .expectAtxV1 (atx2 , sig .NodeID ())
344
- atxHdlr .mockFetch .EXPECT ().GetAtxs (gomock .Any (), gomock .Any (), gomock .Any ())
345
356
require .NoError (t , atxHdlr .HandleGossipAtx (context .Background (), "" , codec .MustEncode (atx2 )))
346
357
347
358
got , err = atxs .VRFNonce (atxHdlr .cdb , sig .NodeID (), atx2 .PublishEpoch + 1 )
@@ -391,7 +402,6 @@ func TestHandler_HandleGossipAtx(t *testing.T) {
391
402
392
403
// second is now valid (deps are in)
393
404
atxHdlr .expectAtxV1 (second , sig .NodeID ())
394
- atxHdlr .mockFetch .EXPECT ().GetAtxs (gomock .Any (), []types.ATXID {second .PrevATXID }, gomock .Any ())
395
405
require .NoError (t , atxHdlr .HandleGossipAtx (context .Background (), "" , codec .MustEncode (second )))
396
406
}
397
407
@@ -695,7 +705,6 @@ func TestHandler_AtxWeight(t *testing.T) {
695
705
buf = codec .MustEncode (atx2 )
696
706
697
707
atxHdlr .expectAtxV1 (atx2 , sig .NodeID (), func (o * atxHandleOpts ) { o .poetLeaves = leaves })
698
- atxHdlr .mockFetch .EXPECT ().GetAtxs (gomock .Any (), []types.ATXID {atx1 .ID ()}, gomock .Any ())
699
708
require .NoError (t , atxHdlr .HandleSyncedAtx (context .Background (), atx2 .ID ().Hash32 (), peer , buf ))
700
709
701
710
stored2 , err := atxHdlr .cdb .GetAtx (atx2 .ID ())
0 commit comments