aboutsummaryrefslogtreecommitdiffstats
path: root/ethvm/vm_test.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-10-14 17:48:52 +0800
committerobscuren <geffobscura@gmail.com>2014-10-14 17:48:52 +0800
commitc5bd32b0ad1a3d0fd20a3d1014cc8a97d889dc28 (patch)
tree5588276a932ac88daaaf9ca1858106ba3ff007b1 /ethvm/vm_test.go
parent2e894b668a2bde3eb83418cfd9128f3a571e0026 (diff)
downloaddexon-c5bd32b0ad1a3d0fd20a3d1014cc8a97d889dc28.tar
dexon-c5bd32b0ad1a3d0fd20a3d1014cc8a97d889dc28.tar.gz
dexon-c5bd32b0ad1a3d0fd20a3d1014cc8a97d889dc28.tar.bz2
dexon-c5bd32b0ad1a3d0fd20a3d1014cc8a97d889dc28.tar.lz
dexon-c5bd32b0ad1a3d0fd20a3d1014cc8a97d889dc28.tar.xz
dexon-c5bd32b0ad1a3d0fd20a3d1014cc8a97d889dc28.tar.zst
dexon-c5bd32b0ad1a3d0fd20a3d1014cc8a97d889dc28.zip
Refactored VM to two separate VMs; std & debug
Standard VM should be about 10x faster than the debug VM. Some error checking has been removed, all of the log statements and therefor quite some unnecessary if-statements.
Diffstat (limited to 'ethvm/vm_test.go')
-rw-r--r--ethvm/vm_test.go62
1 files changed, 54 insertions, 8 deletions
diff --git a/ethvm/vm_test.go b/ethvm/vm_test.go
index 5b3a9aef1..40fb985a6 100644
--- a/ethvm/vm_test.go
+++ b/ethvm/vm_test.go
@@ -2,9 +2,9 @@ package ethvm
import (
"fmt"
+ "io/ioutil"
"log"
"math/big"
- "os"
"testing"
"github.com/ethereum/eth-go/ethlog"
@@ -17,6 +17,7 @@ type TestEnv struct {
func (self TestEnv) Origin() []byte { return nil }
func (self TestEnv) BlockNumber() *big.Int { return nil }
+func (self TestEnv) BlockHash() []byte { return nil }
func (self TestEnv) PrevHash() []byte { return nil }
func (self TestEnv) Coinbase() []byte { return nil }
func (self TestEnv) Time() int64 { return 0 }
@@ -24,20 +25,65 @@ func (self TestEnv) Difficulty() *big.Int { return nil }
func (self TestEnv) Value() *big.Int { return nil }
func (self TestEnv) State() *ethstate.State { return nil }
-func TestVm(t *testing.T) {
- ethlog.AddLogSystem(ethlog.NewStdLogSystem(os.Stdout, log.LstdFlags, ethlog.LogLevel(4)))
+func setup(level int, typ Type) (*Closure, VirtualMachine) {
+ // Pipe output to /dev/null
+ ethlog.AddLogSystem(ethlog.NewStdLogSystem(ioutil.Discard, log.LstdFlags, ethlog.LogLevel(level)))
ethutil.ReadConfig(".ethtest", "/tmp/ethtest", "")
stateObject := ethstate.NewStateObject([]byte{'j', 'e', 'f', 'f'})
- callerClosure := NewClosure(stateObject, stateObject, []byte{0x60, 0x01}, big.NewInt(1000000), big.NewInt(0))
+ callerClosure := NewClosure(nil, stateObject, stateObject, []byte{
+ PUSH1, 1,
+ PUSH1, 0,
+ MSTORE,
+ PUSH1, 32,
+ PUSH1, 0,
+ RETURN,
+ }, big.NewInt(1000000), big.NewInt(0))
- vm := New(TestEnv{})
- vm.Verbose = true
+ return callerClosure, New(TestEnv{}, typ)
+}
- ret, _, e := callerClosure.Call(vm, nil)
+func TestDebugVm(t *testing.T) {
+ closure, vm := setup(4, DebugVmTy)
+ ret, _, e := closure.Call(vm, nil)
if e != nil {
fmt.Println("error", e)
}
- fmt.Println(ret)
+
+ if ret[len(ret)-1] != 1 {
+ t.Errorf("Expected VM to return 1, got", ret, "instead.")
+ }
+}
+
+func TestVm(t *testing.T) {
+ closure, vm := setup(4, StandardVmTy)
+ ret, _, e := closure.Call(vm, nil)
+ if e != nil {
+ fmt.Println("error", e)
+ }
+
+ if ret[len(ret)-1] != 1 {
+ t.Errorf("Expected VM to return 1, got", ret, "instead.")
+ }
+}
+
+func BenchmarkDebugVm(b *testing.B) {
+ closure, vm := setup(3, DebugVmTy)
+
+ b.ResetTimer()
+
+ for i := 0; i < b.N; i++ {
+ closure.Call(vm, nil)
+ }
+}
+
+func BenchmarkVm(b *testing.B) {
+ closure, vm := setup(3, StandardVmTy)
+
+ b.ResetTimer()
+
+ for i := 0; i < b.N; i++ {
+ closure.Call(vm, nil)
+ }
}