diff --git a/statediff/indexer/ipfs/ipld/eth_account.go b/statediff/indexer/ipfs/ipld/eth_account.go index 08e95f81f..bd68968b8 100644 --- a/statediff/indexer/ipfs/ipld/eth_account.go +++ b/statediff/indexer/ipfs/ipld/eth_account.go @@ -111,7 +111,7 @@ func (as *EthAccountSnapshot) Resolve(p []string) (interface{}, []string, error) case "root": return &node.Link{Cid: keccak256ToCid(MEthStorageTrie, as.Root)}, nil, nil default: - return nil, nil, fmt.Errorf("no such link") + return nil, nil, ErrInvalidLink } } diff --git a/statediff/indexer/ipfs/ipld/eth_account_test.go b/statediff/indexer/ipfs/ipld/eth_account_test.go index 77efd8dbe..7a605eb3c 100644 --- a/statediff/indexer/ipfs/ipld/eth_account_test.go +++ b/statediff/indexer/ipfs/ipld/eth_account_test.go @@ -105,7 +105,7 @@ func TestAccountSnapshotResolve(t *testing.T) { if rest != nil { t.Fatal("rest should be nil") } - if err.Error() != fmt.Sprintf("no such link") { + if err != ErrInvalidLink { t.Fatal("wrong error") } } @@ -175,7 +175,7 @@ func TestAccountSnapshotResolveLink(t *testing.T) { if rest != nil { t.Fatal("Expected rest to be nil") } - if err.Error() != "no such link" { + if err != ErrInvalidLink { t.Fatal("Wrong error") } diff --git a/statediff/indexer/ipfs/ipld/eth_header.go b/statediff/indexer/ipfs/ipld/eth_header.go index c5db67efd..5905bdd7e 100644 --- a/statediff/indexer/ipfs/ipld/eth_header.go +++ b/statediff/indexer/ipfs/ipld/eth_header.go @@ -158,7 +158,7 @@ func (b *EthHeader) Resolve(p []string) (interface{}, []string, error) { case "time": return b.Time, nil, nil default: - return nil, nil, fmt.Errorf("no such link") + return nil, nil, ErrInvalidLink } } diff --git a/statediff/indexer/ipfs/ipld/eth_header_test.go b/statediff/indexer/ipfs/ipld/eth_header_test.go index 191c02254..c23b44c71 100644 --- a/statediff/indexer/ipfs/ipld/eth_header_test.go +++ b/statediff/indexer/ipfs/ipld/eth_header_test.go @@ -192,8 +192,8 @@ func TestEthBlockResolveNoSuchLink(t *testing.T) { t.Fatal("Should have failed with unknown field") } - if err.Error() != "no such link" { - t.Fatalf("Wrong error message\r\nexpected %s\r\ngot %s", "no such link", err.Error()) + if err != ErrInvalidLink { + t.Fatalf("Wrong error message\r\nexpected %s\r\ngot %s", ErrInvalidLink, err.Error()) } } @@ -393,8 +393,8 @@ func TestEthBlockResolveLinksBadLink(t *testing.T) { if rest != nil { t.Fatal("Expected rest to be nil") } - if err.Error() != "no such link" { - t.Fatalf("Expected error\r\nexpected %s\r\ngot %s", "no such link", err.Error()) + if err != ErrInvalidLink { + t.Fatalf("Expected error\r\nexpected %s\r\ngot %s", ErrInvalidLink, err) } } diff --git a/statediff/indexer/ipfs/ipld/eth_receipt.go b/statediff/indexer/ipfs/ipld/eth_receipt.go index ae1a43465..822f47345 100644 --- a/statediff/indexer/ipfs/ipld/eth_receipt.go +++ b/statediff/indexer/ipfs/ipld/eth_receipt.go @@ -130,7 +130,7 @@ func (r *EthReceipt) Resolve(p []string) (interface{}, []string, error) { case "gasUsed": return r.GasUsed, nil, nil default: - return nil, nil, fmt.Errorf("no such link") + return nil, nil, ErrInvalidLink } } diff --git a/statediff/indexer/ipfs/ipld/eth_tx.go b/statediff/indexer/ipfs/ipld/eth_tx.go index c4357988e..deb6158bb 100644 --- a/statediff/indexer/ipfs/ipld/eth_tx.go +++ b/statediff/indexer/ipfs/ipld/eth_tx.go @@ -144,7 +144,7 @@ func (t *EthTx) Resolve(p []string) (interface{}, []string, error) { case "value": return hexutil.EncodeBig(t.Value()), nil, nil default: - return nil, nil, fmt.Errorf("no such link") + return nil, nil, ErrInvalidLink } } diff --git a/statediff/indexer/ipfs/ipld/eth_tx_test.go b/statediff/indexer/ipfs/ipld/eth_tx_test.go index 15f01892d..d908c7acf 100644 --- a/statediff/indexer/ipfs/ipld/eth_tx_test.go +++ b/statediff/indexer/ipfs/ipld/eth_tx_test.go @@ -164,8 +164,8 @@ func TestEthTxResolve(t *testing.T) { if rest != nil { t.Fatal("rest should be nil") } - if err.Error() != "no such link" { - t.Fatalf("wrong error\r\nexpected %s\r\ngot %s", "no such link", err.Error()) + if err != ErrInvalidLink { + t.Fatalf("wrong error\r\nexpected %s\r\ngot %s", ErrInvalidLink, err.Error()) } } @@ -245,8 +245,8 @@ func TestEthTxResolveLink(t *testing.T) { if rest != nil { t.Fatal("Expected rest to be nil") } - if err.Error() != "no such link" { - t.Fatalf("Wrong error\r\nexpected %s\r\ngot %s", "no such link", err.Error()) + if err != ErrInvalidLink { + t.Fatalf("Wrong error\r\nexpected %s\r\ngot %s", ErrInvalidLink, err.Error()) } // good case diff --git a/statediff/indexer/ipfs/ipld/eth_tx_trie_test.go b/statediff/indexer/ipfs/ipld/eth_tx_trie_test.go index 97cfd2a4a..e05f4c705 100644 --- a/statediff/indexer/ipfs/ipld/eth_tx_trie_test.go +++ b/statediff/indexer/ipfs/ipld/eth_tx_trie_test.go @@ -216,7 +216,7 @@ func TestTxTrieResolveBranch(t *testing.T) { t.Fatalf("Returned object is not a link") } - for j, _ := range expectedRest { + for j := range expectedRest { if rest[j] != expectedRest[j] { t.Fatalf("Wrong rest of the path returned\r\nexpected %s\r\ngot %s", expectedRest[j], rest[j]) } diff --git a/statediff/indexer/ipfs/ipld/shared.go b/statediff/indexer/ipfs/ipld/shared.go index 37aaf2063..95fbc71c7 100644 --- a/statediff/indexer/ipfs/ipld/shared.go +++ b/statediff/indexer/ipfs/ipld/shared.go @@ -18,6 +18,7 @@ package ipld import ( "bytes" + "errors" "github.com/ipfs/go-cid" mh "github.com/multiformats/go-multihash" @@ -46,7 +47,8 @@ const ( ) var ( - nullHashBytes = common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000000") + nullHashBytes = common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000000") + ErrInvalidLink = errors.New("no such link") ) // RawdataToCid takes the desired codec and a slice of bytes diff --git a/tests/fuzzers/bls12381/bls12381_fuzz.go b/tests/fuzzers/bls12381/bls12381_fuzz.go index 298050ad3..c0f452f3e 100644 --- a/tests/fuzzers/bls12381/bls12381_fuzz.go +++ b/tests/fuzzers/bls12381/bls12381_fuzz.go @@ -159,7 +159,7 @@ func FuzzCrossG1MultiExp(data []byte) int { gethPoints = append(gethPoints, new(bls12381.PointG1).Set(kp1)) gnarkPoints = append(gnarkPoints, *cp1) } - if len(gethScalars) == 0{ + if len(gethScalars) == 0 { return 0 } // compute multi exponentiation