Skip to content

Commit

Permalink
use class hash
Browse files Browse the repository at this point in the history
  • Loading branch information
weiihann committed Nov 5, 2024
1 parent ce85570 commit 9e72cf1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion rpc/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (h *Handler) StorageAt(address, key felt.Felt, id BlockID) (*felt.Felt, *js

// This checks if the contract exists because if a key doesn't exist in contract storage,
// the returned value is always zero and error is nil.
_, err := stateReader.ContractNonce(&address)
_, err := stateReader.ContractClassHash(&address)
if err != nil {
if errors.Is(err, db.ErrKeyNotFound) {
return nil, ErrContractNotFound
Expand Down
11 changes: 5 additions & 6 deletions rpc/contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ func TestStorageAt(t *testing.T) {

t.Run("non-existent contract", func(t *testing.T) {
mockReader.EXPECT().HeadState().Return(mockState, nopCloser, nil)
// we check if the contract exists by getting its nonce
mockState.EXPECT().ContractNonce(gomock.Any()).Return(nil, db.ErrKeyNotFound)
mockState.EXPECT().ContractClassHash(gomock.Any()).Return(nil, db.ErrKeyNotFound)

storage, rpcErr := handler.StorageAt(felt.Zero, felt.Zero, rpc.BlockID{Latest: true})
require.Nil(t, storage)
Expand All @@ -133,7 +132,7 @@ func TestStorageAt(t *testing.T) {

t.Run("non-existent key", func(t *testing.T) {
mockReader.EXPECT().HeadState().Return(mockState, nopCloser, nil)
mockState.EXPECT().ContractNonce(&felt.Zero).Return(nil, nil)
mockState.EXPECT().ContractClassHash(&felt.Zero).Return(nil, nil)
mockState.EXPECT().ContractStorage(gomock.Any(), gomock.Any()).Return(nil, db.ErrKeyNotFound)

storage, rpcErr := handler.StorageAt(felt.Zero, felt.Zero, rpc.BlockID{Latest: true})
Expand All @@ -145,7 +144,7 @@ func TestStorageAt(t *testing.T) {

t.Run("blockID - latest", func(t *testing.T) {
mockReader.EXPECT().HeadState().Return(mockState, nopCloser, nil)
mockState.EXPECT().ContractNonce(&felt.Zero).Return(nil, nil)
mockState.EXPECT().ContractClassHash(&felt.Zero).Return(nil, nil)
mockState.EXPECT().ContractStorage(gomock.Any(), gomock.Any()).Return(expectedStorage, nil)

storage, rpcErr := handler.StorageAt(felt.Zero, felt.Zero, rpc.BlockID{Latest: true})
Expand All @@ -155,7 +154,7 @@ func TestStorageAt(t *testing.T) {

t.Run("blockID - hash", func(t *testing.T) {
mockReader.EXPECT().StateAtBlockHash(&felt.Zero).Return(mockState, nopCloser, nil)
mockState.EXPECT().ContractNonce(&felt.Zero).Return(nil, nil)
mockState.EXPECT().ContractClassHash(&felt.Zero).Return(nil, nil)
mockState.EXPECT().ContractStorage(gomock.Any(), gomock.Any()).Return(expectedStorage, nil)

storage, rpcErr := handler.StorageAt(felt.Zero, felt.Zero, rpc.BlockID{Hash: &felt.Zero})
Expand All @@ -165,7 +164,7 @@ func TestStorageAt(t *testing.T) {

t.Run("blockID - number", func(t *testing.T) {
mockReader.EXPECT().StateAtBlockNumber(uint64(0)).Return(mockState, nopCloser, nil)
mockState.EXPECT().ContractNonce(&felt.Zero).Return(nil, nil)
mockState.EXPECT().ContractClassHash(&felt.Zero).Return(nil, nil)
mockState.EXPECT().ContractStorage(gomock.Any(), gomock.Any()).Return(expectedStorage, nil)

storage, rpcErr := handler.StorageAt(felt.Zero, felt.Zero, rpc.BlockID{Number: 0})
Expand Down

0 comments on commit 9e72cf1

Please sign in to comment.