erigon-pulse/trie/intermediate_hashes_test.go
Alex Sharov fdbba5202b
Trie: store self-destructed accounts (#355)
* squash commits

* enable storage cache

* make linter happy

* fix subtree prefix len check

* save cahnges to test master

* remove restriction on prefix len

* fix comparison of last bits

* fix wrong alignment

* remove debug prints

* commit current state

* commit current state

* avoid changing state of resolver from multiwalk

* remove debug code

* remove debug code

* remove debug code

* remove unnecessary copy

* make code more readable

* reduce rebuildHashes initial resolution

* fix test after rebase to master

* make code more readable

* improve pruner

* pruner add IntermediateCache bucket

* fix panic in Walk on short keys

* reduce allocations for storage keys decompression by increasing default buffer size

* re-run CI

* fix iterator behaviour

* rename cache to hash for unification

* re-run ci

* avoid using underlying DB

* hash all subtree nodes before unload

* fix getNode method

* need to check node type, not parent - before put to hashBucket

* return back parent type check, doesn't work without it.

* don't recalculate hash again

* move unloadFunc from trie to pruner

* rename bucket to shorter name

* rename bucket to shorter name

* clean

* rebase to master
2020-02-12 13:52:59 +00:00

44 lines
1.1 KiB
Go

package trie
import (
"fmt"
"strconv"
"testing"
"github.com/ledgerwatch/turbo-geth/common"
"github.com/ledgerwatch/turbo-geth/common/pool"
"github.com/stretchr/testify/assert"
)
func TestCompressNibbles(t *testing.T) {
cases := []struct {
in string
expect string
}{
{in: "0000", expect: "00"},
{in: "0102", expect: "12"},
{in: "0102030405060708090f", expect: "123456789f"},
{in: "0f000101", expect: "f011"},
{in: "", expect: ""},
}
compressBuf := pool.GetBuffer(64)
defer pool.PutBuffer(compressBuf)
decompressBuf := pool.GetBuffer(64)
defer pool.PutBuffer(decompressBuf)
for _, tc := range cases {
compressBuf.Reset()
decompressBuf.Reset()
in := common.Hex2Bytes(tc.in)
CompressNibbles(in, &compressBuf.B)
compressed := compressBuf.Bytes()
msg := "On: " + tc.in + " Len: " + strconv.Itoa(len(compressed))
assert.Equal(t, tc.expect, fmt.Sprintf("%x", compressed), msg)
DecompressNibbles(compressed, &decompressBuf.B)
decompressed := decompressBuf.Bytes()
assert.Equal(t, tc.in, fmt.Sprintf("%x", decompressed), msg)
}
}