Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
adf2b8d0
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 搜索 >>
提交
adf2b8d0
编写于
10月 21, 2015
作者:
J
Jeffrey Wilcke
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'release/1.1.0' of github.com-obscure:ethereum/go-ethereum into release/1.1.0
上级
4bf0cbcd
59d25c0c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
105 addition
and
0 deletion
+105
-0
core/state/state_object.go
core/state/state_object.go
+1
-0
core/state/state_test.go
core/state/state_test.go
+104
-0
未找到文件。
core/state/state_object.go
浏览文件 @
adf2b8d0
...
...
@@ -263,6 +263,7 @@ func (self *StateObject) Copy() *StateObject {
stateObject
.
gasPool
.
Set
(
self
.
gasPool
)
stateObject
.
remove
=
self
.
remove
stateObject
.
dirty
=
self
.
dirty
stateObject
.
deleted
=
self
.
deleted
return
stateObject
}
...
...
core/state/state_test.go
浏览文件 @
adf2b8d0
...
...
@@ -17,6 +17,7 @@
package
state
import
(
"bytes"
"math/big"
"testing"
...
...
@@ -117,3 +118,106 @@ func (s *StateSuite) TestSnapshot(c *checker.C) {
c
.
Assert
(
data1
,
checker
.
DeepEquals
,
res
)
}
// use testing instead of checker because checker does not support
// printing/logging in tests (-check.vv does not work)
func
TestSnapshot2
(
t
*
testing
.
T
)
{
db
,
_
:=
ethdb
.
NewMemDatabase
()
state
:=
New
(
common
.
Hash
{},
db
)
stateobjaddr0
:=
toAddr
([]
byte
(
"so0"
))
stateobjaddr1
:=
toAddr
([]
byte
(
"so1"
))
var
storageaddr
common
.
Hash
data0
:=
common
.
BytesToHash
([]
byte
{
17
})
data1
:=
common
.
BytesToHash
([]
byte
{
18
})
state
.
SetState
(
stateobjaddr0
,
storageaddr
,
data0
)
state
.
SetState
(
stateobjaddr1
,
storageaddr
,
data1
)
// db, trie are already non-empty values
so0
:=
state
.
GetStateObject
(
stateobjaddr0
)
so0
.
balance
=
big
.
NewInt
(
42
)
so0
.
nonce
=
43
so0
.
gasPool
=
big
.
NewInt
(
44
)
so0
.
code
=
[]
byte
{
'c'
,
'a'
,
'f'
,
'e'
}
so0
.
codeHash
=
so0
.
CodeHash
()
so0
.
remove
=
true
so0
.
deleted
=
false
so0
.
dirty
=
false
state
.
SetStateObject
(
so0
)
// and one with deleted == true
so1
:=
state
.
GetStateObject
(
stateobjaddr1
)
so1
.
balance
=
big
.
NewInt
(
52
)
so1
.
nonce
=
53
so1
.
gasPool
=
big
.
NewInt
(
54
)
so1
.
code
=
[]
byte
{
'c'
,
'a'
,
'f'
,
'e'
,
'2'
}
so1
.
codeHash
=
so1
.
CodeHash
()
so1
.
remove
=
true
so1
.
deleted
=
true
so1
.
dirty
=
true
state
.
SetStateObject
(
so1
)
so1
=
state
.
GetStateObject
(
stateobjaddr1
)
if
so1
!=
nil
{
t
.
Fatalf
(
"deleted object not nil when getting"
)
}
snapshot
:=
state
.
Copy
()
state
.
Set
(
snapshot
)
so0Restored
:=
state
.
GetStateObject
(
stateobjaddr0
)
so1Restored
:=
state
.
GetStateObject
(
stateobjaddr1
)
// non-deleted is equal (restored)
compareStateObjects
(
so0Restored
,
so0
,
t
)
// deleted should be nil, both before and after restore of state copy
if
so1Restored
!=
nil
{
t
.
Fatalf
(
"deleted object not nil after restoring snapshot"
)
}
}
func
compareStateObjects
(
so0
,
so1
*
StateObject
,
t
*
testing
.
T
)
{
if
so0
.
address
!=
so1
.
address
{
t
.
Fatalf
(
"Address mismatch: have %v, want %v"
,
so0
.
address
,
so1
.
address
)
}
if
so0
.
balance
.
Cmp
(
so1
.
balance
)
!=
0
{
t
.
Fatalf
(
"Balance mismatch: have %v, want %v"
,
so0
.
balance
,
so1
.
balance
)
}
if
so0
.
nonce
!=
so1
.
nonce
{
t
.
Fatalf
(
"Nonce mismatch: have %v, want %v"
,
so0
.
nonce
,
so1
.
nonce
)
}
if
!
bytes
.
Equal
(
so0
.
codeHash
,
so1
.
codeHash
)
{
t
.
Fatalf
(
"CodeHash mismatch: have %v, want %v"
,
so0
.
codeHash
,
so1
.
codeHash
)
}
if
!
bytes
.
Equal
(
so0
.
code
,
so1
.
code
)
{
t
.
Fatalf
(
"Code mismatch: have %v, want %v"
,
so0
.
code
,
so1
.
code
)
}
if
!
bytes
.
Equal
(
so0
.
initCode
,
so1
.
initCode
)
{
t
.
Fatalf
(
"InitCode mismatch: have %v, want %v"
,
so0
.
initCode
,
so1
.
initCode
)
}
for
k
,
v
:=
range
so1
.
storage
{
if
so0
.
storage
[
k
]
!=
v
{
t
.
Fatalf
(
"Storage key %s mismatch: have %v, want %v"
,
k
,
so0
.
storage
[
k
],
v
)
}
}
for
k
,
v
:=
range
so0
.
storage
{
if
so1
.
storage
[
k
]
!=
v
{
t
.
Fatalf
(
"Storage key %s mismatch: have %v, want none."
,
k
,
v
)
}
}
if
so0
.
gasPool
.
Cmp
(
so1
.
gasPool
)
!=
0
{
t
.
Fatalf
(
"GasPool mismatch: have %v, want %v"
,
so0
.
gasPool
,
so1
.
gasPool
)
}
if
so0
.
remove
!=
so1
.
remove
{
t
.
Fatalf
(
"Remove mismatch: have %v, want %v"
,
so0
.
remove
,
so1
.
remove
)
}
if
so0
.
deleted
!=
so1
.
deleted
{
t
.
Fatalf
(
"Deleted mismatch: have %v, want %v"
,
so0
.
deleted
,
so1
.
deleted
)
}
if
so0
.
dirty
!=
so1
.
dirty
{
t
.
Fatalf
(
"Dirty mismatch: have %v, want %v"
,
so0
.
dirty
,
so1
.
dirty
)
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录