mirror of https://github.com/ethereum/go-ethereum
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
988 B
52 lines
988 B
11 years ago
|
package main
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
11 years ago
|
"encoding/hex"
|
||
11 years ago
|
)
|
||
|
|
||
|
func TestTriePut(t *testing.T) {
|
||
|
db, err := NewMemDatabase()
|
||
11 years ago
|
trie := NewTrie(db, "")
|
||
11 years ago
|
|
||
|
if err != nil {
|
||
|
t.Error("Error starting db")
|
||
|
}
|
||
|
|
||
11 years ago
|
key := trie.Put([]byte("testing node"))
|
||
11 years ago
|
|
||
|
data, err := db.Get(key)
|
||
|
if err != nil {
|
||
|
t.Error("Nothing at node")
|
||
|
}
|
||
|
|
||
|
s, _ := Decode(data, 0)
|
||
|
if str, ok := s.([]byte); ok {
|
||
|
if string(str) != "testing node" {
|
||
|
t.Error("Wrong value node", str)
|
||
|
}
|
||
|
} else {
|
||
|
t.Error("Invalid return type")
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestTrieUpdate(t *testing.T) {
|
||
|
db, err := NewMemDatabase()
|
||
11 years ago
|
trie := NewTrie(db, "")
|
||
11 years ago
|
|
||
|
if err != nil {
|
||
|
t.Error("Error starting db")
|
||
|
}
|
||
|
|
||
11 years ago
|
|
||
|
trie.Update("doe", "reindeer")
|
||
|
trie.Update("dog", "puppy")
|
||
|
trie.Update("dogglesworth", "cat")
|
||
|
root := hex.EncodeToString([]byte(trie.root))
|
||
|
req := "e378927bfc1bd4f01a2e8d9f59bd18db8a208bb493ac0b00f93ce51d4d2af76c"
|
||
|
if root != req {
|
||
|
t.Error("trie.root do not match, expected", req, "got", root)
|
||
|
}
|
||
11 years ago
|
}
|
||
|
|