Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
6ff95639
Commit
6ff95639
authored
Jun 10, 2015
by
Taylor Gerring
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DRY file loading
parent
ac0637c4
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
42 additions
and
58 deletions
+42
-58
block_test_util.go
tests/block_test_util.go
+12
-44
init.go
tests/init.go
+27
-5
state_test_util.go
tests/state_test_util.go
+1
-7
transaction_test_util.go
tests/transaction_test_util.go
+1
-1
vm_test_util.go
tests/vm_test_util.go
+1
-1
No files found.
tests/block_test_util.go
View file @
6ff95639
...
...
@@ -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
:=
L
oadBlockTests
(
filepath
)
bt
,
err
:=
l
oadBlockTests
(
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...
...
...
tests/init.go
View file @
6ff95639
...
...
@@ -2,6 +2,7 @@ package tests
import
(
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
...
...
@@ -24,14 +25,35 @@ var (
func
readJSON
(
reader
io
.
Reader
,
value
interface
{})
error
{
data
,
err
:=
ioutil
.
ReadAll
(
reader
)
err
=
json
.
Unmarshal
(
data
,
&
value
)
if
err
!=
nil
{
return
err
return
fmt
.
Errorf
(
"Error reading JSON file"
,
err
.
Error
())
}
if
err
=
json
.
Unmarshal
(
data
,
&
value
);
err
!=
nil
{
if
syntaxerr
,
ok
:=
err
.
(
*
json
.
SyntaxError
);
ok
{
line
:=
findLine
(
data
,
syntaxerr
.
Offset
)
return
fmt
.
Errorf
(
"JSON syntax error at line %v: %v"
,
line
,
err
)
}
return
fmt
.
Errorf
(
"JSON unmarshal error: %v"
,
err
)
}
return
nil
}
func
CreateHttpTests
(
uri
string
,
value
interface
{})
error
{
// 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
++
}
}
return
}
func
readHttpFile
(
uri
string
,
value
interface
{})
error
{
resp
,
err
:=
http
.
Get
(
uri
)
if
err
!=
nil
{
return
err
...
...
@@ -45,7 +67,7 @@ func CreateHttpTests(uri string, value interface{}) error {
return
nil
}
func
CreateFileTests
(
fn
string
,
value
interface
{})
error
{
func
readTestFile
(
fn
string
,
value
interface
{})
error
{
file
,
err
:=
os
.
Open
(
fn
)
if
err
!=
nil
{
return
err
...
...
@@ -54,7 +76,7 @@ func CreateFileTests(fn string, value interface{}) error {
err
=
readJSON
(
file
,
value
)
if
err
!=
nil
{
return
err
return
fmt
.
Errorf
(
"%s in file %s"
,
err
.
Error
(),
fn
)
}
return
nil
}
tests/state_test_util.go
View file @
6ff95639
...
...
@@ -21,7 +21,7 @@ func RunStateTest(p string) error {
}
tests
:=
make
(
map
[
string
]
VmTest
)
CreateFileTests
(
p
,
&
tests
)
readTestFile
(
p
,
&
tests
)
for
name
,
test
:=
range
tests
{
if
skipTest
[
name
]
{
...
...
@@ -61,16 +61,10 @@ func RunStateTest(p string) error {
ret
,
logs
,
_
,
_
=
RunState
(
statedb
,
env
,
test
.
Transaction
)
// // Compare expected and actual return
// switch name {
// // the memory required for these tests (4294967297 bytes) would take too much time.
// // on 19 May 2015 decided to skip these tests their output.
// case "mload32bitBound_return", "mload32bitBound_return2":
// default:
rexp
:=
common
.
FromHex
(
test
.
Out
)
if
bytes
.
Compare
(
rexp
,
ret
)
!=
0
{
return
fmt
.
Errorf
(
"%s's return failed. Expected %x, got %x
\n
"
,
name
,
rexp
,
ret
)
}
// }
// check post state
for
addr
,
account
:=
range
test
.
Post
{
...
...
tests/transaction_test_util.go
View file @
6ff95639
...
...
@@ -37,7 +37,7 @@ func RunTransactionTests(file string) error {
}
bt
:=
make
(
map
[
string
]
TransactionTest
)
if
err
:=
LoadJSON
(
file
,
&
bt
);
err
!=
nil
{
if
err
:=
readTestFile
(
file
,
&
bt
);
err
!=
nil
{
return
err
}
...
...
tests/vm_test_util.go
View file @
6ff95639
...
...
@@ -19,7 +19,7 @@ func RunVmTest(p string) error {
}
tests
:=
make
(
map
[
string
]
VmTest
)
err
:=
CreateFileTests
(
p
,
&
tests
)
err
:=
readTestFile
(
p
,
&
tests
)
if
err
!=
nil
{
return
err
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment