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
31a95151
Commit
31a95151
authored
Mar 12, 2015
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated rnd vm test => state test
parent
96496888
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
91 additions
and
30 deletions
+91
-30
main.go
cmd/ethtest/main.go
+88
-28
stack.go
vm/stack.go
+3
-2
No files found.
cmd/ethtest/main.go
View file @
31a95151
...
...
@@ -24,10 +24,13 @@ package main
import
(
"bytes"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"log"
"math/big"
"os"
"strconv"
"strings"
"github.com/ethereum/go-ethereum/ethdb"
...
...
@@ -37,6 +40,24 @@ import (
"github.com/ethereum/go-ethereum/tests/helper"
)
type
Log
struct
{
AddressF
string
`json:"address"`
DataF
string
`json:"data"`
TopicsF
[]
string
`json:"topics"`
BloomF
string
`json:"bloom"`
}
func
(
self
Log
)
Address
()
[]
byte
{
return
ethutil
.
Hex2Bytes
(
self
.
AddressF
)
}
func
(
self
Log
)
Data
()
[]
byte
{
return
ethutil
.
Hex2Bytes
(
self
.
DataF
)
}
func
(
self
Log
)
RlpData
()
interface
{}
{
return
nil
}
func
(
self
Log
)
Topics
()
[][]
byte
{
t
:=
make
([][]
byte
,
len
(
self
.
TopicsF
))
for
i
,
topic
:=
range
self
.
TopicsF
{
t
[
i
]
=
ethutil
.
Hex2Bytes
(
topic
)
}
return
t
}
type
Account
struct
{
Balance
string
Code
string
...
...
@@ -59,12 +80,25 @@ func StateObjectFromAccount(db ethutil.Database, addr string, account Account) *
type
VmTest
struct
{
Callcreates
interface
{}
Env
map
[
string
]
string
Exec
map
[
string
]
string
Gas
string
Out
string
Post
map
[
string
]
Account
Pre
map
[
string
]
Account
//Env map[string]string
Env
Env
Exec
map
[
string
]
string
Transaction
map
[
string
]
string
Logs
[]
Log
Gas
string
Out
string
Post
map
[
string
]
Account
Pre
map
[
string
]
Account
PostStateRoot
string
}
type
Env
struct
{
CurrentCoinbase
string
CurrentDifficulty
string
CurrentGasLimit
string
CurrentNumber
string
CurrentTimestamp
interface
{}
PreviousHash
string
}
func
RunVmTest
(
r
io
.
Reader
)
(
failed
int
)
{
...
...
@@ -78,49 +112,75 @@ func RunVmTest(r io.Reader) (failed int) {
for
name
,
test
:=
range
tests
{
db
,
_
:=
ethdb
.
NewMemDatabase
()
state
:=
state
.
New
(
nil
,
db
)
state
db
:=
state
.
New
(
nil
,
db
)
for
addr
,
account
:=
range
test
.
Pre
{
obj
:=
StateObjectFromAccount
(
db
,
addr
,
account
)
state
.
SetStateObject
(
obj
)
state
db
.
SetStateObject
(
obj
)
}
ret
,
_
,
gas
,
err
:=
helper
.
RunVm
(
state
,
test
.
Env
,
test
.
Exec
)
// When an error is returned it doesn't always mean the tests fails.
// Have to come up with some conditional failing mechanism.
if
err
!=
nil
{
log
.
Println
(
err
)
env
:=
make
(
map
[
string
]
string
)
env
[
"currentCoinbase"
]
=
test
.
Env
.
CurrentCoinbase
env
[
"currentDifficulty"
]
=
test
.
Env
.
CurrentDifficulty
env
[
"currentGasLimit"
]
=
test
.
Env
.
CurrentGasLimit
env
[
"currentNumber"
]
=
test
.
Env
.
CurrentNumber
env
[
"previousHash"
]
=
test
.
Env
.
PreviousHash
if
n
,
ok
:=
test
.
Env
.
CurrentTimestamp
.
(
float64
);
ok
{
env
[
"currentTimestamp"
]
=
strconv
.
Itoa
(
int
(
n
))
}
else
{
env
[
"currentTimestamp"
]
=
test
.
Env
.
CurrentTimestamp
.
(
string
)
}
ret
,
logs
,
_
,
_
:=
helper
.
RunState
(
statedb
,
env
,
test
.
Transaction
)
statedb
.
Sync
()
rexp
:=
helper
.
FromHex
(
test
.
Out
)
if
bytes
.
Compare
(
rexp
,
ret
)
!=
0
{
log
.
Printf
(
"%s's return failed. Expected %x, got %x
\n
"
,
name
,
rexp
,
ret
)
failed
=
1
fmt
.
Printf
(
"%s's return failed. Expected %x, got %x
\n
"
,
name
,
rexp
,
ret
)
}
if
len
(
test
.
Gas
)
==
0
&&
err
==
nil
{
log
.
Printf
(
"0 gas indicates error but no error given by VM"
)
failed
=
1
}
else
{
gexp
:=
ethutil
.
Big
(
test
.
Gas
)
if
gexp
.
Cmp
(
gas
)
!=
0
{
log
.
Printf
(
"%s's gas failed. Expected %v, got %v
\n
"
,
name
,
gexp
,
gas
)
failed
=
1
for
addr
,
account
:=
range
test
.
Post
{
obj
:=
statedb
.
GetStateObject
(
helper
.
FromHex
(
addr
))
if
obj
==
nil
{
continue
}
if
len
(
test
.
Exec
)
==
0
{
if
obj
.
Balance
()
.
Cmp
(
ethutil
.
Big
(
account
.
Balance
))
!=
0
{
fmt
.
Printf
(
"%s's : (%x) balance failed. Expected %v, got %v => %v
\n
"
,
name
,
obj
.
Address
()[
:
4
],
account
.
Balance
,
obj
.
Balance
(),
new
(
big
.
Int
)
.
Sub
(
ethutil
.
Big
(
account
.
Balance
),
obj
.
Balance
()))
}
}
}
for
addr
,
account
:=
range
test
.
Post
{
obj
:=
state
.
GetStateObject
(
helper
.
FromHex
(
addr
))
for
addr
,
value
:=
range
account
.
Storage
{
v
:=
obj
.
GetState
(
helper
.
FromHex
(
addr
))
.
Bytes
()
vexp
:=
helper
.
FromHex
(
value
)
if
bytes
.
Compare
(
v
,
vexp
)
!=
0
{
log
.
Printf
(
"%s's : (%x: %s) storage failed. Expected %x, got %x (%v %v)
\n
"
,
name
,
obj
.
Address
()[
0
:
4
],
addr
,
vexp
,
v
,
ethutil
.
BigD
(
vexp
),
ethutil
.
BigD
(
v
))
failed
=
1
fmt
.
Printf
(
"%s's : (%x: %s) storage failed. Expected %x, got %x (%v %v)
\n
"
,
name
,
obj
.
Address
()[
0
:
4
],
addr
,
vexp
,
v
,
ethutil
.
BigD
(
vexp
),
ethutil
.
BigD
(
v
))
}
}
}
if
!
bytes
.
Equal
(
ethutil
.
Hex2Bytes
(
test
.
PostStateRoot
),
statedb
.
Root
())
{
fmt
.
Printf
(
"%s's : Post state root error. Expected %s, got %x"
,
name
,
test
.
PostStateRoot
,
statedb
.
Root
())
}
if
len
(
test
.
Logs
)
>
0
{
if
len
(
test
.
Logs
)
!=
len
(
logs
)
{
fmt
.
Printf
(
"log length mismatch. Expected %d, got %d"
,
len
(
test
.
Logs
),
len
(
logs
))
}
else
{
/*
fmt.Println("A", test.Logs)
fmt.Println("B", logs)
for i, log := range test.Logs {
genBloom := ethutil.LeftPadBytes(types.LogsBloom(state.Logs{logs[i]}).Bytes(), 256)
if !bytes.Equal(genBloom, ethutil.Hex2Bytes(log.BloomF)) {
t.Errorf("bloom mismatch")
}
}
*/
}
}
logger
.
Flush
()
}
...
...
vm/stack.go
View file @
31a95151
...
...
@@ -15,10 +15,11 @@ type stack struct {
}
func
(
st
*
stack
)
push
(
d
*
big
.
Int
)
{
stackItem
:=
new
(
big
.
Int
)
.
Set
(
d
)
if
len
(
st
.
data
)
>
st
.
ptr
{
st
.
data
[
st
.
ptr
]
=
d
st
.
data
[
st
.
ptr
]
=
stackItem
}
else
{
st
.
data
=
append
(
st
.
data
,
d
)
st
.
data
=
append
(
st
.
data
,
stackItem
)
}
st
.
ptr
++
}
...
...
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