aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-12-03 20:50:51 +0800
committerobscuren <geffobscura@gmail.com>2014-12-03 20:50:51 +0800
commit6095edac5843aa18e389ef2deaa49fe05b7fcfb9 (patch)
tree851b5616b2024248b6b9790199ef289e04725cbb /tests
parent64f35ba8d1f31d6821a0a1bf946c71396a996f30 (diff)
parent3d9a4e7084c33cb28a2265c0dd232a0ea3871c92 (diff)
downloaddexon-6095edac5843aa18e389ef2deaa49fe05b7fcfb9.tar.gz
dexon-6095edac5843aa18e389ef2deaa49fe05b7fcfb9.tar.zst
dexon-6095edac5843aa18e389ef2deaa49fe05b7fcfb9.zip
merge
Diffstat (limited to 'tests')
-rw-r--r--tests/helper/vm.go17
-rw-r--r--tests/vm/gh_test.go40
2 files changed, 43 insertions, 14 deletions
diff --git a/tests/helper/vm.go b/tests/helper/vm.go
index b4ad93193..8e6645fc3 100644
--- a/tests/helper/vm.go
+++ b/tests/helper/vm.go
@@ -20,6 +20,8 @@ type Env struct {
time int64
difficulty *big.Int
gasLimit *big.Int
+
+ logs state.Logs
}
func NewEnv(state *state.State) *Env {
@@ -51,24 +53,27 @@ func (self *Env) Difficulty() *big.Int { return self.difficulty }
func (self *Env) BlockHash() []byte { return nil }
func (self *Env) State() *state.State { return self.state }
func (self *Env) GasLimit() *big.Int { return self.gasLimit }
-func (self *Env) AddLog(*state.Log) {}
+func (self *Env) AddLog(log *state.Log) {
+ self.logs = append(self.logs, log)
+}
func (self *Env) Transfer(from, to vm.Account, amount *big.Int) error {
return vm.Transfer(from, to, amount)
}
-func RunVm(state *state.State, env, exec map[string]string) ([]byte, *big.Int, error) {
+func RunVm(state *state.State, env, exec map[string]string) ([]byte, state.Logs, *big.Int, error) {
address := FromHex(exec["address"])
caller := state.GetOrNewStateObject(FromHex(exec["caller"]))
- evm := vm.New(NewEnvFromMap(state, env, exec), vm.DebugVmTy)
+ vmenv := NewEnvFromMap(state, env, exec)
+ evm := vm.New(vmenv, vm.DebugVmTy)
execution := vm.NewExecution(evm, address, FromHex(exec["data"]), ethutil.Big(exec["gas"]), ethutil.Big(exec["gasPrice"]), ethutil.Big(exec["value"]))
execution.SkipTransfer = true
ret, err := execution.Exec(address, caller)
- return ret, execution.Gas, err
+ return ret, vmenv.logs, execution.Gas, err
}
-func RunState(state *state.State, env, tx map[string]string) ([]byte, *big.Int, error) {
+func RunState(state *state.State, env, tx map[string]string) ([]byte, state.Logs, *big.Int, error) {
address := FromHex(tx["to"])
keyPair, _ := crypto.NewKeyPairFromSec([]byte(ethutil.Hex2Bytes(tx["secretKey"])))
caller := state.GetOrNewStateObject(keyPair.Address())
@@ -79,5 +84,5 @@ func RunState(state *state.State, env, tx map[string]string) ([]byte, *big.Int,
execution := vm.NewExecution(evm, address, FromHex(tx["data"]), ethutil.Big(tx["gasLimit"]), ethutil.Big(tx["gasPrice"]), ethutil.Big(tx["value"]))
ret, err := execution.Exec(address, caller)
- return ret, execution.Gas, err
+ return ret, vmenv.logs, execution.Gas, err
}
diff --git a/tests/vm/gh_test.go b/tests/vm/gh_test.go
index 50722bd5b..4c18d29e6 100644
--- a/tests/vm/gh_test.go
+++ b/tests/vm/gh_test.go
@@ -141,6 +141,7 @@ import (
"strconv"
"testing"
+ "github.com/ethereum/go-ethereum/chain"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/tests/helper"
@@ -153,6 +154,12 @@ type Account struct {
Storage map[string]string
}
+type Log struct {
+ Address string
+ Data string
+ Topics []string
+}
+
func StateObjectFromAccount(addr string, account Account) *state.StateObject {
obj := state.NewStateObject(ethutil.Hex2Bytes(addr))
obj.SetBalance(ethutil.Big(account.Balance))
@@ -181,6 +188,7 @@ type VmTest struct {
Env Env
Exec map[string]string
Transaction map[string]string
+ Logs map[string]Log
Gas string
Out string
Post map[string]Account
@@ -192,10 +200,10 @@ func RunVmTest(p string, t *testing.T) {
helper.CreateFileTests(t, p, &tests)
for name, test := range tests {
- state := state.New(helper.NewTrie())
+ statedb := state.New(helper.NewTrie())
for addr, account := range test.Pre {
obj := StateObjectFromAccount(addr, account)
- state.SetStateObject(obj)
+ statedb.SetStateObject(obj)
}
// XXX Yeah, yeah...
@@ -212,15 +220,16 @@ func RunVmTest(p string, t *testing.T) {
}
var (
- ret []byte
- gas *big.Int
- err error
+ ret []byte
+ gas *big.Int
+ err error
+ logs state.Logs
)
if len(test.Exec) > 0 {
- ret, gas, err = helper.RunVm(state, env, test.Exec)
+ ret, logs, gas, err = helper.RunVm(statedb, env, test.Exec)
} else {
- ret, gas, err = helper.RunState(state, env, test.Transaction)
+ ret, logs, gas, err = helper.RunState(statedb, env, test.Transaction)
}
// When an error is returned it doesn't always mean the tests fails.
@@ -242,7 +251,7 @@ func RunVmTest(p string, t *testing.T) {
}
for addr, account := range test.Post {
- obj := state.GetStateObject(helper.FromHex(addr))
+ obj := statedb.GetStateObject(helper.FromHex(addr))
for addr, value := range account.Storage {
v := obj.GetState(helper.FromHex(addr)).Bytes()
vexp := helper.FromHex(value)
@@ -252,6 +261,16 @@ func RunVmTest(p string, t *testing.T) {
}
}
}
+
+ if len(test.Logs) > 0 {
+ genBloom := ethutil.LeftPadBytes(chain.LogsBloom(logs).Bytes(), 64)
+ // Logs within the test itself aren't correct, missing empty fields (32 0s)
+ for bloom /*logs*/, _ := range test.Logs {
+ if !bytes.Equal(genBloom, ethutil.Hex2Bytes(bloom)) {
+ t.Errorf("bloom mismatch")
+ }
+ }
+ }
}
}
@@ -296,6 +315,11 @@ func TestVm(t *testing.T) {
RunVmTest(fn, t)
}
+func TestVmLog(t *testing.T) {
+ const fn = "../files/vmtests/vmLogTest.json"
+ RunVmTest(fn, t)
+}
+
func TestStateSystemOperations(t *testing.T) {
const fn = "../files/StateTests/stSystemOperationsTest.json"
RunVmTest(fn, t)