@@ -450,24 +450,65 @@ func TestInvalidGetLogsRequest(t *testing.T) {
450450 t .Parallel ()
451451
452452 var (
453- db = rawdb .NewMemoryDatabase ()
454- _ , sys = newTestFilterSystem (db , Config {})
455- api = NewFilterAPI (sys )
456- blockHash = common .HexToHash ("0x1111111111111111111111111111111111111111111111111111111111111111" )
453+ genesis = & core.Genesis {
454+ Config : params .TestChainConfig ,
455+ BaseFee : big .NewInt (params .InitialBaseFee ),
456+ }
457+ db , blocks , _ = core .GenerateChainWithGenesis (genesis , ethash .NewFaker (), 10 , func (i int , gen * core.BlockGen ) {})
458+ _ , sys = newTestFilterSystem (db , Config {})
459+ api = NewFilterAPI (sys )
460+ blockHash = blocks [0 ].Hash ()
461+ unknownBlockHash = common .HexToHash ("0x1111111111111111111111111111111111111111111111111111111111111111" )
457462 )
458463
459- // Reason: Cannot specify both BlockHash and FromBlock/ToBlock)
460- testCases := []FilterCriteria {
461- 0 : {BlockHash : & blockHash , FromBlock : big .NewInt (100 )},
462- 1 : {BlockHash : & blockHash , ToBlock : big .NewInt (500 )},
463- 2 : {BlockHash : & blockHash , FromBlock : big .NewInt (rpc .LatestBlockNumber .Int64 ())},
464- 3 : {BlockHash : & blockHash , Topics : [][]common.Hash {{}, {}, {}, {}, {}}},
465- 4 : {BlockHash : & blockHash , Addresses : make ([]common.Address , maxAddresses + 1 )},
464+ // Insert the blocks into the chain so filter can look them up
465+ blockchain , err := core .NewBlockChain (db , genesis , ethash .NewFaker (), nil )
466+ if err != nil {
467+ t .Fatalf ("failed to create tester chain: %v" , err )
468+ }
469+ if n , err := blockchain .InsertChain (blocks ); err != nil {
470+ t .Fatalf ("block %d: failed to insert into chain: %v" , n , err )
471+ }
472+
473+ type testcase struct {
474+ f FilterCriteria
475+ err error
476+ }
477+ testCases := []testcase {
478+ {
479+ f : FilterCriteria {BlockHash : & blockHash , FromBlock : big .NewInt (100 )},
480+ err : errBlockHashWithRange ,
481+ },
482+ {
483+ f : FilterCriteria {BlockHash : & blockHash , ToBlock : big .NewInt (500 )},
484+ err : errBlockHashWithRange ,
485+ },
486+ {
487+ f : FilterCriteria {BlockHash : & blockHash , FromBlock : big .NewInt (rpc .LatestBlockNumber .Int64 ())},
488+ err : errBlockHashWithRange ,
489+ },
490+ {
491+ f : FilterCriteria {BlockHash : & unknownBlockHash },
492+ err : errUnknownBlock ,
493+ },
494+ {
495+ f : FilterCriteria {BlockHash : & blockHash , Topics : [][]common.Hash {{}, {}, {}, {}, {}}},
496+ err : errExceedMaxTopics ,
497+ },
498+ {
499+ f : FilterCriteria {BlockHash : & blockHash , Topics : [][]common.Hash {{}, {}, {}, {}, {}}},
500+ err : errExceedMaxTopics ,
501+ },
502+ {
503+ f : FilterCriteria {BlockHash : & blockHash , Addresses : make ([]common.Address , maxAddresses + 1 )},
504+ err : errExceedMaxAddresses ,
505+ },
466506 }
467507
468508 for i , test := range testCases {
469- if _ , err := api .GetLogs (context .Background (), test ); err == nil {
470- t .Errorf ("Expected Logs for case #%d to fail" , i )
509+ _ , err := api .GetLogs (context .Background (), test .f )
510+ if ! errors .Is (err , test .err ) {
511+ t .Errorf ("case %d: wrong error: %q\n want: %q" , i , err , test .err )
471512 }
472513 }
473514}
0 commit comments