fix tests

This commit is contained in:
Roy Crihfield 2024-04-15 20:28:07 +08:00
parent 9d9332fed1
commit 31580d333e
2 changed files with 10 additions and 10 deletions

View File

@ -162,11 +162,8 @@ func (v *Validator) ValidateStateTrie(stateRoot common.Hash) error {
func (v *Validator) ValidateStorageTrie(stateRoot common.Hash, address common.Address, storageRoot common.Hash) error { func (v *Validator) ValidateStorageTrie(stateRoot common.Hash, address common.Address, storageRoot common.Hash) error {
// Generate the state.NodeIterator for this root // Generate the state.NodeIterator for this root
addrHash := crypto.Keccak256Hash(address.Bytes()) addrHash := crypto.Keccak256Hash(address.Bytes())
st, err := v.stateDatabase.OpenTrie(stateRoot) // Note: the last argument is the redundant state trie, but will be needed for Verkle tries
if err != nil { storage, err := v.stateDatabase.OpenStorageTrie(stateRoot, addrHash, storageRoot, nil)
return err
}
storage, err := v.stateDatabase.OpenStorageTrie(stateRoot, addrHash, storageRoot, st)
if err != nil { if err != nil {
return err return err
} }
@ -200,6 +197,7 @@ func (v *Validator) iterate(stateRoot common.Hash, it trie.NodeIterator, storage
if err := rlp.Decode(bytes.NewReader(it.LeafBlob()), &account); err != nil { if err := rlp.Decode(bytes.NewReader(it.LeafBlob()), &account); err != nil {
return err return err
} }
// Note: the last argument is the redundant state trie, but will be needed for Verkle tries
dataTrie, err := v.stateDatabase.OpenStorageTrie(stateRoot, common.BytesToHash(it.LeafKey()), account.Root, nil) dataTrie, err := v.stateDatabase.OpenStorageTrie(stateRoot, common.BytesToHash(it.LeafKey()), account.Root, nil)
if err != nil { if err != nil {
return err return err

View File

@ -249,14 +249,14 @@ var _ = Describe("PG-IPFS Validator", func() {
err = v.ValidateTrie(stateRoot) err = v.ValidateTrie(stateRoot)
Expect(err).To(HaveOccurred()) Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("missing trie node")) Expect(err.Error()).To(ContainSubstring("missing trie node"))
Expect(err.Error()).To(ContainSubstring("%x", missingStateNodePath)) Expect(err.Error()).To(ContainSubstring("path %x", missingStateNodePath))
}) })
It("Returns an error if the storage trie is missing node(s)", func() { It("Returns an error if the storage trie is missing node(s)", func() {
loadTrie(trieStateNodes, missingNodeStorageNodes, mockCode) loadTrie(trieStateNodes, missingNodeStorageNodes, mockCode)
err = v.ValidateTrie(stateRoot) err = v.ValidateTrie(stateRoot)
Expect(err).To(HaveOccurred()) Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("missing trie node")) Expect(err.Error()).To(ContainSubstring("missing trie node"))
Expect(err.Error()).To(ContainSubstring("%x", missingStorageNodePath)) Expect(err.Error()).To(ContainSubstring("path %x", missingStorageNodePath))
}) })
It("Returns an error if contract code is missing", func() { It("Returns an error if contract code is missing", func() {
loadTrie(trieStateNodes, trieStorageNodes) loadTrie(trieStateNodes, trieStorageNodes)
@ -288,6 +288,7 @@ var _ = Describe("PG-IPFS Validator", func() {
err = v.ValidateStateTrie(stateRoot) err = v.ValidateStateTrie(stateRoot)
Expect(err).To(HaveOccurred()) Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("missing trie node")) Expect(err.Error()).To(ContainSubstring("missing trie node"))
Expect(err.Error()).To(ContainSubstring("path %x", missingStateNodePath))
}) })
It("Returns no error if the entire state trie can be validated", func() { It("Returns no error if the entire state trie can be validated", func() {
loadTrie(trieStateNodes, nil) loadTrie(trieStateNodes, nil)
@ -302,19 +303,20 @@ var _ = Describe("PG-IPFS Validator", func() {
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
}) })
It("Returns an error the storage root node is missing", func() { It("Returns an error the storage root node is missing", func() {
loadTrie(nil, missingRootStorageNodes) loadTrie(trieStateNodes, missingRootStorageNodes)
err = v.ValidateStorageTrie(stateRoot, contractAddr, storageRoot) err = v.ValidateStorageTrie(stateRoot, contractAddr, storageRoot)
Expect(err).To(HaveOccurred()) Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("missing trie node")) Expect(err.Error()).To(ContainSubstring("missing trie node"))
}) })
It("Returns an error if the entire storage trie cannot be validated", func() { It("Returns an error if the entire storage trie cannot be validated", func() {
loadTrie(nil, missingNodeStorageNodes) loadTrie(trieStateNodes, missingNodeStorageNodes)
err = v.ValidateStorageTrie(stateRoot, contractAddr, storageRoot) err = v.ValidateStorageTrie(stateRoot, contractAddr, storageRoot)
Expect(err).To(HaveOccurred()) Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("missing trie node")) Expect(err.Error()).To(ContainSubstring("missing trie node"))
Expect(err.Error()).To(ContainSubstring("path %x", missingStorageNodePath))
}) })
It("Returns no error if the entire storage trie can be validated", func() { It("Returns no error if the entire storage trie can be validated", func() {
loadTrie(nil, trieStorageNodes) loadTrie(trieStateNodes, trieStorageNodes)
err = v.ValidateStorageTrie(stateRoot, contractAddr, storageRoot) err = v.ValidateStorageTrie(stateRoot, contractAddr, storageRoot)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
}) })