aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorobscuren <obscuren@obscura.com>2014-01-01 22:49:38 +0800
committerobscuren <obscuren@obscura.com>2014-01-01 22:49:38 +0800
commit5b3d4fae6e03e5471a10c653fc0b016cc5e5dcfa (patch)
treeafddcdcfbc1eac391b2619af9fcb1663032edaaf
parent61d67f2ae965a9a1113084f2352e2c2dd97ab9a7 (diff)
downloadgo-tangerine-5b3d4fae6e03e5471a10c653fc0b016cc5e5dcfa.tar
go-tangerine-5b3d4fae6e03e5471a10c653fc0b016cc5e5dcfa.tar.gz
go-tangerine-5b3d4fae6e03e5471a10c653fc0b016cc5e5dcfa.tar.bz2
go-tangerine-5b3d4fae6e03e5471a10c653fc0b016cc5e5dcfa.tar.lz
go-tangerine-5b3d4fae6e03e5471a10c653fc0b016cc5e5dcfa.tar.xz
go-tangerine-5b3d4fae6e03e5471a10c653fc0b016cc5e5dcfa.tar.zst
go-tangerine-5b3d4fae6e03e5471a10c653fc0b016cc5e5dcfa.zip
Work in progress external test runner
-rw-r--r--db_query_interface.go12
-rw-r--r--test_runner.go35
-rw-r--r--test_runner_test.go31
3 files changed, 75 insertions, 3 deletions
diff --git a/db_query_interface.go b/db_query_interface.go
index 572dd6684..11137e4c2 100644
--- a/db_query_interface.go
+++ b/db_query_interface.go
@@ -68,12 +68,18 @@ func (i *DbInterface) ParseInput(input string) bool {
fmt.Println(hex.EncodeToString([]byte(i.trie.root)))
case "get":
fmt.Println(i.trie.Get(tokens[1]))
+ case "root":
+ fmt.Println(hex.EncodeToString([]byte(i.trie.root)))
+ case "rawroot":
+ fmt.Println(i.trie.root)
case "exit", "quit", "q":
return false
case "help":
- fmt.Println(`query commands:
-update KEY VALUE
-get KEY
+ fmt.Printf(`QUERY COMMANDS:
+update KEY VALUE - Updates/Creates a new value for the given key
+get KEY - Retrieves the given key
+root - Prints the hex encoded merkle root
+rawroot - Prints the raw merkle root
`)
default:
fmt.Println("Unknown command:", tokens[0])
diff --git a/test_runner.go b/test_runner.go
new file mode 100644
index 000000000..da93533dd
--- /dev/null
+++ b/test_runner.go
@@ -0,0 +1,35 @@
+package main
+
+import (
+ "fmt"
+ "testing"
+ "encoding/json"
+)
+
+type TestSource struct {
+ Inputs map[string]string
+ Expectation string
+}
+
+func NewTestSource(source string) *TestSource {
+ s := &TestSource{}
+ err := json.Unmarshal([]byte(source), s)
+ if err != nil {
+ fmt.Println(err)
+ }
+
+ return s
+}
+
+type TestRunner struct {
+ source *TestSource
+}
+
+func NewTestRunner(t *testing.T) *TestRunner {
+ return &TestRunner{}
+}
+
+func (runner *TestRunner) RunFromString(input string, Cb func(*TestSource)) {
+ source := NewTestSource(input)
+ Cb(source)
+}
diff --git a/test_runner_test.go b/test_runner_test.go
new file mode 100644
index 000000000..190bf3caf
--- /dev/null
+++ b/test_runner_test.go
@@ -0,0 +1,31 @@
+package main
+
+import (
+ _"fmt"
+ "testing"
+ "encoding/hex"
+)
+
+var testsource = `{"Inputs":{
+ "doe": "reindeer",
+ "dog": "puppy",
+ "dogglesworth": "cat"
+ },
+ "Expectation":"e378927bfc1bd4f01a2e8d9f59bd18db8a208bb493ac0b00f93ce51d4d2af76c"
+}`
+
+func TestTestRunner(t *testing.T) {
+ db, _ := NewMemDatabase()
+ trie := NewTrie(db, "")
+
+ runner := NewTestRunner(t)
+ runner.RunFromString(testsource, func(source *TestSource) {
+ for key, value := range source.Inputs {
+ trie.Update(key, value)
+ }
+
+ if hex.EncodeToString([]byte(trie.root)) != source.Expectation {
+ t.Error("trie root did not match")
+ }
+ })
+}