Skip to content

Commit 23e3053

Browse files
committed
feat: types.WithTempRegisteredExtras()
1 parent adfef8b commit 23e3053

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright 2025 the libevm authors.
2+
//
3+
// The libevm additions to go-ethereum are free software: you can redistribute
4+
// them and/or modify them under the terms of the GNU Lesser General Public License
5+
// as published by the Free Software Foundation, either version 3 of the License,
6+
// or (at your option) any later version.
7+
//
8+
// The libevm additions are distributed in the hope that they will be useful,
9+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
11+
// General Public License for more details.
12+
//
13+
// You should have received a copy of the GNU Lesser General Public License
14+
// along with the go-ethereum library. If not, see
15+
// <http://www.gnu.org/licenses/>.
16+
17+
package types
18+
19+
import (
20+
"testing"
21+
)
22+
23+
func TestTempRegisteredExtras(t *testing.T) {
24+
TestOnlyClearRegisteredExtras()
25+
t.Cleanup(TestOnlyClearRegisteredExtras)
26+
27+
type (
28+
primary struct {
29+
NOOPHeaderHooks
30+
}
31+
override struct {
32+
NOOPHeaderHooks
33+
}
34+
)
35+
36+
RegisterExtras[primary, *primary, NOOPBlockBodyHooks, *NOOPBlockBodyHooks, bool]()
37+
testPrimaryExtras := func(t *testing.T) {
38+
t.Helper()
39+
assertHeaderHooksConcreteType[*primary](t)
40+
}
41+
42+
t.Run("before_temp", testPrimaryExtras)
43+
t.Run("WithTempRegisteredExtras", func(t *testing.T) {
44+
WithTempRegisteredExtras(func(ExtraPayloads[*override, *NOOPBlockBodyHooks, bool]) {
45+
assertHeaderHooksConcreteType[*override](t)
46+
})
47+
})
48+
t.Run("after_temp", testPrimaryExtras)
49+
}
50+
51+
func assertHeaderHooksConcreteType[WantT any](t *testing.T) {
52+
t.Helper()
53+
54+
hdr := new(Header)
55+
switch got := hdr.hooks().(type) {
56+
case WantT:
57+
default:
58+
var want WantT
59+
t.Errorf("%T.hooks() got concrete type %T; want %T", hdr, got, want)
60+
}
61+
}

0 commit comments

Comments
 (0)