From b3f1d35171ebb9d0e4f0e8b9e9fb5b64c205900c Mon Sep 17 00:00:00 2001 From: philip-morlier Date: Thu, 22 Jun 2023 01:05:10 -0700 Subject: [PATCH] functional test plugin. This PR will also include the stand alone tests. --- cmd/geth/main.go | 1 - cmd/geth/plugin_hooks.go | 19 ------------------- core/blockchain.go | 1 - core/plugin_hooks.go | 1 - eth/tracers/api.go | 3 --- rpc/plugin_subscriptions.go | 18 ++++++++++++++++++ 6 files changed, 18 insertions(+), 25 deletions(-) diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 40d1b25e9..71e88af2c 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -357,7 +357,6 @@ func geth(ctx *cli.Context) error { stack.RegisterAPIs(pluginGetAPIs(stack, wrapperBackend)) startNode(ctx, stack, backend, false) pluginBlockChain() - pluginHookTester() //end PluGeth code injection stack.Wait() return nil diff --git a/cmd/geth/plugin_hooks.go b/cmd/geth/plugin_hooks.go index 3f1dca401..2a1053c3a 100644 --- a/cmd/geth/plugin_hooks.go +++ b/cmd/geth/plugin_hooks.go @@ -86,7 +86,6 @@ func pluginsInitializeNode(stack *node.Node, backend restricted.Backend) { } func OnShutdown(pl *plugins.PluginLoader) { - log.Error("inside of on shutdown") fnList := pl.Lookup("OnShutdown", func(item interface{}) bool { _, ok := item.(func()) return ok @@ -120,22 +119,4 @@ func pluginBlockChain() { return } BlockChain(plugins.DefaultPluginLoader) -} - -func HookTester(pl *plugins.PluginLoader) { - fnList := pl.Lookup("HookTester", func(item interface{}) bool { - _, ok := item.(func()) - return ok - }) - for _, fni := range fnList { - fni.(func())() - } -} - -func pluginHookTester() { - if plugins.DefaultPluginLoader == nil { - log.Warn("Attempting HookTester, but default PluginLoader has not been initialized") - return - } - HookTester(plugins.DefaultPluginLoader) } \ No newline at end of file diff --git a/core/blockchain.go b/core/blockchain.go index d79a64d32..aa723598b 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1333,7 +1333,6 @@ func (bc *BlockChain) writeKnownBlock(block *types.Block) error { // writeBlockWithState writes block, metadata and corresponding state data to the // database. func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.Receipt, state *state.StateDB) error { - log.Error("inside of the target function") // Calculate the total difficulty of the block ptd := bc.GetTd(block.ParentHash(), block.NumberU64()-1) if ptd == nil { diff --git a/core/plugin_hooks.go b/core/plugin_hooks.go index 5d95af640..3052b1b44 100644 --- a/core/plugin_hooks.go +++ b/core/plugin_hooks.go @@ -125,7 +125,6 @@ func PluginNewHead(pl *plugins.PluginLoader, block *types.Block, hash common.Has _, ok := item.(func([]byte, core.Hash, [][]byte, *big.Int)) return ok }) - log.Error("inside of pluginNewHead()", "len fnList", len(fnList)) blockBytes, _ := rlp.EncodeToBytes(block) logBytes := make([][]byte, len(logs)) for i, l := range logs { diff --git a/eth/tracers/api.go b/eth/tracers/api.go index f22effa2b..b0c1de365 100644 --- a/eth/tracers/api.go +++ b/eth/tracers/api.go @@ -956,17 +956,14 @@ func (api *API) traceTx(ctx context.Context, message *core.Message, txctx *Conte if config == nil { config = &TraceConfig{} } - log.Error("outside of geth condition", "config", config.Tracer) // Default tracer is the struct logger tracer = logger.NewStructLogger(config.Config) if config.Tracer != nil { // Get the tracer from the plugin loader //begin PluGeth code injection if tr, ok := getPluginTracer(*config.Tracer); ok { - log.Error("inside geth", "tracer config", *config.Tracer) tracer = tr(statedb, vmctx) } else { - log.Error("default geth condition", "config", config.Tracer) tracer, err = DefaultDirectory.New(*config.Tracer, txctx, config.TracerConfig) if err != nil { return nil, err diff --git a/rpc/plugin_subscriptions.go b/rpc/plugin_subscriptions.go index ac8282925..2c960fa0b 100644 --- a/rpc/plugin_subscriptions.go +++ b/rpc/plugin_subscriptions.go @@ -4,6 +4,7 @@ import ( "context" "reflect" "github.com/ethereum/go-ethereum/log" + "github.com/ethereum/go-ethereum/plugins" ) @@ -121,7 +122,24 @@ func callbackifyChanPubSub(receiver, fn reflect.Value) *callback { return c } +func RPCSubscription(pl *plugins.PluginLoader) { + fnList := pl.Lookup("RPCSubscriptionTest", func(item interface{}) bool { + _, ok := item.(func()) + return ok + }) + for _, fni := range fnList { + if fn, ok := fni.(func()); ok { + fn() + } + } +} + func pluginExtendedCallbacks(callbacks map[string]*callback, receiver reflect.Value) { + if plugins.DefaultPluginLoader == nil { + log.Warn("Attempting RPCSubscriptionTest, but default PluginLoader has not been initialized") + return + } + RPCSubscription(plugins.DefaultPluginLoader) typ := receiver.Type() for m := 0; m < typ.NumMethod(); m++ { method := typ.Method(m)