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
c95a27e3
Commit
c95a27e3
authored
Feb 16, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added more tests
parent
066940f1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
8 deletions
+24
-8
value.go
ethutil/value.go
+7
-5
value_test.go
ethutil/value_test.go
+17
-3
No files found.
ethutil/value.go
View file @
c95a27e3
...
@@ -84,6 +84,8 @@ func (val *Value) BigInt() *big.Int {
...
@@ -84,6 +84,8 @@ func (val *Value) BigInt() *big.Int {
b
:=
new
(
big
.
Int
)
.
SetBytes
(
a
)
b
:=
new
(
big
.
Int
)
.
SetBytes
(
a
)
return
b
return
b
}
else
if
a
,
ok
:=
val
.
Val
.
(
*
big
.
Int
);
ok
{
return
a
}
else
{
}
else
{
return
big
.
NewInt
(
int64
(
val
.
Uint
()))
return
big
.
NewInt
(
int64
(
val
.
Uint
()))
}
}
...
@@ -106,7 +108,7 @@ func (val *Value) Bytes() []byte {
...
@@ -106,7 +108,7 @@ func (val *Value) Bytes() []byte {
return
a
return
a
}
}
return
make
([]
byte
,
0
)
return
[]
byte
{}
}
}
func
(
val
*
Value
)
Slice
()
[]
interface
{}
{
func
(
val
*
Value
)
Slice
()
[]
interface
{}
{
...
@@ -144,7 +146,7 @@ func (val *Value) Get(idx int) *Value {
...
@@ -144,7 +146,7 @@ func (val *Value) Get(idx int) *Value {
}
}
if
idx
<
0
{
if
idx
<
0
{
panic
(
"negative idx for
Rlp
Get"
)
panic
(
"negative idx for
Value
Get"
)
}
}
return
NewValue
(
d
[
idx
])
return
NewValue
(
d
[
idx
])
...
@@ -162,9 +164,9 @@ func (val *Value) Encode() []byte {
...
@@ -162,9 +164,9 @@ func (val *Value) Encode() []byte {
return
Encode
(
val
.
Val
)
return
Encode
(
val
.
Val
)
}
}
func
NewValueFromBytes
(
rlpD
ata
[]
byte
)
*
Value
{
func
NewValueFromBytes
(
d
ata
[]
byte
)
*
Value
{
if
len
(
rlpD
ata
)
!=
0
{
if
len
(
d
ata
)
!=
0
{
data
,
_
:=
Decode
(
rlpD
ata
,
0
)
data
,
_
:=
Decode
(
d
ata
,
0
)
return
NewValue
(
data
)
return
NewValue
(
data
)
}
}
...
...
ethutil/value_test.go
View file @
c95a27e3
package
ethutil
package
ethutil
import
(
import
(
"bytes"
"math/big"
"testing"
"testing"
)
)
...
@@ -22,6 +24,8 @@ func TestValueTypes(t *testing.T) {
...
@@ -22,6 +24,8 @@ func TestValueTypes(t *testing.T) {
str
:=
NewValue
(
"str"
)
str
:=
NewValue
(
"str"
)
num
:=
NewValue
(
1
)
num
:=
NewValue
(
1
)
inter
:=
NewValue
([]
interface
{}{
1
})
inter
:=
NewValue
([]
interface
{}{
1
})
byt
:=
NewValue
([]
byte
{
1
,
2
,
3
,
4
})
bigInt
:=
NewValue
(
big
.
NewInt
(
10
))
if
str
.
Str
()
!=
"str"
{
if
str
.
Str
()
!=
"str"
{
t
.
Errorf
(
"expected Str to return 'str', got %s"
,
str
.
Str
())
t
.
Errorf
(
"expected Str to return 'str', got %s"
,
str
.
Str
())
...
@@ -31,8 +35,18 @@ func TestValueTypes(t *testing.T) {
...
@@ -31,8 +35,18 @@ func TestValueTypes(t *testing.T) {
t
.
Errorf
(
"expected Uint to return '1', got %d"
,
num
.
Uint
())
t
.
Errorf
(
"expected Uint to return '1', got %d"
,
num
.
Uint
())
}
}
exp
:=
[]
interface
{}{
1
}
interExp
:=
[]
interface
{}{
1
}
if
!
NewValue
(
inter
.
Interface
())
.
Cmp
(
NewValue
(
exp
))
{
if
!
NewValue
(
inter
.
Interface
())
.
Cmp
(
NewValue
(
interExp
))
{
t
.
Errorf
(
"expected Interface to return '%v', got %v"
,
exp
,
num
.
Interface
())
t
.
Errorf
(
"expected Interface to return '%v', got %v"
,
interExp
,
num
.
Interface
())
}
bytExp
:=
[]
byte
{
1
,
2
,
3
,
4
}
if
bytes
.
Compare
(
byt
.
Bytes
(),
bytExp
)
!=
0
{
t
.
Errorf
(
"expected Bytes to return '%v', got %v"
,
bytExp
,
byt
.
Bytes
())
}
bigExp
:=
big
.
NewInt
(
10
)
if
bigInt
.
BigInt
()
.
Cmp
(
bigExp
)
!=
0
{
t
.
Errorf
(
"expected BigInt to return '%v', got %v"
,
bigExp
,
bigInt
.
BigInt
())
}
}
}
}
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