Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
b0ebccb3
G
go-ethereum
项目概览
whqwjb
/
go-ethereum
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
go-ethereum
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b0ebccb3
编写于
3月 17, 2015
作者:
O
obscuren
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fixed to
上级
17c5ba2b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
65 addition
and
50 deletion
+65
-50
tests/helper/vm.go
tests/helper/vm.go
+49
-41
tests/vm/gh_test.go
tests/vm/gh_test.go
+16
-9
未找到文件。
tests/helper/vm.go
浏览文件 @
b0ebccb3
...
...
@@ -4,9 +4,9 @@ import (
"errors"
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/vm"
)
...
...
@@ -18,9 +18,9 @@ type Env struct {
initial
bool
Gas
*
big
.
Int
origin
[]
byte
parent
[]
byte
coinbase
[]
byte
origin
common
.
Address
//parent common.Hash
coinbase
common
.
Address
number
*
big
.
Int
time
int64
...
...
@@ -41,9 +41,9 @@ func NewEnv(state *state.StateDB) *Env {
func
NewEnvFromMap
(
state
*
state
.
StateDB
,
envValues
map
[
string
]
string
,
exeValues
map
[
string
]
string
)
*
Env
{
env
:=
NewEnv
(
state
)
env
.
origin
=
common
.
Hex
2Byte
s
(
exeValues
[
"caller"
])
env
.
parent
=
common
.
Hex2Bytes
(
envValues
[
"previousHash"
])
env
.
coinbase
=
common
.
Hex
2Byte
s
(
envValues
[
"currentCoinbase"
])
env
.
origin
=
common
.
Hex
ToAddres
s
(
exeValues
[
"caller"
])
//
env.parent = common.Hex2Bytes(envValues["previousHash"])
env
.
coinbase
=
common
.
Hex
ToAddres
s
(
envValues
[
"currentCoinbase"
])
env
.
number
=
common
.
Big
(
envValues
[
"currentNumber"
])
env
.
time
=
common
.
Big
(
envValues
[
"currentTimestamp"
])
.
Int64
()
env
.
difficulty
=
common
.
Big
(
envValues
[
"currentDifficulty"
])
...
...
@@ -53,17 +53,18 @@ func NewEnvFromMap(state *state.StateDB, envValues map[string]string, exeValues
return
env
}
func
(
self
*
Env
)
Origin
()
[]
byte
{
return
self
.
origin
}
func
(
self
*
Env
)
BlockNumber
()
*
big
.
Int
{
return
self
.
number
}
func
(
self
*
Env
)
PrevHash
()
[]
byte
{
return
self
.
parent
}
func
(
self
*
Env
)
Coinbase
()
[]
byte
{
return
self
.
coinbase
}
func
(
self
*
Env
)
Time
()
int64
{
return
self
.
time
}
func
(
self
*
Env
)
Difficulty
()
*
big
.
Int
{
return
self
.
difficulty
}
func
(
self
*
Env
)
State
()
*
state
.
StateDB
{
return
self
.
state
}
func
(
self
*
Env
)
GasLimit
()
*
big
.
Int
{
return
self
.
gasLimit
}
func
(
self
*
Env
)
VmType
()
vm
.
Type
{
return
vm
.
StdVmTy
}
func
(
self
*
Env
)
GetHash
(
n
uint64
)
[]
byte
{
return
crypto
.
Sha3
([]
byte
(
big
.
NewInt
(
int64
(
n
))
.
String
()))
func
(
self
*
Env
)
Origin
()
common
.
Address
{
return
self
.
origin
}
func
(
self
*
Env
)
BlockNumber
()
*
big
.
Int
{
return
self
.
number
}
//func (self *Env) PrevHash() []byte { return self.parent }
func
(
self
*
Env
)
Coinbase
()
common
.
Address
{
return
self
.
coinbase
}
func
(
self
*
Env
)
Time
()
int64
{
return
self
.
time
}
func
(
self
*
Env
)
Difficulty
()
*
big
.
Int
{
return
self
.
difficulty
}
func
(
self
*
Env
)
State
()
*
state
.
StateDB
{
return
self
.
state
}
func
(
self
*
Env
)
GasLimit
()
*
big
.
Int
{
return
self
.
gasLimit
}
func
(
self
*
Env
)
VmType
()
vm
.
Type
{
return
vm
.
StdVmTy
}
func
(
self
*
Env
)
GetHash
(
n
uint64
)
common
.
Hash
{
return
common
.
BytesToHash
(
crypto
.
Sha3
([]
byte
(
big
.
NewInt
(
int64
(
n
))
.
String
())))
}
func
(
self
*
Env
)
AddLog
(
log
state
.
Log
)
{
self
.
logs
=
append
(
self
.
logs
,
log
)
...
...
@@ -87,37 +88,39 @@ func (self *Env) Transfer(from, to vm.Account, amount *big.Int) error {
return
vm
.
Transfer
(
from
,
to
,
amount
)
}
func
(
self
*
Env
)
vm
(
addr
,
data
[]
byte
,
gas
,
price
,
value
*
big
.
Int
)
*
core
.
Execution
{
func
(
self
*
Env
)
vm
(
addr
*
common
.
Address
,
data
[]
byte
,
gas
,
price
,
value
*
big
.
Int
)
*
core
.
Execution
{
exec
:=
core
.
NewExecution
(
self
,
addr
,
data
,
gas
,
price
,
value
)
return
exec
}
func
(
self
*
Env
)
Call
(
caller
vm
.
ContextRef
,
addr
,
data
[]
byte
,
gas
,
price
,
value
*
big
.
Int
)
([]
byte
,
error
)
{
func
(
self
*
Env
)
Call
(
caller
vm
.
ContextRef
,
addr
common
.
Address
,
data
[]
byte
,
gas
,
price
,
value
*
big
.
Int
)
([]
byte
,
error
)
{
if
self
.
vmTest
&&
self
.
depth
>
0
{
caller
.
ReturnGas
(
gas
,
price
)
return
nil
,
nil
}
exe
:=
self
.
vm
(
addr
,
data
,
gas
,
price
,
value
)
exe
:=
self
.
vm
(
&
addr
,
data
,
gas
,
price
,
value
)
ret
,
err
:=
exe
.
Call
(
addr
,
caller
)
self
.
Gas
=
exe
.
Gas
return
ret
,
err
}
func
(
self
*
Env
)
CallCode
(
caller
vm
.
ContextRef
,
addr
,
data
[]
byte
,
gas
,
price
,
value
*
big
.
Int
)
([]
byte
,
error
)
{
func
(
self
*
Env
)
CallCode
(
caller
vm
.
ContextRef
,
addr
common
.
Address
,
data
[]
byte
,
gas
,
price
,
value
*
big
.
Int
)
([]
byte
,
error
)
{
if
self
.
vmTest
&&
self
.
depth
>
0
{
caller
.
ReturnGas
(
gas
,
price
)
return
nil
,
nil
}
exe
:=
self
.
vm
(
caller
.
Address
(),
data
,
gas
,
price
,
value
)
caddr
:=
caller
.
Address
()
exe
:=
self
.
vm
(
&
caddr
,
data
,
gas
,
price
,
value
)
return
exe
.
Call
(
addr
,
caller
)
}
func
(
self
*
Env
)
Create
(
caller
vm
.
ContextRef
,
addr
,
data
[]
byte
,
gas
,
price
,
value
*
big
.
Int
)
([]
byte
,
error
,
vm
.
ContextRef
)
{
exe
:=
self
.
vm
(
addr
,
data
,
gas
,
price
,
value
)
func
(
self
*
Env
)
Create
(
caller
vm
.
ContextRef
,
data
[]
byte
,
gas
,
price
,
value
*
big
.
Int
)
([]
byte
,
error
,
vm
.
ContextRef
)
{
exe
:=
self
.
vm
(
nil
,
data
,
gas
,
price
,
value
)
if
self
.
vmTest
{
caller
.
ReturnGas
(
gas
,
price
)
...
...
@@ -132,8 +135,8 @@ func (self *Env) Create(caller vm.ContextRef, addr, data []byte, gas, price, val
func
RunVm
(
state
*
state
.
StateDB
,
env
,
exec
map
[
string
]
string
)
([]
byte
,
state
.
Logs
,
*
big
.
Int
,
error
)
{
var
(
to
=
FromHex
(
exec
[
"address"
])
from
=
FromHex
(
exec
[
"caller"
])
to
=
common
.
HexToAddress
(
exec
[
"address"
])
from
=
common
.
HexToAddress
(
exec
[
"caller"
])
data
=
FromHex
(
exec
[
"data"
])
gas
=
common
.
Big
(
exec
[
"gas"
])
price
=
common
.
Big
(
exec
[
"gasPrice"
])
...
...
@@ -156,14 +159,18 @@ func RunVm(state *state.StateDB, env, exec map[string]string) ([]byte, state.Log
func
RunState
(
statedb
*
state
.
StateDB
,
env
,
tx
map
[
string
]
string
)
([]
byte
,
state
.
Logs
,
*
big
.
Int
,
error
)
{
var
(
keyPair
,
_
=
crypto
.
NewKeyPairFromSec
([]
byte
(
common
.
Hex2Bytes
(
tx
[
"secretKey"
])))
to
=
FromHex
(
tx
[
"to"
])
data
=
FromHex
(
tx
[
"data"
])
gas
=
common
.
Big
(
tx
[
"gasLimit"
])
price
=
common
.
Big
(
tx
[
"gasPrice"
])
value
=
common
.
Big
(
tx
[
"value"
])
caddr
=
FromHex
(
env
[
"currentCoinbase"
])
caddr
=
common
.
HexToAddress
(
env
[
"currentCoinbase"
])
)
var
to
*
common
.
Address
if
len
(
tx
[
"to"
])
>
2
{
t
:=
common
.
HexToAddress
(
tx
[
"to"
])
to
=
&
t
}
// Set pre compiled contracts
vm
.
Precompiled
=
vm
.
PrecompiledContracts
()
...
...
@@ -171,9 +178,9 @@ func RunState(statedb *state.StateDB, env, tx map[string]string) ([]byte, state.
coinbase
:=
statedb
.
GetOrNewStateObject
(
caddr
)
coinbase
.
SetGasPool
(
common
.
Big
(
env
[
"currentGasLimit"
]))
message
:=
NewMessage
(
keyPair
.
Address
(
),
to
,
data
,
value
,
gas
,
price
)
message
:=
NewMessage
(
common
.
BytesToAddress
(
keyPair
.
Address
()
),
to
,
data
,
value
,
gas
,
price
)
vmenv
:=
NewEnvFromMap
(
statedb
,
env
,
tx
)
vmenv
.
origin
=
keyPair
.
Address
(
)
vmenv
.
origin
=
common
.
BytesToAddress
(
keyPair
.
Address
()
)
ret
,
_
,
err
:=
core
.
ApplyMessage
(
vmenv
,
message
,
coinbase
)
if
core
.
IsNonceErr
(
err
)
||
core
.
IsInvalidTxErr
(
err
)
{
statedb
.
Set
(
snapshot
)
...
...
@@ -184,20 +191,21 @@ func RunState(statedb *state.StateDB, env, tx map[string]string) ([]byte, state.
}
type
Message
struct
{
from
,
to
[]
byte
from
common
.
Address
to
*
common
.
Address
value
,
gas
,
price
*
big
.
Int
data
[]
byte
}
func
NewMessage
(
from
,
to
,
data
[]
byte
,
value
,
gas
,
price
*
big
.
Int
)
Message
{
func
NewMessage
(
from
common
.
Address
,
to
*
common
.
Address
,
data
[]
byte
,
value
,
gas
,
price
*
big
.
Int
)
Message
{
return
Message
{
from
,
to
,
value
,
gas
,
price
,
data
}
}
func
(
self
Message
)
Hash
()
[]
byte
{
return
nil
}
func
(
self
Message
)
From
()
[]
byte
{
return
self
.
from
}
func
(
self
Message
)
To
()
[]
byte
{
return
self
.
to
}
func
(
self
Message
)
GasPrice
()
*
big
.
Int
{
return
self
.
price
}
func
(
self
Message
)
Gas
()
*
big
.
Int
{
return
self
.
gas
}
func
(
self
Message
)
Value
()
*
big
.
Int
{
return
self
.
value
}
func
(
self
Message
)
Nonce
()
uint64
{
return
0
}
func
(
self
Message
)
Data
()
[]
byte
{
return
self
.
data
}
func
(
self
Message
)
Hash
()
[]
byte
{
return
nil
}
func
(
self
Message
)
From
()
(
common
.
Address
,
error
)
{
return
self
.
from
,
nil
}
func
(
self
Message
)
To
()
*
common
.
Address
{
return
self
.
to
}
func
(
self
Message
)
GasPrice
()
*
big
.
Int
{
return
self
.
price
}
func
(
self
Message
)
Gas
()
*
big
.
Int
{
return
self
.
gas
}
func
(
self
Message
)
Value
()
*
big
.
Int
{
return
self
.
value
}
func
(
self
Message
)
Nonce
()
uint64
{
return
0
}
func
(
self
Message
)
Data
()
[]
byte
{
return
self
.
data
}
tests/vm/gh_test.go
浏览文件 @
b0ebccb3
...
...
@@ -6,11 +6,12 @@ import (
"strconv"
"testing"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/tests/helper"
"github.com/ethereum/go-ethereum/vm"
)
type
Account
struct
{
...
...
@@ -39,7 +40,7 @@ func (self Log) Topics() [][]byte {
}
func
StateObjectFromAccount
(
db
common
.
Database
,
addr
string
,
account
Account
)
*
state
.
StateObject
{
obj
:=
state
.
NewStateObject
(
common
.
Hex
2Byte
s
(
addr
),
db
)
obj
:=
state
.
NewStateObject
(
common
.
Hex
ToAddres
s
(
addr
),
db
)
obj
.
SetBalance
(
common
.
Big
(
account
.
Balance
))
if
common
.
IsHex
(
account
.
Code
)
{
...
...
@@ -80,13 +81,18 @@ func RunVmTest(p string, t *testing.T) {
helper
.
CreateFileTests
(
t
,
p
,
&
tests
)
for
name
,
test
:=
range
tests
{
helper
.
Logger
.
SetLogLevel
(
5
)
vm
.
Debug
=
true
if
name
!=
"TransactionCreateSuicideContract"
{
continue
}
db
,
_
:=
ethdb
.
NewMemDatabase
()
statedb
:=
state
.
New
(
nil
,
db
)
statedb
:=
state
.
New
(
common
.
Hash
{}
,
db
)
for
addr
,
account
:=
range
test
.
Pre
{
obj
:=
StateObjectFromAccount
(
db
,
addr
,
account
)
statedb
.
SetStateObject
(
obj
)
for
a
,
v
:=
range
account
.
Storage
{
obj
.
SetState
(
helper
.
FromHex
(
a
),
common
.
NewValue
(
helper
.
FromHex
(
v
)))
obj
.
SetState
(
common
.
HexToHash
(
a
),
common
.
NewValue
(
helper
.
FromHex
(
v
)))
}
}
...
...
@@ -134,30 +140,31 @@ func RunVmTest(p string, t *testing.T) {
}
for
addr
,
account
:=
range
test
.
Post
{
obj
:=
statedb
.
GetStateObject
(
helper
.
FromHex
(
addr
))
obj
:=
statedb
.
GetStateObject
(
common
.
HexToAddress
(
addr
))
if
obj
==
nil
{
continue
}
if
len
(
test
.
Exec
)
==
0
{
if
obj
.
Balance
()
.
Cmp
(
common
.
Big
(
account
.
Balance
))
!=
0
{
t
.
Errorf
(
"%s's : (%x) balance failed. Expected %v, got %v => %v
\n
"
,
name
,
obj
.
Address
()[
:
4
],
account
.
Balance
,
obj
.
Balance
(),
new
(
big
.
Int
)
.
Sub
(
common
.
Big
(
account
.
Balance
),
obj
.
Balance
()))
t
.
Errorf
(
"%s's : (%x) balance failed. Expected %v, got %v => %v
\n
"
,
name
,
obj
.
Address
()
.
Bytes
()
[
:
4
],
account
.
Balance
,
obj
.
Balance
(),
new
(
big
.
Int
)
.
Sub
(
common
.
Big
(
account
.
Balance
),
obj
.
Balance
()))
}
}
for
addr
,
value
:=
range
account
.
Storage
{
v
:=
obj
.
GetState
(
helper
.
FromHex
(
addr
))
.
Bytes
()
v
:=
obj
.
GetState
(
common
.
HexToHash
(
addr
))
.
Bytes
()
vexp
:=
helper
.
FromHex
(
value
)
if
bytes
.
Compare
(
v
,
vexp
)
!=
0
{
t
.
Errorf
(
"%s's : (%x: %s) storage failed. Expected %x, got %x (%v %v)
\n
"
,
name
,
obj
.
Address
()[
0
:
4
],
addr
,
vexp
,
v
,
common
.
BigD
(
vexp
),
common
.
BigD
(
v
))
t
.
Errorf
(
"%s's : (%x: %s) storage failed. Expected %x, got %x (%v %v)
\n
"
,
name
,
obj
.
Address
()
.
Bytes
()
[
0
:
4
],
addr
,
vexp
,
v
,
common
.
BigD
(
vexp
),
common
.
BigD
(
v
))
}
}
}
if
!
isVmTest
{
statedb
.
Sync
()
if
!
bytes
.
Equal
(
common
.
Hex2Bytes
(
test
.
PostStateRoot
),
statedb
.
Root
())
{
//if !bytes.Equal(common.Hex2Bytes(test.PostStateRoot), statedb.Root()) {
if
common
.
HexToHash
(
test
.
PostStateRoot
)
!=
statedb
.
Root
()
{
t
.
Errorf
(
"%s's : Post state root error. Expected %s, got %x"
,
name
,
test
.
PostStateRoot
,
statedb
.
Root
())
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录