mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 14:46:42 +00:00
Merge branch 'master' of https://github.com/ethereum/go-ethereum into 3498
This commit is contained in:
commit
799caf8289
2 changed files with 44 additions and 2 deletions
|
|
@ -853,7 +853,7 @@ func (self *BlockChain) WriteBlock(block *types.Block) (status WriteStatus, err
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// InsertChain will attempt to insert the given chain in to the canonical chain or, otherwise, create a fork. It an error is returned
|
// InsertChain will attempt to insert the given chain in to the canonical chain or, otherwise, create a fork. If an error is returned
|
||||||
// it will return the index number of the failing block as well an error describing what went wrong (for possible errors see core/errors.go).
|
// it will return the index number of the failing block as well an error describing what went wrong (for possible errors see core/errors.go).
|
||||||
func (self *BlockChain) InsertChain(chain types.Blocks) (int, error) {
|
func (self *BlockChain) InsertChain(chain types.Blocks) (int, error) {
|
||||||
// Do a sanity check that the provided chain is actually ordered and linked
|
// Do a sanity check that the provided chain is actually ordered and linked
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ package types
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
|
"encoding/json"
|
||||||
"math/big"
|
"math/big"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
|
@ -29,7 +30,6 @@ import (
|
||||||
|
|
||||||
// The values in those tests are from the Transaction Tests
|
// The values in those tests are from the Transaction Tests
|
||||||
// at github.com/ethereum/tests.
|
// at github.com/ethereum/tests.
|
||||||
|
|
||||||
var (
|
var (
|
||||||
emptyTx = NewTransaction(
|
emptyTx = NewTransaction(
|
||||||
0,
|
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())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue