mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-07 03:22:18 +00:00
32375df7af
* made changeSet an helper type * added comment * removed dbutils.Add * remove common.CopyBytes from walk * fixes
47 lines
1.3 KiB
Go
47 lines
1.3 KiB
Go
package dbutils
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/common"
|
|
)
|
|
|
|
func createTestChangeSet() []byte {
|
|
// empty ChangeSet first
|
|
ch := NewChangeSet()
|
|
// add some entries
|
|
_ = ch.Add(common.FromHex("56fb07ee"), common.FromHex("f7f6db1eb17c6d582078e0ffdd0c"))
|
|
_ = ch.Add(common.FromHex("a5e4c9a1"), common.FromHex("b1e9b5c16355eede662031dd621d08faf4ea"))
|
|
_ = ch.Add(common.FromHex("22bb06f4"), common.FromHex("862cf52b74f1cea41ddd8ffa4b3e7c7790"))
|
|
encoded, _ := ch.Encode()
|
|
return encoded
|
|
}
|
|
|
|
func TestEncoding(t *testing.T) {
|
|
// empty ChangeSet first
|
|
ch := NewChangeSet()
|
|
_, err := ch.Encode()
|
|
assert.NoError(t, err)
|
|
assert.NoError(t, err)
|
|
|
|
// add some entries
|
|
err = ch.Add(common.FromHex("56fb07ee"), common.FromHex("f7f6db1eb17c6d582078e0ffdd0c"))
|
|
assert.NoError(t, err)
|
|
err = ch.Add(common.FromHex("a5e4c9a1"), common.FromHex("b1e9b5c16355eede662031dd621d08faf4ea"))
|
|
assert.NoError(t, err)
|
|
err = ch.Add(common.FromHex("22bb06f4"), common.FromHex("862cf52b74f1cea41ddd8ffa4b3e7c7790"))
|
|
assert.NoError(t, err)
|
|
}
|
|
|
|
func TestFindLast(t *testing.T) {
|
|
encoded := createTestChangeSet()
|
|
val, err := FindLast(encoded, common.FromHex("56fb07ee"))
|
|
assert.NoError(t, err)
|
|
if !bytes.Equal(val, common.FromHex("f7f6db1eb17c6d582078e0ffdd0c")) {
|
|
t.Error("Invalid value")
|
|
}
|
|
}
|