mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-27 22:28:21 +00:00
cc137af1ce
* new storage changeset encoding * fix lint
56 lines
1.2 KiB
Go
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)
|
|
}
|
|
}
|