aboutsummaryrefslogtreecommitdiffstats
path: root/ethutil
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-02-17 03:30:33 +0800
committerobscuren <geffobscura@gmail.com>2014-02-17 03:30:33 +0800
commitc95a27e39485eeeebd8608537115a4fd246c246c (patch)
tree96545c7ff18382da5c672fcc496e95f7da1864ea /ethutil
parent066940f134170ab4b0901887b69f824418c322fc (diff)
downloaddexon-c95a27e39485eeeebd8608537115a4fd246c246c.tar
dexon-c95a27e39485eeeebd8608537115a4fd246c246c.tar.gz
dexon-c95a27e39485eeeebd8608537115a4fd246c246c.tar.bz2
dexon-c95a27e39485eeeebd8608537115a4fd246c246c.tar.lz
dexon-c95a27e39485eeeebd8608537115a4fd246c246c.tar.xz
dexon-c95a27e39485eeeebd8608537115a4fd246c246c.tar.zst
dexon-c95a27e39485eeeebd8608537115a4fd246c246c.zip
Added more tests
Diffstat (limited to 'ethutil')
-rw-r--r--ethutil/value.go12
-rw-r--r--ethutil/value_test.go20
2 files changed, 24 insertions, 8 deletions
diff --git a/ethutil/value.go b/ethutil/value.go
index f91c33983..701ece5bb 100644
--- a/ethutil/value.go
+++ b/ethutil/value.go
@@ -84,6 +84,8 @@ func (val *Value) BigInt() *big.Int {
b := new(big.Int).SetBytes(a)
return b
+ } else if a, ok := val.Val.(*big.Int); ok {
+ return a
} else {
return big.NewInt(int64(val.Uint()))
}
@@ -106,7 +108,7 @@ func (val *Value) Bytes() []byte {
return a
}
- return make([]byte, 0)
+ return []byte{}
}
func (val *Value) Slice() []interface{} {
@@ -144,7 +146,7 @@ func (val *Value) Get(idx int) *Value {
}
if idx < 0 {
- panic("negative idx for Rlp Get")
+ panic("negative idx for Value Get")
}
return NewValue(d[idx])
@@ -162,9 +164,9 @@ func (val *Value) Encode() []byte {
return Encode(val.Val)
}
-func NewValueFromBytes(rlpData []byte) *Value {
- if len(rlpData) != 0 {
- data, _ := Decode(rlpData, 0)
+func NewValueFromBytes(data []byte) *Value {
+ if len(data) != 0 {
+ data, _ := Decode(data, 0)
return NewValue(data)
}
diff --git a/ethutil/value_test.go b/ethutil/value_test.go
index 7d41eb1c9..0e2da5328 100644
--- a/ethutil/value_test.go
+++ b/ethutil/value_test.go
@@ -1,6 +1,8 @@
package ethutil
import (
+ "bytes"
+ "math/big"
"testing"
)
@@ -22,6 +24,8 @@ func TestValueTypes(t *testing.T) {
str := NewValue("str")
num := NewValue(1)
inter := NewValue([]interface{}{1})
+ byt := NewValue([]byte{1, 2, 3, 4})
+ bigInt := NewValue(big.NewInt(10))
if str.Str() != "str" {
t.Errorf("expected Str to return 'str', got %s", str.Str())
@@ -31,8 +35,18 @@ func TestValueTypes(t *testing.T) {
t.Errorf("expected Uint to return '1', got %d", num.Uint())
}
- exp := []interface{}{1}
- if !NewValue(inter.Interface()).Cmp(NewValue(exp)) {
- t.Errorf("expected Interface to return '%v', got %v", exp, num.Interface())
+ interExp := []interface{}{1}
+ if !NewValue(inter.Interface()).Cmp(NewValue(interExp)) {
+ t.Errorf("expected Interface to return '%v', got %v", interExp, num.Interface())
+ }
+
+ bytExp := []byte{1, 2, 3, 4}
+ if bytes.Compare(byt.Bytes(), bytExp) != 0 {
+ t.Errorf("expected Bytes to return '%v', got %v", bytExp, byt.Bytes())
+ }
+
+ bigExp := big.NewInt(10)
+ if bigInt.BigInt().Cmp(bigExp) != 0 {
+ t.Errorf("expected BigInt to return '%v', got %v", bigExp, bigInt.BigInt())
}
}