1 // Copyright 2015 The go-ethereum Authors
2 // This file is part of the go-ethereum library.
4 // The go-ethereum library is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Lesser General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // The go-ethereum library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public License
15 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
24 func TestBytesConversion(t *testing.T) {
26 hash := BytesToHash(bytes)
32 t.Errorf("expected %x got %x", exp, hash)
36 func TestHashJsonValidation(t *testing.T) {
38 var tests = []struct {
43 {"", 2, hashJsonLengthErr},
44 {"", 62, hashJsonLengthErr},
45 {"", 66, hashJsonLengthErr},
46 {"", 65, hashJsonLengthErr},
49 {"0x", 62, hashJsonLengthErr},
51 for i, test := range tests {
52 if err := h.UnmarshalJSON(append([]byte(test.Prefix), make([]byte, test.Size)...)); err != test.Error {
53 t.Errorf("test #%d: error mismatch: have %v, want %v", i, err, test.Error)
59 func TestAddressUnmarshalJSON(t *testing.T) {
61 var tests = []struct {
69 {`"0x00"`, true, nil},
70 {`"0xG000000000000000000000000000000000000000"`, true, nil},
71 {`"0x0000000000000000000000000000000000000000"`, false, big.NewInt(0)},
72 {`"0x0000000000000000000000000000000000000010"`, false, big.NewInt(16)},
74 for i, test := range tests {
75 err := a.UnmarshalJSON([]byte(test.Input))
76 if err != nil && !test.ShouldErr {
77 t.Errorf("test #%d: unexpected error: %v", i, err)
81 t.Errorf("test #%d: expected error, got none", i)
83 if a.Big().Cmp(test.Output) != 0 {
84 t.Errorf("test #%d: address mismatch: have %v, want %v", i, a.Big(), test.Output)