Skip to content

Commit

Permalink
Fixes getStorageAt undeployed contract response
Browse files Browse the repository at this point in the history
fix
  • Loading branch information
weiihann committed Nov 4, 2024
1 parent bf4aeda commit ab431d2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion core/contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func TestUpdateStorageAndStorage(t *testing.T) {
require.NoError(t, contract.UpdateStorage(map[felt.Felt]*felt.Felt{*addr: new(felt.Felt)}, NoopOnValueChanged))

val, err := core.ContractStorage(addr, addr, txn)
require.NoError(t, err)
require.Error(t, err)
require.Equal(t, &felt.Zero, val)

sRoot, err := core.ContractRoot(addr, txn)
Expand Down
4 changes: 2 additions & 2 deletions core/trie/trie.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ func (t *Trie) Get(key *felt.Felt) (*felt.Felt, error) {
storageKey := t.feltToKey(key)
value, err := t.storage.Get(&storageKey)
if err != nil {
if errors.Is(err, db.ErrKeyNotFound) {
return &felt.Zero, nil
if errors.Is(err, db.ErrKeyNotFound) { // a non-existent key returns a zero value
return &felt.Zero, db.ErrKeyNotFound
}
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions core/trie/trie_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestTriePut(t *testing.T) {
require.NoError(t, err)

value, err := tempTrie.Get(key)
assert.NoError(t, err)
assert.Error(t, err)
assert.Equal(t, &felt.Zero, value)
// Trie's root should be nil
assert.Nil(t, tempTrie.RootKey())
Expand Down Expand Up @@ -138,7 +138,7 @@ func TestTrieDeleteBasic(t *testing.T) {

val, err := tempTrie.Get(key)

assert.NoError(t, err, "shouldnt return an error when access a deleted key")
assert.Error(t, err, "should return an error when access a deleted key")
assert.Equal(t, &felt.Zero, val, "should return zero value when access a deleted key")
}

Expand Down

0 comments on commit ab431d2

Please sign in to comment.