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
a20d3fc3
Commit
a20d3fc3
authored
Apr 22, 2016
by
Paulo L F Casaretto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
common: Add tests for Address#UnmarshalJSON
parent
18580e15
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
3 deletions
+37
-3
types.go
common/types.go
+1
-1
types_test.go
common/types_test.go
+36
-2
No files found.
common/types.go
View file @
a20d3fc3
...
...
@@ -167,7 +167,7 @@ func (a Address) MarshalJSON() ([]byte, error) {
// Parse address from raw json data
func
(
a
*
Address
)
UnmarshalJSON
(
data
[]
byte
)
error
{
if
len
(
data
)
>
2
&&
data
[
0
]
==
'"'
&&
data
[
len
(
data
)
-
1
]
==
'"'
{
data
=
data
[
:
len
(
data
)
-
1
][
1
:
]
data
=
data
[
1
:
len
(
data
)
-
1
]
}
if
len
(
data
)
>
2
&&
data
[
0
]
==
'0'
&&
data
[
1
]
==
'x'
{
...
...
common/types_test.go
View file @
a20d3fc3
...
...
@@ -16,7 +16,10 @@
package
common
import
"testing"
import
(
"math/big"
"testing"
)
func
TestBytesConversion
(
t
*
testing
.
T
)
{
bytes
:=
[]
byte
{
5
}
...
...
@@ -47,7 +50,38 @@ func TestHashJsonValidation(t *testing.T) {
}
for
i
,
test
:=
range
tests
{
if
err
:=
h
.
UnmarshalJSON
(
append
([]
byte
(
test
.
Prefix
),
make
([]
byte
,
test
.
Size
)
...
));
err
!=
test
.
Error
{
t
.
Error
(
i
,
"expected"
,
test
.
Error
,
"got"
,
err
)
t
.
Errorf
(
"test #%d: error mismatch: have %v, want %v"
,
i
,
err
,
test
.
Error
)
}
}
}
func
TestAddressUnmarshalJSON
(
t
*
testing
.
T
)
{
var
a
Address
var
tests
=
[]
struct
{
Input
string
ShouldErr
bool
Output
*
big
.
Int
}{
{
""
,
true
,
nil
},
{
`""`
,
true
,
nil
},
{
`"0x"`
,
true
,
nil
},
{
`"0x00"`
,
true
,
nil
},
{
`"0xG000000000000000000000000000000000000000"`
,
true
,
nil
},
{
`"0x0000000000000000000000000000000000000000"`
,
false
,
big
.
NewInt
(
0
)},
{
`"0x0000000000000000000000000000000000000010"`
,
false
,
big
.
NewInt
(
16
)},
}
for
i
,
test
:=
range
tests
{
err
:=
a
.
UnmarshalJSON
([]
byte
(
test
.
Input
))
if
err
!=
nil
&&
!
test
.
ShouldErr
{
t
.
Errorf
(
"test #%d: unexpected error: %v"
,
i
,
err
)
}
if
err
==
nil
{
if
test
.
ShouldErr
{
t
.
Errorf
(
"test #%d: expected error, got none"
,
i
)
}
if
a
.
Big
()
.
Cmp
(
test
.
Output
)
!=
0
{
t
.
Errorf
(
"test #%d: address mismatch: have %v, want %v"
,
i
,
a
.
Big
(),
test
.
Output
)
}
}
}
}
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