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
c46c41ea
Commit
c46c41ea
authored
Jan 26, 2017
by
bas-vk
Committed by
Felix Lange
Jan 26, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core/types: add unittest for tx json serialization (#3609)
parent
82aa5b1d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
1 deletion
+43
-1
transaction_test.go
core/types/transaction_test.go
+43
-1
No files found.
core/types/transaction_test.go
View file @
c46c41ea
...
...
@@ -19,6 +19,7 @@ package types
import
(
"bytes"
"crypto/ecdsa"
"encoding/json"
"math/big"
"testing"
...
...
@@ -29,7 +30,6 @@ import (
// The values in those tests are from the Transaction Tests
// at github.com/ethereum/tests.
var
(
emptyTx
=
NewTransaction
(
0
,
...
...
@@ -190,3 +190,45 @@ func TestTransactionPriceNonceSort(t *testing.T) {
}
}
}
// TestTransactionJSON tests serializing/de-serializing to/from JSON.
func
TestTransactionJSON
(
t
*
testing
.
T
)
{
key
,
err
:=
crypto
.
GenerateKey
()
if
err
!=
nil
{
t
.
Fatalf
(
"could not generate key: %v"
,
err
)
}
signer
:=
NewEIP155Signer
(
common
.
Big1
)
for
i
:=
uint64
(
0
);
i
<
25
;
i
++
{
var
tx
*
Transaction
switch
i
%
2
{
case
0
:
tx
=
NewTransaction
(
i
,
common
.
Address
{
1
},
common
.
Big0
,
common
.
Big1
,
common
.
Big2
,
[]
byte
(
"abcdef"
))
case
1
:
tx
=
NewContractCreation
(
i
,
common
.
Big0
,
common
.
Big1
,
common
.
Big2
,
[]
byte
(
"abcdef"
))
}
tx
,
err
:=
SignTx
(
tx
,
signer
,
key
)
if
err
!=
nil
{
t
.
Fatalf
(
"could not sign transaction: %v"
,
err
)
}
data
,
err
:=
json
.
Marshal
(
tx
)
if
err
!=
nil
{
t
.
Errorf
(
"json.Marshal failed: %v"
,
err
)
}
var
parsedTx
*
Transaction
if
err
:=
json
.
Unmarshal
(
data
,
&
parsedTx
);
err
!=
nil
{
t
.
Errorf
(
"json.Unmarshal failed: %v"
,
err
)
}
// compare nonce, price, gaslimit, recipient, amount, payload, V, R, S
if
tx
.
Hash
()
!=
parsedTx
.
Hash
()
{
t
.
Errorf
(
"parsed tx differs from original tx, want %v, got %v"
,
tx
,
parsedTx
)
}
if
tx
.
ChainId
()
.
Cmp
(
parsedTx
.
ChainId
())
!=
0
{
t
.
Errorf
(
"invalid chain id, want %d, got %d"
,
tx
.
ChainId
(),
parsedTx
.
ChainId
())
}
}
}
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