From 750d70c2024784227c8ac920d651c337c2de207e Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 13 Jan 2015 00:25:45 +0100 Subject: [PATCH] updated tests --- ethutil/common.go | 1 + tests/helper/vm.go | 11 ++++++++++- tests/vm/gh_test.go | 6 ------ vm/vm_debug.go | 16 +++++++++------- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/ethutil/common.go b/ethutil/common.go index 0a29cac6c..271c56fd5 100644 --- a/ethutil/common.go +++ b/ethutil/common.go @@ -84,4 +84,5 @@ var ( BigFalse = Big0 Big32 = big.NewInt(32) Big256 = big.NewInt(0xff) + Big257 = big.NewInt(257) ) diff --git a/tests/helper/vm.go b/tests/helper/vm.go index 797a2acf5..2f3ec30f7 100644 --- a/tests/helper/vm.go +++ b/tests/helper/vm.go @@ -15,6 +15,7 @@ type Env struct { depth int state *state.StateDB skipTransfer bool + initial bool Gas *big.Int origin []byte @@ -68,9 +69,17 @@ func (self *Env) Depth() int { return self.depth } func (self *Env) SetDepth(i int) { self.depth = i } func (self *Env) Transfer(from, to vm.Account, amount *big.Int) error { if self.skipTransfer { + // ugly hack + if self.initial { + self.initial = false + return nil + } + if from.Balance().Cmp(amount) < 0 { return errors.New("Insufficient balance in account") } + + return nil } return vm.Transfer(from, to, amount) } @@ -109,10 +118,10 @@ func RunVm(state *state.StateDB, env, exec map[string]string) ([]byte, state.Log ) caller := state.GetOrNewStateObject(from) - caller.SetBalance(ethutil.Big("1000000000000000000")) vmenv := NewEnvFromMap(state, env, exec) vmenv.skipTransfer = true + vmenv.initial = true ret, err := vmenv.Call(caller, to, data, gas, price, value) return ret, vmenv.logs, vmenv.Gas, err diff --git a/tests/vm/gh_test.go b/tests/vm/gh_test.go index 47b588268..699225e90 100644 --- a/tests/vm/gh_test.go +++ b/tests/vm/gh_test.go @@ -79,12 +79,6 @@ func RunVmTest(p string, t *testing.T) { helper.CreateFileTests(t, p, &tests) for name, test := range tests { - /* - helper.Logger.SetLogLevel(5) - if name != "createNameRegistratorZeroMem" { - continue - } - */ db, _ := ethdb.NewMemDatabase() statedb := state.New(nil, db) for addr, account := range test.Pre { diff --git a/vm/vm_debug.go b/vm/vm_debug.go index 81db45f19..255faefb0 100644 --- a/vm/vm_debug.go +++ b/vm/vm_debug.go @@ -50,10 +50,6 @@ func (self *DebugVm) Run(me, caller ContextRef, code []byte, value, gas, price * vmlogger.Debugf("(%d) (%x) %x (code=%d) gas: %v (d) %x\n", self.env.Depth(), caller.Address()[:4], context.Address(), len(code), context.Gas, callData) - if p := Precompiled[string(me.Address())]; p != nil { - return self.RunPrecompiled(p, callData, context) - } - if self.Recoverable { // Recover from any require exception defer func() { @@ -70,6 +66,10 @@ func (self *DebugVm) Run(me, caller ContextRef, code []byte, value, gas, price * }() } + if p := Precompiled[string(me.Address())]; p != nil { + return self.RunPrecompiled(p, callData, context) + } + var ( op OpCode @@ -513,10 +513,12 @@ func (self *DebugVm) Run(me, caller ContextRef, code []byte, value, gas, price * // 0x40 range case BLOCKHASH: num := stack.Pop() - if num.Cmp(new(big.Int).Sub(self.env.BlockNumber(), ethutil.Big256)) < 0 { - stack.Push(ethutil.Big0) - } else { + + n := U256(new(big.Int).Sub(self.env.BlockNumber(), ethutil.Big257)) + if num.Cmp(n) > 0 && num.Cmp(self.env.BlockNumber()) < 0 { stack.Push(ethutil.BigD(self.env.GetHash(num.Uint64()))) + } else { + stack.Push(ethutil.Big0) } self.Printf(" => 0x%x", stack.Peek().Bytes())