Skip to content

Commit

Permalink
Fix statedb unit tests (#14)
Browse files Browse the repository at this point in the history
* debug code

* Fix more unit tests

* remove traces

* Go back to the full range
  • Loading branch information
gballet committed Aug 5, 2021
1 parent 4d27208 commit 93cf056
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
12 changes: 9 additions & 3 deletions core/state/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,16 @@ func (db *VerkleDB) OpenStorageTrie(accTrie Trie, addrHash, root common.Hash) (T
// CopyTrie returns an independent copy of the given trie.
func (db *VerkleDB) CopyTrie(tr Trie) Trie {
t, ok := tr.(*trie.VerkleTrie)
if !ok {
panic("invalid tree type != VerkleTrie")
if ok {
return t.Copy(db.db)
}
return t.Copy(db.db)

s, ok := tr.(*trie.VerkleStorageAdapter)
if ok {
return s.Copy(db.db)
}

panic("invalid tree type != VerkleTrie")
}

// ContractCode retrieves a particular contract's code.
Expand Down
7 changes: 5 additions & 2 deletions trie/verkle.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,16 @@ func (adapter *VerkleStorageAdapter) TryUpdate(key, value []byte) error {
// TryDelete removes any existing value for key from the trie. If a node was not
// found in the database, a trie.MissingNodeError is returned.
func (adapter *VerkleStorageAdapter) TryDelete(key []byte) error {
return adapter.trie.root.Delete(key)
return adapter.trie.root.Delete(adapter.key2Storage(key))
}

// Hash returns the root hash of the trie. It does not write to the database and
// can be used even if the trie doesn't have one.
func (adapter *VerkleStorageAdapter) Hash() common.Hash {
return adapter.trie.Hash()
// Return an empty hash for the moment.
// XXX this could be the wrong value, but at this stage I don't
// want to send the signal that this account has no storage.
return common.Hash{}
}

// Commit writes all nodes to the trie's memory database, tracking the internal
Expand Down

0 comments on commit 93cf056

Please sign in to comment.