Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
81ec564e
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,发现更多精彩内容 >>
提交
81ec564e
编写于
10月 29, 2014
作者:
J
Jeffrey Wilcke
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #168 from fjl/feature/working-tests
Fix the tests
上级
9e2f071d
4cf69d7c
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
70 addition
and
93 deletion
+70
-93
ethchain/helper_test.go
ethchain/helper_test.go
+3
-3
ethcrypto/crypto_test.go
ethcrypto/crypto_test.go
+26
-7
ethpipe/pipe_test.go
ethpipe/pipe_test.go
+0
-58
ethwire/client_identity_test.go
ethwire/client_identity_test.go
+6
-6
vm/vm_test.go
vm/vm_test.go
+35
-19
未找到文件。
ethchain/helper_test.go
浏览文件 @
81ec564e
...
...
@@ -18,7 +18,7 @@ type TestManager struct {
db
ethutil
.
Database
txPool
*
TxPool
blockChain
*
BlockChain
blockChain
*
ChainManager
Blocks
[]
*
Block
}
...
...
@@ -38,7 +38,7 @@ func (s *TestManager) Peers() *list.List {
return
list
.
New
()
}
func
(
s
*
TestManager
)
BlockChain
()
*
BlockChain
{
func
(
s
*
TestManager
)
ChainManager
()
*
ChainManager
{
return
s
.
blockChain
}
...
...
@@ -82,7 +82,7 @@ func NewTestManager() *TestManager {
testManager
.
eventMux
=
new
(
event
.
TypeMux
)
testManager
.
db
=
db
testManager
.
txPool
=
NewTxPool
(
testManager
)
testManager
.
blockChain
=
New
BlockChain
(
testManager
)
testManager
.
blockChain
=
New
ChainManager
(
testManager
)
testManager
.
stateManager
=
NewStateManager
(
testManager
)
// Start the tx pool
...
...
ethcrypto/crypto_test.go
浏览文件 @
81ec564e
...
...
@@ -2,16 +2,35 @@ package ethcrypto
import
(
"bytes"
"encoding/hex"
"testing"
"github.com/ethereum/go-ethereum/ethutil"
)
// FIPS 202 test (reverted back to FIPS 180)
// These tests are sanity checks.
// They should ensure that we don't e.g. use Sha3-224 instead of Sha3-256
// and that the sha3 library uses keccak-f permutation.
func
TestSha3
(
t
*
testing
.
T
)
{
const
exp
=
"3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532"
sha3_256
:=
Sha3Bin
([]
byte
(
"abc"
))
if
bytes
.
Compare
(
sha3_256
,
ethutil
.
Hex2Bytes
(
exp
))
!=
0
{
t
.
Errorf
(
"Sha3_256 failed. Incorrect result %x"
,
sha3_256
)
msg
:=
[]
byte
(
"abc"
)
exp
,
_
:=
hex
.
DecodeString
(
"4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45"
)
checkhash
(
t
,
"Sha3-256"
,
Sha3
,
msg
,
exp
)
}
func
TestSha256
(
t
*
testing
.
T
)
{
msg
:=
[]
byte
(
"abc"
)
exp
,
_
:=
hex
.
DecodeString
(
"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"
)
checkhash
(
t
,
"Sha256"
,
Sha256
,
msg
,
exp
)
}
func
TestRipemd160
(
t
*
testing
.
T
)
{
msg
:=
[]
byte
(
"abc"
)
exp
,
_
:=
hex
.
DecodeString
(
"8eb208f7e05d987a9b044a8e98c6b087f15a0bfc"
)
checkhash
(
t
,
"Ripemd160"
,
Ripemd160
,
msg
,
exp
)
}
func
checkhash
(
t
*
testing
.
T
,
name
string
,
f
func
([]
byte
)
[]
byte
,
msg
,
exp
[]
byte
)
{
sum
:=
f
(
msg
)
if
bytes
.
Compare
(
exp
,
sum
)
!=
0
{
t
.
Errorf
(
"hash %s returned wrong result.
\n
got: %x
\n
want: %x"
,
name
,
sum
,
exp
)
}
}
ethpipe/pipe_test.go
已删除
100644 → 0
浏览文件 @
9e2f071d
package
ethpipe
import
(
"testing"
"github.com/ethereum/go-ethereum/ethcrypto"
"github.com/ethereum/go-ethereum/ethstate"
"github.com/ethereum/go-ethereum/ethutil"
)
func
Val
(
v
interface
{})
*
ethutil
.
Value
{
return
ethutil
.
NewValue
(
v
)
}
func
TestNew
(
t
*
testing
.
T
)
{
pipe
:=
New
(
nil
)
var
addr
,
privy
,
recp
,
data
[]
byte
var
object
*
ethstate
.
StateObject
var
key
*
ethcrypto
.
KeyPair
world
:=
pipe
.
World
()
world
.
Get
(
addr
)
world
.
Coinbase
()
world
.
IsMining
()
world
.
IsListening
()
world
.
State
()
peers
:=
world
.
Peers
()
peers
.
Len
()
// Shortcut functions
pipe
.
Balance
(
addr
)
pipe
.
Nonce
(
addr
)
pipe
.
Block
(
addr
)
pipe
.
Storage
(
addr
,
addr
)
pipe
.
ToAddress
(
privy
)
pipe
.
Exists
(
addr
)
// Doesn't change state
pipe
.
Execute
(
addr
,
nil
,
Val
(
0
),
Val
(
1000000
),
Val
(
10
))
// Doesn't change state
pipe
.
ExecuteObject
(
object
,
nil
,
Val
(
0
),
Val
(
1000000
),
Val
(
10
))
conf
:=
world
.
Config
()
namereg
:=
conf
.
Get
(
"NameReg"
)
namereg
.
Storage
(
addr
)
var
err
error
// Transact
err
=
pipe
.
Transact
(
key
,
recp
,
ethutil
.
NewValue
(
0
),
ethutil
.
NewValue
(
0
),
ethutil
.
NewValue
(
0
),
nil
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
// Create
err
=
pipe
.
Transact
(
key
,
nil
,
ethutil
.
NewValue
(
0
),
ethutil
.
NewValue
(
0
),
ethutil
.
NewValue
(
0
),
data
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
}
ethwire/client_identity_test.go
浏览文件 @
81ec564e
...
...
@@ -9,22 +9,22 @@ import (
func
TestClientIdentity
(
t
*
testing
.
T
)
{
clientIdentity
:=
NewSimpleClientIdentity
(
"Ethereum(G)"
,
"0.5.16"
,
"test"
)
clientString
:=
clientIdentity
.
String
()
expected
:=
fmt
.
Sprintf
(
"Ethereum(G)/v0.5.16/test/%s/
Go"
,
runtime
.
GOOS
)
expected
:=
fmt
.
Sprintf
(
"Ethereum(G)/v0.5.16/test/%s/
%s"
,
runtime
.
GOOS
,
runtime
.
Version
()
)
if
clientString
!=
expected
{
t
.
Error
(
"Expected clientIdentity to be %v, got %v
"
,
expected
,
clientString
)
t
.
Error
f
(
"Expected clientIdentity to be %q, got %q
"
,
expected
,
clientString
)
}
customIdentifier
:=
clientIdentity
.
GetCustomIdentifier
()
if
customIdentifier
!=
"test"
{
t
.
Error
(
"Expected clientIdentity.GetCustomIdentifier() to be 'test', got %v
"
,
customIdentifier
)
t
.
Error
f
(
"Expected clientIdentity.GetCustomIdentifier() to be 'test', got %q
"
,
customIdentifier
)
}
clientIdentity
.
SetCustomIdentifier
(
"test2"
)
customIdentifier
=
clientIdentity
.
GetCustomIdentifier
()
if
customIdentifier
!=
"test2"
{
t
.
Error
(
"Expected clientIdentity.GetCustomIdentifier() to be 'test2', got %v
"
,
customIdentifier
)
t
.
Error
f
(
"Expected clientIdentity.GetCustomIdentifier() to be 'test2', got %q
"
,
customIdentifier
)
}
clientString
=
clientIdentity
.
String
()
expected
=
fmt
.
Sprintf
(
"Ethereum(G)/v0.5.16/test2/%s/
Go"
,
runtime
.
GOOS
)
expected
=
fmt
.
Sprintf
(
"Ethereum(G)/v0.5.16/test2/%s/
%s"
,
runtime
.
GOOS
,
runtime
.
Version
()
)
if
clientString
!=
expected
{
t
.
Error
(
"Expected clientIdentity to be %v, got %v
"
,
expected
,
clientString
)
t
.
Error
f
(
"Expected clientIdentity to be %q, got %q
"
,
expected
,
clientString
)
}
}
vm/vm_test.go
浏览文件 @
81ec564e
...
...
@@ -14,22 +14,30 @@ import (
"github.com/ethereum/go-ethereum/ethstate"
"github.com/ethereum/go-ethereum/ethtrie"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/obscuren/mutan"
)
type
TestEnv
struct
{
type
TestEnv
struct
{}
func
(
TestEnv
)
Origin
()
[]
byte
{
return
nil
}
func
(
TestEnv
)
BlockNumber
()
*
big
.
Int
{
return
nil
}
func
(
TestEnv
)
BlockHash
()
[]
byte
{
return
nil
}
func
(
TestEnv
)
PrevHash
()
[]
byte
{
return
nil
}
func
(
TestEnv
)
Coinbase
()
[]
byte
{
return
nil
}
func
(
TestEnv
)
Time
()
int64
{
return
0
}
func
(
TestEnv
)
GasLimit
()
*
big
.
Int
{
return
nil
}
func
(
TestEnv
)
Difficulty
()
*
big
.
Int
{
return
nil
}
func
(
TestEnv
)
Value
()
*
big
.
Int
{
return
nil
}
func
(
TestEnv
)
AddLog
(
Log
)
{}
func
(
TestEnv
)
Transfer
(
from
,
to
Account
,
amount
*
big
.
Int
)
error
{
return
nil
}
func
(
self
TestEnv
)
Origin
()
[]
byte
{
return
nil
}
func
(
self
TestEnv
)
BlockNumber
()
*
big
.
Int
{
return
nil
}
func
(
self
TestEnv
)
BlockHash
()
[]
byte
{
return
nil
}
func
(
self
TestEnv
)
PrevHash
()
[]
byte
{
return
nil
}
func
(
self
TestEnv
)
Coinbase
()
[]
byte
{
return
nil
}
func
(
self
TestEnv
)
Time
()
int64
{
return
0
}
func
(
self
TestEnv
)
Difficulty
()
*
big
.
Int
{
return
nil
}
func
(
self
TestEnv
)
Value
()
*
big
.
Int
{
return
nil
}
// This is likely to fail if anything ever gets looked up in the state trie :-)
func
(
self
TestEnv
)
State
()
*
ethstate
.
State
{
return
ethstate
.
New
(
ethtrie
.
New
(
nil
,
""
))
}
func
(
TestEnv
)
State
()
*
ethstate
.
State
{
return
ethstate
.
New
(
ethtrie
.
New
(
nil
,
""
))
}
const
mutcode
=
`
var x = 0;
...
...
@@ -56,27 +64,35 @@ func setup(level ethlog.LogLevel, typ Type) (*Closure, VirtualMachine) {
return
callerClosure
,
New
(
TestEnv
{},
typ
)
}
var
big9
=
ethutil
.
Hex2Bytes
(
"0000000000000000000000000000000000000000000000000000000000000009"
)
func
TestDebugVm
(
t
*
testing
.
T
)
{
if
mutan
.
Version
<
"0.6"
{
t
.
Skip
(
"skipping for mutan version"
,
mutan
.
Version
,
" < 0.6"
)
}
closure
,
vm
:=
setup
(
ethlog
.
DebugLevel
,
DebugVmTy
)
ret
,
_
,
e
:=
closure
.
Call
(
vm
,
nil
)
if
e
!=
nil
{
fmt
.
Println
(
"error
"
,
e
)
t
.
Fatalf
(
"Call returned error: %v
"
,
e
)
}
if
ret
[
len
(
ret
)
-
1
]
!=
9
{
t
.
Errorf
(
"Expected VM to return 9, got"
,
ret
,
"instead."
)
if
!
bytes
.
Equal
(
ret
,
big9
)
{
t
.
Errorf
(
"Wrong return value '%x', want '%x'"
,
ret
,
big9
)
}
}
func
TestVm
(
t
*
testing
.
T
)
{
if
mutan
.
Version
<
"0.6"
{
t
.
Skip
(
"skipping for mutan version"
,
mutan
.
Version
,
" < 0.6"
)
}
closure
,
vm
:=
setup
(
ethlog
.
DebugLevel
,
StandardVmTy
)
ret
,
_
,
e
:=
closure
.
Call
(
vm
,
nil
)
if
e
!=
nil
{
fmt
.
Println
(
"error
"
,
e
)
t
.
Fatalf
(
"Call returned error: %v
"
,
e
)
}
if
ret
[
len
(
ret
)
-
1
]
!=
9
{
t
.
Errorf
(
"Expected VM to return 9, got"
,
ret
,
"instead."
)
if
!
bytes
.
Equal
(
ret
,
big9
)
{
t
.
Errorf
(
"Wrong return value '%x', want '%x'"
,
ret
,
big9
)
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录