mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 17:33:47 +00:00
triedb/pathdb: add rawStorageKey check to encode/decode unit tests
This commit is contained in:
parent
f458ddef40
commit
8757ad4499
2 changed files with 26 additions and 5 deletions
|
|
@ -49,9 +49,9 @@ func randomStateSet(n int) (map[common.Address][]byte, map[common.Address]map[co
|
|||
return accounts, storages
|
||||
}
|
||||
|
||||
func makeHistory() *history {
|
||||
func makeHistory(rawStorageKey bool) *history {
|
||||
accounts, storages := randomStateSet(3)
|
||||
return newHistory(testrand.Hash(), types.EmptyRootHash, 0, accounts, storages, false)
|
||||
return newHistory(testrand.Hash(), types.EmptyRootHash, 0, accounts, storages, rawStorageKey)
|
||||
}
|
||||
|
||||
func makeHistories(n int) []*history {
|
||||
|
|
@ -70,10 +70,15 @@ func makeHistories(n int) []*history {
|
|||
}
|
||||
|
||||
func TestEncodeDecodeHistory(t *testing.T) {
|
||||
testEncodeDecodeHistory(t, false)
|
||||
testEncodeDecodeHistory(t, true)
|
||||
}
|
||||
|
||||
func testEncodeDecodeHistory(t *testing.T, rawStorageKey bool) {
|
||||
var (
|
||||
m meta
|
||||
dec history
|
||||
obj = makeHistory()
|
||||
obj = makeHistory(rawStorageKey)
|
||||
)
|
||||
// check if meta data can be correctly encode/decode
|
||||
blob := obj.meta.encode()
|
||||
|
|
|
|||
|
|
@ -290,6 +290,11 @@ func TestStateRevertStorageNullMarker(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestStatesEncode(t *testing.T) {
|
||||
testStatesEncode(t, false)
|
||||
testStatesEncode(t, true)
|
||||
}
|
||||
|
||||
func testStatesEncode(t *testing.T, rawStorageKey bool) {
|
||||
s := newStates(
|
||||
map[common.Hash][]byte{
|
||||
{0x1}: {0x1},
|
||||
|
|
@ -299,7 +304,7 @@ func TestStatesEncode(t *testing.T) {
|
|||
common.Hash{0x1}: {0x1},
|
||||
},
|
||||
},
|
||||
false,
|
||||
rawStorageKey,
|
||||
)
|
||||
buf := bytes.NewBuffer(nil)
|
||||
if err := s.encode(buf); err != nil {
|
||||
|
|
@ -315,9 +320,17 @@ func TestStatesEncode(t *testing.T) {
|
|||
if !reflect.DeepEqual(s.storageData, dec.storageData) {
|
||||
t.Fatal("Unexpected storage data")
|
||||
}
|
||||
if s.rawStorageKey != dec.rawStorageKey {
|
||||
t.Fatal("Unexpected rawStorageKey flag")
|
||||
}
|
||||
}
|
||||
|
||||
func TestStateWithOriginEncode(t *testing.T) {
|
||||
testStateWithOriginEncode(t, false)
|
||||
testStateWithOriginEncode(t, true)
|
||||
}
|
||||
|
||||
func testStateWithOriginEncode(t *testing.T, rawStorageKey bool) {
|
||||
s := NewStateSetWithOrigin(
|
||||
map[common.Hash][]byte{
|
||||
{0x1}: {0x1},
|
||||
|
|
@ -335,7 +348,7 @@ func TestStateWithOriginEncode(t *testing.T) {
|
|||
common.Hash{0x1}: {0x1},
|
||||
},
|
||||
},
|
||||
false,
|
||||
rawStorageKey,
|
||||
)
|
||||
buf := bytes.NewBuffer(nil)
|
||||
if err := s.encode(buf); err != nil {
|
||||
|
|
@ -357,6 +370,9 @@ func TestStateWithOriginEncode(t *testing.T) {
|
|||
if !reflect.DeepEqual(s.storageOrigin, dec.storageOrigin) {
|
||||
t.Fatal("Unexpected storage origin data")
|
||||
}
|
||||
if s.rawStorageKey != dec.rawStorageKey {
|
||||
t.Fatal("Unexpected rawStorageKey flag")
|
||||
}
|
||||
}
|
||||
|
||||
func TestStateSizeTracking(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue