Fix compilation, small improvements

This commit is contained in:
Paweł Bylica 2019-10-03 12:09:22 +02:00
parent 2f4a259c56
commit 77aea4f0d9
No known key found for this signature in database
GPG key ID: 7A0C037434FE77EF

View file

@ -17,40 +17,36 @@
package runtime package runtime
import ( import (
"math/big"
"testing"
"flag" "flag"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"math/big"
"testing"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
) )
var ( var (
codefile string codefile string
input string input string
expected string expected string
) )
var testVMConfig = func() vm.Config { var flagsParsed = func() bool {
vmconfig := vm.Config{}
flag.StringVar(&codefile, "codefile", "", "EVM code to run") flag.StringVar(&codefile, "codefile", "", "EVM code to run")
flag.StringVar(&input, "input", "", "input calldata") flag.StringVar(&input, "input", "", "input calldata")
flag.StringVar(&expected, "expected", "", "expected return data") flag.StringVar(&expected, "expected", "", "expected return data")
flag.Parse() flag.Parse()
// don't actually need this vmconfig, but we need to parse custom command args in some way like this return true
return vmconfig
}() }()
func BenchmarkEvmCode(b *testing.B) { func BenchmarkEvmCode(b *testing.B) {
state, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase())) state, _ := state.New(common.Hash{}, state.NewDatabase(rawdb.NewMemoryDatabase()))
address := common.HexToAddress("0x0a") address := common.HexToAddress("0x0a")
var ( var (
@ -78,7 +74,6 @@ func BenchmarkEvmCode(b *testing.B) {
codebytes = common.Hex2Bytes(codehexstr) codebytes = common.Hex2Bytes(codehexstr)
state.SetCode(address, codebytes) state.SetCode(address, codebytes)
evmChainConfig := &params.ChainConfig{ evmChainConfig := &params.ChainConfig{
ChainID: big.NewInt(1), ChainID: big.NewInt(1),
@ -90,13 +85,15 @@ func BenchmarkEvmCode(b *testing.B) {
EIP158Block: new(big.Int), EIP158Block: new(big.Int),
ByzantiumBlock: big.NewInt(0), ByzantiumBlock: big.NewInt(0),
ConstantinopleBlock: big.NewInt(0), ConstantinopleBlock: big.NewInt(0),
}; }
startGas := uint64(100000000) // 100 million startGas := uint64(100000000) // 100 million
inputBytes := common.Hex2Bytes(input)
config := &Config{ChainConfig: evmChainConfig, State: state, EVMConfig: vm.Config{}, GasLimit: startGas}
b.ResetTimer() b.ResetTimer()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
ret, gasLeft, err = Call(address, common.Hex2Bytes(input), &Config{ChainConfig: evmChainConfig, State: state, EVMConfig: testVMConfig, GasLimit: startGas}) ret, gasLeft, err = Call(address, inputBytes, config)
} }
b.StopTimer() b.StopTimer()
//Check if it is correct //Check if it is correct