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 {
// Generate the state.NodeIterator for this root
addrHash := crypto.Keccak256Hash(address.Bytes())
st, err := v.stateDatabase.OpenTrie(stateRoot)
if err != nil {
return err
}
storage, err := v.stateDatabase.OpenStorageTrie(stateRoot, addrHash, storageRoot, st)
// Note: the last argument is the redundant state trie, but will be needed for Verkle tries
storage, err := v.stateDatabase.OpenStorageTrie(stateRoot, addrHash, storageRoot, nil)
if err != nil {
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 {
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)
if err != nil {
return err

View File

@ -249,14 +249,14 @@ var _ = Describe("PG-IPFS Validator", func() {
err = v.ValidateTrie(stateRoot)
Expect(err).To(HaveOccurred())
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() {
loadTrie(trieStateNodes, missingNodeStorageNodes, mockCode)
err = v.ValidateTrie(stateRoot)
Expect(err).To(HaveOccurred())
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() {
loadTrie(trieStateNodes, trieStorageNodes)
@ -288,6 +288,7 @@ var _ = Describe("PG-IPFS Validator", func() {
err = v.ValidateStateTrie(stateRoot)
Expect(err).To(HaveOccurred())
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() {
loadTrie(trieStateNodes, nil)
@ -302,19 +303,20 @@ var _ = Describe("PG-IPFS Validator", func() {
Expect(err).ToNot(HaveOccurred())
})
It("Returns an error the storage root node is missing", func() {
loadTrie(nil, missingRootStorageNodes)
loadTrie(trieStateNodes, missingRootStorageNodes)
err = v.ValidateStorageTrie(stateRoot, contractAddr, storageRoot)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("missing trie node"))
})
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)
Expect(err).To(HaveOccurred())
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() {
loadTrie(nil, trieStorageNodes)
loadTrie(trieStateNodes, trieStorageNodes)
err = v.ValidateStorageTrie(stateRoot, contractAddr, storageRoot)
Expect(err).ToNot(HaveOccurred())
})