ethclient: ensure tx json is not nil before accessing it (#19653)

TransactionInBlock crashed if json was nil and there was an error
because it tried to access fields `From` and `BlockHash` of the nil object.
This commit is contained in:
Dmitry Shulyak
2019-06-03 18:52:02 +03:00
committed by Felix Lange
parent 17381ecc66
commit 15f24ff189
2 changed files with 25 additions and 6 deletions

View File

@ -301,3 +301,21 @@ func TestBalanceAt(t *testing.T) {
})
}
}
func TestTransactionInBlockInterrupted(t *testing.T) {
backend, _ := newTestBackend(t)
client, _ := backend.Attach()
defer backend.Stop()
defer client.Close()
ec := NewClient(client)
ctx, cancel := context.WithCancel(context.Background())
cancel()
tx, err := ec.TransactionInBlock(ctx, common.Hash{1}, 1)
if tx != nil {
t.Fatal("transaction should be nil")
}
if err == nil {
t.Fatal("error should not be nil")
}
}