-
Notifications
You must be signed in to change notification settings - Fork 5
feat: CheckConfig{Compatible,ForkOrder} + Description hooks
#29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
6e09eb3
0fc930a
fbe5e53
6122f03
9be23e3
de2d302
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,6 +51,11 @@ func constructRulesExtra(c *params.ChainConfig, r *params.Rules, cEx ChainConfig | |
| // the standard [params.ChainConfig] struct. | ||
| type ChainConfigExtra struct { | ||
| MyForkTime *uint64 `json:"myForkTime"` | ||
|
|
||
| // (Optional) If not all hooks are desirable then embedding a [NOOPHooks] | ||
| // allows the type to satisfy the [ChainConfigHooks] interface, resulting in | ||
| // default Ethereum behaviour. | ||
| params.NOOPHooks | ||
| } | ||
|
|
||
| // RulesExtra can be any struct. It too mirrors a common pattern in | ||
|
|
@@ -59,9 +64,6 @@ type RulesExtra struct { | |
| IsMyFork bool | ||
| timestamp uint64 | ||
|
|
||
| // (Optional) If not all hooks are desirable then embedding a [NOOPHooks] | ||
| // allows the type to satisfy the [RulesHooks] interface, resulting in | ||
| // default Ethereum behaviour. | ||
|
Comment on lines
-62
to
-64
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we keep this comment? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's just been moved to |
||
| params.NOOPHooks | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| package params_test | ||
|
|
||
| import ( | ||
| "errors" | ||
| "fmt" | ||
| "math/big" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
|
|
||
| "github.com/ethereum/go-ethereum/libevm/ethtest" | ||
| "github.com/ethereum/go-ethereum/libevm/hookstest" | ||
| "github.com/ethereum/go-ethereum/params" | ||
| ) | ||
|
|
||
| func TestChainConfigHooks_Description(t *testing.T) { | ||
| const suffix = "Arran was here" | ||
| c := new(params.ChainConfig) | ||
| want := c.Description() + suffix | ||
|
|
||
| hooks := &hookstest.Stub{ | ||
| DescriptionSuffix: "Arran was here", | ||
| } | ||
| hooks.Register(t).SetOnChainConfig(c, hooks) | ||
| require.Equal(t, want, c.Description(), "ChainConfigHooks.Description() is appended to non-extras equivalent") | ||
| } | ||
|
|
||
| func TestChainConfigHooks_CheckConfigForkOrder(t *testing.T) { | ||
| err := errors.New("uh oh") | ||
|
|
||
| c := new(params.ChainConfig) | ||
| require.NoError(t, c.CheckConfigForkOrder(), "CheckConfigForkOrder() with no hooks") | ||
|
|
||
| hooks := &hookstest.Stub{ | ||
| CheckConfigForkOrderFn: func() error { return err }, | ||
| } | ||
| hooks.Register(t).SetOnChainConfig(c, hooks) | ||
| require.Equal(t, err, c.CheckConfigForkOrder(), "CheckConfigForkOrder() with error-producing hook") | ||
| } | ||
|
|
||
| func TestChainConfigHooks_CheckConfigCompatible(t *testing.T) { | ||
| rng := ethtest.NewPseudoRand(1234567890) | ||
| newcfg := ¶ms.ChainConfig{ | ||
| ChainID: rng.BigUint64(), | ||
| } | ||
| headNumber := rng.Uint64() | ||
| headTimestamp := rng.Uint64() | ||
|
|
||
| c := new(params.ChainConfig) | ||
| require.Nil(t, c.CheckCompatible(newcfg, headNumber, headTimestamp), "CheckCompatible() with no hooks") | ||
|
|
||
| makeCompatErr := func(newcfg *params.ChainConfig, headNumber *big.Int, headTimestamp uint64) *params.ConfigCompatError { | ||
| return ¶ms.ConfigCompatError{ | ||
| What: fmt.Sprintf("ChainID: %v Head #: %v Head Time: %d", newcfg.ChainID, headNumber, headTimestamp), | ||
| } | ||
| } | ||
| hooks := &hookstest.Stub{ | ||
| CheckConfigCompatibleFn: makeCompatErr, | ||
| } | ||
| hooks.Register(t).SetOnChainConfig(c, hooks) | ||
| want := makeCompatErr(newcfg, new(big.Int).SetUint64(headNumber), headTimestamp) | ||
| require.Equal(t, want, c.CheckCompatible(newcfg, headNumber, headTimestamp), "CheckCompatible() with error-producing hook") | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.