From 892f98ad6a7658ead972c9449895005495ba2fd7 Mon Sep 17 00:00:00 2001 From: philip-morlier Date: Fri, 1 Dec 2023 21:06:25 -0800 Subject: [PATCH 1/2] Added psudoCreateEngine function to test CreateEngine call --- plugins/test-plugin/engine.go | 2 ++ plugins/test-plugin/hooks.go | 12 ++++++++++++ plugins/test-plugin/main.go | 3 +++ 3 files changed, 17 insertions(+) diff --git a/plugins/test-plugin/engine.go b/plugins/test-plugin/engine.go index 76097ba6f..fac7cd505 100644 --- a/plugins/test-plugin/engine.go +++ b/plugins/test-plugin/engine.go @@ -17,6 +17,7 @@ var ( backend restricted.Backend log core.Logger events core.Feed + createEngineCalled bool ) var httpApiFlagName = "http.api" @@ -107,6 +108,7 @@ func (e *engine) Close() error { } func CreateEngine(chainConfig *params.ChainConfig, db restricted.Database) consensus.Engine { + createEngineCalled = true return &engine{} } diff --git a/plugins/test-plugin/hooks.go b/plugins/test-plugin/hooks.go index b1a11e44a..417eafeed 100644 --- a/plugins/test-plugin/hooks.go +++ b/plugins/test-plugin/hooks.go @@ -187,6 +187,17 @@ func OpCodeSelect() []int { return nil } +// eth/ethconfig + +func pseudoCreateEngine() { + if createEngineCalled { + m := map[string]struct{}{ + "CreateEngine":struct{}{}, + } + hookChan <- m + } +} + // rpc/ @@ -239,6 +250,7 @@ func Is160(num *big.Int) bool { } var plugins map[string]struct{} = map[string]struct{}{ + "CreateEngine":struct{}{}, "OnShutdown": struct{}{}, "SetTrieFlushIntervalClone":struct{}{}, "StateUpdate": struct{}{}, diff --git a/plugins/test-plugin/main.go b/plugins/test-plugin/main.go index 75cba1eee..3ec113d2a 100644 --- a/plugins/test-plugin/main.go +++ b/plugins/test-plugin/main.go @@ -53,6 +53,8 @@ func BlockChain() { var ok bool f := func(key string) bool {_, ok = m[key]; return ok} switch { + case f("CreateEngine"): + delete(plugins, "CreateEngine") case f("OnShutdown"): delete(plugins, "OnShutdown") case f("StateUpdate"): @@ -139,6 +141,7 @@ func BlockChain() { } }() + pseudoCreateEngine() txFactory() txTracer() } From c7efabf8d672c8198153abe961c88151def1c403 Mon Sep 17 00:00:00 2001 From: philip-morlier Date: Thu, 7 Dec 2023 13:03:43 -0800 Subject: [PATCH 2/2] Added InitializeNode converage to test plugin --- plugins/test-plugin/hooks.go | 11 +++++++++++ plugins/test-plugin/main.go | 2 ++ 2 files changed, 13 insertions(+) diff --git a/plugins/test-plugin/hooks.go b/plugins/test-plugin/hooks.go index 417eafeed..47f8249ed 100644 --- a/plugins/test-plugin/hooks.go +++ b/plugins/test-plugin/hooks.go @@ -6,6 +6,7 @@ import ( "sync" "github.com/openrelayxyz/plugeth-utils/core" + "github.com/openrelayxyz/plugeth-utils/restricted" ) @@ -37,6 +38,15 @@ func GetAPIs(stack core.Node, backend core.Backend) []core.API { return apis } +func InitializeNode(stack core.Node, b restricted.Backend) { + go func() { + m := map[string]struct{}{ + "InitializeNode":struct{}{}, + } + hookChan <- m + }() +} + // func OnShutdown(){ // this injection is covered by another test in this package. See documentation for details. // } @@ -250,6 +260,7 @@ func Is160(num *big.Int) bool { } var plugins map[string]struct{} = map[string]struct{}{ + "InitializeNode":struct{}{}, "CreateEngine":struct{}{}, "OnShutdown": struct{}{}, "SetTrieFlushIntervalClone":struct{}{}, diff --git a/plugins/test-plugin/main.go b/plugins/test-plugin/main.go index 3ec113d2a..30f272606 100644 --- a/plugins/test-plugin/main.go +++ b/plugins/test-plugin/main.go @@ -53,6 +53,8 @@ func BlockChain() { var ok bool f := func(key string) bool {_, ok = m[key]; return ok} switch { + case f("InitializeNode"): + delete(plugins, "InitializeNode") case f("CreateEngine"): delete(plugins, "CreateEngine") case f("OnShutdown"):