mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-22 11:41:19 +00:00
c68f00045a
* Revert "remove tombstones (#426)"
This reverts commit aa6bab40e8
.
* tombstones don't hide storage or account anymore
* auto-format code by prettier (similar to gofmt)
* wow, it works.....
* small simplification, but need make it more clear
* rebase to master
* rebase to master
* rebase to master
* re-run ci
* clean test files
43 lines
1.1 KiB
Go
43 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)
|
|
}
|
|
}
|