From 07c12f0b921a05aec668ae8ce63b6dfac51d76a6 Mon Sep 17 00:00:00 2001 From: obscuren Date: Sat, 15 Feb 2014 13:21:11 +0100 Subject: Added trie tests, value tests --- ethutil/value_test.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 ethutil/value_test.go (limited to 'ethutil/value_test.go') diff --git a/ethutil/value_test.go b/ethutil/value_test.go new file mode 100644 index 000000000..7d41eb1c9 --- /dev/null +++ b/ethutil/value_test.go @@ -0,0 +1,38 @@ +package ethutil + +import ( + "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}) + + 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()) + } + + exp := []interface{}{1} + if !NewValue(inter.Interface()).Cmp(NewValue(exp)) { + t.Errorf("expected Interface to return '%v', got %v", exp, num.Interface()) + } +} -- cgit From c95a27e39485eeeebd8608537115a4fd246c246c Mon Sep 17 00:00:00 2001 From: obscuren Date: Sun, 16 Feb 2014 20:30:33 +0100 Subject: Added more tests --- ethutil/value_test.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'ethutil/value_test.go') 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()) } } -- cgit From 92f2abdf769f52ea8e5e6d02bf326744e926f5b4 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 5 Mar 2014 10:42:51 +0100 Subject: Partially refactored server/txpool/block manager/block chain The Ethereum structure now complies to a EthManager interface which is being used by the tx pool, block manager and block chain in order to gain access to each other. It's become simpeler. TODO: BlockManager => StateManager --- ethutil/value_test.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'ethutil/value_test.go') diff --git a/ethutil/value_test.go b/ethutil/value_test.go index 0e2da5328..a100f44bc 100644 --- a/ethutil/value_test.go +++ b/ethutil/value_test.go @@ -50,3 +50,16 @@ func TestValueTypes(t *testing.T) { t.Errorf("expected BigInt to return '%v', got %v", bigExp, bigInt.BigInt()) } } + +func TestIterator(t *testing.T) { + value := NewValue([]interface{}{1, 2, 3}) + it := value.NewIterator() + values := []uint64{1, 2, 3} + i := 0 + for it.Next() { + if values[i] != it.Value().Uint() { + t.Errorf("Expected %d, got %d", values[i], it.Value().Uint()) + } + i++ + } +} -- cgit From 8e7c4f91e33bd99d3a4d320cdc59cf0bab3831b6 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 29 Jul 2014 10:33:30 +0200 Subject: Added ops --- ethutil/value_test.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'ethutil/value_test.go') diff --git a/ethutil/value_test.go b/ethutil/value_test.go index a100f44bc..710cbd887 100644 --- a/ethutil/value_test.go +++ b/ethutil/value_test.go @@ -63,3 +63,18 @@ func TestIterator(t *testing.T) { i++ } } + +func TestMath(t *testing.T) { + a := NewValue(1) + a.Add(1).Add(1) + + if !a.DeepCmp(NewValue(3)) { + t.Error("Expected 3, got", a) + } + + a = NewValue(2) + a.Sub(1).Sub(1) + if !a.DeepCmp(NewValue(0)) { + t.Error("Expected 0, got", a) + } +} -- cgit From 10564723b9ffa14904907a0ebc984fa25e4f1eab Mon Sep 17 00:00:00 2001 From: obscuren Date: Sat, 13 Sep 2014 13:14:24 +0200 Subject: added string casting --- ethutil/value_test.go | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'ethutil/value_test.go') diff --git a/ethutil/value_test.go b/ethutil/value_test.go index 710cbd887..5452a0790 100644 --- a/ethutil/value_test.go +++ b/ethutil/value_test.go @@ -2,6 +2,7 @@ package ethutil import ( "bytes" + "fmt" "math/big" "testing" ) @@ -78,3 +79,8 @@ func TestMath(t *testing.T) { t.Error("Expected 0, got", a) } } + +func TestString(t *testing.T) { + a := NewValue("10") + fmt.Println("VALUE WITH STRING:", a.Int()) +} -- cgit