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
2f4cc721
Commit
2f4cc721
authored
Apr 22, 2015
by
Felix Lange
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #765 from Gustav-Simonsson/more_block_test_improvements
Further fixes to block test wrapper
parents
15550dc8
b4483908
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
185 additions
and
50 deletions
+185
-50
blocktest.go
cmd/geth/blocktest.go
+3
-3
block_test.go
tests/block_test.go
+126
-0
block_test_util.go
tests/block_test_util.go
+56
-47
No files found.
cmd/geth/blocktest.go
View file @
2f4cc721
...
...
@@ -109,10 +109,10 @@ func runOneBlockTest(ctx *cli.Context, test *tests.BlockTest) (*eth.Ethereum, er
return
ethereum
,
fmt
.
Errorf
(
"InsertPreState: %v"
,
err
)
}
// insert the test blocks, which will execute all transactions
if
err
:=
test
.
InsertBlocks
(
ethereum
.
ChainManager
());
err
!=
nil
{
return
ethereum
,
fmt
.
Errorf
(
"Block Test load error: %v %T"
,
err
,
err
)
if
err
:=
test
.
TryBlocksInsert
(
ethereum
.
ChainManager
());
err
!=
nil
{
return
ethereum
,
fmt
.
Errorf
(
"Block Test load error: %v"
,
err
)
}
fmt
.
Println
(
"chain loaded"
)
if
err
:=
test
.
ValidatePostState
(
statedb
);
err
!=
nil
{
return
ethereum
,
fmt
.
Errorf
(
"post state validation failed: %v"
,
err
)
...
...
cmd/geth/block_go
_test.go
→
tests/block
_test.go
View file @
2f4cc721
package
main
package
tests
import
(
"path"
...
...
@@ -9,32 +9,78 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/tests"
)
// TODO: refactor test setup & execution to better align with vm and tx tests
// TODO: refactor to avoid duplication with cmd/geth/blocktest.go
func
TestBcValidBlockTests
(
t
*
testing
.
T
)
{
runBlockTestsInFile
(
"../../tests/files/BlockTests/bcValidBlockTest.json"
,
t
)
t
.
Skip
(
"Skipped in lieu of performance fixes."
)
runBlockTestsInFile
(
"files/BlockTests/bcValidBlockTest.json"
,
[]
string
{},
t
)
}
/*
func
TestBcUncleTests
(
t
*
testing
.
T
)
{
runBlockTestsInFile("../../tests/files/BlockTests/bcUncleTest.json", t)
t
.
Skip
(
"Skipped in lieu of performance fixes."
)
runBlockTestsInFile
(
"files/BlockTests/bcUncleTest.json"
,
[]
string
{},
t
)
}
*/
func
runBlockTestsInFile
(
filepath
string
,
t
*
testing
.
T
)
{
bt
,
err
:=
tests
.
LoadBlockTests
(
filepath
)
func
TestBcUncleHeaderValidityTests
(
t
*
testing
.
T
)
{
t
.
Skip
(
"Skipped in lieu of performance fixes."
)
runBlockTestsInFile
(
"files/BlockTests/bcUncleHeaderValiditiy.json"
,
[]
string
{},
t
)
}
func
TestBcInvalidHeaderTests
(
t
*
testing
.
T
)
{
t
.
Skip
(
"Skipped in lieu of performance fixes."
)
snafus
:=
[]
string
{
"wrongUncleHash"
,
// TODO: why does this fail?
}
runBlockTestsInFile
(
"files/BlockTests/bcInvalidHeaderTest.json"
,
snafus
,
t
)
}
func
TestBcInvalidRLPTests
(
t
*
testing
.
T
)
{
t
.
Skip
(
"Skipped in lieu of performance fixes."
)
snafus
:=
[]
string
{
// TODO: why does these fail?
"TRANSCT__ZeroByteAtTheEnd"
,
"TRANSCT__RandomByteAtTheEnd"
,
"BLOCK__ZeroByteAtTheEnd"
,
"BLOCK__RandomByteAtTheEnd"
,
}
runBlockTestsInFile
(
"files/BlockTests/bcInvalidRLPTest.json"
,
snafus
,
t
)
}
func
TestBcJSAPITests
(
t
*
testing
.
T
)
{
t
.
Skip
(
"Skipped in lieu of performance fixes."
)
runBlockTestsInFile
(
"files/BlockTests/bcJS_API_Test.json"
,
[]
string
{},
t
)
}
func
TestBcRPCAPITests
(
t
*
testing
.
T
)
{
t
.
Skip
(
"Skipped in lieu of performance fixes."
)
runBlockTestsInFile
(
"files/BlockTests/bcRPC_API_Test.json"
,
[]
string
{},
t
)
}
func
TestBcForkBlockTests
(
t
*
testing
.
T
)
{
t
.
Skip
(
"Skipped in lieu of performance fixes."
)
runBlockTestsInFile
(
"files/BlockTests/bcForkBlockTest.json"
,
[]
string
{},
t
)
}
func
runBlockTestsInFile
(
filepath
string
,
snafus
[]
string
,
t
*
testing
.
T
)
{
bt
,
err
:=
LoadBlockTests
(
filepath
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
notWorking
:=
make
(
map
[
string
]
bool
,
100
)
for
_
,
name
:=
range
snafus
{
notWorking
[
name
]
=
true
}
for
name
,
test
:=
range
bt
{
runTest
(
name
,
test
,
t
)
if
!
notWorking
[
name
]
{
runBlockTest
(
name
,
test
,
t
)
}
}
}
func
run
Test
(
name
string
,
test
*
tests
.
BlockTest
,
t
*
testing
.
T
)
{
func
run
BlockTest
(
name
string
,
test
*
BlockTest
,
t
*
testing
.
T
)
{
t
.
Log
(
"Running test: "
,
name
)
cfg
:=
testEthConfig
()
ethereum
,
err
:=
eth
.
New
(
cfg
)
...
...
@@ -56,15 +102,15 @@ func runTest(name string, test *tests.BlockTest, t *testing.T) {
t
.
Fatalf
(
"InsertPreState: %v"
,
err
)
}
// insert the test blocks, which will execute all transactions
if
err
:=
test
.
InsertBlocks
(
ethereum
.
ChainManager
());
err
!=
nil
{
t
.
Fatal
f
(
"Block Test load error: %v %T"
,
err
,
err
)
err
=
test
.
TryBlocksInsert
(
ethereum
.
ChainManager
())
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
err
:
=
test
.
ValidatePostState
(
statedb
);
err
!=
nil
{
if
err
=
test
.
ValidatePostState
(
statedb
);
err
!=
nil
{
t
.
Fatal
(
"post state validation failed: %v"
,
err
)
}
t
.
Log
(
"Test passed: "
,
name
)
t
.
Log
(
"Test passed:
"
,
name
)
}
func
testEthConfig
()
*
eth
.
Config
{
...
...
tests/block_test_util.go
View file @
2f4cc721
...
...
@@ -19,6 +19,13 @@ import (
)
// Block Test JSON Format
type
BlockTest
struct
{
Genesis
*
types
.
Block
Json
*
btJSON
preAccounts
map
[
string
]
btAccount
}
type
btJSON
struct
{
Blocks
[]
btBlock
GenesisBlockHeader
btHeader
...
...
@@ -26,6 +33,13 @@ type btJSON struct {
PostState
map
[
string
]
btAccount
}
type
btBlock
struct
{
BlockHeader
*
btHeader
Rlp
string
Transactions
[]
btTransaction
UncleHeaders
[]
*
btHeader
}
type
btAccount
struct
{
Balance
string
Code
string
...
...
@@ -65,20 +79,6 @@ type btTransaction struct {
Value
string
}
type
btBlock
struct
{
BlockHeader
*
btHeader
Rlp
string
Transactions
[]
btTransaction
UncleHeaders
[]
*
btHeader
}
type
BlockTest
struct
{
Genesis
*
types
.
Block
json
*
btJSON
preAccounts
map
[
string
]
btAccount
}
// LoadBlockTests loads a block test JSON file.
func
LoadBlockTests
(
file
string
)
(
map
[
string
]
*
BlockTest
,
error
)
{
bt
:=
make
(
map
[
string
]
*
btJSON
)
...
...
@@ -125,13 +125,43 @@ func (t *BlockTest) InsertPreState(db common.Database) (*state.StateDB, error) {
return
statedb
,
nil
}
// InsertBlocks loads the test's blocks into the given chain.
func
(
t
*
BlockTest
)
InsertBlocks
(
chain
*
core
.
ChainManager
)
error
{
blocks
,
err
:=
t
.
convertBlocks
()
if
err
!=
nil
{
return
err
/* See https://github.com/ethereum/tests/wiki/Blockchain-Tests-II
Whether a block is valid or not is a bit subtle, it's defined by presence of
blockHeader, transactions and uncleHeaders fields. If they are missing, the block is
invalid and we must verify that we do not accept it.
Since some tests mix valid and invalid blocks we need to check this for every block.
If a block is invalid it does not necessarily fail the test, if it's invalidness is
expected we are expected to ignore it and continue processing and then validate the
post state.
*/
func
(
t
*
BlockTest
)
TryBlocksInsert
(
chainManager
*
core
.
ChainManager
)
error
{
// insert the test blocks, which will execute all transactions
for
_
,
b
:=
range
t
.
Json
.
Blocks
{
cb
,
err
:=
mustConvertBlock
(
b
)
if
err
!=
nil
{
if
b
.
BlockHeader
==
nil
{
continue
// OK - block is supposed to be invalid, continue with next block
}
else
{
return
fmt
.
Errorf
(
"Block RLP decoding failed when expected to succeed: "
,
err
)
}
}
// RLP decoding worked, try to insert into chain:
err
=
chainManager
.
InsertChain
(
types
.
Blocks
{
cb
})
if
err
!=
nil
{
if
b
.
BlockHeader
==
nil
{
continue
// OK - block is supposed to be invalid, continue with next block
}
else
{
return
fmt
.
Errorf
(
"Block insertion into chain failed: "
,
err
)
}
}
if
b
.
BlockHeader
==
nil
{
return
fmt
.
Errorf
(
"Block insertion should have failed"
)
}
}
return
chain
.
InsertChain
(
blocks
)
return
nil
}
func
(
t
*
BlockTest
)
ValidatePostState
(
statedb
*
state
.
StateDB
)
error
{
...
...
@@ -159,21 +189,6 @@ func (t *BlockTest) ValidatePostState(statedb *state.StateDB) error {
return
nil
}
func
(
t
*
BlockTest
)
convertBlocks
()
(
blocks
[]
*
types
.
Block
,
err
error
)
{
// the conversion handles errors by catching panics.
// you might consider this ugly, but the alternative (passing errors)
// would be much harder to read.
defer
func
()
{
if
recovered
:=
recover
();
recovered
!=
nil
{
buf
:=
make
([]
byte
,
64
<<
10
)
buf
=
buf
[
:
runtime
.
Stack
(
buf
,
false
)]
err
=
fmt
.
Errorf
(
"%v
\n
%s"
,
recovered
,
buf
)
}
}()
blocks
=
mustConvertBlocks
(
t
.
json
.
Blocks
)
return
blocks
,
nil
}
func
convertTest
(
in
*
btJSON
)
(
out
*
BlockTest
,
err
error
)
{
// the conversion handles errors by catching panics.
// you might consider this ugly, but the alternative (passing errors)
...
...
@@ -185,7 +200,7 @@ func convertTest(in *btJSON) (out *BlockTest, err error) {
err
=
fmt
.
Errorf
(
"%v
\n
%s"
,
recovered
,
buf
)
}
}()
out
=
&
BlockTest
{
preAccounts
:
in
.
Pre
,
j
son
:
in
}
out
=
&
BlockTest
{
preAccounts
:
in
.
Pre
,
J
son
:
in
}
out
.
Genesis
=
mustConvertGenesis
(
in
.
GenesisBlockHeader
)
return
out
,
err
}
...
...
@@ -221,17 +236,11 @@ func mustConvertHeader(in btHeader) *types.Header {
return
header
}
func
mustConvertBlocks
(
testBlocks
[]
btBlock
)
[]
*
types
.
Block
{
var
out
[]
*
types
.
Block
for
i
,
inb
:=
range
testBlocks
{
var
b
types
.
Block
r
:=
bytes
.
NewReader
(
mustConvertBytes
(
inb
.
Rlp
))
if
err
:=
rlp
.
Decode
(
r
,
&
b
);
err
!=
nil
{
panic
(
fmt
.
Errorf
(
"invalid block %d: %q
\n
error: %v"
,
i
,
inb
.
Rlp
,
err
))
}
out
=
append
(
out
,
&
b
)
}
return
out
func
mustConvertBlock
(
testBlock
btBlock
)
(
*
types
.
Block
,
error
)
{
var
b
types
.
Block
r
:=
bytes
.
NewReader
(
mustConvertBytes
(
testBlock
.
Rlp
))
err
:=
rlp
.
Decode
(
r
,
&
b
)
return
&
b
,
err
}
func
mustConvertBytes
(
in
string
)
[]
byte
{
...
...
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