aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-12-19 04:58:26 +0800
committerobscuren <geffobscura@gmail.com>2014-12-19 04:58:26 +0800
commit198cc69357a0f25ae486a041786e1239c6f5ab0f (patch)
tree39f4b8c4a8b8360d2fe2fc5583438f948e095524 /tests
parent5ad473d7581b92811c3a3e035274a82fc5568f57 (diff)
downloadgo-tangerine-198cc69357a0f25ae486a041786e1239c6f5ab0f.tar
go-tangerine-198cc69357a0f25ae486a041786e1239c6f5ab0f.tar.gz
go-tangerine-198cc69357a0f25ae486a041786e1239c6f5ab0f.tar.bz2
go-tangerine-198cc69357a0f25ae486a041786e1239c6f5ab0f.tar.lz
go-tangerine-198cc69357a0f25ae486a041786e1239c6f5ab0f.tar.xz
go-tangerine-198cc69357a0f25ae486a041786e1239c6f5ab0f.tar.zst
go-tangerine-198cc69357a0f25ae486a041786e1239c6f5ab0f.zip
Gas corrections and vm fixes
Diffstat (limited to 'tests')
-rw-r--r--tests/helper/vm.go37
-rw-r--r--tests/vm/gh_test.go26
2 files changed, 57 insertions, 6 deletions
diff --git a/tests/helper/vm.go b/tests/helper/vm.go
index 0c77e87fb..11bcedc49 100644
--- a/tests/helper/vm.go
+++ b/tests/helper/vm.go
@@ -44,6 +44,7 @@ func NewEnvFromMap(state *state.StateDB, envValues map[string]string, exeValues
env.time = ethutil.Big(envValues["currentTimestamp"]).Int64()
env.difficulty = ethutil.Big(envValues["currentDifficulty"])
env.gasLimit = ethutil.Big(envValues["currentGasLimit"])
+ env.Gas = new(big.Int)
return env
}
@@ -110,7 +111,7 @@ func RunVm(state *state.StateDB, env, exec map[string]string) ([]byte, state.Log
return ret, vmenv.logs, vmenv.Gas, err
}
-func RunState(state *state.StateDB, env, tx map[string]string) ([]byte, state.Logs, *big.Int, error) {
+func RunState(statedb *state.StateDB, env, tx map[string]string) ([]byte, state.Logs, *big.Int, error) {
var (
keyPair, _ = crypto.NewKeyPairFromSec([]byte(ethutil.Hex2Bytes(tx["secretKey"])))
to = FromHex(tx["to"])
@@ -118,13 +119,39 @@ func RunState(state *state.StateDB, env, tx map[string]string) ([]byte, state.Lo
gas = ethutil.Big(tx["gasLimit"])
price = ethutil.Big(tx["gasPrice"])
value = ethutil.Big(tx["value"])
+ caddr = FromHex(env["currentCoinbase"])
)
- caller := state.GetOrNewStateObject(keyPair.Address())
+ coinbase := statedb.GetOrNewStateObject(caddr)
+ coinbase.SetGasPool(ethutil.Big(env["currentGasLimit"]))
- vmenv := NewEnvFromMap(state, env, tx)
- vmenv.origin = caller.Address()
- ret, err := vmenv.Call(caller, to, data, gas, price, value)
+ message := NewMessage(keyPair.Address(), to, data, value, gas, price)
+ Log.DebugDetailf("message{ to: %x, from %x, value: %v, gas: %v, price: %v }\n", message.to[:4], message.from[:4], message.value, message.gas, message.price)
+ st := core.NewStateTransition(coinbase, message, statedb, nil)
+ vmenv := NewEnvFromMap(statedb, env, tx)
+ vmenv.origin = keyPair.Address()
+ st.Env = vmenv
+ ret, err := st.TransitionState()
+ statedb.Update(vmenv.Gas)
return ret, vmenv.logs, vmenv.Gas, err
}
+
+type Message struct {
+ from, to []byte
+ value, gas, price *big.Int
+ data []byte
+}
+
+func NewMessage(from, to, data []byte, value, gas, price *big.Int) Message {
+ return Message{from, to, value, gas, price, data}
+}
+
+func (self Message) Hash() []byte { return nil }
+func (self Message) From() []byte { return self.from }
+func (self Message) To() []byte { return self.to }
+func (self Message) GasPrice() *big.Int { return self.price }
+func (self Message) Gas() *big.Int { return self.gas }
+func (self Message) Value() *big.Int { return self.value }
+func (self Message) Nonce() uint64 { return 0 }
+func (self Message) Data() []byte { return self.data }
diff --git a/tests/vm/gh_test.go b/tests/vm/gh_test.go
index da5a41251..42dcc0ae1 100644
--- a/tests/vm/gh_test.go
+++ b/tests/vm/gh_test.go
@@ -8,6 +8,7 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethutil"
+ "github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/tests/helper"
)
@@ -76,11 +77,18 @@ func RunVmTest(p string, t *testing.T) {
tests := make(map[string]VmTest)
helper.CreateFileTests(t, p, &tests)
+ helper.Logger.SetLogLevel(5)
for name, test := range tests {
+ if name != "ABAcalls1" {
+ continue
+ }
statedb := state.New(helper.NewTrie())
for addr, account := range test.Pre {
obj := StateObjectFromAccount(addr, account)
statedb.SetStateObject(obj)
+ for a, v := range account.Storage {
+ obj.SetState(helper.FromHex(a), ethutil.NewValue(helper.FromHex(v)))
+ }
}
// XXX Yeah, yeah...
@@ -129,6 +137,16 @@ func RunVmTest(p string, t *testing.T) {
for addr, account := range test.Post {
obj := statedb.GetStateObject(helper.FromHex(addr))
+ if obj == nil {
+ continue
+ }
+
+ if len(test.Exec) == 0 {
+ if obj.Balance().Cmp(ethutil.Big(account.Balance)) != 0 {
+ t.Errorf("%s's : (%x) balance failed. Expected %v, got %v => %v\n", name, obj.Address()[:4], account.Balance, obj.Balance(), new(big.Int).Sub(ethutil.Big(account.Balance), obj.Balance()))
+ }
+ }
+
for addr, value := range account.Storage {
v := obj.GetState(helper.FromHex(addr)).Bytes()
vexp := helper.FromHex(value)
@@ -149,6 +167,7 @@ func RunVmTest(p string, t *testing.T) {
}
}
}
+ logger.Flush()
}
// I've created a new function for each tests so it's easier to identify where the problem lies if any of them fail.
@@ -212,7 +231,12 @@ func TestStateRecursiveCreate(t *testing.T) {
RunVmTest(fn, t)
}
-func TestStateSpecialTest(t *testing.T) {
+func TestStateSpecial(t *testing.T) {
const fn = "../files/StateTests/stSpecialTest.json"
RunVmTest(fn, t)
}
+
+func TestStateRefund(t *testing.T) {
+ const fn = "../files/StateTests/stRefundTest.json"
+ RunVmTest(fn, t)
+}