Skip to content

Commit

Permalink
Reorder params for starknet_getStorageAt RPC method
Browse files Browse the repository at this point in the history
  • Loading branch information
jelilat committed May 8, 2023
1 parent 4e5379a commit 46d00e7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func makeHTTP(port uint16, rpcHandler *rpc.Handler, log utils.SimpleLogger) *jso
},
{
Name: "starknet_getStorageAt",
Params: []jsonrpc.Parameter{{Name: "block_id"}, {Name: "contract_address"}, {Name: "key"}},
Params: []jsonrpc.Parameter{{Name: "contract_address"}, {Name: "key"}, {Name: "block_id"}},
Handler: rpcHandler.StorageAt,
},
{
Expand Down
2 changes: 1 addition & 1 deletion rpc/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ func (h *Handler) Nonce(id *BlockID, address *felt.Felt) (*felt.Felt, *jsonrpc.E
//
// It follows the specification defined here:
// https://github.com/starkware-libs/starknet-specs/blob/a789ccc3432c57777beceaa53a34a7ae2f25fda0/api/starknet_api_openrpc.json#L110
func (h *Handler) StorageAt(id *BlockID, address, key *felt.Felt) (*felt.Felt, *jsonrpc.Error) {
func (h *Handler) StorageAt(address, key *felt.Felt, id *BlockID) (*felt.Felt, *jsonrpc.Error) {
stateReader, stateCloser, err := h.stateByBlockID(id)
if err != nil {
return nil, ErrBlockNotFound
Expand Down
16 changes: 8 additions & 8 deletions rpc/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1041,23 +1041,23 @@ func TestStorageAt(t *testing.T) {
t.Run("empty blockchain", func(t *testing.T) {
mockReader.EXPECT().HeadState().Return(nil, nil, errors.New("empty blockchain"))

storage, rpcErr := handler.StorageAt(&rpc.BlockID{Latest: true}, &felt.Zero, &felt.Zero)
storage, rpcErr := handler.StorageAt(&felt.Zero, &felt.Zero, &rpc.BlockID{Latest: true})
require.Nil(t, storage)
assert.Equal(t, rpc.ErrBlockNotFound, rpcErr)
})

t.Run("non-existent block hash", func(t *testing.T) {
mockReader.EXPECT().StateAtBlockHash(&felt.Zero).Return(nil, nil, errors.New("non-existent block hash"))

storage, rpcErr := handler.StorageAt(&rpc.BlockID{Hash: &felt.Zero}, &felt.Zero, &felt.Zero)
storage, rpcErr := handler.StorageAt(&felt.Zero, &felt.Zero, &rpc.BlockID{Hash: &felt.Zero})
require.Nil(t, storage)
assert.Equal(t, rpc.ErrBlockNotFound, rpcErr)
})

t.Run("non-existent block number", func(t *testing.T) {
mockReader.EXPECT().StateAtBlockNumber(uint64(0)).Return(nil, nil, errors.New("non-existent block number"))

storage, rpcErr := handler.StorageAt(&rpc.BlockID{Number: 0}, &felt.Zero, &felt.Zero)
storage, rpcErr := handler.StorageAt(&felt.Zero, &felt.Zero, &rpc.BlockID{Number: 0})
require.Nil(t, storage)
assert.Equal(t, rpc.ErrBlockNotFound, rpcErr)
})
Expand All @@ -1069,7 +1069,7 @@ func TestStorageAt(t *testing.T) {
mockReader.EXPECT().HeadState().Return(mockState, NoopCloser, nil)
mockState.EXPECT().ContractStorage(gomock.Any(), gomock.Any()).Return(nil, errors.New("non-existent contract"))

storage, rpcErr := handler.StorageAt(&rpc.BlockID{Latest: true}, &felt.Zero, &felt.Zero)
storage, rpcErr := handler.StorageAt(&felt.Zero, &felt.Zero, &rpc.BlockID{Latest: true})
require.Nil(t, storage)
assert.Equal(t, rpc.ErrContractNotFound, rpcErr)
})
Expand All @@ -1078,7 +1078,7 @@ func TestStorageAt(t *testing.T) {
mockReader.EXPECT().HeadState().Return(mockState, NoopCloser, nil)
mockState.EXPECT().ContractStorage(gomock.Any(), gomock.Any()).Return(&felt.Zero, errors.New("non-existent key"))

storage, rpcErr := handler.StorageAt(&rpc.BlockID{Latest: true}, &felt.Zero, &felt.Zero)
storage, rpcErr := handler.StorageAt(&felt.Zero, &felt.Zero, &rpc.BlockID{Latest: true})
require.Nil(t, storage)
assert.Equal(t, rpc.ErrContractNotFound, rpcErr)
})
Expand All @@ -1089,7 +1089,7 @@ func TestStorageAt(t *testing.T) {
mockReader.EXPECT().HeadState().Return(mockState, NoopCloser, nil)
mockState.EXPECT().ContractStorage(gomock.Any(), gomock.Any()).Return(expectedStorage, nil)

storage, rpcErr := handler.StorageAt(&rpc.BlockID{Latest: true}, &felt.Zero, &felt.Zero)
storage, rpcErr := handler.StorageAt(&felt.Zero, &felt.Zero, &rpc.BlockID{Latest: true})
require.Nil(t, rpcErr)
assert.Equal(t, expectedStorage, storage)
})
Expand All @@ -1098,7 +1098,7 @@ func TestStorageAt(t *testing.T) {
mockReader.EXPECT().StateAtBlockHash(&felt.Zero).Return(mockState, NoopCloser, nil)
mockState.EXPECT().ContractStorage(gomock.Any(), gomock.Any()).Return(expectedStorage, nil)

storage, rpcErr := handler.StorageAt(&rpc.BlockID{Hash: &felt.Zero}, &felt.Zero, &felt.Zero)
storage, rpcErr := handler.StorageAt(&felt.Zero, &felt.Zero, &rpc.BlockID{Hash: &felt.Zero})
require.Nil(t, rpcErr)
assert.Equal(t, expectedStorage, storage)
})
Expand All @@ -1107,7 +1107,7 @@ func TestStorageAt(t *testing.T) {
mockReader.EXPECT().StateAtBlockNumber(uint64(0)).Return(mockState, NoopCloser, nil)
mockState.EXPECT().ContractStorage(gomock.Any(), gomock.Any()).Return(expectedStorage, nil)

storage, rpcErr := handler.StorageAt(&rpc.BlockID{Number: 0}, &felt.Zero, &felt.Zero)
storage, rpcErr := handler.StorageAt(&felt.Zero, &felt.Zero, &rpc.BlockID{Number: 0})
require.Nil(t, rpcErr)
assert.Equal(t, expectedStorage, storage)
})
Expand Down

0 comments on commit 46d00e7

Please sign in to comment.