Unverified Commit aa8b2189 authored by meowsbits's avatar meowsbits Committed by GitHub

ethclient: fix error handling for header test (#22514)

The wantErr field was disused, and the error returned by HeaderByNumber
was not properly tested.

This simplifies the error checking using errors.Is and asserts that getting
an expected missing header returns ethereum.NotFound. Also adds a nil
check condition for header.Number before using big.Int's Sign method.
parent 6a528fce
......@@ -288,8 +288,9 @@ func testHeader(t *testing.T, chain []*types.Block, client *rpc.Client) {
want: chain[1].Header(),
},
"future_block": {
block: big.NewInt(1000000000),
want: nil,
block: big.NewInt(1000000000),
want: nil,
wantErr: ethereum.NotFound,
},
}
for name, tt := range tests {
......@@ -299,10 +300,10 @@ func testHeader(t *testing.T, chain []*types.Block, client *rpc.Client) {
defer cancel()
got, err := ec.HeaderByNumber(ctx, tt.block)
if tt.wantErr != nil && (err == nil || err.Error() != tt.wantErr.Error()) {
if !errors.Is(err, tt.wantErr) {
t.Fatalf("HeaderByNumber(%v) error = %q, want %q", tt.block, err, tt.wantErr)
}
if got != nil && got.Number.Sign() == 0 {
if got != nil && got.Number != nil && got.Number.Sign() == 0 {
got.Number = big.NewInt(0) // hack to make DeepEqual work
}
if !reflect.DeepEqual(got, tt.want) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment