tests: validate snapshot after test

This commit is contained in:
Martin Holst Swende 2020-03-18 09:40:01 +01:00
parent fc378fa0c8
commit 976c209c8b
No known key found for this signature in database
GPG key ID: 683B438C05A5DDF0

View file

@ -22,6 +22,7 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"github.com/ethereum/go-ethereum/core/state/snapshot"
"math/big"
"github.com/ethereum/go-ethereum/common"
@ -144,6 +145,19 @@ func (t *BlockTest) Run(snapshotter bool) error {
if err = t.validatePostState(newDB); err != nil {
return fmt.Errorf("post state validation failed: %v", err)
}
// Cross-check the snapshot-to-hash against the trie hash
if snapshotter {
snapTree := chain.Snapshot()
root := chain.CurrentBlock().Root()
it, err := snapTree.AccountIterator(root, common.Hash{})
if err != nil {
return fmt.Errorf("Could not create iterator for root %x: %v", root, err)
}
generatedRoot := snapshot.GenerateTrieRoot(it)
if generatedRoot != root {
return fmt.Errorf("Snapshot corruption, got %d exp %d", generatedRoot, root)
}
}
return t.validateImportedHeaders(chain, validBlocks)
}