From 31580d333e1551825b1d38a7beaabeffd27b6e3c Mon Sep 17 00:00:00 2001 From: Roy Crihfield Date: Mon, 15 Apr 2024 20:28:07 +0800 Subject: [PATCH] fix tests --- pkg/validator.go | 8 +++----- pkg/validator_test.go | 12 +++++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pkg/validator.go b/pkg/validator.go index 4fed351..2bb4673 100644 --- a/pkg/validator.go +++ b/pkg/validator.go @@ -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 diff --git a/pkg/validator_test.go b/pkg/validator_test.go index dfb8da9..a57c620 100644 --- a/pkg/validator_test.go +++ b/pkg/validator_test.go @@ -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()) })