aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-10-15 23:12:26 +0800
committerobscuren <geffobscura@gmail.com>2014-10-15 23:12:26 +0800
commit311c6f8a3fed5ac03ee4b442fd0f420072bc41b4 (patch)
treede823080f3704d7690fd7172c9742962b66baf3a /tests
parent266d21209478bdb8c89e1ffb95d7f0de34635968 (diff)
downloadgo-tangerine-311c6f8a3fed5ac03ee4b442fd0f420072bc41b4.tar.gz
go-tangerine-311c6f8a3fed5ac03ee4b442fd0f420072bc41b4.tar.zst
go-tangerine-311c6f8a3fed5ac03ee4b442fd0f420072bc41b4.zip
Fixed remote Arithmetic tests
Diffstat (limited to 'tests')
-rw-r--r--tests/helper/http.go11
-rw-r--r--tests/helper/init.go5
-rw-r--r--tests/helper/vm.go8
-rw-r--r--tests/vm/gh_test.go27
4 files changed, 32 insertions, 19 deletions
diff --git a/tests/helper/http.go b/tests/helper/http.go
index b379695d0..3c570d106 100644
--- a/tests/helper/http.go
+++ b/tests/helper/http.go
@@ -4,12 +4,15 @@ import (
"encoding/json"
"io/ioutil"
"net/http"
+ "testing"
)
-func CreateTests(uri string, value interface{}) error {
+func CreateTests(t *testing.T, uri string, value interface{}) {
resp, err := http.Get(uri)
if err != nil {
- panic(err)
+ t.Error(err)
+
+ return
}
defer resp.Body.Close()
@@ -17,8 +20,6 @@ func CreateTests(uri string, value interface{}) error {
err = json.Unmarshal(data, &value)
if err != nil {
- return err
+ t.Error(err)
}
-
- return nil
}
diff --git a/tests/helper/init.go b/tests/helper/init.go
index 1f2ee208a..5f95dfc2f 100644
--- a/tests/helper/init.go
+++ b/tests/helper/init.go
@@ -8,8 +8,11 @@ import (
"github.com/ethereum/eth-go/ethutil"
)
+var Logger ethlog.LogSystem
+
func init() {
- ethlog.AddLogSystem(ethlog.NewStdLogSystem(os.Stdout, log.LstdFlags, ethlog.LogLevel(4)))
+ Logger = ethlog.NewStdLogSystem(os.Stdout, log.LstdFlags, ethlog.LogLevel(4))
+ ethlog.AddLogSystem(Logger)
ethutil.ReadConfig(".ethtest", "/tmp/ethtest", "")
}
diff --git a/tests/helper/vm.go b/tests/helper/vm.go
index 49a0bfeae..44eb8fda1 100644
--- a/tests/helper/vm.go
+++ b/tests/helper/vm.go
@@ -1,7 +1,6 @@
package helper
import (
- "fmt"
"math/big"
"github.com/ethereum/eth-go/ethstate"
@@ -51,16 +50,13 @@ func (self *Env) BlockHash() []byte { return nil }
// This is likely to fail if anything ever gets looked up in the state trie :-)
func (self *Env) State() *ethstate.State { return ethstate.New(ethtrie.New(nil, "")) }
-func RunVm(state *ethstate.State, env, exec map[string]string) ([]byte, *big.Int) {
+func RunVm(state *ethstate.State, env, exec map[string]string) ([]byte, *big.Int, error) {
caller := state.NewStateObject(ethutil.Hex2Bytes(exec["caller"]))
callee := state.GetStateObject(ethutil.Hex2Bytes(exec["address"]))
closure := ethvm.NewClosure(nil, caller, callee, callee.Code, ethutil.Big(exec["gas"]), ethutil.Big(exec["gasPrice"]))
vm := ethvm.New(NewEnvFromMap(state, env, exec), ethvm.DebugVmTy)
ret, _, e := closure.Call(vm, nil)
- if e != nil {
- fmt.Println(e)
- }
- return ret, closure.Gas
+ return ret, closure.Gas, e
}
diff --git a/tests/vm/gh_test.go b/tests/vm/gh_test.go
index ac8d47fe6..067b1fe8e 100644
--- a/tests/vm/gh_test.go
+++ b/tests/vm/gh_test.go
@@ -2,7 +2,6 @@ package ethvm
import (
"bytes"
- "log"
"testing"
"github.com/ethereum/eth-go/ethstate"
@@ -40,12 +39,9 @@ type VmTest struct {
Pre map[string]Account
}
-func TestRemote(t *testing.T) {
+func RunVmTest(url string, t *testing.T) {
tests := make(map[string]VmTest)
- err := helper.CreateTests("https://raw.githubusercontent.com/ethereum/tests/master/vmtests/vmSha3Test.json", &tests)
- if err != nil {
- log.Fatal(err)
- }
+ helper.CreateTests(t, url, &tests)
for name, test := range tests {
state := ethstate.New(helper.NewTrie())
@@ -54,7 +50,10 @@ func TestRemote(t *testing.T) {
state.SetStateObject(obj)
}
- ret, gas := helper.RunVm(state, test.Env, test.Exec)
+ ret, gas, err := helper.RunVm(state, test.Env, test.Exec)
+ if err != nil {
+ t.Errorf("%s's execution failed. %v\n", name, err)
+ }
rexp := helper.FromHex(test.Out)
if bytes.Compare(rexp, ret) != 0 {
@@ -79,3 +78,17 @@ func TestRemote(t *testing.T) {
}
}
}
+
+// I've created a new function for each tests so it's easier to identify where the problem lies if any of them fail.
+func TestVMSha3(t *testing.T) {
+ helper.Logger.SetLogLevel(0)
+ defer helper.Logger.SetLogLevel(4)
+
+ const url = "https://raw.githubusercontent.com/ethereum/tests/master/vmtests/vmSha3Test.json"
+ RunVmTest(url, t)
+}
+
+func TestVMArithmetic(t *testing.T) {
+ const url = "https://raw.githubusercontent.com/ethereum/tests/master/vmtests/vmArithmeticTest.json"
+ RunVmTest(url, t)
+}