@@ -307,6 +307,12 @@ func testTransactionInBlock(t *testing.T, client *rpc.Client) {
307307 if tx .Hash () != testTx2 .Hash () {
308308 t .Fatalf ("unexpected transaction: %v" , tx )
309309 }
310+
311+ // Test pending block
312+ _ , err = ec .BlockByNumber (context .Background (), big .NewInt (int64 (rpc .PendingBlockNumber )))
313+ if err != nil {
314+ t .Fatalf ("unexpected error: %v" , err )
315+ }
310316}
311317
312318func testChainID (t * testing.T , client * rpc.Client ) {
@@ -619,6 +625,21 @@ func testAtFunctions(t *testing.T, client *rpc.Client) {
619625 if gas != 21000 {
620626 t .Fatalf ("unexpected gas limit: %v" , gas )
621627 }
628+
629+ // Verify that sender address of pending transaction is saved in cache.
630+ pendingBlock , err := ec .BlockByNumber (context .Background (), big .NewInt (int64 (rpc .PendingBlockNumber )))
631+ if err != nil {
632+ t .Fatalf ("unexpected error: %v" , err )
633+ }
634+ // No additional RPC should be required, ensure the server is not asked by
635+ // canceling the context.
636+ sender , err := ec .TransactionSender (newCanceledContext (), pendingBlock .Transactions ()[0 ], pendingBlock .Hash (), 0 )
637+ if err != nil {
638+ t .Fatal ("unable to recover sender:" , err )
639+ }
640+ if sender != testAddr {
641+ t .Fatal ("wrong sender:" , sender )
642+ }
622643}
623644
624645func testTransactionSender (t * testing.T , client * rpc.Client ) {
@@ -640,10 +661,7 @@ func testTransactionSender(t *testing.T, client *rpc.Client) {
640661
641662 // The sender address is cached in tx1, so no additional RPC should be required in
642663 // TransactionSender. Ensure the server is not asked by canceling the context here.
643- canceledCtx , cancel := context .WithCancel (context .Background ())
644- cancel ()
645- <- canceledCtx .Done () // Ensure the close of the Done channel
646- sender1 , err := ec .TransactionSender (canceledCtx , tx1 , block2 .Hash (), 0 )
664+ sender1 , err := ec .TransactionSender (newCanceledContext (), tx1 , block2 .Hash (), 0 )
647665 if err != nil {
648666 t .Fatal (err )
649667 }
@@ -662,6 +680,13 @@ func testTransactionSender(t *testing.T, client *rpc.Client) {
662680 }
663681}
664682
683+ func newCanceledContext () context.Context {
684+ ctx , cancel := context .WithCancel (context .Background ())
685+ cancel ()
686+ <- ctx .Done () // Ensure the close of the Done channel
687+ return ctx
688+ }
689+
665690func sendTransaction (ec * ethclient.Client ) error {
666691 chainID , err := ec .ChainID (context .Background ())
667692 if err != nil {
0 commit comments