fixing tests for internals

This commit is contained in:
Dustin Brickwood 2018-07-16 11:43:17 -04:00
parent 5d37a31a12
commit 2813a0bb65
10 changed files with 693 additions and 454 deletions

View file

@ -34,10 +34,10 @@ import (
"github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/node"
) )
const ( const (
testInstance = "console-tester" testInstance = "console-tester"
testAddress = "0x8605cdbbdb6d264aa742e77020dcbc58fcdce182" testAddress = "0x8605cdbbdb6d264aa742e77020dcbc58fcdce182"
) )
// hookedPrompter implements UserPrompter to simulate use input via channels. // hookedPrompter implements UserPrompter to simulate use input via channels.
type hookedPrompter struct { type hookedPrompter struct {

View file

@ -3,18 +3,25 @@ package core
import ( import (
"fmt" "fmt"
"database/sql" "database/sql"
"os"
) )
var blockExplorerDb *sql.DB var blockExplorerDb *sql.DB
func InitDB() (*sql.DB, error){ func InitDB() (*sql.DB, error){
var connStr string var connStr = "user=postgres dbname=shyftdb sslmode=disable"
if "test" == os.Getenv("SHYFT_ENV") { db, err := sql.Open("postgres", connStr)
connStr = "user=postgres dbname=shyftdbtest sslmode=disable" if err != nil {
fmt.Println("ERROR OPENING DB, NOT INITIALIZING")
fmt.Println(err)
return nil, err
} else { } else {
connStr = "user=postgres dbname=shyftdb sslmode=disable" blockExplorerDb = db
return blockExplorerDb, nil
} }
}
func InitDBTest() (*sql.DB, error){
var connStr = "user=postgres dbname=shyftdbtest sslmode=disable"
db, err := sql.Open("postgres", connStr) db, err := sql.Open("postgres", connStr)
if err != nil { if err != nil {
fmt.Println("ERROR OPENING DB, NOT INITIALIZING") fmt.Println("ERROR OPENING DB, NOT INITIALIZING")

View file

@ -114,7 +114,7 @@ type SendAndReceive struct {
func SWriteBlock(block *types.Block, receipts []*types.Receipt) error { func SWriteBlock(block *types.Block, receipts []*types.Receipt) error {
sqldb, err := DBConnection() sqldb, err := DBConnection()
if (err != nil) { if err != nil {
panic(err) panic(err)
} }
@ -204,7 +204,6 @@ func SwriteTransactions(sqldb *sql.DB, tx *types.Transaction, blockHash common.H
isContract = true isContract = true
sqlStatement := `INSERT INTO txs(txhash, from_addr, to_addr, blockhash, blockNumber, amount, gasprice, gas, gasLimit,txfee, nonce, isContract, txStatus, age, data) VALUES(($1), ($2), ($3), ($4), ($5), ($6), ($7), ($8), ($9), ($10), ($11), ($12), ($13), ($14), ($15)) RETURNING nonce` sqlStatement := `INSERT INTO txs(txhash, from_addr, to_addr, blockhash, blockNumber, amount, gasprice, gas, gasLimit,txfee, nonce, isContract, txStatus, age, data) VALUES(($1), ($2), ($3), ($4), ($5), ($6), ($7), ($8), ($9), ($10), ($11), ($12), ($13), ($14), ($15)) RETURNING nonce`
qerr := sqldb.QueryRow(sqlStatement, txHash, from, contractAddressFromReciept, blockHasher, blockNumber, amount, gasPrice, gas, gasLimit, txFee, nonce, isContract, statusFromReciept, age,data).Scan(&retNonce) qerr := sqldb.QueryRow(sqlStatement, txHash, from, contractAddressFromReciept, blockHasher, blockNumber, amount, gasPrice, gas, gasLimit, txFee, nonce, isContract, statusFromReciept, age,data).Scan(&retNonce)
if qerr != nil { if qerr != nil {
panic(qerr) panic(qerr)
} }
@ -228,7 +227,6 @@ func SwriteTransactions(sqldb *sql.DB, tx *types.Transaction, blockHash common.H
panic(qerr) panic(qerr)
} }
} }
IShyftTracer.GetTracerToRun(hash) IShyftTracer.GetTracerToRun(hash)
return nil return nil

View file

@ -561,10 +561,12 @@ func (api *PrivateDebugAPI) STraceTransaction(ctx context.Context, hash common.H
if config != nil && config.Reexec != nil { if config != nil && config.Reexec != nil {
reexec = *config.Reexec reexec = *config.Reexec
} }
fmt.Println("+++++++++++++++++++++++++++ Middle")
msg, vmctx, statedb, err := api.computeTxEnv(blockHash, int(index), reexec) msg, vmctx, statedb, err := api.computeTxEnv(blockHash, int(index), reexec)
if err != nil { if err != nil {
return nil, err return nil, err
} }
fmt.Println("+++++++++++++++++++++++++++ BOTTOM")
return api.StraceTx(ctx, msg, vmctx, statedb, config, hash) return api.StraceTx(ctx, msg, vmctx, statedb, config, hash)
} }
@ -581,7 +583,7 @@ func (api *PrivateDebugAPI) StraceTx(ctx context.Context, message core.Message,
switch { switch {
case config != nil && config.Tracer != nil: case config != nil && config.Tracer != nil:
// Define a meaningful timeout of a single transaction trace // Define a meaningful timeout of a single transaction trace
fmt.Println("STRACETX")
_ = defaultTraceTimeout _ = defaultTraceTimeout
if config.Timeout != nil { if config.Timeout != nil {
@ -701,6 +703,7 @@ func (api *PrivateDebugAPI) traceTx(ctx context.Context, message core.Message, v
// computeTxEnv returns the execution environment of a certain transaction. // computeTxEnv returns the execution environment of a certain transaction.
func (api *PrivateDebugAPI) computeTxEnv(blockHash common.Hash, txIndex int, reexec uint64) (core.Message, vm.Context, *state.StateDB, error) { func (api *PrivateDebugAPI) computeTxEnv(blockHash common.Hash, txIndex int, reexec uint64) (core.Message, vm.Context, *state.StateDB, error) {
// Create the parent state database // Create the parent state database
fmt.Println("COMPUTETXENV")
block := api.eth.blockchain.GetBlockByHash(blockHash) block := api.eth.blockchain.GetBlockByHash(blockHash)
if block == nil { if block == nil {
return nil, vm.Context{}, nil, fmt.Errorf("block %x not found", blockHash) return nil, vm.Context{}, nil, fmt.Errorf("block %x not found", blockHash)
@ -730,5 +733,6 @@ func (api *PrivateDebugAPI) computeTxEnv(blockHash common.Hash, txIndex int, ree
} }
statedb.DeleteSuicides() statedb.DeleteSuicides()
} }
fmt.Println("+++++++++++++++++ BOTTOM COMPUTETXENV")
return nil, vm.Context{}, nil, fmt.Errorf("tx index %d out of range for block %x", txIndex, blockHash) return nil, vm.Context{}, nil, fmt.Errorf("tx index %d out of range for block %x", txIndex, blockHash)
} }

View file

@ -103,9 +103,10 @@ func (s *Ethereum) AddLesServer(ls LesServer) {
} }
func SNew(config *Config) (*Ethereum, error) { func SNew(config *Config) (*Ethereum, error) {
fmt.Println("SNEW FROM SHYFTREACER")
stopDbUpgrade := upgradeDeduplicateData(Chaindb_global) stopDbUpgrade := upgradeDeduplicateData(Chaindb_global)
fmt.Println("ChainGlobal v+%", Chaindb_global)
chainConfig, _, _ := core.SetupGenesisBlock(Chaindb_global, config.Genesis) chainConfig, _, _ := core.SetupGenesisBlock(Chaindb_global, config.Genesis)
eth := &Ethereum{ eth := &Ethereum{
config: config, config: config,
chainDb: Chaindb_global, chainDb: Chaindb_global,
@ -139,10 +140,9 @@ func SNew(config *Config) (*Ethereum, error) {
// New creates a new Ethereum object (including the // New creates a new Ethereum object (including the
// initialisation of the common Ethereum object) // initialisation of the common Ethereum object)
func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) { func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
shyft_tracer := new(ShyftTracer) shyft_tracer := new(ShyftTracer)
core.SetIShyftTracer(shyft_tracer) core.SetIShyftTracer(shyft_tracer)
setGlobalConfig(config) SetGlobalConfig(config)
_, file, no, ok := runtime.Caller(1) _, file, no, ok := runtime.Caller(1)
if ok { if ok {

View file

@ -3,6 +3,7 @@ package eth
import ( 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"
) )
var Chaindb_global ethdb.Database var Chaindb_global ethdb.Database
@ -12,6 +13,7 @@ func SetChainDB(db ethdb.Database){
} }
func chaindb(ctx *node.ServiceContext, config *Config) (ethdb.Database, error) { func chaindb(ctx *node.ServiceContext, config *Config) (ethdb.Database, error) {
fmt.Printf("CTX v+%", ctx)
if Chaindb_global != nil { if Chaindb_global != nil {
return Chaindb_global, nil return Chaindb_global, nil
} }

View file

@ -5,19 +5,17 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
"context" "context"
"fmt"
) )
var EthereumObject interface{} var EthereumObject interface{}
type ShyftTracer struct {} type ShyftTracer struct {}
//(
func (st ShyftTracer) GetTracerToRun (hash common.Hash) (interface{}, error) { func (st ShyftTracer) GetTracerToRun (hash common.Hash) (interface{}, error) {
config2 := params.ShyftNetworkChainConfig config2 := params.ShyftNetworkChainConfig
jsTracer := "callTracer" jsTracer := "callTracer"
//
//var cfg *Config
var ctx2 context.Context var ctx2 context.Context
config := &TraceConfig{ config := &TraceConfig{
LogConfig: nil, LogConfig: nil,
@ -25,9 +23,11 @@ func (st ShyftTracer) GetTracerToRun (hash common.Hash) (interface{}, error) {
Timeout: nil, Timeout: nil,
Reexec: nil, Reexec: nil,
} }
//var fullNode *Ethereum fmt.Println("+++++++++++++++++++++++++++ before FULLNODE", Global_config)
fullNode, _ := SNew(Global_config) fullNode, _ := SNew(Global_config)
fmt.Println("+++++++++++++++++++++++++++ after FULLNODE")
privateAPI := NewPrivateDebugAPI(config2, fullNode) privateAPI := NewPrivateDebugAPI(config2, fullNode)
fmt.Println("+++++++++++++++++++++++++++ after privateAPI")
return privateAPI.STraceTransaction(ctx2, hash, config) return privateAPI.STraceTransaction(ctx2, hash, config)
} }
@ -37,6 +37,7 @@ func setEthObject(ethobj interface{}){
var Global_config *Config var Global_config *Config
func setGlobalConfig(c *Config) { func SetGlobalConfig(c *Config) {
fmt.Println("SETGLOBAL")
Global_config = c Global_config = c
} }

View file

@ -27,11 +27,11 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"gopkg.in/olebedev/go-duktape.v3" "gopkg.in/olebedev/go-duktape.v3"
"database/sql"
) )
// bigIntegerJS is the minified version of https://github.com/peterolson/BigInteger.js. // bigIntegerJS is the minified version of https://github.com/peterolson/BigInteger.js.
@ -592,10 +592,10 @@ type Internals struct {
//@NOTE:SHYFT //@NOTE:SHYFT
func (i *Internals) SWriteInteralTxs(hash common.Hash) { func (i *Internals) SWriteInteralTxs(hash common.Hash) {
connStr := "user=postgres dbname=shyftdb sslmode=disable" fmt.Println("WRITE INTERNAL")
sqldb, err := sql.Open("postgres", connStr) sqldb, err := core.DBConnection()
if err != nil { if err != nil {
return panic(err)
} }
gas, _ := hexutil.DecodeUint64(i.Gas) gas, _ := hexutil.DecodeUint64(i.Gas)
@ -612,6 +612,7 @@ func (i *Internals) SWriteInteralTxs(hash common.Hash) {
} }
//@NOTE:SHYFT //@NOTE:SHYFT
func (i *Internals) InternalRecursive(hash common.Hash) { func (i *Internals) InternalRecursive(hash common.Hash) {
fmt.Println("internal recursive")
i.SWriteInteralTxs(hash) i.SWriteInteralTxs(hash)
lengthOfCalls := len(i.Calls) lengthOfCalls := len(i.Calls)
if lengthOfCalls == 0 { if lengthOfCalls == 0 {
@ -670,6 +671,7 @@ func (jst *Tracer) GetResult() (json.RawMessage, error) {
//@NOTE:SHYFT //@NOTE:SHYFT
func (jst *Tracer) SGetResult(hash common.Hash) (json.RawMessage, error) { func (jst *Tracer) SGetResult(hash common.Hash) (json.RawMessage, error) {
fmt.Println("SGETRESULT")
// Transform the context into a JavaScript object and inject into the state // Transform the context into a JavaScript object and inject into the state
obj := jst.vm.PushObject() obj := jst.vm.PushObject()

File diff suppressed because it is too large Load diff

View file

@ -8,7 +8,3 @@ type IShyftTracer interface {
GetTracerToRun(hash common.Hash) (interface{}, error) GetTracerToRun(hash common.Hash) (interface{}, error)
} }
//type IShyftTracer interface {
// MyTraceTransaction(hash string) (interface{})
//}