From 34c8045d5be6488e9800c24e1e696e1b912f344c Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 17 Jun 2014 18:05:46 +0200 Subject: Fixed issue where JUMPI would do an equally check with 1 instead of GT --- ethutil/trie_test.go | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) (limited to 'ethutil') diff --git a/ethutil/trie_test.go b/ethutil/trie_test.go index c89f2fbb7..15dbc5567 100644 --- a/ethutil/trie_test.go +++ b/ethutil/trie_test.go @@ -1,7 +1,12 @@ package ethutil import ( + "bytes" + "encoding/json" "fmt" + "io" + "io/ioutil" + "net/http" "reflect" "testing" ) @@ -171,14 +176,34 @@ func TestTriePurge(t *testing.T) { } } +type TestItem struct { + Name string + Inputs [][]string + Expectations string +} + func TestTrieIt(t *testing.T) { - _, trie := New() - trie.Update("c", LONG_WORD) - trie.Update("ca", LONG_WORD) - trie.Update("cat", LONG_WORD) + //_, trie := New() + resp, err := http.Get("https://raw.githubusercontent.com/ethereum/tests/master/trietest.json") + if err != nil { + t.Fail() + } - it := trie.NewIterator() - it.Each(func(key string, node *Value) { - fmt.Println(key, ":", node.Str()) - }) + defer resp.Body.Close() + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + t.Fail() + } + + dec := json.NewDecoder(bytes.NewReader(body)) + for { + var test TestItem + if err := dec.Decode(&test); err == io.EOF { + break + } else if err != nil { + t.Error("Fail something", err) + break + } + fmt.Println(test) + } } -- cgit v1.2.3 From 2fbcfd88249de8f55b7f06619d9003fadcc8e1e3 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 18 Jun 2014 11:55:05 +0200 Subject: Proper checks for multiple data items. Fixes #80 --- ethutil/bytes.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'ethutil') diff --git a/ethutil/bytes.go b/ethutil/bytes.go index bd0df68ec..5e3ee4a6f 100644 --- a/ethutil/bytes.go +++ b/ethutil/bytes.go @@ -5,6 +5,7 @@ import ( "encoding/binary" "fmt" "math/big" + "strings" ) // Number to bytes @@ -91,7 +92,7 @@ func IsHex(str string) bool { } func StringToByteFunc(str string, cb func(str string) []byte) (ret []byte) { - if len(str) > 1 && str[0:2] == "0x" { + if len(str) > 1 && str[0:2] == "0x" && !strings.Contains(str, "\n") { ret = FromHex(str[2:]) } else { ret = cb(str) -- cgit v1.2.3 From 7f94bd09ae5791836d94d4d9efb9e345212e49b6 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 18 Jun 2014 13:47:40 +0200 Subject: Return a single byte if byte get called --- ethutil/value.go | 2 ++ 1 file changed, 2 insertions(+) (limited to 'ethutil') diff --git a/ethutil/value.go b/ethutil/value.go index c86c24a7a..ddd864d8a 100644 --- a/ethutil/value.go +++ b/ethutil/value.go @@ -114,6 +114,8 @@ func (val *Value) Str() string { func (val *Value) Bytes() []byte { if a, ok := val.Val.([]byte); ok { return a + } else if s, ok := val.Val.(byte); ok { + return []byte{s} } return []byte{} -- cgit v1.2.3 From c4af1340fac12397b6cc5c9f32a1bea4aa6400f5 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 18 Jun 2014 13:48:29 +0200 Subject: Updated test --- ethutil/trie_test.go | 44 ++++++++++++++------------------------------ 1 file changed, 14 insertions(+), 30 deletions(-) (limited to 'ethutil') diff --git a/ethutil/trie_test.go b/ethutil/trie_test.go index 15dbc5567..2937b1525 100644 --- a/ethutil/trie_test.go +++ b/ethutil/trie_test.go @@ -1,12 +1,7 @@ package ethutil import ( - "bytes" - "encoding/json" "fmt" - "io" - "io/ioutil" - "net/http" "reflect" "testing" ) @@ -176,34 +171,23 @@ func TestTriePurge(t *testing.T) { } } -type TestItem struct { - Name string - Inputs [][]string - Expectations string -} - func TestTrieIt(t *testing.T) { - //_, trie := New() - resp, err := http.Get("https://raw.githubusercontent.com/ethereum/tests/master/trietest.json") - if err != nil { - t.Fail() - } + _, trie := New() - defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) - if err != nil { - t.Fail() + data := [][]string{ + {"do", "verb"}, + {"ether", "wookiedoo"}, + {"horse", "stallion"}, + {"shaman", "horse"}, + {"doge", "coin"}, + {"ether", ""}, + {"dog", "puppy"}, + {"shaman", ""}, } - dec := json.NewDecoder(bytes.NewReader(body)) - for { - var test TestItem - if err := dec.Decode(&test); err == io.EOF { - break - } else if err != nil { - t.Error("Fail something", err) - break - } - fmt.Println(test) + for _, item := range data { + trie.Update(item[0], item[1]) } + + fmt.Printf("root %x", trie.Root) } -- cgit v1.2.3 From 7ad073fb30e92689942d938939223bd01cb5fe38 Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 20 Jun 2014 00:47:50 +0200 Subject: bump --- ethutil/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethutil') diff --git a/ethutil/config.go b/ethutil/config.go index a24c39bfe..a573e108b 100644 --- a/ethutil/config.go +++ b/ethutil/config.go @@ -75,7 +75,7 @@ func ReadConfig(base string, logTypes LoggerType, g *globalconf.GlobalConf, id s if Config == nil { path := ApplicationFolder(base) - Config = &config{ExecPath: path, Debug: true, Ver: "0.5.13"} + Config = &config{ExecPath: path, Debug: true, Ver: "0.5.14"} Config.conf = g Config.Identifier = id Config.Log = NewLogger(logTypes, LogLevelDebug) -- cgit v1.2.3