Skip to content

Commit

Permalink
refactor: explicit err variables in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ARR4N committed Dec 19, 2024
1 parent 3f91899 commit d1f4816
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions core/types/block.libevm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,26 @@ func TestHeaderHooks(t *testing.T) {
}

setStub()
_, err := json.Marshal(hdr)
assert.ErrorIs(t, err, errMarshal, "via json.Marshal()") //nolint:testifylint // require is inappropriate here as we wish to keep going
assert.Equal(t, errUnmarshal, json.Unmarshal([]byte("{}"), hdr), "via json.Unmarshal()")
// The { } blocks are defensive, avoiding accidentally having the wrong
// error checked in a future refactor. The verbosity is acceptable for
// clarity in tests.
{
_, err := json.Marshal(hdr)
assert.ErrorIs(t, err, errMarshal, "via json.Marshal()") //nolint:testifylint // require is inappropriate here as we wish to keep going
}
{
err := json.Unmarshal([]byte("{}"), hdr)
assert.Equal(t, errUnmarshal, err, "via json.Unmarshal()")
}

setStub() // [stubHeaderHooks] completely overrides the Header
assert.Equal(t, errEncode, rlp.Encode(io.Discard, hdr), "via rlp.Encode()")
assert.Equal(t, errDecode, rlp.DecodeBytes([]byte{0}, hdr), "via rlp.DecodeBytes()")
{
err := rlp.Encode(io.Discard, hdr)
assert.Equal(t, errEncode, err, "via rlp.Encode()")
}
{
err := rlp.DecodeBytes([]byte{0}, hdr)
assert.Equal(t, errDecode, err, "via rlp.DecodeBytes()")
}
})
}

0 comments on commit d1f4816

Please sign in to comment.