mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
get tests to run with tracer correctly initialized
This commit is contained in:
parent
2813a0bb65
commit
7c98e75c72
4 changed files with 39 additions and 2 deletions
|
|
@ -232,6 +232,8 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
|
||||||
|
|
||||||
DebugApi.eth = eth
|
DebugApi.eth = eth
|
||||||
DebugApi.config = chainConfig
|
DebugApi.config = chainConfig
|
||||||
|
// Shyft Tracer
|
||||||
|
InitTracerEnv()
|
||||||
|
|
||||||
return eth, nil
|
return eth, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/ethdb"
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
"github.com/ethereum/go-ethereum/node"
|
"github.com/ethereum/go-ethereum/node"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Chaindb_global ethdb.Database
|
var Chaindb_global ethdb.Database
|
||||||
|
|
@ -24,4 +26,22 @@ func chaindb(ctx *node.ServiceContext, config *Config) (ethdb.Database, error) {
|
||||||
return Chaindb_global, nil
|
return Chaindb_global, nil
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
//(*ethdb.LDBDatabase, func())
|
||||||
|
func NewShyftTestLDB() {
|
||||||
|
dirname, err := ioutil.TempDir(os.TempDir(), "shyftdb_test_")
|
||||||
|
if err != nil {
|
||||||
|
panic("failed to create test file: " + err.Error())
|
||||||
|
}
|
||||||
|
db, err := ethdb.NewLDBDatabase(dirname, 0, 0)
|
||||||
|
if err != nil {
|
||||||
|
panic("failed to create test database: " + err.Error())
|
||||||
|
}
|
||||||
|
Chaindb_global = db
|
||||||
|
|
||||||
|
//return db, func() {
|
||||||
|
// db.Close()
|
||||||
|
// os.RemoveAll(dirname)
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
|
|
@ -12,23 +12,35 @@ var EthereumObject interface{}
|
||||||
|
|
||||||
type ShyftTracer struct {}
|
type ShyftTracer struct {}
|
||||||
|
|
||||||
func (st ShyftTracer) GetTracerToRun (hash common.Hash) (interface{}, error) {
|
var PrivateAPI *PrivateDebugAPI
|
||||||
|
var Context context.Context
|
||||||
|
var TracerConfig *TraceConfig
|
||||||
|
|
||||||
|
func InitTracerEnv() {
|
||||||
|
fmt.Println("INIT tracer Env")
|
||||||
config2 := params.ShyftNetworkChainConfig
|
config2 := params.ShyftNetworkChainConfig
|
||||||
|
|
||||||
jsTracer := "callTracer"
|
jsTracer := "callTracer"
|
||||||
var ctx2 context.Context
|
var ctx2 context.Context
|
||||||
|
Context = ctx2
|
||||||
config := &TraceConfig{
|
config := &TraceConfig{
|
||||||
LogConfig: nil,
|
LogConfig: nil,
|
||||||
Tracer: &jsTracer, // needs to be non-nil
|
Tracer: &jsTracer, // needs to be non-nil
|
||||||
Timeout: nil,
|
Timeout: nil,
|
||||||
Reexec: nil,
|
Reexec: nil,
|
||||||
}
|
}
|
||||||
|
TracerConfig = config
|
||||||
fmt.Println("+++++++++++++++++++++++++++ before FULLNODE", Global_config)
|
fmt.Println("+++++++++++++++++++++++++++ before FULLNODE", Global_config)
|
||||||
|
// called here
|
||||||
fullNode, _ := SNew(Global_config)
|
fullNode, _ := SNew(Global_config)
|
||||||
fmt.Println("+++++++++++++++++++++++++++ after FULLNODE")
|
fmt.Println("+++++++++++++++++++++++++++ after FULLNODE")
|
||||||
privateAPI := NewPrivateDebugAPI(config2, fullNode)
|
privateAPI := NewPrivateDebugAPI(config2, fullNode)
|
||||||
|
PrivateAPI = privateAPI
|
||||||
fmt.Println("+++++++++++++++++++++++++++ after privateAPI")
|
fmt.Println("+++++++++++++++++++++++++++ after privateAPI")
|
||||||
return privateAPI.STraceTransaction(ctx2, hash, config)
|
}
|
||||||
|
|
||||||
|
func (st ShyftTracer) GetTracerToRun (hash common.Hash) (interface{}, error) {
|
||||||
|
return PrivateAPI.STraceTransaction(Context, hash, TracerConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
func setEthObject(ethobj interface{}){
|
func setEthObject(ethobj interface{}){
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestBlock(t *testing.T) {
|
func TestBlock(t *testing.T) {
|
||||||
|
eth.NewShyftTestLDB()
|
||||||
core.InitDBTest()
|
core.InitDBTest()
|
||||||
shyft_tracer := new(eth.ShyftTracer)
|
shyft_tracer := new(eth.ShyftTracer)
|
||||||
core.SetIShyftTracer(shyft_tracer)
|
core.SetIShyftTracer(shyft_tracer)
|
||||||
|
|
@ -55,6 +56,8 @@ func TestBlock(t *testing.T) {
|
||||||
|
|
||||||
eth.SetGlobalConfig(ethConf)
|
eth.SetGlobalConfig(ethConf)
|
||||||
|
|
||||||
|
eth.InitTracerEnv()
|
||||||
|
|
||||||
t.Run("TestBlockToReturnBlock", func(t *testing.T) {
|
t.Run("TestBlockToReturnBlock", func(t *testing.T) {
|
||||||
key, _ := crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
|
key, _ := crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
|
||||||
signer := types.NewEIP155Signer(big.NewInt(2147483647))
|
signer := types.NewEIP155Signer(big.NewInt(2147483647))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue