aboutsummaryrefslogtreecommitdiffstats
path: root/rpc/types_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'rpc/types_test.go')
-rw-r--r--rpc/types_test.go154
1 files changed, 154 insertions, 0 deletions
diff --git a/rpc/types_test.go b/rpc/types_test.go
index 91f0152dc..9ef7b8d38 100644
--- a/rpc/types_test.go
+++ b/rpc/types_test.go
@@ -1,7 +1,13 @@
package rpc
import (
+ "bytes"
+ "encoding/json"
+ "math/big"
"testing"
+
+ "github.com/ethereum/go-ethereum/common"
+ "github.com/ethereum/go-ethereum/core/types"
)
func TestInvalidTypeError(t *testing.T) {
@@ -48,3 +54,151 @@ func TestValidationError(t *testing.T) {
t.Error(err.Error())
}
}
+
+func TestHexdataMarshalNil(t *testing.T) {
+ hd := newHexData([]byte{})
+ hd.isNil = true
+ v, _ := json.Marshal(hd)
+ if string(v) != "null" {
+ t.Errorf("Expected null, got %s", v)
+ }
+}
+
+func TestHexnumMarshalNil(t *testing.T) {
+ hn := newHexNum([]byte{})
+ hn.isNil = true
+ v, _ := json.Marshal(hn)
+ if string(v) != "null" {
+ t.Errorf("Expected null, got %s", v)
+ }
+}
+
+func TestHexdataNil(t *testing.T) {
+ v := newHexData(nil)
+ if v.isNil != true {
+ t.Errorf("Expected isNil to be true, but is %v", v.isNil)
+ }
+}
+
+func TestHexdataPtrHash(t *testing.T) {
+ in := common.Hash{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}
+ v := newHexData(&in)
+ if bytes.Compare(in.Bytes(), v.data) != 0 {
+ t.Errorf("Got % x expected % x", in, v.data)
+ }
+}
+
+func TestHexdataPtrHashNil(t *testing.T) {
+ var in *common.Hash
+ in = nil
+ v := newHexData(in)
+ if !v.isNil {
+ t.Errorf("Expect isNil to be true, but is %v", v.isNil)
+ }
+}
+
+func TestHexdataPtrAddress(t *testing.T) {
+ in := common.Address{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19}
+ v := newHexData(&in)
+ if bytes.Compare(in.Bytes(), v.data) != 0 {
+ t.Errorf("Got % x expected % x", in, v.data)
+ }
+}
+
+func TestHexdataPtrAddressNil(t *testing.T) {
+ var in *common.Address
+ in = nil
+ v := newHexData(in)
+ if !v.isNil {
+ t.Errorf("Expect isNil to be true, but is %v", v.isNil)
+ }
+}
+
+func TestHexdataPtrBloom(t *testing.T) {
+ in := types.Bloom{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19}
+ v := newHexData(&in)
+ if bytes.Compare(in.Bytes(), v.data) != 0 {
+ t.Errorf("Got % x expected % x", in, v.data)
+ }
+}
+
+func TestHexdataPtrBloomNil(t *testing.T) {
+ var in *types.Bloom
+ in = nil
+ v := newHexData(in)
+ if !v.isNil {
+ t.Errorf("Expect isNil to be true, but is %v", v.isNil)
+ }
+}
+
+func TestHexdataBigintNil(t *testing.T) {
+ var in *big.Int
+ in = nil
+ v := newHexData(in)
+ if !v.isNil {
+ t.Errorf("Expect isNil to be true, but is %v", v.isNil)
+ }
+}
+
+func TestHexdataUint(t *testing.T) {
+ var in = uint(16)
+ var expected = []byte{0x10}
+ v := newHexData(in)
+ if bytes.Compare(expected, v.data) != 0 {
+ t.Errorf("Expected % x got % x", expected, v.data)
+ }
+}
+
+func TestHexdataInt8(t *testing.T) {
+ var in = int8(16)
+ var expected = []byte{0x10}
+ v := newHexData(in)
+ if bytes.Compare(expected, v.data) != 0 {
+ t.Errorf("Expected % x got % x", expected, v.data)
+ }
+}
+
+func TestHexdataUint8(t *testing.T) {
+ var in = uint8(16)
+ var expected = []byte{0x10}
+ v := newHexData(in)
+ if bytes.Compare(expected, v.data) != 0 {
+ t.Errorf("Expected % x got % x", expected, v.data)
+ }
+}
+
+func TestHexdataInt16(t *testing.T) {
+ var in = int16(16)
+ var expected = []byte{0x10}
+ v := newHexData(in)
+ if bytes.Compare(expected, v.data) != 0 {
+ t.Errorf("Expected % x got % x", expected, v.data)
+ }
+}
+
+func TestHexdataUint16(t *testing.T) {
+ var in = uint16(16)
+ var expected = []byte{0x0, 0x10}
+ v := newHexData(in)
+ if bytes.Compare(expected, v.data) != 0 {
+ t.Errorf("Expected % x got % x", expected, v.data)
+ }
+}
+
+func TestHexdataInt32(t *testing.T) {
+ var in = int32(16)
+ var expected = []byte{0x10}
+ v := newHexData(in)
+ if bytes.Compare(expected, v.data) != 0 {
+ t.Errorf("Expected % x got % x", expected, v.data)
+ }
+}
+
+func TestHexdataUint32(t *testing.T) {
+ var in = uint32(16)
+ var expected = []byte{0x0, 0x0, 0x0, 0x10}
+ v := newHexData(in)
+ if bytes.Compare(expected, v.data) != 0 {
+ t.Errorf("Expected % x got % x", expected, v.data)
+ }
+}