Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
2df8ad63
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,体验更适合开发者的 AI 搜索 >>
提交
2df8ad63
编写于
12月 02, 2014
作者:
O
obscuren
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added state tests
上级
a0523578
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
86 addition
and
7 deletion
+86
-7
tests/helper/vm.go
tests/helper/vm.go
+15
-0
tests/vm/gh_test.go
tests/vm/gh_test.go
+64
-5
vm/address.go
vm/address.go
+6
-2
vm/execution.go
vm/execution.go
+1
-0
未找到文件。
tests/helper/vm.go
浏览文件 @
2df8ad63
...
...
@@ -3,6 +3,7 @@ package helper
import
(
"math/big"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/vm"
...
...
@@ -66,3 +67,17 @@ func RunVm(state *state.State, env, exec map[string]string) ([]byte, *big.Int, e
return
ret
,
execution
.
Gas
,
err
}
func
RunState
(
state
*
state
.
State
,
env
,
tx
map
[
string
]
string
)
([]
byte
,
*
big
.
Int
,
error
)
{
address
:=
FromHex
(
tx
[
"to"
])
keyPair
,
_
:=
crypto
.
NewKeyPairFromSec
([]
byte
(
ethutil
.
Hex2Bytes
(
tx
[
"secretKey"
])))
caller
:=
state
.
GetOrNewStateObject
(
keyPair
.
Address
())
vmenv
:=
NewEnvFromMap
(
state
,
env
,
tx
)
vmenv
.
origin
=
caller
.
Address
()
evm
:=
vm
.
New
(
vmenv
,
vm
.
DebugVmTy
)
execution
:=
vm
.
NewExecution
(
evm
,
address
,
FromHex
(
tx
[
"data"
]),
ethutil
.
Big
(
tx
[
"gasLimit"
]),
ethutil
.
Big
(
tx
[
"gasPrice"
]),
ethutil
.
Big
(
tx
[
"value"
]))
ret
,
err
:=
execution
.
Exec
(
address
,
caller
)
return
ret
,
execution
.
Gas
,
err
}
tests/vm/gh_test.go
浏览文件 @
2df8ad63
...
...
@@ -2,6 +2,8 @@ package vm
import
(
"bytes"
"math/big"
"strconv"
"testing"
"github.com/ethereum/go-ethereum/ethutil"
...
...
@@ -29,10 +31,21 @@ func StateObjectFromAccount(addr string, account Account) *state.StateObject {
return
obj
}
type
Env
struct
{
CurrentCoinbase
string
CurrentDifficulty
string
CurrentGasLimit
string
CurrentNumber
string
CurrentTimestamp
interface
{}
PreviousHash
string
}
type
VmTest
struct
{
Callcreates
interface
{}
Env
map
[
string
]
string
//Env map[string]string
Env
Env
Exec
map
[
string
]
string
Transaction
map
[
string
]
string
Gas
string
Out
string
Post
map
[
string
]
Account
...
...
@@ -50,7 +63,31 @@ func RunVmTest(p string, t *testing.T) {
state
.
SetStateObject
(
obj
)
}
ret
,
gas
,
err
:=
helper
.
RunVm
(
state
,
test
.
Env
,
test
.
Exec
)
// XXX Yeah, yeah...
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
)
}
var
(
ret
[]
byte
gas
*
big
.
Int
err
error
)
if
len
(
test
.
Exec
)
>
0
{
ret
,
gas
,
err
=
helper
.
RunVm
(
state
,
env
,
test
.
Exec
)
}
else
{
ret
,
gas
,
err
=
helper
.
RunState
(
state
,
env
,
test
.
Transaction
)
}
// 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
{
...
...
@@ -62,9 +99,11 @@ func RunVmTest(p string, t *testing.T) {
t
.
Errorf
(
"%s's return failed. Expected %x, got %x
\n
"
,
name
,
rexp
,
ret
)
}
gexp
:=
ethutil
.
Big
(
test
.
Gas
)
if
gexp
.
Cmp
(
gas
)
!=
0
{
t
.
Errorf
(
"%s's gas failed. Expected %v, got %v
\n
"
,
name
,
gexp
,
gas
)
if
len
(
test
.
Gas
)
>
0
{
gexp
:=
ethutil
.
Big
(
test
.
Gas
)
if
gexp
.
Cmp
(
gas
)
!=
0
{
t
.
Errorf
(
"%s's gas failed. Expected %v, got %v
\n
"
,
name
,
gexp
,
gas
)
}
}
for
addr
,
account
:=
range
test
.
Post
{
...
...
@@ -123,3 +162,23 @@ func TestVm(t *testing.T) {
const
fn
=
"../files/vmtests/vmtests.json"
RunVmTest
(
fn
,
t
)
}
func
TestStateSystemOperations
(
t
*
testing
.
T
)
{
const
fn
=
"../files/StateTests/stSystemOperationsTest.json"
RunVmTest
(
fn
,
t
)
}
func
TestStatePreCompiledContracts
(
t
*
testing
.
T
)
{
const
fn
=
"../files/StateTests/stPreCompiledContracts.json"
RunVmTest
(
fn
,
t
)
}
func
TestStateRecursiveCreate
(
t
*
testing
.
T
)
{
const
fn
=
"../files/StateTests/stRecursiveCreate.json"
RunVmTest
(
fn
,
t
)
}
func
TestStateSpecialTest
(
t
*
testing
.
T
)
{
const
fn
=
"../files/StateTests/stSpecialTest.json"
RunVmTest
(
fn
,
t
)
}
vm/address.go
浏览文件 @
2df8ad63
...
...
@@ -31,12 +31,16 @@ func sha256Func(in []byte) []byte {
}
func
ripemd160Func
(
in
[]
byte
)
[]
byte
{
return
ethutil
.
Righ
tPadBytes
(
crypto
.
Ripemd160
(
in
),
32
)
return
ethutil
.
Lef
tPadBytes
(
crypto
.
Ripemd160
(
in
),
32
)
}
func
ecrecoverFunc
(
in
[]
byte
)
[]
byte
{
// In case of an invalid sig. Defaults to return nil
defer
func
()
{
recover
()
}()
return
crypto
.
Ecrecover
(
in
)
hash
:=
in
[
:
32
]
v
:=
ethutil
.
BigD
(
in
[
32
:
64
])
.
Bytes
()[
0
]
-
27
sig
:=
append
(
in
[
64
:
],
v
)
return
crypto
.
Sha3
(
crypto
.
Ecrecover
(
append
(
hash
,
sig
...
))[
1
:
])
}
vm/execution.go
浏览文件 @
2df8ad63
...
...
@@ -69,6 +69,7 @@ func (self *Execution) exec(code, caddr []byte, caller ClosureRef) (ret []byte,
if
self
.
Gas
.
Cmp
(
p
.
Gas
)
>=
0
{
ret
=
p
.
Call
(
self
.
input
)
self
.
vm
.
Printf
(
"NATIVE_FUNC(%x) => %x"
,
naddr
,
ret
)
self
.
vm
.
Endl
()
}
}
else
{
// Create a new callable closure
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录