-
Notifications
You must be signed in to change notification settings - Fork 782
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* remove earlier hardcoded test added in block_test and revert other helper changes in block_test
- Loading branch information
Showing
3 changed files
with
60 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package types | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func decodeEncodeJSON(input []byte, val interface{}) error { | ||
if err := json.Unmarshal(input, &val); err != nil { | ||
// not valid JSON, nothing to do | ||
return nil | ||
} | ||
output, err := json.Marshal(val) | ||
if err != nil { | ||
return err | ||
} | ||
if !bytes.Equal(input, output) { | ||
return fmt.Errorf("encode-decode is not equal, \ninput : %x\noutput: %x", input, output) | ||
} | ||
return nil | ||
} | ||
|
||
func FuzzJSON(f *testing.F) { | ||
f.Fuzz(fuzzJSON) | ||
} | ||
|
||
func fuzzJSON(t *testing.T, input []byte) { | ||
if len(input) == 0 { | ||
return | ||
} | ||
{ | ||
var h Header | ||
if err := decodeEncodeJSON(input, &h); err != nil { | ||
t.Fatal(err) | ||
} | ||
var b Block | ||
if err := decodeEncodeJSON(input, &b); err != nil { | ||
t.Fatal(err) | ||
} | ||
var tx Transaction | ||
if err := decodeEncodeJSON(input, &tx); err != nil { | ||
t.Fatal(err) | ||
} | ||
var txs Transactions | ||
if err := decodeEncodeJSON(input, &txs); err != nil { | ||
t.Fatal(err) | ||
} | ||
var rs Receipts | ||
if err := decodeEncodeJSON(input, &rs); err != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
} |