aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-12-04 18:30:41 +0800
committerobscuren <geffobscura@gmail.com>2014-12-04 18:30:41 +0800
commit3664cd58e3631fccf4d9aba1932e0bb63ad442a6 (patch)
tree6e2b1037916ffa035c8bfc13bca99ad151124dd9 /cmd
parent491edc16e778e3d232f643a4b4155c4f71ef27cc (diff)
downloaddexon-3664cd58e3631fccf4d9aba1932e0bb63ad442a6.tar
dexon-3664cd58e3631fccf4d9aba1932e0bb63ad442a6.tar.gz
dexon-3664cd58e3631fccf4d9aba1932e0bb63ad442a6.tar.bz2
dexon-3664cd58e3631fccf4d9aba1932e0bb63ad442a6.tar.lz
dexon-3664cd58e3631fccf4d9aba1932e0bb63ad442a6.tar.xz
dexon-3664cd58e3631fccf4d9aba1932e0bb63ad442a6.tar.zst
dexon-3664cd58e3631fccf4d9aba1932e0bb63ad442a6.zip
Updated testing tools
Diffstat (limited to 'cmd')
-rw-r--r--cmd/ethtest/main.go2
-rw-r--r--cmd/evm/main.go90
2 files changed, 69 insertions, 23 deletions
diff --git a/cmd/ethtest/main.go b/cmd/ethtest/main.go
index 82e1c6d59..94ab779db 100644
--- a/cmd/ethtest/main.go
+++ b/cmd/ethtest/main.go
@@ -82,7 +82,7 @@ func RunVmTest(js string) (failed int) {
state.SetStateObject(obj)
}
- ret, gas, err := helper.RunVm(state, test.Env, test.Exec)
+ ret, _, gas, err := helper.RunVm(state, test.Env, test.Exec)
// When an error is returned it doesn't always mean the tests fails.
// Have to come up with some conditional failing mechanism.
if err != nil {
diff --git a/cmd/evm/main.go b/cmd/evm/main.go
index 2b4d47684..fb1be3caa 100644
--- a/cmd/evm/main.go
+++ b/cmd/evm/main.go
@@ -32,6 +32,8 @@ import (
"runtime"
"time"
+ "github.com/ethereum/go-ethereum/core"
+ "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/logger"
@@ -45,6 +47,7 @@ var (
loglevel = flag.Int("log", 4, "log level")
gas = flag.String("gas", "1000000", "gas amount")
price = flag.String("price", "0", "gas price")
+ value = flag.String("value", "0", "tx value")
dump = flag.Bool("dump", false, "dump state after run")
data = flag.String("data", "", "data")
)
@@ -61,13 +64,17 @@ func main() {
ethutil.ReadConfig("/tm/evmtest", "/tmp/evm", "")
- stateObject := state.NewStateObject([]byte("evmuser"))
- closure := vm.NewClosure(nil, stateObject, stateObject, ethutil.Hex2Bytes(*code), ethutil.Big(*gas), ethutil.Big(*price))
+ db, _ := ethdb.NewMemDatabase()
+ statedb := state.New(trie.New(db, ""))
+ sender := statedb.NewStateObject([]byte("sender"))
+ receiver := statedb.NewStateObject([]byte("receiver"))
+ receiver.SetCode([]byte(*code))
+
+ vmenv := NewEnv(statedb, []byte("evmuser"), ethutil.Big(*value))
tstart := time.Now()
- env := NewVmEnv()
- ret, _, e := closure.Call(vm.New(env, vm.DebugVmTy), ethutil.Hex2Bytes(*data))
+ ret, e := vmenv.Call(sender, receiver.Address(), ethutil.Hex2Bytes(*data), ethutil.Big(*gas), ethutil.Big(*price), ethutil.Big(*value))
logger.Flush()
if e != nil {
@@ -75,7 +82,7 @@ func main() {
}
if *dump {
- fmt.Println(string(env.state.Dump()))
+ fmt.Println(string(statedb.Dump()))
}
var mem runtime.MemStats
@@ -92,26 +99,65 @@ num gc: %d
fmt.Printf("%x\n", ret)
}
-type VmEnv struct {
+type VMEnv struct {
state *state.State
+ block *types.Block
+
+ transactor []byte
+ value *big.Int
+
+ depth int
+ Gas *big.Int
+ time int64
}
-func NewVmEnv() *VmEnv {
- db, _ := ethdb.NewMemDatabase()
- return &VmEnv{state.New(trie.New(db, ""))}
+func NewEnv(state *state.State, transactor []byte, value *big.Int) *VMEnv {
+ return &VMEnv{
+ state: state,
+ transactor: transactor,
+ value: value,
+ time: time.Now().Unix(),
+ }
+}
+
+func (self *VMEnv) State() *state.State { return self.state }
+func (self *VMEnv) Origin() []byte { return self.transactor }
+func (self *VMEnv) BlockNumber() *big.Int { return ethutil.Big0 }
+func (self *VMEnv) PrevHash() []byte { return make([]byte, 32) }
+func (self *VMEnv) Coinbase() []byte { return self.transactor }
+func (self *VMEnv) Time() int64 { return self.time }
+func (self *VMEnv) Difficulty() *big.Int { return ethutil.Big1 }
+func (self *VMEnv) BlockHash() []byte { return make([]byte, 32) }
+func (self *VMEnv) Value() *big.Int { return self.value }
+func (self *VMEnv) GasLimit() *big.Int { return big.NewInt(1000000000) }
+func (self *VMEnv) Depth() int { return self.depth }
+func (self *VMEnv) SetDepth(i int) { self.depth = i }
+func (self *VMEnv) AddLog(log *state.Log) {
+ self.state.AddLog(log)
+}
+func (self *VMEnv) Transfer(from, to vm.Account, amount *big.Int) error {
+ return vm.Transfer(from, to, amount)
+}
+
+func (self *VMEnv) vm(addr, data []byte, gas, price, value *big.Int) *core.Execution {
+ evm := vm.New(self, vm.DebugVmTy)
+
+ return core.NewExecution(evm, addr, data, gas, price, value)
+}
+
+func (self *VMEnv) Call(caller vm.ClosureRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error) {
+ exe := self.vm(addr, data, gas, price, value)
+ ret, err := exe.Call(addr, caller)
+ self.Gas = exe.Gas
+
+ return ret, err
+}
+func (self *VMEnv) CallCode(caller vm.ClosureRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error) {
+ exe := self.vm(caller.Address(), data, gas, price, value)
+ return exe.Call(addr, caller)
}
-func (VmEnv) Origin() []byte { return nil }
-func (VmEnv) BlockNumber() *big.Int { return nil }
-func (VmEnv) BlockHash() []byte { return nil }
-func (VmEnv) PrevHash() []byte { return nil }
-func (VmEnv) Coinbase() []byte { return nil }
-func (VmEnv) Time() int64 { return 0 }
-func (VmEnv) GasLimit() *big.Int { return nil }
-func (VmEnv) Difficulty() *big.Int { return nil }
-func (VmEnv) Value() *big.Int { return nil }
-func (self *VmEnv) State() *state.State { return self.state }
-func (VmEnv) AddLog(*state.Log) {}
-func (VmEnv) Transfer(from, to vm.Account, amount *big.Int) error {
- return nil
+func (self *VMEnv) Create(caller vm.ClosureRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error, vm.ClosureRef) {
+ exe := self.vm(addr, data, gas, price, value)
+ return exe.Create(caller)
}