aboutsummaryrefslogtreecommitdiffstats
path: root/core/types/json_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'core/types/json_test.go')
-rw-r--r--core/types/json_test.go77
1 files changed, 77 insertions, 0 deletions
diff --git a/core/types/json_test.go b/core/types/json_test.go
index 5f422b873..605c2b564 100644
--- a/core/types/json_test.go
+++ b/core/types/json_test.go
@@ -2,6 +2,7 @@ package types
import (
"encoding/json"
+ "reflect"
"testing"
"github.com/ethereum/go-ethereum/common"
@@ -44,6 +45,31 @@ func TestUnmarshalHeader(t *testing.T) {
}
}
+func TestMarshalHeader(t *testing.T) {
+ for name, test := range unmarshalHeaderTests {
+ if test.wantError != nil {
+ continue
+ }
+ var original *Header
+ json.Unmarshal([]byte(test.input), &original)
+
+ blob, err := json.Marshal(original)
+ if err != nil {
+ t.Errorf("test %q: failed to marshal header: %v", name, err)
+ continue
+ }
+ var proced *Header
+ if err := json.Unmarshal(blob, &proced); err != nil {
+ t.Errorf("Test %q: failed to unmarshal marhsalled header: %v", name, err)
+ continue
+ }
+ if !reflect.DeepEqual(original, proced) {
+ t.Errorf("test %q: header mismatch: have %+v, want %+v", name, proced, original)
+ continue
+ }
+ }
+}
+
var unmarshalTransactionTests = map[string]struct {
input string
wantHash common.Hash
@@ -94,6 +120,32 @@ func TestUnmarshalTransaction(t *testing.T) {
}
}
+func TestMarshalTransaction(t *testing.T) {
+ for name, test := range unmarshalTransactionTests {
+ if test.wantError != nil {
+ continue
+ }
+ var original *Transaction
+ json.Unmarshal([]byte(test.input), &original)
+
+ blob, err := json.Marshal(original)
+ if err != nil {
+ t.Errorf("test %q: failed to marshal transaction: %v", name, err)
+ continue
+ }
+ var proced *Transaction
+ if err := json.Unmarshal(blob, &proced); err != nil {
+ t.Errorf("Test %q: failed to unmarshal marhsalled transaction: %v", name, err)
+ continue
+ }
+ proced.Hash() // hack private fields to pass deep equal
+ if !reflect.DeepEqual(original, proced) {
+ t.Errorf("test %q: transaction mismatch: have %+v, want %+v", name, proced, original)
+ continue
+ }
+ }
+}
+
var unmarshalReceiptTests = map[string]struct {
input string
wantError error
@@ -119,6 +171,31 @@ func TestUnmarshalReceipt(t *testing.T) {
}
}
+func TestMarshalReceipt(t *testing.T) {
+ for name, test := range unmarshalReceiptTests {
+ if test.wantError != nil {
+ continue
+ }
+ var original *Receipt
+ json.Unmarshal([]byte(test.input), &original)
+
+ blob, err := json.Marshal(original)
+ if err != nil {
+ t.Errorf("test %q: failed to marshal receipt: %v", name, err)
+ continue
+ }
+ var proced *Receipt
+ if err := json.Unmarshal(blob, &proced); err != nil {
+ t.Errorf("Test %q: failed to unmarshal marhsalled receipt: %v", name, err)
+ continue
+ }
+ if !reflect.DeepEqual(original, proced) {
+ t.Errorf("test %q: receipt mismatch: have %+v, want %+v", name, proced, original)
+ continue
+ }
+ }
+}
+
func checkError(t *testing.T, testname string, got, want error) bool {
if got == nil {
if want != nil {