Commit 3bc64b6b authored by obscuren's avatar obscuren

Readers

parent 73c1c2c4
...@@ -2,12 +2,22 @@ package helper ...@@ -2,12 +2,22 @@ package helper
import ( import (
"encoding/json" "encoding/json"
"io"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"os"
"testing" "testing"
) )
func CreateTests(t *testing.T, uri string, value interface{}) { func readJSON(t *testing.T, reader io.Reader, value interface{}) {
data, err := ioutil.ReadAll(reader)
err = json.Unmarshal(data, &value)
if err != nil {
t.Error(err)
}
}
func CreateHttpTests(t *testing.T, uri string, value interface{}) {
resp, err := http.Get(uri) resp, err := http.Get(uri)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
...@@ -16,10 +26,17 @@ func CreateTests(t *testing.T, uri string, value interface{}) { ...@@ -16,10 +26,17 @@ func CreateTests(t *testing.T, uri string, value interface{}) {
} }
defer resp.Body.Close() defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body) readJSON(t, resp.Body, value)
}
err = json.Unmarshal(data, &value) func CreateFileTests(t *testing.T, fn string, value interface{}) {
file, err := os.Open(fn)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
return
} }
defer file.Close()
readJSON(t, file, value)
} }
...@@ -41,7 +41,7 @@ type VmTest struct { ...@@ -41,7 +41,7 @@ type VmTest struct {
func RunVmTest(url string, t *testing.T) { func RunVmTest(url string, t *testing.T) {
tests := make(map[string]VmTest) tests := make(map[string]VmTest)
helper.CreateTests(t, url, &tests) helper.CreateHttpTests(t, url, &tests)
for name, test := range tests { for name, test := range tests {
state := ethstate.New(helper.NewTrie()) state := ethstate.New(helper.NewTrie())
...@@ -88,12 +88,12 @@ func RunVmTest(url string, t *testing.T) { ...@@ -88,12 +88,12 @@ func RunVmTest(url string, 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. // 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 TestVMArithmetic(t *testing.T) { func TestVMArithmetic(t *testing.T) {
//helper.Logger.SetLogLevel(5)
const url = "https://raw.githubusercontent.com/ethereum/tests/develop/vmtests/vmArithmeticTest.json" const url = "https://raw.githubusercontent.com/ethereum/tests/develop/vmtests/vmArithmeticTest.json"
RunVmTest(url, t) RunVmTest(url, t)
} }
func TestVMSystemOperation(t *testing.T) { func TestVMSystemOperation(t *testing.T) {
//helper.Logger.SetLogLevel(5)
const url = "https://raw.githubusercontent.com/ethereum/tests/develop/vmtests/vmSystemOperationsTest.json" const url = "https://raw.githubusercontent.com/ethereum/tests/develop/vmtests/vmSystemOperationsTest.json"
RunVmTest(url, t) RunVmTest(url, t)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment