@@ -3,6 +3,7 @@ package selfhealing
3
3
import (
4
4
"context"
5
5
json "github.com/json-iterator/go"
6
+ "github.com/pastelnetwork/gonode/common/types"
6
7
"golang.org/x/crypto/sha3"
7
8
"testing"
8
9
@@ -220,3 +221,84 @@ func TestCreateClosestNodeMapAgainstKeys(t *testing.T) {
220
221
}
221
222
222
223
}
224
+
225
+ func TestCreateSelfHealingTicketsMap (t * testing.T ) {
226
+ t .Parallel ()
227
+
228
+ ctx := context .Background ()
229
+
230
+ config := NewConfig ()
231
+ pastelClient := pastelMock .NewMockClient (t )
232
+ p2pClient := p2pMock .NewMockClient (t )
233
+ raptorQClient := rqmock .NewMockClient (t )
234
+ var nodeClient * shtest.Client
235
+
236
+ nodes := pastel.MasterNodes {}
237
+ nodes = append (nodes , pastel.MasterNode {ExtKey : "PrimaryID" })
238
+ nodes = append (nodes , pastel.MasterNode {ExtKey : "A" })
239
+ nodes = append (nodes , pastel.MasterNode {ExtKey : "B" })
240
+ nodes = append (nodes , pastel.MasterNode {ExtKey : "C" })
241
+ nodes = append (nodes , pastel.MasterNode {ExtKey : "D" })
242
+ nodes = append (nodes , pastel.MasterNode {ExtKey : "E" })
243
+
244
+ closestNodesMap := make (map [string ][]string )
245
+ closestNodesMap ["file-hash-to-challenge" ] = []string {"A" , "B" , "C" , "D" , "E" , "F" }
246
+ closestNodesMap ["cascade-file-hash-to-challenge" ] = []string {"G" , "H" , "I" , "J" , "K" , "L" }
247
+ closestNodesMap ["sense-file-hash-to-challenge" ] = []string {"AG" , "BH" , "CI" , "DJ" , "EK" , "FL" }
248
+
249
+ watchlistPingInfo := []types.PingInfo {
250
+ types.PingInfo {SupernodeID : "A" },
251
+ types.PingInfo {SupernodeID : "B" },
252
+ types.PingInfo {SupernodeID : "C" },
253
+ types.PingInfo {SupernodeID : "D" },
254
+ types.PingInfo {SupernodeID : "E" },
255
+ types.PingInfo {SupernodeID : "F" },
256
+ }
257
+
258
+ symbolFileKeyMap := make (map [string ]SymbolFileKeyDetails )
259
+ symbolFileKeyMap ["file-hash-to-challenge" ] = SymbolFileKeyDetails {TicketTxID : "test-tx-id-nft" , TicketType : nftTicketType }
260
+ symbolFileKeyMap ["file-hash-to-challenge-cascade" ] = SymbolFileKeyDetails {TicketTxID : "test-tx-id-nft" , TicketType : cascadeTicketType }
261
+ symbolFileKeyMap ["file-hash-to-challenge-sense" ] = SymbolFileKeyDetails {TicketTxID : "test-tx-id-nft" , TicketType : senseTicketType }
262
+
263
+ tests := []struct {
264
+ testcase string
265
+ keys []string
266
+ setup func ()
267
+ expect func (* testing.T , map [string ]SymbolFileKeyDetails )
268
+ }{
269
+ {
270
+ testcase : "when all the closest nodes are on watchlist, should include the ticket for self-healing" ,
271
+ keys : []string {"file-hash-to-challenge" , "cascade-file-hash-to-challenge" , "sense-file-hash-to-challenge" },
272
+ setup : func () {
273
+ p2pClient .ListenOnNClosestNodes ([]string {"A" , "B" , "C" , "D" , "E" , "F" }, nil )
274
+ },
275
+ expect : func (t * testing.T , selfHealingTicketsMap map [string ]SymbolFileKeyDetails ) {
276
+ require .Equal (t , len (selfHealingTicketsMap ), 1 )
277
+
278
+ ticketDetails := selfHealingTicketsMap ["test-tx-id-nft" ]
279
+ require .Equal (t , ticketDetails .TicketType , nftTicketType )
280
+ require .Equal (t , len (ticketDetails .Keys ), 1 )
281
+ require .Equal (t , ticketDetails .Keys [0 ], "file-hash-to-challenge" )
282
+ },
283
+ },
284
+ }
285
+
286
+ for _ , tt := range tests {
287
+ tt := tt
288
+
289
+ t .Run (tt .testcase , func (t * testing.T ) {
290
+ // Run the setup for the testcase
291
+ tt .setup ()
292
+
293
+ service := NewService (config , nil , pastelClient , nodeClient ,
294
+ p2pClient , nil )
295
+ task := NewSHTask (service )
296
+ task .StorageHandler .RqClient = raptorQClient
297
+ // call the function to get return values
298
+ selfHealingTicketsMap := task .identifySelfHealingTickets (ctx , watchlistPingInfo , closestNodesMap , symbolFileKeyMap )
299
+ // handle the test case's assertions with the provided func
300
+ tt .expect (t , selfHealingTicketsMap )
301
+ })
302
+ }
303
+
304
+ }
0 commit comments