erigon-pulse/common/dbutils/changeset_test.go
b00ris bcee4845dc
Thin history (#272)
* save state

* remove repair

* save state

* remove emptydb check

* save state

* add walkAsOf test

* add WalkAsOf and MultiWalkAsOf tests

* deployed contracts counter

* reference counter for contract code

* drop storage root&contract hash for changesets

* start incarnation is 1(save state)

* fix ReorgOverSelfDestruct test

* hack fix TestReorgOverSelfDestruct

* test benchmark

* cleanup

* remove useless debug

* remove print trie

* return remove subtrie call  to updateTrieRoot

* save state

* add mutation test

* remove useless test

* fix

* added mutation commit test

* rename experiment to thin history

* thin history mutation commit test

* fix ethdb tests

* getAsOf test

* add test&fix history index

* fix test

* make test for index search

* compute trie root incarnation fix

* tests fixes

* done job in case of panic

* fix lint

* fix&test for bad incarnation

* fix initial incarnation for genesis

* fix lint

* fix changeset test

* fix storage ranges test

* fix lint

* move set incarnation to create contract

* add comment

Co-authored-by: ledgerwatch <akhounov@gmail.com>
Co-authored-by: Evgeny Danilenko <6655321@bk.ru>
2019-12-20 15:25:40 +03:00

35 lines
922 B
Go

package dbutils
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/ledgerwatch/turbo-geth/common"
)
func TestEncoding(t *testing.T) {
// empty ChangeSet first
ch := NewChangeSet()
encoded, err := ch.Encode()
assert.NoError(t, err)
decoded, err := DecodeChangeSet(encoded)
assert.NoError(t, err)
assert.Equal(t, 0, decoded.Len())
// 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)
// test Decode(Encode(ch)) == ch
encoded, err = ch.Encode()
assert.NoError(t, err)
decoded, err = DecodeChangeSet(encoded)
assert.NoError(t, err)
assert.Equal(t, ch, decoded)
}