Commit e07b48c9 authored by clabby's avatar clabby

lint

parent 01ec03a8
...@@ -50,12 +50,10 @@ func FuzzTrie() { ...@@ -50,12 +50,10 @@ func FuzzTrie() {
switch variant { switch variant {
case valid: case valid:
testCase = genTrieTestCase(false) testCase = genTrieTestCase(false)
break
case extraProofElems: case extraProofElems:
testCase = genTrieTestCase(false) testCase = genTrieTestCase(false)
// Duplicate the last element of the proof // Duplicate the last element of the proof
testCase.Proof = append(testCase.Proof, [][]byte{testCase.Proof[len(testCase.Proof)-1]}...) testCase.Proof = append(testCase.Proof, [][]byte{testCase.Proof[len(testCase.Proof)-1]}...)
break
case corruptedProof: case corruptedProof:
testCase = genTrieTestCase(false) testCase = genTrieTestCase(false)
...@@ -63,17 +61,17 @@ func FuzzTrie() { ...@@ -63,17 +61,17 @@ func FuzzTrie() {
idx := randRange(0, int64(len(testCase.Proof))) idx := randRange(0, int64(len(testCase.Proof)))
encoded, _ := rlp.EncodeToBytes(testCase.Proof[idx]) encoded, _ := rlp.EncodeToBytes(testCase.Proof[idx])
testCase.Proof[idx] = encoded testCase.Proof[idx] = encoded
break
case invalidDataRemainder: case invalidDataRemainder:
testCase = genTrieTestCase(false) testCase = genTrieTestCase(false)
// Alter true length of random proof element by appending random bytes // Alter true length of random proof element by appending random bytes
// Do not update the encoded length // Do not update the encoded length
idx := randRange(0, int64(len(testCase.Proof))) idx := randRange(0, int64(len(testCase.Proof)))
bytes := make([]byte, randRange(1, 512)) b := make([]byte, randRange(1, 512))
rand.Read(bytes) if _, err := rand.Read(b); err != nil {
testCase.Proof[idx] = append(testCase.Proof[idx], bytes...) log.Fatal("Error generating random bytes")
break }
testCase.Proof[idx] = append(testCase.Proof[idx], b...)
case invalidLargeInternalHash: case invalidLargeInternalHash:
testCase = genTrieTestCase(false) testCase = genTrieTestCase(false)
...@@ -82,7 +80,9 @@ func FuzzTrie() { ...@@ -82,7 +80,9 @@ func FuzzTrie() {
// bytes to overwrite. // bytes to overwrite.
idx := randRange(1, int64(len(testCase.Proof))) idx := randRange(1, int64(len(testCase.Proof)))
b := make([]byte, 4) b := make([]byte, 4)
rand.Read(b) if _, err := rand.Read(b); err != nil {
log.Fatal("Error generating random bytes")
}
testCase.Proof[idx] = append( testCase.Proof[idx] = append(
testCase.Proof[idx][:20], testCase.Proof[idx][:20],
append( append(
...@@ -90,27 +90,26 @@ func FuzzTrie() { ...@@ -90,27 +90,26 @@ func FuzzTrie() {
testCase.Proof[idx][24:]..., testCase.Proof[idx][24:]...,
)..., )...,
) )
break
case invalidInternalNodeHash: case invalidInternalNodeHash:
testCase = genTrieTestCase(false) testCase = genTrieTestCase(false)
// Assign the last proof element to an encoded list containing a // Assign the last proof element to an encoded list containing a
// random 29 byte value // random 29 byte value
b := make([]byte, 29) b := make([]byte, 29)
rand.Read(b) if _, err := rand.Read(b); err != nil {
log.Fatal("Error generating random bytes")
}
e, _ := rlp.EncodeToBytes(b) e, _ := rlp.EncodeToBytes(b)
testCase.Proof[len(testCase.Proof)-1] = append([]byte{0xc0 + 30}, e...) testCase.Proof[len(testCase.Proof)-1] = append([]byte{0xc0 + 30}, e...)
break
case prefixedValidKey: case prefixedValidKey:
testCase = genTrieTestCase(false) testCase = genTrieTestCase(false)
bytes := make([]byte, randRange(1, 16)) b := make([]byte, randRange(1, 16))
rand.Read(bytes) if _, err := rand.Read(b); err != nil {
testCase.Key = append(bytes, testCase.Key...) log.Fatal("Error generating random bytes")
break }
testCase.Key = append(b, testCase.Key...)
case emptyKey: case emptyKey:
testCase = genTrieTestCase(true) testCase = genTrieTestCase(true)
break
case partialProof: case partialProof:
testCase = genTrieTestCase(false) testCase = genTrieTestCase(false)
...@@ -122,7 +121,6 @@ func FuzzTrie() { ...@@ -122,7 +121,6 @@ func FuzzTrie() {
} }
testCase.Proof = newProof testCase.Proof = newProof
break
default: default:
log.Fatal("Invalid variant passed to trie fuzzer!") log.Fatal("Invalid variant passed to trie fuzzer!")
} }
...@@ -154,8 +152,12 @@ func genTrieTestCase(selectEmptyKey bool) trieTestCase { ...@@ -154,8 +152,12 @@ func genTrieTestCase(selectEmptyKey bool) trieTestCase {
// Add `randN` elements to the trie // Add `randN` elements to the trie
for i := int64(0); i < randN; i++ { for i := int64(0); i < randN; i++ {
// Randomize the contents of `randKey` and `randValue` // Randomize the contents of `randKey` and `randValue`
rand.Read(randKey) if _, err := rand.Read(randKey); err != nil {
rand.Read(randValue) log.Fatal("Error generating random bytes")
}
if _, err := rand.Read(randValue); err != nil {
log.Fatal("Error generating random bytes")
}
// Clear the selected key if `selectEmptyKey` is true // Clear the selected key if `selectEmptyKey` is true
if i == randSelect && selectEmptyKey { if i == randSelect && selectEmptyKey {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment