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
c453f1f3
Commit
c453f1f3
authored
Apr 17, 2015
by
Felix Lange
Committed by
Gustav Simonsson
Apr 18, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests: hopefully improve test conversion helpers
(cherry picked from commit 035a30acbefb5eeadc1fc8dbd567775d5688f8a9)
parent
235ed7ec
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
30 deletions
+35
-30
blocktest.go
tests/blocktest.go
+30
-25
transaction_test_util.go
tests/transaction_test_util.go
+5
-5
No files found.
tests/blocktest.go
View file @
c453f1f3
...
...
@@ -211,13 +211,13 @@ func mustConvertHeader(in btHeader) *types.Header {
UncleHash
:
mustConvertHash
(
in
.
UncleHash
),
ParentHash
:
mustConvertHash
(
in
.
ParentHash
),
Extra
:
mustConvertBytes
(
in
.
ExtraData
),
GasUsed
:
mustConvertBigInt
(
in
.
GasUsed
),
GasLimit
:
mustConvertBigInt
(
in
.
GasLimit
),
Difficulty
:
mustConvertBigInt
(
in
.
Difficulty
),
Time
:
mustConvertUint
(
in
.
Timestamp
),
GasUsed
:
mustConvertBigInt
(
in
.
GasUsed
,
10
),
GasLimit
:
mustConvertBigInt
(
in
.
GasLimit
,
10
),
Difficulty
:
mustConvertBigInt
(
in
.
Difficulty
,
10
),
Time
:
mustConvertUint
(
in
.
Timestamp
,
10
),
}
// XXX cheats? :-)
header
.
SetNonce
(
common
.
BytesToHash
(
mustConvertBytes
(
in
.
Nonce
))
.
Big
()
.
Uint64
(
))
header
.
SetNonce
(
mustConvertUint
(
in
.
Nonce
,
16
))
return
header
}
...
...
@@ -238,7 +238,7 @@ func mustConvertBytes(in string) []byte {
if
in
==
"0x"
{
return
[]
byte
{}
}
h
:=
strings
.
TrimPrefix
(
unfuckCPPHexInts
(
in
),
"0x"
)
h
:=
nibbleFix
(
strings
.
TrimPrefix
(
in
,
"0x"
)
)
out
,
err
:=
hex
.
DecodeString
(
h
)
if
err
!=
nil
{
panic
(
fmt
.
Errorf
(
"invalid hex: %q"
,
h
))
...
...
@@ -255,7 +255,7 @@ func mustConvertHash(in string) common.Hash {
}
func
mustConvertAddress
(
in
string
)
common
.
Address
{
out
,
err
:=
hex
.
DecodeString
(
strings
.
TrimPrefix
(
in
,
"0x"
))
out
,
err
:=
hex
.
DecodeString
(
nibbleFix
(
strings
.
TrimPrefix
(
in
,
"0x"
)
))
if
err
!=
nil
{
panic
(
fmt
.
Errorf
(
"invalid hex: %q"
,
in
))
}
...
...
@@ -270,16 +270,18 @@ func mustConvertBloom(in string) types.Bloom {
return
types
.
BytesToBloom
(
out
)
}
func
mustConvertBigInt
(
in
string
)
*
big
.
Int
{
out
,
ok
:=
new
(
big
.
Int
)
.
SetString
(
unfuckCPPHexInts
(
in
),
0
)
func
mustConvertBigInt
(
in
string
,
base
int
)
*
big
.
Int
{
in
=
prepInt
(
base
,
in
)
out
,
ok
:=
new
(
big
.
Int
)
.
SetString
(
in
,
base
)
if
!
ok
{
panic
(
fmt
.
Errorf
(
"invalid integer: %q"
,
in
))
}
return
out
}
func
mustConvertUint
(
in
string
)
uint64
{
out
,
err
:=
strconv
.
ParseUint
(
unfuckCPPHexInts
(
in
),
0
,
64
)
func
mustConvertUint
(
in
string
,
base
int
)
uint64
{
in
=
prepInt
(
base
,
in
)
out
,
err
:=
strconv
.
ParseUint
(
in
,
base
,
64
)
if
err
!=
nil
{
panic
(
fmt
.
Errorf
(
"invalid integer: %q"
,
in
))
}
...
...
@@ -316,19 +318,22 @@ func findLine(data []byte, offset int64) (line int) {
return
}
func
unfuckCPPHexInts
(
s
string
)
string
{
switch
{
case
s
==
"0x"
:
// no respect for the empty value :(
return
"0x00"
case
len
(
s
)
==
0
:
return
"0x00"
case
len
(
s
)
==
1
:
return
"0x0"
+
s
[
:
1
]
case
len
(
s
)
%
2
!=
0
:
// motherfucking nibbles
return
"0x0"
+
s
[
2
:
]
default
:
return
s
func
prepInt
(
base
int
,
s
string
)
string
{
if
base
==
16
{
if
strings
.
HasPrefix
(
s
,
"0x"
)
{
s
=
s
[
2
:
]
}
if
len
(
s
)
==
0
{
s
=
"00"
}
s
=
nibbleFix
(
s
)
}
return
s
}
func
nibbleFix
(
s
string
)
string
{
if
len
(
s
)
%
2
!=
0
{
s
=
"0"
+
s
}
return
s
}
tests/transaction_test_util.go
View file @
c453f1f3
...
...
@@ -127,15 +127,15 @@ func convertTestTypes(txTest TransactionTest) (sender, to common.Address,
txInputData
=
mustConvertBytes
(
txTest
.
Transaction
.
Data
)
rlpBytes
=
mustConvertBytes
(
txTest
.
Rlp
)
gasLimit
=
mustConvertBigInt
(
txTest
.
Transaction
.
GasLimit
)
gasPrice
=
mustConvertBigInt
(
txTest
.
Transaction
.
GasPrice
)
value
=
mustConvertBigInt
(
txTest
.
Transaction
.
Value
)
gasLimit
=
mustConvertBigInt
(
txTest
.
Transaction
.
GasLimit
,
16
)
gasPrice
=
mustConvertBigInt
(
txTest
.
Transaction
.
GasPrice
,
16
)
value
=
mustConvertBigInt
(
txTest
.
Transaction
.
Value
,
16
)
r
=
common
.
Bytes2Big
(
mustConvertBytes
(
txTest
.
Transaction
.
R
))
s
=
common
.
Bytes2Big
(
mustConvertBytes
(
txTest
.
Transaction
.
S
))
nonce
=
mustConvertUint
(
txTest
.
Transaction
.
Nonce
)
v
=
mustConvertUint
(
txTest
.
Transaction
.
V
)
nonce
=
mustConvertUint
(
txTest
.
Transaction
.
Nonce
,
16
)
v
=
mustConvertUint
(
txTest
.
Transaction
.
V
,
16
)
return
sender
,
to
,
txInputData
,
rlpBytes
,
gasLimit
,
gasPrice
,
value
,
r
,
s
,
nonce
,
v
,
nil
}
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