1
- // Package hookstest provides test doubles for testing subsets of libevm hooks.
1
+ // Package hookstest provides test doubles and convenience wrappers for testing
2
+ // libevm hooks.
2
3
package hookstest
3
4
4
5
import (
@@ -10,6 +11,15 @@ import (
10
11
"github.com/ethereum/go-ethereum/params"
11
12
)
12
13
14
+ // Register clears any registered [params.Extras] and then registers `extras`
15
+ // for the liftime of the current test, clearing them via tb's
16
+ // [testing.TB.Cleanup].
17
+ func Register [C params.ChainConfigHooks , R params.RulesHooks ](tb testing.TB , extras params.Extras [C , R ]) {
18
+ params .TestOnlyClearRegisteredExtras ()
19
+ tb .Cleanup (params .TestOnlyClearRegisteredExtras )
20
+ params .RegisterExtras (extras )
21
+ }
22
+
13
23
// A Stub is a test double for [params.ChainConfigHooks] and
14
24
// [params.RulesHooks]. Each of the fields, if non-nil, back their respective
15
25
// hook methods, which otherwise fall back to the default behaviour.
@@ -19,17 +29,14 @@ type Stub struct {
19
29
CanCreateContractFn func (* libevm.AddressContext , libevm.StateReader ) error
20
30
}
21
31
22
- // RegisterForRules clears any registered [params.Extras] and then registers s
23
- // as [params.RulesHooks], which are themselves cleared by the
24
- // [testing.TB.Cleanup] routine.
25
- func (s * Stub ) RegisterForRules (tb testing.TB ) {
26
- params .TestOnlyClearRegisteredExtras ()
27
- params .RegisterExtras (params.Extras [params.NOOPHooks , Stub ]{
28
- NewRules : func (_ * params.ChainConfig , _ * params.Rules , _ * params.NOOPHooks , blockNum * big.Int , isMerge bool , timestamp uint64 ) * Stub {
32
+ // Register is a convenience wrapper for registering s as both the
33
+ // [params.ChainConfigHooks] and [params.RulesHooks] via [Register].
34
+ func (s * Stub ) Register (tb testing.TB ) {
35
+ Register (tb , params.Extras [Stub , Stub ]{
36
+ NewRules : func (_ * params.ChainConfig , _ * params.Rules , _ * Stub , blockNum * big.Int , isMerge bool , timestamp uint64 ) * Stub {
29
37
return s
30
38
},
31
39
})
32
- tb .Cleanup (params .TestOnlyClearRegisteredExtras )
33
40
}
34
41
35
42
func (s Stub ) PrecompileOverride (a common.Address ) (libevm.PrecompiledContract , bool ) {
0 commit comments