diff options
-rw-r--r-- | build/ci.go | 2 | ||||
-rw-r--r-- | cmd/geth/chaincmd.go | 1 | ||||
-rw-r--r-- | cmd/swarm/hash.go | 1 | ||||
-rw-r--r-- | core/types/transaction_test.go | 44 |
4 files changed, 46 insertions, 2 deletions
diff --git a/build/ci.go b/build/ci.go index 319691e8a..51540f9b6 100644 --- a/build/ci.go +++ b/build/ci.go @@ -309,7 +309,7 @@ func spellcheck(packages []string) { // Ensure the spellchecker is available build.MustRun(goTool("get", "github.com/client9/misspell/cmd/misspell")) - // Windows chokes on long argument lists, check packages individualy + // Windows chokes on long argument lists, check packages individually for _, pkg := range packages { // The spell checker doesn't work on packages, gather all .go files for it out, err := goTool("list", "-f", "{{.Dir}}{{range .GoFiles}}\n{{.}}{{end}}{{range .CgoFiles}}\n{{.}}{{end}}{{range .TestGoFiles}}\n{{.}}{{end}}", pkg).CombinedOutput() diff --git a/cmd/geth/chaincmd.go b/cmd/geth/chaincmd.go index c77bd554c..f38ee046f 100644 --- a/cmd/geth/chaincmd.go +++ b/cmd/geth/chaincmd.go @@ -123,6 +123,7 @@ func initGenesis(ctx *cli.Context) error { if err != nil { utils.Fatalf("failed to read genesis file: %v", err) } + defer genesisFile.Close() block, err := core.WriteGenesisBlock(chaindb, genesisFile) if err != nil { diff --git a/cmd/swarm/hash.go b/cmd/swarm/hash.go index 0a20bea82..bcba77a2a 100644 --- a/cmd/swarm/hash.go +++ b/cmd/swarm/hash.go @@ -36,6 +36,7 @@ func hash(ctx *cli.Context) { fmt.Println("Error opening file " + args[1]) os.Exit(1) } + defer f.Close() stat, _ := f.Stat() chunker := storage.NewTreeChunker(storage.NewChunkerParams()) diff --git a/core/types/transaction_test.go b/core/types/transaction_test.go index f52f80d34..6e4519c04 100644 --- a/core/types/transaction_test.go +++ b/core/types/transaction_test.go @@ -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()) + } + } +} |