@@ -293,6 +293,33 @@ func TestTxValidationClient_ErrorResponse(t *testing.T) {
293293 require .Equal (t , ErrInternal , err )
294294}
295295
296+ func TestTxValidationClient_CanceledParentContextStillValidates (t * testing.T ) {
297+ requestReachedServer := make (chan struct {}, 1 )
298+
299+ server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
300+ requestReachedServer <- struct {}{}
301+ time .Sleep (50 * time .Millisecond )
302+ w .Header ().Set ("Content-Type" , "application/json" )
303+ w .WriteHeader (http .StatusOK )
304+ _ , _ = w .Write ([]byte (`{"unauthorized": {}}` ))
305+ }))
306+ defer server .Close ()
307+
308+ ctx , cancel := context .WithCancel (context .Background ())
309+ cancel () // Cancel parent request context before validation call
310+
311+ client := NewTxValidationClient (5 )
312+ unauthorized , err := client .Validate (ctx , server .URL , []byte (`{}` ))
313+ require .NoError (t , err )
314+ require .Empty (t , unauthorized )
315+
316+ select {
317+ case <- requestReachedServer :
318+ case <- time .After (500 * time .Millisecond ):
319+ t .Fatal ("validation request did not reach server" )
320+ }
321+ }
322+
296323func TestDecodeSignedTx (t * testing.T ) {
297324 tx := createSignedTestTransaction (t )
298325 txBytes , err := tx .MarshalBinary ()
@@ -322,24 +349,6 @@ func TestDecodeSignedTx_Missing0xPrefix(t *testing.T) {
322349 require .Error (t , err )
323350}
324351
325- func TestTxValidationClient_CanceledContext (t * testing.T ) {
326- server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
327- time .Sleep (100 * time .Millisecond )
328- w .Header ().Set ("Content-Type" , "application/json" )
329- w .WriteHeader (http .StatusOK )
330- _ , _ = w .Write ([]byte (`{"unauthorized": {}}` ))
331- }))
332- defer server .Close ()
333-
334- ctx , cancel := context .WithCancel (context .Background ())
335- cancel () // Cancel immediately
336-
337- client := NewTxValidationClient (5 )
338- _ , err := client .Validate (ctx , server .URL , []byte (`{}` ))
339- require .Error (t , err )
340- require .True (t , errors .Is (err , context .Canceled ))
341- }
342-
343352func TestValidateTransactions_CanceledContext (t * testing.T ) {
344353 tx := createSignedTestTransaction (t )
345354
0 commit comments