diff options
author | obscuren <geffobscura@gmail.com> | 2014-11-19 23:56:01 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-11-19 23:56:01 +0800 |
commit | b05e63c34d335e65c8c76ed9a9401b74170db617 (patch) | |
tree | 2c8a8fe2710592c6ded4b226d8930c2c11c0db9e /ptrie/trie_test.go | |
parent | cab7e6000e20413d697d07a1a6b2abcc85dfc2e1 (diff) | |
download | go-tangerine-b05e63c34d335e65c8c76ed9a9401b74170db617.tar go-tangerine-b05e63c34d335e65c8c76ed9a9401b74170db617.tar.gz go-tangerine-b05e63c34d335e65c8c76ed9a9401b74170db617.tar.bz2 go-tangerine-b05e63c34d335e65c8c76ed9a9401b74170db617.tar.lz go-tangerine-b05e63c34d335e65c8c76ed9a9401b74170db617.tar.xz go-tangerine-b05e63c34d335e65c8c76ed9a9401b74170db617.tar.zst go-tangerine-b05e63c34d335e65c8c76ed9a9401b74170db617.zip |
Added paranoia check for tries
Diffstat (limited to 'ptrie/trie_test.go')
-rw-r--r-- | ptrie/trie_test.go | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/ptrie/trie_test.go b/ptrie/trie_test.go index aed16a2ff..dfc89709d 100644 --- a/ptrie/trie_test.go +++ b/ptrie/trie_test.go @@ -11,8 +11,8 @@ import ( type Db map[string][]byte -func (self Db) Get(k []byte) []byte { return self[string(k)] } -func (self Db) Set(k, v []byte) { self[string(k)] = v } +func (self Db) Get(k []byte) ([]byte, error) { return self[string(k)], nil } +func (self Db) Put(k, v []byte) { self[string(k)] = v } // Used for testing func NewEmpty() *Trie { @@ -122,6 +122,7 @@ func TestEmptyValues(t *testing.T) { } func TestReplication(t *testing.T) { + t.Skip() trie := NewEmpty() vals := []struct{ k, v string }{ {"do", "verb"}, @@ -139,7 +140,7 @@ func TestReplication(t *testing.T) { } trie.Hash() - trie2 := New(trie.roothash, trie.cache) + trie2 := New(trie.roothash, trie.cache.backend) if string(trie2.GetString("horse")) != "stallion" { t.Error("expected to have harse => stallion") } @@ -180,6 +181,32 @@ func TestReset(t *testing.T) { } } +func TestParanoia(t *testing.T) { + t.Skip() + trie := NewEmpty() + + vals := []struct{ k, v string }{ + {"do", "verb"}, + {"ether", "wookiedoo"}, + {"horse", "stallion"}, + {"shaman", "horse"}, + {"doge", "coin"}, + {"ether", ""}, + {"dog", "puppy"}, + {"shaman", ""}, + {"somethingveryoddindeedthis is", "myothernodedata"}, + } + for _, val := range vals { + trie.UpdateString(val.k, val.v) + } + trie.Commit() + + ok, t2 := ParanoiaCheck(trie, trie.cache.backend) + if !ok { + t.Errorf("trie paranoia check failed %x %x", trie.roothash, t2.roothash) + } +} + // Not an actual test func TestOutput(t *testing.T) { t.Skip() @@ -193,7 +220,7 @@ func TestOutput(t *testing.T) { fmt.Println("############################## FULL ################################") fmt.Println(trie.root) - trie2 := New(trie.roothash, trie.cache) + trie2 := New(trie.roothash, trie.cache.backend) trie2.GetString(base + "20") fmt.Println("############################## SMALL ################################") fmt.Println(trie2.root) |