mirror of https://github.com/ethereum/go-ethereum
parent
61d67f2ae9
commit
5b3d4fae6e
@ -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) |
||||
} |
@ -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") |
||||
} |
||||
}) |
||||
} |
Loading…
Reference in new issue