Skip to content

Commit b292454

Browse files
committed
linter & formatting
1 parent fcf4395 commit b292454

File tree

5 files changed

+35
-61
lines changed

5 files changed

+35
-61
lines changed

blockchain/pending.go

+14-10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package blockchain
22

33
import (
44
"errors"
5+
56
"github.com/NethermindEth/juno/core"
67
"github.com/NethermindEth/juno/core/felt"
78
"github.com/NethermindEth/juno/core/trie"
@@ -69,20 +70,23 @@ func (p *PendingState) Class(classHash *felt.Felt) (*core.DeclaredClass, error)
6970
}
7071

7172
// Note[pnowosie]: Maybe extending StateReader with the following methods was not a good idea?
72-
func (s *PendingState) ClassTrie() (*trie.Trie, func() error, error) {
73-
return nil, nopCloser, featureNotImplemented
73+
func (p *PendingState) ClassTrie() (*trie.Trie, func() error, error) {
74+
return nil, nopCloser, errFeatureNotImplemented
7475
}
75-
func (s *PendingState) StorageTrie() (*trie.Trie, func() error, error) {
76-
return nil, nopCloser, featureNotImplemented
76+
77+
func (p *PendingState) StorageTrie() (*trie.Trie, func() error, error) {
78+
return nil, nopCloser, errFeatureNotImplemented
7779
}
78-
func (s *PendingState) StorageTrieForAddr(*felt.Felt) (*trie.Trie, error) {
79-
return nil, featureNotImplemented
80+
81+
func (p *PendingState) StorageTrieForAddr(*felt.Felt) (*trie.Trie, error) {
82+
return nil, errFeatureNotImplemented
8083
}
81-
func (s *PendingState) StateAndClassRoot() (*felt.Felt, *felt.Felt, error) {
82-
return nil, nil, featureNotImplemented
84+
85+
func (p *PendingState) StateAndClassRoot() (*felt.Felt, *felt.Felt, error) {
86+
return nil, nil, errFeatureNotImplemented
8387
}
8488

8589
var (
86-
featureNotImplemented = errors.New("feature not implemented for a historical state")
87-
nopCloser = func() error { return nil }
90+
errFeatureNotImplemented = errors.New("feature not implemented for a historical state")
91+
nopCloser = func() error { return nil }
8892
)

core/state_snapshot.go

+10-7
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ package core
22

33
import (
44
"errors"
5-
"github.com/NethermindEth/juno/core/trie"
65

76
"github.com/NethermindEth/juno/core/felt"
7+
"github.com/NethermindEth/juno/core/trie"
88
"github.com/NethermindEth/juno/db"
99
)
1010

@@ -91,19 +91,22 @@ func (s *stateSnapshot) Class(classHash *felt.Felt) (*DeclaredClass, error) {
9191

9292
// Note[pnowosie]: Maybe extending StateReader with the following methods was not a good idea?
9393
func (s *stateSnapshot) ClassTrie() (*trie.Trie, func() error, error) {
94-
return nil, nopCloser, featureNotImplemented
94+
return nil, nopCloser, errFeatureNotImplemented
9595
}
96+
9697
func (s *stateSnapshot) StorageTrie() (*trie.Trie, func() error, error) {
97-
return nil, nopCloser, featureNotImplemented
98+
return nil, nopCloser, errFeatureNotImplemented
9899
}
100+
99101
func (s *stateSnapshot) StorageTrieForAddr(*felt.Felt) (*trie.Trie, error) {
100-
return nil, featureNotImplemented
102+
return nil, errFeatureNotImplemented
101103
}
104+
102105
func (s *stateSnapshot) StateAndClassRoot() (*felt.Felt, *felt.Felt, error) {
103-
return nil, nil, featureNotImplemented
106+
return nil, nil, errFeatureNotImplemented
104107
}
105108

106109
var (
107-
featureNotImplemented = errors.New("feature not implemented for a historical state")
108-
nopCloser = func() error { return nil }
110+
errFeatureNotImplemented = errors.New("feature not implemented for a historical state")
111+
nopCloser = func() error { return nil }
109112
)

rpc/handlers.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ var (
6060
ErrSubscriptionNotFound = &jsonrpc.Error{Code: 100, Message: "Subscription not found"}
6161

6262
// TODO[pnowosie]: Update the error while specification describe it
63-
ErrBlockNotRecentForProof = &jsonrpc.Error{Code: 1001, Message: "Block is not sufficiently recent for storage proofs. Use 'latest' as block id"}
63+
ErrBlockNotRecentForProof = &jsonrpc.Error{
64+
Code: 1001,
65+
Message: "Block is not sufficiently recent for storage proofs. Use 'latest' as block id",
66+
}
6467
)
6568

6669
const (

rpc/storage.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ func (h *Handler) StorageAt(address, key felt.Felt, id BlockID) (*felt.Felt, *js
3737
//
3838
// It follows the specification defined here:
3939
// https://github.com/starkware-libs/starknet-specs/blob/647caa00c0223e1daab1b2f3acc4e613ba2138aa/api/starknet_api_openrpc.json#L910
40-
func (h *Handler) StorageProof(id BlockID, classes, contracts []felt.Felt, storageKeys []StorageKeys) (*StorageProofResult, *jsonrpc.Error) {
40+
func (h *Handler) StorageProof(
41+
id BlockID,
42+
classes, contracts []felt.Felt,
43+
storageKeys []StorageKeys,
44+
) (*StorageProofResult, *jsonrpc.Error) {
4145
stateReader, stateCloser, err := h.bcReader.HeadState()
4246
if err != nil {
4347
return nil, ErrInternal.CloneWithData(err)

rpc/storage_test.go

+2-42
Original file line numberDiff line numberDiff line change
@@ -123,25 +123,6 @@ func TestStorageProof(t *testing.T) {
123123
require.NoError(t, err)
124124
require.NoError(t, tempTrie.Commit())
125125

126-
// TODO[pnowosie]: There is smth wrong with proof verification, see `Trie proofs sanity check` test
127-
//verifyIf := func(proof []*rpc.HashToNode, key *felt.Felt, value *felt.Felt) bool {
128-
// root, err := tempTrie.Root()
129-
// require.NoError(t, err)
130-
// fmt.Println("root", root)
131-
//
132-
// pnodes := []trie.ProofNode{}
133-
// for _, hn := range proof {
134-
// pnodes = append(pnodes, NodeToProofNode(hn))
135-
// }
136-
//
137-
// kbs := key.Bytes()
138-
// kkey := trie.NewKey(251, kbs[:])
139-
// result := trie.VerifyProof(root, &kkey, value, pnodes, tempTrie.HashFunc())
140-
// fmt.Println("result", result)
141-
//
142-
// return result
143-
//}
144-
145126
mockCtrl := gomock.NewController(t)
146127
t.Cleanup(mockCtrl.Finish)
147128

@@ -270,6 +251,7 @@ func TestStorageProof(t *testing.T) {
270251
arityTest(t, proof, 0, 0, 0, 1)
271252
require.Len(t, proof.ContractsStorageProofs[0], 0)
272253
})
254+
//nolint:dupl
273255
t.Run("contract storage trie key slot does not exist in a trie", func(t *testing.T) {
274256
contract := utils.HexToFelt(t, "0xabcd")
275257
mockState.EXPECT().StorageTrieForAddr(gomock.Any()).Return(tempTrie, nil).Times(1)
@@ -283,6 +265,7 @@ func TestStorageProof(t *testing.T) {
283265

284266
verifyIf(proof.ContractsStorageProofs[0], noSuchKey, nil)
285267
})
268+
//nolint:dupl
286269
t.Run("contract storage trie address/key exists in a trie", func(t *testing.T) {
287270
contract := utils.HexToFelt(t, "0xabcd")
288271
mockState.EXPECT().StorageTrieForAddr(gomock.Any()).Return(tempTrie, nil).Times(1)
@@ -332,26 +315,3 @@ func emptyTrie(t *testing.T) *trie.Trie {
332315
require.NoError(t, err)
333316
return tempTrie
334317
}
335-
336-
func NodeToProofNode(hn *rpc.HashToNode) trie.ProofNode {
337-
var proofNode trie.ProofNode
338-
339-
switch pnode := hn.Node.(type) {
340-
case *rpc.MerkleEdgeNode:
341-
pbs := pnode.Path.Bytes()
342-
path := trie.NewKey(uint8(pnode.Length), pbs[:])
343-
proofNode = &trie.Edge{
344-
Path: &path,
345-
Child: pnode.Child,
346-
}
347-
case *rpc.MerkleBinaryNode:
348-
proofNode = &trie.Binary{
349-
LeftHash: pnode.Left,
350-
RightHash: pnode.Right,
351-
}
352-
default:
353-
panic(fmt.Errorf("unsupported node type %T", pnode))
354-
}
355-
356-
return proofNode
357-
}

0 commit comments

Comments
 (0)