aboutsummaryrefslogtreecommitdiffstats
path: root/common/hexutil/json_test.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2017-03-23 23:36:38 +0800
committerGitHub <noreply@github.com>2017-03-23 23:36:38 +0800
commit8771c3061f340451d0966adcc547338a25f2231f (patch)
treec566cab81cf95a39f85fbe2c98a932af9495eb68 /common/hexutil/json_test.go
parent11e7a712f469fb24ddb88ecebcefab6ed8880eb8 (diff)
parent37dd9086ec491900311fc39837f4a62ef5fd3a4a (diff)
downloaddexon-8771c3061f340451d0966adcc547338a25f2231f.tar
dexon-8771c3061f340451d0966adcc547338a25f2231f.tar.gz
dexon-8771c3061f340451d0966adcc547338a25f2231f.tar.bz2
dexon-8771c3061f340451d0966adcc547338a25f2231f.tar.lz
dexon-8771c3061f340451d0966adcc547338a25f2231f.tar.xz
dexon-8771c3061f340451d0966adcc547338a25f2231f.tar.zst
dexon-8771c3061f340451d0966adcc547338a25f2231f.zip
Merge pull request #3794 from fjl/core-genesis-refactor
core: refactor genesis handling
Diffstat (limited to 'common/hexutil/json_test.go')
-rw-r--r--common/hexutil/json_test.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/common/hexutil/json_test.go b/common/hexutil/json_test.go
index af7f44915..e4e827491 100644
--- a/common/hexutil/json_test.go
+++ b/common/hexutil/json_test.go
@@ -337,3 +337,38 @@ func TestUnmarshalUint(t *testing.T) {
}
}
}
+
+func TestUnmarshalFixedUnprefixedText(t *testing.T) {
+ tests := []struct {
+ input string
+ want []byte
+ wantErr error
+ }{
+ {input: "0x2", wantErr: ErrOddLength},
+ {input: "2", wantErr: ErrOddLength},
+ {input: "4444", wantErr: errors.New("hex string has length 4, want 8 for x")},
+ {input: "4444", wantErr: errors.New("hex string has length 4, want 8 for x")},
+ // check that output is not modified for partially correct input
+ {input: "444444gg", wantErr: ErrSyntax, want: []byte{0, 0, 0, 0}},
+ {input: "0x444444gg", wantErr: ErrSyntax, want: []byte{0, 0, 0, 0}},
+ // valid inputs
+ {input: "44444444", want: []byte{0x44, 0x44, 0x44, 0x44}},
+ {input: "0x44444444", want: []byte{0x44, 0x44, 0x44, 0x44}},
+ }
+
+ for _, test := range tests {
+ out := make([]byte, 4)
+ err := UnmarshalFixedUnprefixedText("x", []byte(test.input), out)
+ switch {
+ case err == nil && test.wantErr != nil:
+ t.Errorf("%q: got no error, expected %q", test.input, test.wantErr)
+ case err != nil && test.wantErr == nil:
+ t.Errorf("%q: unexpected error %q", test.input, err)
+ case err != nil && err.Error() != test.wantErr.Error():
+ t.Errorf("%q: error mismatch: got %q, want %q", test.input, err, test.wantErr)
+ }
+ if test.want != nil && !bytes.Equal(out, test.want) {
+ t.Errorf("%q: output mismatch: got %x, want %x", test.input, out, test.want)
+ }
+ }
+}