aboutsummaryrefslogtreecommitdiffstats
path: root/tests/block_test_util.go
diff options
context:
space:
mode:
authorTaylor Gerring <taylor.gerring@gmail.com>2015-06-11 06:11:30 +0800
committerTaylor Gerring <taylor.gerring@gmail.com>2015-06-19 04:20:45 +0800
commit6ff956394a26fe13c774797284220b8231ebf809 (patch)
treef5d739218bf55a62505cb809e076613c9bb5ebac /tests/block_test_util.go
parentac0637c41332de1f49fb0955f4fbe0fb908a77d5 (diff)
downloaddexon-6ff956394a26fe13c774797284220b8231ebf809.tar
dexon-6ff956394a26fe13c774797284220b8231ebf809.tar.gz
dexon-6ff956394a26fe13c774797284220b8231ebf809.tar.bz2
dexon-6ff956394a26fe13c774797284220b8231ebf809.tar.lz
dexon-6ff956394a26fe13c774797284220b8231ebf809.tar.xz
dexon-6ff956394a26fe13c774797284220b8231ebf809.tar.zst
dexon-6ff956394a26fe13c774797284220b8231ebf809.zip
DRY file loading
Diffstat (limited to 'tests/block_test_util.go')
-rw-r--r--tests/block_test_util.go56
1 files changed, 12 insertions, 44 deletions
diff --git a/tests/block_test_util.go b/tests/block_test_util.go
index a04019111..7db47566b 100644
--- a/tests/block_test_util.go
+++ b/tests/block_test_util.go
@@ -3,9 +3,7 @@ package tests
import (
"bytes"
"encoding/hex"
- "encoding/json"
"fmt"
- "io/ioutil"
"math/big"
"path/filepath"
"runtime"
@@ -87,9 +85,9 @@ type btTransaction struct {
}
func RunBlockTest(filepath string) error {
- bt, err := LoadBlockTests(filepath)
+ bt, err := loadBlockTests(filepath)
if err != nil {
- return nil
+ return err
}
// map skipped tests to boolean set
@@ -158,22 +156,6 @@ func testEthConfig() *eth.Config {
}
}
-// LoadBlockTests loads a block test JSON file.
-func LoadBlockTests(file string) (map[string]*BlockTest, error) {
- bt := make(map[string]*btJSON)
- if err := LoadJSON(file, &bt); err != nil {
- return nil, err
- }
- out := make(map[string]*BlockTest)
- for name, in := range bt {
- var err error
- if out[name], err = convertTest(in); err != nil {
- return out, fmt.Errorf("bad test %q: %v", name, err)
- }
- }
- return out, nil
-}
-
// InsertPreState populates the given database with the genesis
// accounts defined by the test.
func (t *BlockTest) InsertPreState(ethereum *eth.Ethereum) (*state.StateDB, error) {
@@ -467,34 +449,20 @@ func mustConvertUint(in string, base int) uint64 {
return out
}
-// LoadJSON reads the given file and unmarshals its content.
-func LoadJSON(file string, val interface{}) error {
- content, err := ioutil.ReadFile(file)
- if err != nil {
- return err
- }
- if err := json.Unmarshal(content, val); err != nil {
- if syntaxerr, ok := err.(*json.SyntaxError); ok {
- line := findLine(content, syntaxerr.Offset)
- return fmt.Errorf("JSON syntax error at %v:%v: %v", file, line, err)
- }
- return fmt.Errorf("JSON unmarshal error in %v: %v", file, err)
+func loadBlockTests(file string) (map[string]*BlockTest, error) {
+ bt := make(map[string]*btJSON)
+ if err := readTestFile(file, &bt); err != nil {
+ return nil, err
}
- return nil
-}
-// findLine returns the line number for the given offset into data.
-func findLine(data []byte, offset int64) (line int) {
- line = 1
- for i, r := range string(data) {
- if int64(i) >= offset {
- return
- }
- if r == '\n' {
- line++
+ out := make(map[string]*BlockTest)
+ for name, in := range bt {
+ var err error
+ if out[name], err = convertTest(in); err != nil {
+ return out, fmt.Errorf("bad test %q: %v", name, err)
}
}
- return
+ return out, nil
}
// Nothing to see here, please move along...