@@ -23,7 +23,6 @@ func RunTests(t *testing.T, s nonce.Store, teardown func()) {
2323 testUpdate ,
2424 testGetAllByState ,
2525 testGetCount ,
26- testGetRandomAvailableByPurpose ,
2726 testBatchClaimAvailableByPurpose ,
2827 testBatchClaimAvailableByPurposeExpirationRandomness ,
2928 } {
@@ -285,105 +284,6 @@ func testGetCount(t *testing.T, s nonce.Store) {
285284 })
286285}
287286
288- func testGetRandomAvailableByPurpose (t * testing.T , s nonce.Store ) {
289- t .Run ("testGetRandomAvailableByPurpose" , func (t * testing.T ) {
290- ctx := context .Background ()
291-
292- _ , err := s .GetRandomAvailableByPurpose (ctx , nonce .EnvironmentSolana , nonce .EnvironmentInstanceSolanaMainnet , nonce .PurposeClientTransaction )
293- assert .Equal (t , nonce .ErrNonceNotFound , err )
294-
295- for _ , purpose := range []nonce.Purpose {
296- nonce .PurposeClientTransaction ,
297- nonce .PurposeInternalServerProcess ,
298- } {
299- for _ , state := range []nonce.State {
300- nonce .StateUnknown ,
301- nonce .StateAvailable ,
302- nonce .StateReserved ,
303- nonce .StateReleased ,
304- nonce .StateClaimed ,
305- } {
306- for i := 0 ; i < 50 ; i ++ {
307- record := & nonce.Record {
308- Address : fmt .Sprintf ("nonce_%s_%s_%d" , purpose , state , i ),
309- Authority : "authority" ,
310- Blockhash : "bh" ,
311- Environment : nonce .EnvironmentSolana ,
312- EnvironmentInstance : nonce .EnvironmentInstanceSolanaMainnet ,
313- Purpose : purpose ,
314- State : state ,
315- Signature : "" ,
316- }
317- if state == nonce .StateClaimed {
318- record .ClaimNodeID = pointer .String ("node_id" )
319-
320- if i < 25 {
321- record .ClaimExpiresAt = pointer .Time (time .Now ().Add (- time .Hour ))
322- } else {
323- record .ClaimExpiresAt = pointer .Time (time .Now ().Add (time .Hour ))
324- }
325- }
326- require .NoError (t , s .Save (ctx , record ))
327- }
328- }
329- }
330-
331- for i := 0 ; i < 100 ; i ++ {
332- record := & nonce.Record {
333- Address : fmt .Sprintf ("nonce_devnet_%d" , i ),
334- Authority : "authority" ,
335- Blockhash : "bh" ,
336- Environment : nonce .EnvironmentSolana ,
337- EnvironmentInstance : nonce .EnvironmentInstanceSolanaDevnet ,
338- Purpose : nonce .PurposeInternalServerProcess ,
339- State : nonce .StateAvailable ,
340- Signature : "" ,
341- }
342- require .NoError (t , s .Save (ctx , record ))
343-
344- record = & nonce.Record {
345- Address : fmt .Sprintf ("nonce_cvm_%d" , i ),
346- Authority : "authority" ,
347- Blockhash : "bh" ,
348- Environment : nonce .EnvironmentCvm ,
349- EnvironmentInstance : "pubkey" ,
350- Purpose : nonce .PurposeClientTransaction ,
351- State : nonce .StateClaimed ,
352- Signature : "" ,
353- ClaimNodeID : pointer .String ("node_id" ),
354- ClaimExpiresAt : pointer .Time (time .Now ().Add (- time .Hour )),
355- }
356- require .NoError (t , s .Save (ctx , record ))
357- }
358-
359- for _ , purpose := range []nonce.Purpose {nonce .PurposeClientTransaction , nonce .PurposeInternalServerProcess } {
360- availableState , claimedState := 0 , 0
361- selectedByAddress := make (map [string ]struct {})
362- for i := 0 ; i < 100 ; i ++ {
363- actual , err := s .GetRandomAvailableByPurpose (ctx , nonce .EnvironmentSolana , nonce .EnvironmentInstanceSolanaMainnet , purpose )
364- require .NoError (t , err )
365- assert .Equal (t , purpose , actual .Purpose )
366- assert .Equal (t , nonce .EnvironmentSolana , actual .Environment )
367- assert .Equal (t , nonce .EnvironmentInstanceSolanaMainnet , actual .EnvironmentInstance )
368- assert .True (t , actual .IsAvailableToClaim ())
369- assert .True (t , actual .CanReserveWithSignature ())
370- switch actual .State {
371- case nonce .StateAvailable :
372- availableState ++
373- case nonce .StateClaimed :
374- claimedState ++
375- assert .True (t , time .Now ().After (* actual .ClaimExpiresAt ))
376- default :
377- }
378- selectedByAddress [actual .Address ] = struct {}{}
379- }
380- assert .True (t , len (selectedByAddress ) > 10 )
381- assert .NotZero (t , availableState )
382- assert .NotZero (t , claimedState )
383- }
384- })
385- }
386-
387287func testBatchClaimAvailableByPurpose (t * testing.T , s nonce.Store ) {
388288 t .Run ("testBatchClaimAvailableByPurpose" , func (t * testing.T ) {
389289 ctx := context .Background ()
0 commit comments