erigon-pulse/common/debug/hack/cs_test.go
b00ris cc137af1ce
[WIP] New storage changeset encoding (#493)
* new storage changeset encoding

* fix lint
2020-04-28 08:41:55 +01:00

56 lines
1.2 KiB
Go

package hack
import (
"bytes"
"fmt"
"github.com/ledgerwatch/turbo-geth/common"
"github.com/ledgerwatch/turbo-geth/common/changeset"
"github.com/ledgerwatch/turbo-geth/common/dbutils"
"github.com/ledgerwatch/turbo-geth/ethdb"
"testing"
)
func TestDecodeNewStorageDebug(t *testing.T) {
t.Skip("debug test")
pathToDB := ""
db, err := ethdb.NewBoltDatabase(pathToDB)
if err != nil {
t.Fatal(err)
}
data, err := db.Get(dbutils.StorageChangeSetBucket, dbutils.EncodeTimestamp(116526))
if err != nil {
t.Fatal(err)
}
cs, err := changeset.DecodeStorage(data)
if err != nil {
t.Fatal(err)
}
newData, err := changeset.EncodeStorage(cs)
if err != nil {
t.Fatal(err)
}
for _, v := range cs.Changes {
fmt.Println(common.Bytes2Hex(v.Key), " - ", common.Bytes2Hex(v.Value))
}
j := 0
fmt.Println()
err = changeset.StorageChangeSetBytes(newData).Walk(func(kk, vv []byte) error {
fmt.Println(common.Bytes2Hex(kk), " - ", common.Bytes2Hex(vv))
if !bytes.Equal(kk, cs.Changes[j].Key) {
t.Errorf("incorrect order. element: %v", j)
}
if !bytes.Equal(vv, cs.Changes[j].Value) {
t.Errorf("incorrect value. key:%v", common.Bytes2Hex(cs.Changes[j].Key))
}
j++
return nil
})
if err != nil {
t.Fatal(err)
}
}