mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-21 06:04:33 +00:00
* feat: pseudo-generic extra payloads in `params.ChainConfig` and `params.Rules` * feat: `params.ExtraPayloadGetter` for end-user type safety * refactor: payloads only available through `params.ExtraPayloadGetter` * chore: make `libevm/examples/extraparams` a `params` testable example * doc: `libevm/pseudo` package comments and improved readability * doc: `params.*Extra*` comments and improved readability * doc: `params.ExtraPayloadGetter` comments and improved readability * doc: `params/config.libevm_test.go` comments and improved readability * refactor: simplify `params.ChainConfig.UnmarshalJSON()` * refactor: abstract new/nil-pointer creation into `pseudo.Constructor`s * feat: precompile override via `params.Extras` hooks * doc: flesh out `PrecompileOverride()` in example * doc: complete commentary and improve readability * refactor: `ChainConfig.Hooks()` + `Rules` equivalent * chore: rename precompiles test file in keeping with geth equivalent * feat: stateful precompiles + allowlist hooks The allowlist hooks are included in this commit because they allow for the same functionality as stateful precompiles in `ava-labs/coreth` and `ava-labs/subnet-evm`. * fix: `StateTransition.canExecuteTransaction()` used `msg.From` instead of `To` * test: `params.RulesHooks.CanCreateContract` integration * test: `params.RulesHooks.CanExecuteTransaction` integration * test: `vm.NewStatefulPrecompile()` integration * refactor: simplify test of `CanCreateContract` * refactor: abstract generation of random `Address`/`Hash` values * doc: full documentation + readability refactoring/renaming * fix: remove circular dependency in tests
40 lines
1.1 KiB
Go
40 lines
1.1 KiB
Go
package core_test
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
"github.com/ethereum/go-ethereum/core"
|
|
"github.com/ethereum/go-ethereum/libevm"
|
|
"github.com/ethereum/go-ethereum/libevm/ethtest"
|
|
"github.com/ethereum/go-ethereum/libevm/hookstest"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestCanExecuteTransaction(t *testing.T) {
|
|
rng := ethtest.NewPseudoRand(42)
|
|
account := rng.Address()
|
|
slot := rng.Hash()
|
|
|
|
makeErr := func(from common.Address, to *common.Address, val common.Hash) error {
|
|
return fmt.Errorf("From: %v To: %v State: %v", from, to, val)
|
|
}
|
|
hooks := &hookstest.Stub{
|
|
CanExecuteTransactionFn: func(from common.Address, to *common.Address, s libevm.StateReader) error {
|
|
return makeErr(from, to, s.GetState(account, slot))
|
|
},
|
|
}
|
|
hooks.RegisterForRules(t)
|
|
|
|
value := rng.Hash()
|
|
|
|
state, evm := ethtest.NewZeroEVM(t)
|
|
state.SetState(account, slot, value)
|
|
msg := &core.Message{
|
|
From: rng.Address(),
|
|
To: rng.AddressPtr(),
|
|
}
|
|
_, err := core.ApplyMessage(evm, msg, new(core.GasPool).AddGas(30e6))
|
|
require.EqualError(t, err, makeErr(msg.From, msg.To, value).Error())
|
|
}
|