Skip to content

Commit

Permalink
Revert to using assertNonZero function in allExportedFieldsSet
Browse files Browse the repository at this point in the history
  • Loading branch information
qdm12 committed Feb 25, 2025
1 parent 4d2f143 commit 57a6734
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions core/types/header_ext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,22 @@ func allExportedFieldsSet[T interface {

t.Run(field.Name, func(t *testing.T) {
switch f := v.Field(i).Interface().(type) {
case common.Hash, common.Address, BlockNonce, Bloom, uint64:
assert.NotZero(t, f)
case common.Hash:
assertNonZero(t, f)
case common.Address:
assertNonZero(t, f)
case BlockNonce:
assertNonZero(t, f)
case Bloom:
assertNonZero(t, f)
case uint64:
assertNonZero(t, f)
case *big.Int:
assert.NotZero(t, *f)
assertNonZero(t, f)
case *common.Hash:
assert.NotZero(t, *f)
assertNonZero(t, f)
case *uint64:
assert.NotZero(t, *f)
assertNonZero(t, f)
case []uint8:
assert.NotEmpty(t, f)
default:
Expand All @@ -148,4 +156,15 @@ func allExportedFieldsSet[T interface {
}
}

func assertNonZero[T interface {
common.Hash | common.Address | BlockNonce | uint64 | Bloom |
*big.Int | *common.Hash | *uint64
}](t *testing.T, v T) {
t.Helper()
var zero T
if v == zero {
t.Errorf("must not be zero value for %T", v)
}
}

func ptrTo[T any](x T) *T { return &x }

0 comments on commit 57a6734

Please sign in to comment.