mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-25 21:17:16 +00:00
b3f1915d09
* change_set_dup * change_set_dup * change_set_dup * change_set_dup * change_set_dup * change_set_dup * change_set_dup * change_set_dup * change_set_dup * change_set_dup * change_set_dup * change_set_dup * change_set_dup * change_set_dup * change_set_dup * change_set_dup * change_set_dup * change_set_dup * change_set_dup * change_set_dup * change_set_dup * working version * working version * working version * working version * working version * working version * working version * working version * working version * working version * working version * working version * working version * working version * working version * working version * working version * working version * working version * working version * working version * working version * working version * working version * working version * working version * working version * working version * working version * working version * working version * working version * working version * working version * working version * working version * working version * working version * working version * working version * working version * working version * working version * working version * aa * aa * aa * aa * aa * aa * aa * aa * aa * aa * aa * aa * aa * aa * aa * squash * squash * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * history_early_stop * history_early_stop * vmConfig with ReadOnly false * auto_increment * auto_increment * rebase master Co-authored-by: Alexey Akhunov <akhounov@gmail.com>
79 lines
2.1 KiB
Go
79 lines
2.1 KiB
Go
package changeset
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/common"
|
|
"github.com/ledgerwatch/turbo-geth/common/dbutils"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestEncodingAccountHashed(t *testing.T) {
|
|
bkt := dbutils.AccountChangeSetBucket
|
|
m := Mapper[bkt]
|
|
runTestAccountEncoding(t, true /*isHashed*/, m.New, m.Encode, m.Decode)
|
|
}
|
|
|
|
func TestEncodingAccountPlain(t *testing.T) {
|
|
bkt := dbutils.PlainAccountChangeSetBucket
|
|
m := Mapper[bkt]
|
|
runTestAccountEncoding(t, false /*isHashed*/, m.New, m.Encode, m.Decode)
|
|
}
|
|
|
|
func runTestAccountEncoding(t *testing.T, isHashed bool, New func() *ChangeSet, enc Encoder, dec Decoder) {
|
|
ch := New()
|
|
// empty StorageChangeSset first
|
|
err := enc(1, ch, func(k, v []byte) error {
|
|
return fmt.Errorf("must never call")
|
|
})
|
|
assert.NoError(t, err)
|
|
|
|
vals := [][]byte{
|
|
common.FromHex("f7f6db1eb17c6d582078e0ffdd0c"),
|
|
common.FromHex("b1e9b5c16355eede662031dd621d08faf4ea"),
|
|
common.FromHex("862cf52b74f1cea41ddd8ffa4b3e7c7790"),
|
|
}
|
|
numOfElements := 3
|
|
for i := 0; i < numOfElements; i++ {
|
|
address := common.HexToAddress(fmt.Sprintf("0xBe828AD8B538D1D691891F6c725dEdc5989abBc%d", i))
|
|
if isHashed {
|
|
addrHash, _ := common.HashData(address[:])
|
|
err = ch.Add(addrHash.Bytes(), vals[i])
|
|
} else {
|
|
err = ch.Add(address[:], vals[i])
|
|
}
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
ch2 := New()
|
|
err = enc(1, ch, func(k, v []byte) error {
|
|
_, k, v = dec(k, v)
|
|
return ch2.Add(k, v)
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if !reflect.DeepEqual(ch, ch2) {
|
|
fmt.Println("ch", len(ch.Changes), "ch2", len(ch2.Changes))
|
|
for i, v := range ch.Changes {
|
|
fmt.Println("Line ", i)
|
|
|
|
if !bytes.Equal(v.Key, ch2.Changes[i].Key) || !bytes.Equal(v.Value, ch2.Changes[i].Value) {
|
|
fmt.Println("Diff ", i)
|
|
fmt.Println("k1", common.Bytes2Hex(v.Key), len(v.Key))
|
|
fmt.Println("k2", common.Bytes2Hex(ch2.Changes[i].Key))
|
|
fmt.Println("v1", common.Bytes2Hex(v.Value))
|
|
fmt.Println("v2", common.Bytes2Hex(ch2.Changes[i].Value))
|
|
}
|
|
}
|
|
fmt.Printf("%+v %+v\n", ch, ch2)
|
|
t.Fatal("not equal")
|
|
}
|
|
}
|