2014-02-15 14:21:11 +02:00
|
|
|
package ethutil
|
|
|
|
|
|
|
|
import (
|
2014-02-16 21:30:33 +02:00
|
|
|
"bytes"
|
|
|
|
"math/big"
|
2014-02-15 14:21:11 +02:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestValueCmp(t *testing.T) {
|
|
|
|
val1 := NewValue("hello")
|
|
|
|
val2 := NewValue("world")
|
|
|
|
if val1.Cmp(val2) {
|
|
|
|
t.Error("Expected values not to be equal")
|
|
|
|
}
|
|
|
|
|
|
|
|
val3 := NewValue("hello")
|
|
|
|
val4 := NewValue("hello")
|
|
|
|
if !val3.Cmp(val4) {
|
|
|
|
t.Error("Expected values to be equal")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestValueTypes(t *testing.T) {
|
|
|
|
str := NewValue("str")
|
|
|
|
num := NewValue(1)
|
|
|
|
inter := NewValue([]interface{}{1})
|
2014-02-16 21:30:33 +02:00
|
|
|
byt := NewValue([]byte{1, 2, 3, 4})
|
|
|
|
bigInt := NewValue(big.NewInt(10))
|
2014-02-15 14:21:11 +02:00
|
|
|
|
|
|
|
if str.Str() != "str" {
|
|
|
|
t.Errorf("expected Str to return 'str', got %s", str.Str())
|
|
|
|
}
|
|
|
|
|
|
|
|
if num.Uint() != 1 {
|
|
|
|
t.Errorf("expected Uint to return '1', got %d", num.Uint())
|
|
|
|
}
|
|
|
|
|
2014-02-16 21:30:33 +02:00
|
|
|
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())
|
2014-02-15 14:21:11 +02:00
|
|
|
}
|
|
|
|
}
|